Why WordPress malware comes back
Attackers don’t want to lose a site they’ve taken over. So most infections today come with persistence: a second or third way to restore themselves if someone removes the visible malware. If a cleanup removes the payload but misses the persistence, the site is reinfected, often within hours.
In my experience, and in what other WordPress security people report too, it’s almost never one thing. The malware usually has two or three of these working together, each able to restore the others.
Where reinfections usually come from
| Source | Why it survives a normal cleanup |
|---|---|
Must-use plugins (wp-content/mu-plugins) |
They run on every page load and don’t appear in the normal plugin list |
| Code in the database | Payloads stored in wp_options, including transients and autoloaded options, are written back to disk on the next page load |
| Startup files | A few lines in wp-config.php, object-cache.php or advanced-cache.php that restore the malware before WordPress even starts |
| Cron jobs | WordPress cron events or hosting cron jobs that download the malware again every few hours |
| Hidden backdoors | Small files disguised as core files, images or plugin files, often deep inside wp-includes or uploads |
| Fake plugins | Plugins with believable names (“maintenance toolkit”, “cache helper”) that recreate admin accounts |
| Other sites in the same account | Sites under one hosting user can write to each other’s files, so an uncleaned site reinfects the cleaned one |
| Logins that still work | Old login sessions and WordPress application passwords survive a password change |
| Saved passwords | Malware that recorded logins while the site was infected, so the attacker simply logs in again |
| An admin’s browser | A tab left open in the WordPress dashboard since the infection, or a malicious service worker, that re-uploads the malware when an admin is logged in |
| The original hole | The outdated or vulnerable plugin, theme or nulled software that let the attacker in, still installed |
The same files keep getting hacked
A very common version of this problem: one specific file keeps changing. index.php is rewritten every night, wp-config.php gets new lines at the top, or .htaccess files reappear in every folder. Owners search for “index.php keeps getting hacked” or “wp-config keeps getting hacked”, fix the file, and find it changed again the next day.
The file isn’t the problem; it’s the target. Something with write access keeps editing it: a scheduled task, a running PHP process, a backdoor elsewhere on the server, or another site in the same hosting account. If you host a WordPress multisite, an infected subsite can do the same to the whole network. Restoring the file treats the symptom. Finding the process that writes to it fixes the cause. My guide to .htaccess malware in every folder shows how to find what’s recreating files.
Why scanners and quick cleanups miss it
Most cleanups work through a list of infected files. Persistence is designed not to be on that list: it lives in the database, in a startup file, in a cron job, or in an admin’s browser. A scanner also can’t tell you that a sibling site in the same hosting account is the real source, or that an old login session is still active.
That’s why “the scan is clean” and “the site is clean” aren’t the same thing when an infection keeps returning. For a recent real-world example, see my blog post on self-healing malware that rebuilds itself from the database and mu-plugins.
How I stop a reinfection cycle
- Map the whole infection. I look at every site in the hosting account, not just the one with symptoms, and record when each malicious file and database entry appeared.
- Remove all persistence together. Backdoors, mu-plugins, database payloads, startup code and cron jobs all go at the same time, so none of them can restore the others.
- Kick everyone out. I end every login session, revoke application passwords, replace the security keys and remove unknown users, including accounts that look like they belong to WordPress or your host.
- Find the way in. Access logs, file dates and the plugin list usually point to it: an outdated plugin, a nulled theme, a file manager plugin, or a leaked password. Then I close it.
- Make sure your side is clean too. I’ll ask everyone who uses the dashboard to close old tabs, clear site data in their browser and change saved passwords. It sounds trivial, but it matters.
- Watch the site. I check it again after the cleanup, and the 1-month guarantee covers the same infection coming back.
A typical case: a site is cleaned three times in two weeks, once by the host and twice by the owner with a security plugin. Each time the malware returns overnight. The investigation finds three things working together: a must-use plugin that rewrites a fake plugin from a database entry, a hosting cron job that downloads the database entry again if it’s deleted, and an old staging copy of the site in a subfolder that nobody had touched in two years. Removing only one or two of them would have failed again. Removing all three at once, plus the outdated plugin on the staging copy, ended it.
Before you try again yourself
If you’d like one more attempt on your own, follow my step-by-step malware removal guide, and pay particular attention to the database, cron and login sections. And if the malware has already beaten one or two cleanups, that’s usually the point where a fresh, experienced pair of eyes saves you days. Tell me what you’re seeing.