WordPress Hack Investigation & Cleanup

How to tell if a WordPress site was compromised, clean it properly, and harden it afterward.

  • Find the entry point before deleting anything. A hacked WordPress site stays hacked (and webshells and hidden admins keep returning) until you know how the attacker got in.
  • WordPress core is rarely the culprit. The cause is almost always a vulnerable plugin, a theme, or a stolen password.
  • To check for compromise, compare the plugin vulnerability disclosure date with your update date (your exposure window), search access logs in that window, verify core/plugin checksums with WP-CLI, list administrators, and look for recently modified PHP files.
  • Common backdoor hiding spots: wp-content/mu-plugins, PHP files in uploads, wp-config.php and .htaccess, theme functions.php, the database (wp_options, post content, hidden wp_users rows), WP-Cron/server cron jobs, and fake plugin folders.
  • Hidden admin accounts are real in the database but filtered from the Users screen by malicious code. Query via WP-CLI, and remember that deleting the user isn't enough because the code will recreate it.
  • Pro or 'nulled' plugins can themselves be the backdoor. Only install paid plugins from the vendor and diff your copy against a clean one, since checksums only cover wordpress.org plugins.
  • If the webshell returns, you likely have an unpatched plugin or theme, a missed second backdoor, a cron job or process restoring it, a still-valid stolen credential or SFTP key, or a re-infection from another site on the same hosting account.
  • Clean properly: back up files, database and logs first; close the entry point; replace (don't repair) core, plugins and themes from clean sources; manually review uploads, mu-plugins, custom themes and the database; remove unknown users; reset all passwords; rotate salts; clear caches and request a Google review if flagged.
  • Harden and monitor: update quickly or enable auto-updates, remove unused plugins and themes, block PHP in uploads, set DISALLOW_FILE_EDIT, require 2FA with few administrators, use a WAF like Cloudflare, run nightly checksum/admin checks with alerts, and keep tested off-site backups for 30+ days.

A hacked WordPress site stays hacked until the entry point is found, which is why webshells and hidden admin accounts keep coming back.

If you want to clean up a compromised WordPress site, find out how they got in before you delete anything. WordPress core is rarely the cause. It’s almost always a plugin, a theme or a stolen password.

Was the Site Compromised?

When a plugin you run has a critical vulnerability announced, don’t assume you’re fine because the site looks normal. Check:

  1. The dates. Compare when the vulnerability was disclosed with when you updated. The gap is your exposure window.
  2. The access logs. Search that window for requests to the vulnerable plugin’s files and for POST requests to unusual PHP files.
  3. Core and plugin files. Compare them with the official copies.
  4. Users. Look for administrators you didn’t create.
  5. Recently changed files. Anything modified inside the window that you didn’t deploy.
wp core verify-checksums
wp plugin verify-checksums --all
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
find wp-content -name "*.php" -mtime -14
find wp-content/uploads -name "*.php"

Plugin checksums only cover plugins from wordpress.org. For premium plugins, download a fresh copy from the vendor and diff it against what’s on the server.

Where Backdoors Hide

Location What to Look For
wp-content/mu-plugins Files you didn’t add. They load on every request and don’t show in the Plugins screen.
wp-content/uploads Any PHP file. There’s no reason for one to be there.
wp-config.php & .htaccess Added include lines, auto_prepend_file, or rewrite rules for search engine visitors.
Theme functions.php Code that creates a user or hides one from the user list.
The database Scripts in wp_options and post content, and admin rows in wp_users that the dashboard doesn’t show.
WP-Cron & server cron Scheduled events that re-download the malware.
Fake plugins Folders with plausible names and one PHP file.

Hidden Admin Accounts

A hidden admin is usually real in the database and filtered out of the Users screen by malicious code. Query the database directly with WP-CLI, which doesn’t use that screen. Deleting the user isn’t enough, because the code that created it will create it again.

Backdoored Pro Plugins

Occasionally the plugin itself is the backdoor: a vendor’s download server is compromised, or a “nulled” copy of a paid plugin is installed. Nothing looks out of place, because the malicious code arrived inside a plugin you trust. Check the vendor’s security notices, compare your copy with a known clean version, and never install paid plugins from anywhere but the vendor.

Why the Webshell Keeps Coming Back

If a webshell returns after cleanup, one of these is still true:

  • The vulnerable plugin or theme is still installed and unpatched.
  • A second backdoor was missed. Attackers leave several.
  • A cron job or a running process restores the file.
  • A stolen password, application password or SFTP key still works.
  • Another site on the same hosting account is infected and re-infects this one.

Clean It Properly

  1. Take a copy first. Files, database and logs, so you can keep investigating after cleanup.
  2. Close the entry point. Update or remove the vulnerable plugin.
  3. Replace, don’t repair. Reinstall WordPress core and every plugin and theme from clean sources. Don’t try to edit malware out of files.
  4. Review what’s left. Uploads, mu-plugins, custom themes and the database need a manual check.
  5. Remove unknown users and reset every password: WordPress, hosting, SFTP and database.
  6. Rotate the salts to end every logged in session.
  7. Clear caches, then request a review if Google flagged the site.
wp core download --force --skip-content
wp plugin install $(wp plugin list --field=name --status=active) --force
wp config shuffle-salts

Harden & Monitor

The same list works for one site or thirty. For many client sites, the difference is that it has to be automated:

  • Update quickly. Turn on auto-updates for plugins, or patch within a day of a security release.
  • Remove what isn’t used. Inactive plugins and themes can still be exploited.
  • Block PHP in uploads at the server level, and set DISALLOW_FILE_EDIT in wp-config.php.
  • Require two-factor for every administrator, and keep the number of administrators small.
  • Put a firewall in front, like Cloudflare’s WAF.
  • Run the checks nightly. A script that runs the checksum and admin list commands above on every site, and alerts on any change, catches most compromises in a day.
  • Keep off-site backups for at least 30 days, and test a restore.

For more on why WordPress itself isn’t the weak point, see the WordPress security fallacy.