If you have already cleaned the malware but the infection returns, a hidden backdoor is likely letting the attacker back in. This guide shows how backdoors work in WordPress, where they hide, how to locate them, and the steps you need to take to remove them permanently.

What is a WordPress backdoor and how does it work?

A backdoor is a piece of code that gives an attacker remote access to the site without using the normal WordPress login. The code can execute arbitrary PHP, upload new files, or create new admin users. Because it runs inside the normal WordPress environment, the attacker can bypass security plugins, file-permissions checks, and even two-factor authentication. Most backdoors are inserted after a vulnerability is exploited - for example through a vulnerable plugin, an insecure file upload, or stolen credentials - and then they stay hidden until the site is manually cleaned.

Where do attackers usually hide backdoors?

The most common locations are:

  • wp-content/uploads - this folder should only contain media files; any PHP file here is suspicious.
  • wp-content/plugins - especially a fake, abandoned or nulled plugin that the attacker can modify without notice.
  • wp-content/mu-plugins - must-use plugins load automatically on every request, making them perfect for a persistent payload.
  • Theme files - functions.php or other template files are often edited because they are loaded on every page view.
  • Root files - wp-config.php and .htaccess can be altered to inject code that runs before WordPress boots.
  • Files with deceptive names - names that look like core files (wp-user.php, class-wp-ajax.php) but reside in the wrong directory.

What does a backdoor look like in the code?

Typical backdoor code uses functions that can evaluate or execute strings supplied by an attacker. Look for:

  • Obfuscation functions such as eval(, base64_decode(, gzinflate(, str_rot13( - often nested to hide the real payload.
  • Direct use of request variables - $_POST, $_GET, or $_REQUEST passed straight into eval, system, exec, or passthru.
  • Long, random-looking strings - large blocks of characters that are later decoded at runtime.
  • File-manipulation functions - move_uploaded_file, file_put_contents, or fopen used in unexpected places.
  • Database injection - code that writes malicious PHP into the wp_options table or creates new scheduled tasks.

How to locate a backdoor - a realistic step-by-step example

Imagine a site where a file called uploads/2023/09/shell.php has appeared. It holds a single line that takes a value sent in a web request, decodes it and runs it as PHP. Even though the file is not part of WordPress, it runs whenever someone requests it directly, which gives the attacker a remote shell. To find it:

  1. Run a file-system scan that flags any PHP file outside the core directories. Tools that look for the patterns above are more reliable than simple signature scans.
  2. Search for suspicious functions across the whole codebase:
    grep -R "eval(" .
    grep -R "base64_decode(" .
    
  3. Compare core and theme files with a fresh WordPress download. Any differences in core files (wp-admin, wp-includes) are red flags.
  4. Inspect the database for options that contain PHP code. A quick query such as:
    SELECT option_name, option_value FROM wp_options WHERE option_value LIKE '%eval%';
    
    can reveal hidden payloads (use your own table prefix if it isn't wp_).
  5. Check scheduled cron jobs in wp_options (cron option) for unknown callbacks.

How to remove a backdoor - numbered remediation steps

  1. Isolate the site - put the site in maintenance mode or block public traffic while you work.
  2. Take a full backup of files and the database before making changes. This gives you a rollback point if something goes wrong.
  3. Delete any unknown PHP files in uploads, mu-plugins, and other non-core directories.
  4. Replace altered core files with a clean copy from the official WordPress package. Do not rely on the existing files; overwrite them.
  5. Re-install plugins and themes from trusted sources. Remove any plugin that you cannot verify, especially a nulled plugin.
  6. Clean the database - remove options or post meta that contain malicious code, and delete unknown scheduled cron events.
  7. Reset all passwords (admin, FTP/SFTP, database) and rotate the authentication salts in wp-config.php so existing sessions become invalid.
  8. Harden the installation - disable file editing, set correct file permissions, and ensure wp-config.php is not writable by the web server.
  9. Run a second scan with the same tool to confirm no backdoor remnants remain.
  10. Follow the steps to take after a WordPress hack for final hardening and monitoring.

Common mistakes when cleaning backdoors

  • Deleting only the visible file - attackers often leave additional payloads in other files or the database. Always scan the whole site.
  • Re-using compromised credentials - changing passwords after cleaning is mandatory; otherwise the attacker can log in again.
  • Leaving the vulnerable plugin/theme installed - even if you delete the malicious code, the original vulnerability may still be exploitable.
  • Modifying core files directly - this makes future updates harder and can re-introduce hidden code if the change is not tracked.
  • Skipping the second scan - a single pass may miss encoded strings that are only decoded at runtime.

Limitations of the removal process

  • Obfuscated code can be extremely layered; without deep analysis some payloads may remain hidden.
  • Automated scanners may produce false positives - manual review is still required for every flagged file.
  • Database-only backdoors that store the malicious payload in an option and reconstruct it on each request can be missed if the database is not examined.
  • Server-level compromises (e.g., compromised SSH keys) are outside the scope of a WordPress-only cleanup; the server itself may need rebuilding.

How Silent Threads helps

Backdoors are the reason manual cleaning often fails. Silent Threads looks for the code patterns backdoors use and watches for new files appearing in places they should not, so re-infections get caught.

The short version

A WordPress backdoor is hidden code that lets an attacker regain access after a clean-up. Look for PHP files in uploads, suspicious functions like eval and base64_decode, and malicious code in the database. Remove all unknown files, replace core files, reinstall trusted plugins/themes, reset passwords and salts, and scan twice. Finally, follow the post-hack checklist to harden the site.