Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

WordPress Malware Keeps Returning: Find & Remove the Backdoor

· 6 min read · Home Tech

In this article
  1. Why Malware Returns: The Backdoor Explained
  2. Step 1: Scan for Signs of a Backdoor
  3. Step 2: Manually Inspect Suspicious Files
  4. Step 3: Remove the Backdoor and Clean the Infection
  5. Step 4: Close the Entry Points
  6. Frequently Asked Questions

If WordPress malware keeps coming back after you clean it, a backdoor file or a compromised account is almost certainly still on your server, allowing the attacker to re-infect the site. To permanently remove it, you must find and delete the backdoor, then close every entry point the attacker used. This article explains how to locate hidden backdoors, remove them, and harden your site to prevent reinfection.

Why Malware Returns: The Backdoor Explained

A backdoor is a hidden file or script that gives an attacker remote access to your server. Unlike the initial malware (like a redirect or a fake admin user), the backdoor is often small, innocuously named, and designed to evade detection. Common backdoors include:

  • PHP files with obfuscated code (e.g., base64_decode with long encoded strings)
  • Files uploaded to upload directories that execute as PHP (e.g., shell.php in /wp-content/uploads/)
  • Modified core WordPress files (like wp-load.php or wp-config.php) with extra code
  • Malicious plugins or themes that contain backdoor code in their main files

If you only delete the visible malware (like the injected spam links) but leave the backdoor, the attacker simply re-runs their script and the malware reappears. That is why a thorough backdoor hunt is essential.

Step 1: Scan for Signs of a Backdoor

Before you can remove a backdoor, you need to find it. Start with a multi-layered scan:

  1. Use a reputable security plugin (e.g., Wordfence, Sucuri, iThemes) to run a full malware scan. These plugins compare your files against known signatures and flag suspicious code.
  2. Check your server's raw access logs for requests to unusual files (like ?cmd= or eval() or to files in upload directories that are not images. Look for POST requests to PHP files in /uploads/.
  3. Review recently modified files via your hosting file manager or FTP. Sort by modification date and look for files changed around the time of the infection. Backdoors are often created or modified during the attack.
  4. Search for known backdoor signatures using your hosting's file search or a local search tool. Look for strings like eval(, base64_decode, gzinflate, str_rot13, or shell_exec in PHP files.

If your host offers a server-level malware scanner (like Imunify360 or similar), run that as well—it can catch backdoors that are hidden outside your WordPress directory.

Step 2: Manually Inspect Suspicious Files

Automated scans are not perfect. A backdoor can be hidden in a legitimate-looking file. Manually inspect the following high-risk areas:

  • wp-config.php: Look for any code outside the standard define statements, especially after the closing ?> tag.
  • wp-content/uploads/: Backdoors often live here because uploads are usually writable. Look for any .php files in this directory—they should not exist.
  • wp-content/mu-plugins/: Must-use plugins are always loaded, making them a prime spot for backdoors. Check every file here.
  • wp-content/plugins/ and wp-content/themes/: Look for files that do not belong to the plugin/theme. Also check the main plugin/theme files for any encoded or suspicious code.

When you open a file in a text editor, look for long lines of encoded text, functions like eval(), assert(), preg_replace() with the /e flag, or any code that writes to other files. If you see anything that looks obfuscated, it is a backdoor—delete it immediately.

Step 3: Remove the Backdoor and Clean the Infection

Once you have identified the backdoor files, delete them. But do not stop there—the initial malware payload may still be present. Follow these steps:

  1. Delete all backdoor files you found. If you are unsure, quarantine them (rename to .txt) and test your site.
  2. Reinstall WordPress core by going to Dashboard > Updates and clicking “Reinstall Now”. This replaces all core files with clean versions, removing any injected code.
  3. Reinstall your themes and plugins from the official repositories. Delete the existing folders and install fresh copies. This removes any malware hidden in those files.
  4. Clean the database of injected content. Look for unfamiliar admin users, suspicious options in wp_options (like a modified siteurl), and any extra code in posts or widgets.

After cleaning, change every password: your WordPress admin password, FTP password, database password, and your hosting control panel password. Use strong, unique passwords and enable two-factor authentication for your WordPress admin account.

Step 4: Close the Entry Points

A backdoor is only the symptom; you must fix the vulnerability that allowed the attacker in. Common entry points include:

  • Outdated plugins/themes/core: Keep everything updated. Old vulnerabilities are the most common attack vector.
  • Weak passwords: Use a password manager and enforce strong passwords for all users.
  • Unused plugins/themes: Delete any you are not using—they add attack surface.
  • File permissions: Set your files to 644 and directories to 755. Never use 777.
  • XML-RPC: Disable it if you do not use it, as it can be used for brute-force attacks. You can disable it via a plugin or by adding a rule to your .htaccess.

Also, consider using a Web Application Firewall (WAF) like Cloudflare or Sucuri to block malicious traffic before it reaches your server.

Frequently Asked Questions

How do I know if my WordPress site has a backdoor?

Signs include repeated malware infections despite cleaning, unexpected admin users, strange files in your uploads directory, or your site being flagged by Google. A security scan (plugin or server-level) is the best way to confirm.

Can I remove a backdoor manually without a plugin?

Yes, if you are comfortable with FTP and file editing. Look for suspicious PHP files, especially in uploads and mu-plugins, and delete them. Then reinstall core, themes, and plugins from clean sources. For most site owners, using a security plugin is safer and faster.

What if the backdoor is in my hosting account, not in WordPress?

If you have cleaned WordPress and the malware still returns, the backdoor might be in a different directory on your server (like a cron job or a file in the home directory). Contact your hosting provider and ask them to scan the entire account—they can often find and remove backdoors outside your web root.

How do I prevent WordPress malware from coming back?

Keep everything updated, use strong unique passwords, limit login attempts, disable file editing in wp-config.php, and use a security plugin with a firewall. Regular backups also help you restore quickly if you are ever infected again.

Is it safe to just delete all suspicious files?

Not always—some legitimate files might look suspicious (e.g., a plugin that uses base64_encode for a license check). Only delete files you are certain are malicious. When in doubt, move them to a quarantine folder and test your site. If everything works, you can delete them later.

What should I do if I cannot find the backdoor?

If you have exhausted your own search, hire a professional or use a specialized malware removal service (like Sucuri or Wordfence). They have deeper tools and experience to find hidden backdoors. Alternatively, you can do a full manual reinstall: download a fresh copy of WordPress, your theme, and plugins, and replace everything on the server (preserving wp-config.php and the uploads folder).