My site has been hacked. Look around first and change nothing yet: what
state is the site in, which administrators are there, and what is in
mu-plugins and the uploads folder?
Getting a hacked site to load again is not the same as cleaning a hacked site. We have more than once restored a site, reported that it worked again, and then found a handful of strange administrators still in it. A week later the junk was back.
So we stick to a fixed order. Look, clean, prove, harden. Do not reverse it: every step depends on the one before.
1. Look, and change nothing yet
Start read-only. What you find here is your cleanup list; if you have already started deleting, you no longer know what was there.
What your site does tells you straight away which kind of problem you have:
- An error or a 500 usually means a backdoor has a syntax error of its own: a fake file high in the folder tree that refuses to run. Removing that file removes the error immediately.
- A blank page, so a response without content, means a bootstrap file was emptied or deleted. Usually the site's
index.php, or the active theme'sfunctions.php. - A page that simply works means you are here for the deeper job: strange administrators and backdoors.
Mind the cache: after a repair, the first look can still give you the old blank page. Request the page again with a random parameter on the end, and purge the web server cache if needed.
What else you check in this step is in what the hack check looks at.
2. Clean: the symptom and the way back in
Restore the bootstrap file. If index.php is empty, put back the stock WordPress content; that is five lines. If a theme file is gone, do not invent it yourself. Many sites have a copy from just before the change somewhere, for instance in the backup folder of an editor plugin. Check that copy for obfuscated code and put it back. If there is no clean copy anywhere, use the backup of your hosting account.
Remove the backdoors. These are the places where we keep finding them:
- loose files in
mu-pluginswith a name that looks like a WordPress internal; - files in the uploads folder with a random name, often already emptied by the server's scanner; delete the empty husks too;
- fake plugins with a name promising something about speed or maintenance, with obfuscated code and an invented author.
The tell is not the name but the location and the content: a backdoor is a loose file high in the tree with obfuscated code (flattened jumps, base64, a key read from the URL). Leave alone what sits deep inside a real plugin and reads like normal code. Often wrongly flagged: the loader files of maintenance plugins and of an installer, and the internal files of large plugins.
Remove the strange administrators. This is the step most often skipped, and exactly the step that makes the hack come back. They are recognisable by a non-existent email address, a machine-generated login and a registration date of today or yesterday. Keep only the genuine owners and reassign their posts to a real user.
Delete the scheduled job the backdoor left behind. A backdoor in mu-plugins almost always schedules a recurring job so it can re-establish itself. Removing the file does not remove the schedule. Check the scheduled jobs and remove what does not belong.
Remove file manager plugins the attacker installed. That is the easiest way back in. If the owner genuinely uses one, do not quietly remove it but report it.
3. Database rows: on exact names, never on a fragment
A backdoor's options deliberately use a prefix that looks like a real plugin. We once deleted every row with such a prefix in one go, and took the settings of a real calendar plugin with it. That plugin found its version number missing, ran its install routine, wrote default settings and renamed a table.
The approach after that:
- List first, do not delete: which rows match this pattern and how large are they?
- Per row, ask: who reads this option? Search for the name in the folders of the plugins you are keeping. If a real plugin reads it, it stays.
- Delete on a list of exact names, not on a pattern.
4. Prove it is gone
The cleanup is done when a second look says so, not when the deletes returned without an error. A site we reported clean turned out six weeks later to still have two old administrators and two old files in mu-plugins, plus three new administrators.
Three checks, before you tell anyone anything:
- the list of administrators: every row has to be a known person;
- the entire contents of
mu-plugins, with no date filter, reading the first lines of every file you do not recognise. These files appear in no plugin list, and a filter on "changed in the last two weeks" misses an older loader; - the plugin list again.
Show the administrators with email address and registration date, every
file in mu-plugins with its first lines, and the full plugin list. Say
for each whether you recognise it.
5. Harden, in this order
Only once the account is clean:
- A backup first, so you have a clean starting point.
- Update everything: core, database, plugins, themes. Premium themes cannot update without a licence key; you report that, you do not force it.
- With one exception: a customised active theme. A theme update replaces the whole theme folder. For us that once wiped a site's own header, footer and stylesheet. How to spot it: files that do not exist in the official version, or a stylesheet that differs. If the customisation lives in a child theme, updating the original is actually safe. Without a child theme: do not update, and write down that it is excluded. Watch this especially after a cleanup, because what is on disk now is your only copy of that customisation.
- Switch the cache back on if the hack had disabled it, and check that pages are being served from cache again.
- Have passwords changed: WordPress, the hosting account and FTP.
What else matters when updating is in safely updating WordPress.
Common mistakes
Stopping as soon as the site loads again. Repairing the symptom is not the same as removing the way back in.
Updating first, cleaning second. Every update boots WordPress, and as long as a backdoor is still running, that is what plants it back.
Judging files by their name. Location and content decide whether something is a backdoor.
Leaving the scheduled job in place. The file is gone, the schedule puts it back.
Deleting database rows on a prefix. You take a real plugin's settings with you.
Only looking at the last few days. The oldest loader is often the most important file.
Including a customised theme in an update after a cleanup. Then you wipe exactly the repair work you just did.
If the junk comes back after a cleanup, look at the backdoor that lived in the database and at spam that stays after cleanup.