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:
- The dates. Compare when the vulnerability was disclosed with when you updated. The gap is your exposure window.
- The access logs. Search that window for requests to the vulnerable plugin’s files and for POST requests to unusual PHP files.
- Core and plugin files. Compare them with the official copies.
- Users. Look for administrators you didn’t create.
- 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
- Take a copy first. Files, database and logs, so you can keep investigating after cleanup.
- Close the entry point. Update or remove the vulnerable plugin.
- Replace, don’t repair. Reinstall WordPress core and every plugin and theme from clean sources. Don’t try to edit malware out of files.
- Review what’s left. Uploads, mu-plugins, custom themes and the database need a manual check.
- Remove unknown users and reset every password: WordPress, hosting, SFTP and database.
- Rotate the salts to end every logged in session.
- 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_EDITinwp-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.