Skip to content
BlogWebsites

Websites4 min read

The WordPress malware that grows back after you clean it

A WordPress back door hides in files, the database and the server's memory, and rebuilds itself after cleanup. Why it happens, and what actually works.

Amine KHDev, Tradix Technology
00:00-04:38

What happened

A back door is a small program an attacker leaves on your site so they can come back whenever they want. Usually it sits in one or two files. A good cleanup finds them, deletes them, and the story ends there.
The back door Sucuri described in October works differently. It spreads its copies across several hiding places at once:
  1. a special .user.ini file that tells PHP to run the attacker's code before every page
  2. two WordPress files that load before any plugin, db.php and advanced-cache.php
  3. a hidden plugin, and changes to the theme
  4. a full copy stored in a row of the database, under a random name
  5. on servers that allow it, a copy kept in the server's memory, which survives deleting files and cleaning the database
Each hiding place can rebuild the others. Remove four of them, miss the fifth, and the next visit to the site puts everything back.

Why "we cleaned it" so often fails

I've seen this scenario many times with company websites: the site is hacked, a freelancer cleans it, everyone is relieved, and two days later the warning signs are back. The owner pays a second time, then starts to think WordPress itself is the problem.
SC explains this pattern clearly. Three details make it so hard to get rid of:
It runs before your security plugin. The files it uses are loaded by WordPress and PHP before ordinary plugins start. A security plugin scanning from inside the site arrives too late and can be fooled.
A copy lives in memory. You can delete every infected file and clean the database, and a copy still waits in the server's memory, ready to write everything back. Without a restart of PHP, the cleanup isn't finished.
It has no single address to block. Instead of receiving orders from one server, it reads them from the Ethereum blockchain through about twenty public gateways. Block the one you see in your logs and it simply uses the next.
Sucuri has not said how the sites were first infected. That matters too: if the original door is still open, even a perfect cleanup only buys a few days.

What it says about the next ones

Website malware is becoming patient and organised. Its goal isn't to break your site in a visible way, but to stay as long as possible: sending spam, redirecting visitors from Google to scam pages, or stealing what customers type into forms. A site that "still works" can be infected for months.
That changes how a hack should be handled. Cleaning file by file was enough ten years ago. Today, the reliable method is the one used for servers: assume everything on the infected machine is dirty, and rebuild it.

What to do if your site was hacked

1. Take the site offline or put it in maintenance, so it stops infecting visitors and sending spam in your name.
2. Rebuild from a clean backup, made before the first sign of infection, on a fresh hosting space if you can. Reinstall WordPress, the theme and plugins from their official sources rather than copying the old files.
3. Restart PHP, or ask your host to, so no copy survives in memory.
4. Change every password and key: WordPress admins, hosting panel, database, FTP, and the secret keys in wp-config.php.
5. Update everything, and remove what you don't use. Each unused plugin is one more possible way in.
6. Check for the warning signs: a .user.ini file you didn't create, an advanced-cache.php file when you have no cache plugin, a db.php file you can't explain, admin accounts you don't recognise.

The real lesson

A site is not "clean" because the warning disappeared. It is clean when you know exactly what's running on it. If nobody can answer that question for your website, that's the first thing to fix, before the next back door gives you the answer.
Share

Written by

Amine KH

Keep reading