Category: wordpress hacked

What To Do If Your WordPress Website Gets Hacked

What To Do If Your WordPress Website Gets Hacked

What To Do If Your WordPress Website Gets Hacked 1

 

With WordPress being so popular and the vast amount of themes and plugins, it is a favorite target for hackers. In 99% of cases, your WordPress website is not actually targeted, most of the hacks are automated and carried out by bots.

 

Why do hackers hack WordPress websites?

Usually, they are using your site to make money. They do this by finding an exploit that allows them to upload file(s) or inject an existing file with their code. The code most commonly used is mailing scripts to send spam and fake login pages for things like banks, PayPal, etc (phishing). They may also insert ads into your website’s files. In the vast majority of cases, we see, your sites are not specifically targeted and they are not actually after you.

 

How was my WordPress website hacked?

Hackers use bots that scan your WordPress website for vulnerabilities both known and unknown. There are some comprehensive scanning tools out there that will scan your WordPress site for 1000’s of vulnerabilities, and other possible weaknesses such as out of date server software (PHP, Apache, Mysql, etc..). If an exploit is found then the bot will try and use it, usually to upload a script or inject code. Once this has been done files and permissions can be changed/added as needed. Most commonly hackers gain access through out of date WordPress core files, plugins, and themes. Always keep everything up to date and if a plugin is not actively maintained by its developers then you really should get rid of it.

 

How do I know if my WordPress website is hacked?

 

In many cases, you will not know. The hacker that is using your website to make $$ will usually try and keep things quiet. Often you do not know until you are notified by us that your site has been compromised. Our systems constantly monitor your websites for suspicious activity such as mailing scripts, mail sending, and many other forms of malicious code. Other hints that something is awry may be:

  • Website suddenly showing a white page or 500 error
  • Ads and popups that you did not add.
  • Decreased website performance.
  • Logins stop working and mail recovery of login / password no longer working.
  • Your website and or pages of your website redirect to another site.

 

How do I recover my WordPress website after being hacked?

The hackers usually will hide malicious code (backdoors) throughout your website and they can be hard to track down and eliminate them all. If you miss one they will be back in no time at all. The best way to recover your site from a hack is from backup, but before you do that you need to find out when your site was hacked.

 

Finding out when your website was hacked

First thing we need to do is find some of the hacked and or compromised files. There are a variety of ways that this can be accomplished:

  • Use something like Wordfence to scan for malicious files (careful though it can remove legitimate files)
  • Scan for malicious files from SSH (see below)
  • Ask us to run a scan on your account

Scanning from SSH is quick and easy, here I will include the 3 most common types of base64 and variations that we see, these usually are enough to help you quickly identify compromised or added malicious files.

Make sure you are in your website directory using the cd command, for example, “cd public_html”

find . -type f -name '*.php' | xargs grep -l "eval *("

 

This scans for  “eval”. This will return quite a few false positives as there are legitimate uses for this code in WordPress. Here is what I get from a fresh WordPress 4.8 install with this command:

./wp-includes/functions.php
./wp-includes/class-snoopy.php
./wp-includes/class-json.php
./wp-admin/includes/class-pclzip.php

 

These are legitimate and clean files in WordPress 4.8 that come with “eval”. Now lets scan specifically for “base64_decode”.

find . -type f -name '*.php' | xargs grep -l "base64_decode *("

 

Here again is the results from our fresh WordPress 4.8 install:

./wp-includes/class-wp-customize-widgets.php
./wp-includes/class-wp-simplepie-sanitize-kses.php
./wp-includes/class-smtp.php
./wp-includes/class-phpmailer.php
./wp-includes/ID3/module.audio.ogg.php
./wp-includes/IXR/class-IXR-message.php
./wp-includes/SimplePie/Sanitize.php
./wp-includes/random_compat/random_bytes_com_dotnet.php
./wp-admin/includes/file.php

 

These are all legitimate files that include base64 in WordPress 4.8. One last scan for “gzinflate”.

find . -type f -name '*.php' | xargs grep -l "gzinflate *("

 

Again results from our fresh WordPress 4.8 install:

./wp-includes/class-requests.php
./wp-includes/class-wp-http-encoding.php
./wp-includes/SimplePie/File.php
./wp-includes/SimplePie/gzdecode.php
./wp-admin/includes/class-pclzip.php

 

To verify whether the results are indeed bad files you need to compare them against clean WordPress files. Found some suspicious files in a plugin directory? Download a fresh copy of that plugin and compare the files.

Checking when a file was last changed

Once you have a confirmed list of “bad” files you want to check the date they were last changed, you can do so using the “stat” command.

stat date-test.txt

File: ‘date-test.txt

Size: 17

Blocks: 8

IO Block: 4096   regular file

Device: 803h/2051d

Inode: 27798301

Links: 1Access: (0664/-rw-rw-r–)

Uid: ( 1020/xoiwjrbc)

Gid: ( 1020/xoiwjrbc)

Access: 2017-07-03 08:11:22.511398107 -0400

Modify: 2017-07-03 08:11:22.511398107 -0400

Change: 2017-07-03 08:11:22.511398107 -0400

 

Sometimes the hackers script will attempt to hide file activity by modifying the Access and Modify time-stamps to match other files on your WordPress installation, but change time cannot be modified. Now that you have a general idea of when files were changed or modified you can move on to the best option of recovering from a hack, and that is backups.

 

Using backups to recover from hacked WordPress

Due to the complexity and difficulty of cleaning files and databases (yes they might have also added to your database) you best option for recovery is restoring files and database(s) from backup. This is the reason why we went through the above steps of finding a somewhat accurate date as to when the site was compromised. At Kickassd we provide complimentary R1soft backups that are taken daily and stored for 30 days. In the majority of cases a hack becomes apparent inside of that 30 day window, and our R1soft backups allow you to quickly and easily recover your website.

But some hackers will gain access and sit silently for months before using their backdoors. In these cases for most the only option is to clean their website which is a comprehensive and and complex task which is beyond the scope of this article. If you use our hosting services and find this is the case please don’t hesitate to let us know!

The post What To Do If Your WordPress Website Gets Hacked appeared first on Kickassd – The Web Hosting Blog.