Your WordPress website is an indispensable part of your business operations. As advantageous as it can be, it can also become a target for numerous cyber threats. A pervasive threat that many WordPress site owners confront is malware attacks.
However, there’s no cause for alarm. The procedure to remove malware from a WordPress site is not as daunting as it may seem. In this exhaustive guide, we will guide you step-by-step through the procedure, sharing handy advice along the way to boost your site’s security.
Detecting WordPress Malware
Identifying malware infection at an early stage can save your site from substantial damage. Here are some signs to look out for:
- Unusual Traffic Spikes: An unexpected surge in traffic, particularly from unusual locations, may signal a malware attack.
- Sudden Drop in Website Speed: If your site is unusually slow without an apparent reason, it could be due to malware.
- Unwanted Ads, Pop-ups and Redirections: Malware often injects unwanted ads and pop-ups into your site. Even worse, they can redirect to another website.
- Suspicious Files and Changes: Unrecognized files or unexpected changes in your WordPress files could indicate a malware infection.
- Get notification from a Security Plugin: An alert from your security plugin about any detected anomalous activities on your site.
Steps to Remove Malware from a WordPress Site
1. Backup your site
Before commencing the task to remove malware from a WordPress site, it’s crucial to first create a thorough backup of your WordPress site. This step is a critical safety measure. If unforeseen issues arise during the malware removal process, having a comprehensive backup ensures that you won’t lose any valuable data and enables you to restore your website to its original state if necessary.
And, also it helps to conduct a detailed investigation of the hacked data once you restore the website back.
WordPress offers a variety of plugins that automate the backup process. Some of these include UpdraftPlus, BackupBuddy, and VaultPress. These plugins can save your backup to multiple locations, including your computer, cloud storage services like Dropbox, Google Drive, or dedicated backup services.
To backup your site, choose a plugin, install it, and follow its instructions to create a complete backup of your WordPress site. Remember to download the backup file and store it in a safe place.
At WPHandle, We use UpdraftPlus Premium and server-side backup solutions that keep offside secure backups in the Cloud without extra charge.
2. Scan your site for malware
Verify checksum with CLI
WP-CLI can be instrumental in your efforts to remove malware from a WordPress site. Its ‘verify-checksum’ commands proficiently highlight any altered files, offering a straightforward method to identify and locate infected elements within your site.
Next, execute the command ‘wp plugin verify-checksums –all’ to examine if any plugins might have been infected.
Although WP-CLI is unable to run checksums for premium plugins and themes, it remains an effective initial step in identifying potential issues.
Use a malware scanner
A popular method for malware scanning is through the use of plugins. Plugins like Wordfence, Jetpack scan and Sucuri are specifically designed to protect WordPress websites. These tools work by checking your website against known patterns of malicious behavior, alerting you when they find any potential threats.
Wordfence, for instance, offers a range of features from malware scanning to live traffic monitoring. It automatically scans your website for common threats, and if it detects any suspicious behavior or files, it will notify you promptly. (We use Wordfence often for client websites)
However, plugins are not the only way to protect your site. If you have access to your server, you could use a server-side scanner. Server-side scanners examine the files on your server to identify and remove malicious files. These tools are often more powerful and thorough than plugins because they scan every file in your hosting account, not just your WordPress installation. This broad scanning capability allows them to uncover hidden or camouflaged malware, potentially missed by a plugin, thus enhancing your efforts to remove malware from a WordPress site.
3. Replace infected files with a clean copy
If you find changed core files, you can simply run: wp core download --skip-content --force
to override changed files. Alternatively, If you don’t have access to WP-CLI, you can just remove WordPress files other than wp-config.php and wp-content directory and upload the clean core files.
Next, review wp-config.php file, whether it’s infected or not, and create a new wp-config.php if it’s necessary. Also, we recommend updating secret keys in the wp-config.php file.
And then, if the malicious code discovered in themes and/or plugins, it is advisable to reinstall the original, unaltered version of the software.
4. Detect and remove hidden backdoors
In your quest to remove malware from a WordPress site, It is crucial to be aware that hackers often leave behind entry points to regain access to your website. In most cases, we discover multiple types of backdoors within compromised WordPress sites.
These backdoors are frequently concealed within files that resemble WordPress core files but are actually located in incorrect directories. Attackers may also inject backdoors into files like wp-config.php and directories such as wp-content/themes, wp-content/plugins, and wp-content/uploads.
Commonly encountered backdoors involve PHP functions such as:
- eval
- exec
- base64
- gzuncompress
- system
- assert
- stripslashes
- move_uploaded_file
It is worth noting that legitimate plugins may also employ these functions, so it is essential to test any modifications carefully. Removing benign functions or failing to eliminate all malicious code could potentially break your website.
You can utilize the following SSH commands to identify any compromised files within your directories:
To detect hacked files containing suspicious PHP functions, execute the command:
find . -type f -name '*.php' | xargs grep -i "(mail|fsockopen|pfsockopen|stream_socket_client|exec|system|passthru|eval|base64_decode) *("
To locate image files that may contain backdoor functions, use the command:
find wp-content/uploads -type f -iname '*.jpg' | xargs grep -i php
Lastly, to discover infected iframes, execute the following command:
find . -type f -name '*.php' | grep -i '<iframe'
These commands will help you identify potential security issues within your files, allowing you to take appropriate actions. Closing all backdoors is imperative to effectively halt a WordPress hack; otherwise, your site will be vulnerable to quick re-infection.
5. Clean hacked database tables
In the event that your WordPress website has been compromised by malware, it is possible that malicious content has been introduced into your database tables.
To effectively cleanse your tables, follow these steps:
- Access your phpMyAdmin dashboard, which can typically be found through your hosting provider.
- Log in to your phpMyAdmin dashboard.
- Locate the specific database table that has been contaminated with malicious content.
- Proceed to remove the infected content from the identified database table.
6. Remove Malware Warnings
After successfully restoring your website and confirming that everything is functioning normally, it may be necessary to notify your hosting provider if your account was suspended due to the malware attack.
Additionally, it is advisable to inform relevant authorities responsible for blocklisting, such as Google Search Console, Yandex Webmaster, and McAfee SiteAdvisor. Requesting a thorough review of your website from these authorities will help ensure its removal from any security blocklists.
Securing Your WordPress Site: Proactive Steps to Prevent Future Hacks
1. Update Out-of-date Software and Remove Unused Components
Keeping your software up to date is crucial in preventing infections, as outdated software is a prominent cause of security breaches. This encompasses not only the WordPress core, but also plugins, themes, and any other software installed on your site.
Plugin and theme authors frequently release critical vulnerability patches, making it essential to stay current with the latest updates. So, keep them updated.
Furthermore, it is advisable to keep redundant plugins and themes away from your WordPress site, even if they are not currently activated. In some cases, these unused components can still pose a potential attack vector, therefore it is best to remove them entirely from your site.
We provide maintenance plans that include worry-free updates for your WordPress site. With our expert team keeping a close eye on your website, you can ensure that it remains up to date and secure. Feel free to explore our maintenance plans for a hassle-free experience.
2. Prevent direct PHP execution
If you are using nginx, you can use
location ~* /(?:uploads|files|wp-content|wp-includes)/.*.php$ {
deny all;
}
or with apache, something like this
<FilesMatch "\.php$">
<If "%{REQUEST_URI} =~ m#/(uploads|files|wp-content|wp-includes)/#">
Order allow,deny
Deny from all
</If>
</FilesMatch>
would help to direct PHP executions for the specified directories.
3. Change User Passwords and Use Two Factor Authentication
To bolster the security of your WordPress site, it is essential to prioritize two key measures: updating user passwords and implementing two-factor authentication.
- Change User Passwords:
Regularly updating user passwords is a fundamental practice in maintaining a secure WordPress environment. By periodically changing passwords for all user accounts, including administrators and contributors, you significantly reduce the risk of unauthorized access. Remember to encourage users to create strong passwords that incorporate a combination of complexity, length, and uniqueness. This simple yet effective step can fortify the overall security of your website. - Implement Two-Factor Authentication (2FA):
Two-factor authentication provides an additional layer of protection beyond traditional username and password combinations. By enabling 2FA, users are required to verify their identities through an additional authentication method, such as a unique code sent to their mobile device or a biometric scan. This added security measure ensures that even if passwords are compromised, unauthorized access is still thwarted. Implementing 2FA for all user accounts, especially administrative roles, significantly mitigates the risk of malicious attacks.
You can use two-factor plugin for 2FA features.
4. Use a Web Application Firewall (WAF)
To reinforce the security of your WordPress website, it is highly recommended to utilize a Web Application Firewall (WAF). A WAF acts as a protective shield between your site and potential threats, safeguarding it from various forms of malicious activity, including hacking attempts, DDoS attacks, and SQL injections.
Cloudflare, a widely recognized and trusted provider, offers an excellent WAF solution for WordPress sites. By leveraging Cloudflare’s WAF, you can benefit from their extensive network infrastructure, which acts as a barrier against known vulnerabilities and emerging threats. Cloudflare’s WAF employs a combination of signature-based and behavioral-based detection mechanisms, constantly analyzing traffic patterns to identify and mitigate potential risks.
Alternatively, if you prefer a WAF specifically tailored for WordPress, you may consider using the 7G Firewall. The 7G Firewall is an effective firewall that helps prevent various types of attacks by filtering malicious requests at the server level, providing an additional layer of defense against common security vulnerabilities.
There are numerous other reputable Web Application Firewall (WAF) providers available in the market (Sucuri, Akamai, Impreva, ModSecurity…). It is important to conduct your due diligence and carefully evaluate the options to determine the best fit for your specific needs.
5. Setup an Automated Malware Scanner
To maintain a robust security posture for your WordPress website, it is crucial to set up an automated malware scanner. By continuously scanning your site for malicious code and potential security vulnerabilities, you can promptly identify and mitigate any threats before they cause significant harm.
There are various options available for automated malware scanning, including server-side scanners and dedicated services provided by reputable companies. Here are a few notable solutions:
- Sucuri: Sucuri offers a comprehensive suite of security services, including an automated malware scanner. Their scanner examines your website for signs of malware, suspicious code, and other potential security risks. It provides regular scanning reports and alerts you of any detected issues.
- Wordfence: Wordfence is a popular security plugin for WordPress that includes an integrated malware scanner. It scans your website’s files, themes, and plugins for known malware signatures and other indicators of compromise. Wordfence also offers additional security features such as firewall protection and real-time threat intelligence.
- Jetpack Scan: It performs a comprehensive analysis of your site, identifying potential malware and suspicious code. The plugin compares your files and database against a vast database of known threats, ensuring that any malicious activity is swiftly brought to your attention. Upon detection of any anomalies, Jetpack Scan will send you an email notification, allowing you to take immediate action.
Additionally, server-side scanners can be installed directly on your hosting environment. These scanners perform regular scans at the server level, analyzing files, databases, and other components of your website for signs of malware or suspicious activity. Some hosting providers offer server-side scanning as part of their security services, so it’s worth exploring the options available from your hosting provider.
By setting up an automated malware scanner, whether through a dedicated service or a server-side solution, you can proactively identify and address security threats on your WordPress site. Regular scanning helps ensure the integrity of your website and provides peace of mind knowing that potential issues are detected and resolved in a timely manner.
6. Backups for Your WordPress Site: Ensuring Data Protection
Protecting your WordPress site’s data is essential for maintaining the integrity and security of your online presence. Implementing a comprehensive backup strategy is crucial to safeguard against unforeseen incidents, such as data loss, website errors, security breaches, or server failures. Let’s explore the concept of backups, including popular backup plugins and services, as well as the benefits of both onsite and offsite backups.
Backup Plugins and Services:
There are several reliable backup plugins and services available for WordPress users, offering a range of features and capabilities. Some popular options include:
- UpdraftPlus: UpdraftPlus is a widely used backup plugin that allows you to schedule automated backups and store them on various remote storage options like Dropbox, Google Drive, or FTP. It offers both free and premium versions with additional advanced features.
- Jetpack Backup: Jetpack Backup is a comprehensive backup solution offered by Jetpack, a reputable WordPress plugin suite. It provides automated daily or real-time backups, easy restoration options, and secure offsite storage on the WordPress.com cloud.
- BlogVault: BlogVault is a backup and security plugin that offers real-time backups, one-click site restoration, and a comprehensive suite of website management tools. It also includes features like staging, site migration, and malware scanning.
Onsite vs. Offsite Backups:
When it comes to storing backups, you have the option of onsite (local) or offsite (remote) backups.
- Onsite Backups: Onsite backups refer to storing your backup files on the same server as your website. While this method provides quick access and easy restoration, it is important to note that onsite backups may not protect against server failures, physical damage, or targeted attacks.
- Offsite Backups: Offsite backups involve storing your backup files in a remote location or cloud-based storage. This approach offers an additional layer of protection since your backups are stored independently from your website. Offsite backups protect against server failures, disasters, and targeted attacks, providing a reliable means of restoring your site.
Implementing regular backups for your WordPress site yields several significant benefits, including:
- Data Recovery: Backups enable you to recover your website’s data and content in the event of accidental deletion, hacking incidents, or software malfunctions.
- Rollback to a Stable State: With backups, you can revert your site to a previously stable version, minimizing downtime and ensuring a seamless user experience.
- Peace of Mind: Knowing that your valuable website data is securely backed up gives you peace of mind, reducing stress associated with potential data loss or security breaches.
- Site Migration and Development: Backups facilitate smooth site migration and provide a safe environment for testing and development purposes.
To ensure comprehensive data protection, it is recommended to maintain both onsite and offsite backups. Onsite backups offer quick access and restoration options, while offsite backups provide an additional layer of protection against various risks. By employing a reliable backup solution and regularly backing up your WordPress site, you can safeguard your data and mitigate the potential impact of unforeseen incidents.
We offer complimentary daily backups, both onsite and offsite, in the cloud without additional cost.
Conclusion
Being proactive about your WordPress site’s security and knowing how to remove malware is crucial in this digital age. By following the steps outlined in this comprehensive guide, you can help ensure your site remains safe and robust. Remember, prevention is always better than cure, so regularly update your WordPress site, monitor for unusual activity, and prioritize online safety.
Despite your best efforts, however, it’s important to acknowledge that maintaining a secure WordPress site can be a challenging and time-consuming task, especially if you’re also trying to run a business. There may be times when you require a more expert touch or simply don’t have the bandwidth to manage it all on your own.
That’s where we come in. At WP Handle, we specialize in conducting thorough WordPress security audits to identify any vulnerabilities and propose effective solutions. Our team of seasoned WordPress professionals are well-versed in securing websites from all forms of threats and malware. We’re here to help you ensure your site’s security, leaving you more time to focus on what matters most – growing your business.
Feel free to reach out to us and learn more about our security audit services. Let us help you build a safer and more secure digital presence. After all, your peace of mind is our priority.
Remember, the digital world can be a challenging terrain, but with the right knowledge and assistance, you can protect your WordPress site from even the most malicious malware threats. Stay safe online and happy blogging!