WordPress Security ServicesMalware Removal
Malware analysis

Self-Healing WordPress Malware: Why It Was Back 24 Hours After the Cleanup

A pattern keeps coming up in WordPress communities this autumn: the site gets cleaned, every bad file is deleted, and the next morning it's all back. That's not bad luck. Modern WordPress malware is built in layers that restore each other. Here's how it works, based on recent public cases, and the cleanup order that actually breaks the loop.

Sergey By Sergey, WordPress security specialist Published 4 min read
In this post
  1. What happened in the recent cases
  2. The three layers that restore each other
  3. Why mu-plugins are such a good hiding place
  4. The backup that attacked the person restoring it
  5. The cleanup order that breaks the loop

What happened in the recent cases

In September, a developer on r/Wordpress described a cleanup that failed twice. Visitors saw a fake Cloudflare “Verify you are human” box, the kind that tries to trick people into pasting a command into their computer. The team removed all the malicious PHP files. Within 24 hours, everything was back.

The reason: the files weren’t the malware’s “source of truth”. They were just copies.

The three layers that restore each other

Based on that write-up and what the community added, the infection had three layers:

  1. The database. Large base64 blobs stored in wp_options as transients with innocent names such as _site_transient_health_*. Real site-health transients are small. These were 125–225 KB each.
  2. Files. Fake plugins with believable names (cache, performance, security headers), several must-use plugins in wp-content/mu-plugins, and copies hidden in wp-includes and uploads.
  3. Boot code. A small block in wp-config.php and a fake wp-content/object-cache.php that rebuilt the plugin from the database on every request, plus hourly cron jobs doing the same.

Delete layer 2, and layer 3 rebuilds it from layer 1 on the next page view. Clean the database, and a surviving file writes it back. You have to break all three at once.

Diagram: the database stores the payload, boot code loads it on every request and rebuilds deleted files, and a surviving file writes the payload back. Clean boot code first, then the database, then the files.
Each layer restores the others. Remove the boot code first, so nothing is left to rebuild what you delete next.

The same case also showed hidden administrators with service-like names (wpsvc_* and similar) and extra REST API routes registered under a core-looking namespace, so the attacker could talk to the site even after logins were reset.

Why mu-plugins are such a good hiding place

Must-use plugins load automatically, before normal plugins, whenever a PHP file sits in wp-content/mu-plugins. They can’t be deactivated in wp-admin, and they only appear under a small “Must-Use” tab on the Plugins screen that hardly anyone opens.

Hosts use this folder too. Hostinger, Installatron, managed WordPress platforms and others put their own files there. That makes it easy for a malicious file to blend in. In a related discussion on r/ProWordPress, a security plugin developer pointed out the obvious problem: a backdoor can be called hostinger-anything.php just as easily.

How I’d judge a file in mu-plugins:

  • Does your host, or a plugin you use, document it? Ask the host if you’re unsure.
  • If you manage several sites at the same host, is the same file, with the same content, on all of them? The odd one out deserves a closer look.
  • Read it. Host files are usually readable code. Long encoded strings, eval, and code that downloads or writes other files are red flags.

The backup that attacked the person restoring it

In November, a freelancer on r/Wordpress shared an even nastier variant. A “client” sent a site export and asked them to run it locally on their own computer before starting the job. WordPress core in the export was 100% clean. But mu-plugins contained a third file next to two legitimate host files. It looked for a “JPEG” in uploads, renamed it to .exe and tried to run it. The “image” was actually a Windows program, reportedly a password stealer.

Two lessons from that one:

  • Don’t open site backups you didn’t make on your own computer without checking them first, especially when someone insists you run them locally.
  • “Core matches the checksums” says nothing about wp-content. Check mu-plugins by hand, and check that images are really images:
find wp-content/uploads -type f \( -iname "*.jpg" -o -iname "*.jpeg" -o -iname "*.png" -o -iname "*.gif" \) -exec file {} + | grep -viE "image data|JPEG|PNG|GIF"

The cleanup order that breaks the loop

  1. Stop the traffic. Block the site temporarily (an .htaccess rule or your host’s tools). WordPress maintenance mode isn’t enough, because the code still runs.
  2. Back up the infected state. You may need it to work out what happened.
  3. Remove the boot code first: the injected block in wp-config.php, an object-cache.php you didn’t install, and unknown files in mu-plugins.
  4. Clean the database: suspicious large transients, unknown cron hooks, injected scripts, unknown administrators. Until step 3 is done, do this in phpMyAdmin, not WP-CLI. One commenter noted that running WP-CLI can trigger the restore code. A safe, read-only first look:
SELECT option_name, LENGTH(option_value) AS size
FROM wp_options
WHERE option_name LIKE '\_site\_transient\_%' OR option_name LIKE '\_transient\_%'
ORDER BY size DESC LIMIT 20;
  1. Replace core, plugins and themes with fresh copies instead of editing them.
  2. Close the other doors, which community members rightly added:
    • application passwords (they survive password changes and salt resets);
    • other sites in the same hosting account, which often reinfect each other;
    • an infected service worker in the admin’s browser, which can bring the infection back when they log in.
  3. Find the entry point, then change every password and the salts.

From my cleanup work: when a client tells me “it came back overnight”, I don’t start with the files anymore. I start with wp-config.php, mu-plugins, object-cache.php and the biggest rows in wp_options. That’s where the restore logic usually lives. Deleting what the scanner flagged is the last step, not the first.

If you’re stuck in this loop, my page on malware that keeps coming back explains how I handle it, and what it costs.

Sergey, WordPress Security Specialist
About the author
Sergey, WordPress Security Specialist

10 years in WordPress security and incident investigation, and more than 200 websites cleaned of malware. Top Rated on Upwork with a 100% Job Success score. More about me

Frequently Asked Questions

What is self-healing WordPress malware?

Malware that keeps a copy of itself somewhere a normal file cleanup doesn't touch, usually the database, wp-config.php or a must-use plugin, and recreates its files on the next page load or cron run.

Is it safe to use WP-CLI on an infected site?

WP-CLI loads wp-config.php, and often plugins and mu-plugins, so it can run the malware's restore code. Remove the boot code first, or work on the database directly in phpMyAdmin until the restore logic is gone.

Can I just restore a backup?

If you have a backup from before the infection, and you know how the attacker got in, yes. But the restore logic often sits in the database, so make sure the backup really predates it, and fix the entry point, or it comes back.

Need a hand?

Let me clean your WordPress site for you

Send me your site URL and what you're seeing. I'll reply with what I think is going on and the next step.

$95 per infected site · 1-month guarantee · direct contact with the specialist

Get My Site Cleaned →