WordPress reinfection usually means the cleanup removed the files someone could see and missed a copy somewhere else. The site looks clean, then the same malware is back the next morning, or within seconds.
Agencies hear this story often. A recent research write-up from Sucuri shows why it happens and gives a cleanup order that works. This post walks through where malware hides on a WordPress site, why deleting files one at a time fails, and a cleanup and follow-up routine a small team can run.
The short version: modern WordPress malware keeps copies in files, the database, scheduled tasks and sometimes server memory, and each copy can rebuild the others. Turn off the loader first, clear the copies that live outside files, remove scheduled tasks and hidden admins, then clean every file in one pass. After that, close the hole the attacker used and change every credential. Skip either step and WordPress reinfection is likely.
What WordPress reinfection looks like
The pattern is familiar to anyone who supports client sites. A file gets flagged, someone deletes it, and the scanner reports a clean site. Then one of these happens:
- The same file reappears with the same name or a new random name.
- A plugin you never installed shows up again, or a copy sits in two folders.
- Pages start redirecting visitors again, often only for logged-out users.
- An admin account you cannot see in the Users screen keeps making changes.
Each of these points to a piece the cleanup missed, and each is a form of WordPress reinfection. WordPress’s own "FAQ: My site was hacked" guide says reinstall installers "often only overwrite existing files, and hacks often introduce new files." That one line explains a lot of repeat infections. A fresh copy of core leaves the extra files in place.
One example: Sucuri’s write-up on a self-healing strain
On September 30, 2026, Sucuri researcher Gabriel Barbosa published an analysis of a WordPress malware strain it labels SC. According to the write-up, "the same backdoor kept returning within seconds of every removal," even after careful file deletion. Sucuri notes that file names vary from site to site.
Here are the places Sucuri says the payload lived at the same time:
| Location | What it does | Why a normal cleanup misses it |
|---|---|---|
.user.ini (or php.ini, .htaccess) |
Sets auto_prepend_file so a loader runs before every PHP request |
Hidden dot file, not a plugin or theme |
A shim and a hidden loader in wp-content |
Rebuilds the fake plugin | The hidden copy starts with a dot |
db.php and advanced-cache.php drop-ins |
Redeploy the plugin early in every request | Look like normal caching or database files |
Active theme’s functions.php |
A marked block that redeploys the plugin | Lives inside a file you need |
Fake plugin in mu-plugins and plugins |
The main payload, in two identical copies | Hides itself from plugin lists |
| ZIP bundle with a random hex name | A restore kit for the plugin | Looks like a stray upload |
| Database options and transients | Encoded payload plus sc_ control settings |
File scans do not read the database |
| Scheduled tasks | Cron hooks with random names | Run on a timer after files are gone |
| Server shared memory | A copy of the PHP held in RAM | Not on disk at all |
Sucuri also says related variants used database triggers that recreate an administrator account when new rows are inserted.
Why deleting files one at a time fails
According to Sucuri, each piece checks for the others. The drop-ins and the theme block redeploy the plugin when it is missing or too small. The advanced-cache.php drop-in can restore the plugin from five sources: the mu-plugin, the plugin copy, shared memory, the ZIP bundle or the database. The payload also hooks into many WordPress actions and filters, so any surviving copy can rebuild the full set on the next page load.
So if you delete the plugin first, the next request brings it back. If you delete the drop-ins first, the database copy restores them. This is why WordPress reinfection can happen within seconds and not days.
auto_prepend_file points to while the setting is still active. Sucuri warns that “the auto_prepend_file value is cached by PHP for up to 300 seconds,” and removing the target while the cache is warm can take down every PHP request on the account. PHP’s manual confirms that .user.ini files are re-read every 300 seconds by default. Remove or comment out the directive, wait five minutes, then delete the file.The PHP manual’s page on .user.ini files adds one detail worth knowing. These files are only read under CGI/FastCGI, which covers most PHP-FPM hosting. On Apache’s PHP module, the same setting goes in .htaccess. Check both.
Where WordPress reinfection hides beyond plugin files
The SC strain is one example, but the hiding places are general. When a site keeps coming back dirty, check each of these.
Drop-ins. Files like db.php and advanced-cache.php in wp-content load early in each request. Legitimate caching plugins use them, so they do not look strange at first glance. Compare them against the plugin that is supposed to own them.
Must-use plugins. WordPress’s must-use plugins documentation says these run without activation and cannot be turned off from the admin area. They appear in a separate "Must-Use" section, which many people never open.
PHP settings files. Look for .user.ini, php.ini and .htaccess files in the site root and in subfolders. An auto_prepend_file line pointing at a hidden PHP file is a strong sign of compromise.
The database. Options rows with large encoded values, odd transients and unfamiliar user accounts all survive a file cleanup.
Scheduled tasks. Both WordPress cron and server cron can rerun a loader after the files are gone.
Hidden administrators. Sucuri says the SC payload writes an admin account straight into the users and usermeta tables, hides it from user lists and counts, and forges login cookies. Check the database directly, not only the Users screen.
Backups. A backup taken after the break-in holds the same malware. Restoring it causes WordPress reinfection on the spot.
A cleanup order that stops WordPress reinfection
Sucuri lists six steps under "How to Clean It Up." The order matters more than any single step.
- Neutralize the prepend before deleting its target. Remove the
auto_prepend_filedirective, then wait for PHP’s cache to expire. - Clear the off-disk payload copies. Delete the encoded options row, the
sc_-style control options and transients, and any shared memory copy. - Remove scheduled tasks and database triggers. Check WordPress cron, server cron and the database for triggers that recreate users.
- Remove the hidden administrator. Also remove any leftover option that points at that account’s ID.
- Clean the files in one pass. Remove loaders, both plugin copies, ZIP bundles and injected drop-ins together. In
functions.php, trim only the marked block. - Scan again and watch for recreated files. If something comes back, a copy is still out there.
Before step 1, take a backup of the infected site. WordPress’s hacked-site FAQ recommends this so you have a copy to reference if the cleanup breaks something. Keep it apart from your good backups and label it clearly.
On shared hosting, the shared memory copy may be owned by another account, according to Sucuri. You may need your host to clear it.
Close the way in, or WordPress reinfection starts over
A clean site that still has the original hole will be broken into again. Sucuri’s conclusion says to close the original entry point and "rotate every credential the attacker could have touched." The write-up does not say how this particular site was first infected. Its general advice is that most compromises it handles exploit known, already-fixed flaws in outdated components.
That points to a few steps:
- Update everything. Core, plugins and themes. Our post on the WordPress 7.1.4 security release covers the most recent core fixes, including an upgrade-window code execution flaw. For plugin flaws under active attack, see our Bricksforge vulnerability post.
- Stop uploaded PHP from running. Many attacks start with a PHP file dropped into a writable folder. Our guide to blocking PHP execution in upload folders covers Apache and Nginx rules.
- Change every password. WordPress’s FAQ says to reset access for all users, consider a new database password, and update the secret keys in
wp-config.phpto log everyone out. It also says to change passwords again "after making sure your site is clean." - Check your own computer. The same FAQ says to scan your local machine, since attackers may have taken credentials from it.
For accounts with admin rights, two-factor sign-in or passkeys make stolen passwords less useful. Our passkeys explainer covers how they work.
Checks that catch WordPress reinfection early
After the cleanup, watch the site closely for a few weeks. These checks use free tools and WordPress’s own documentation.
Verify core files. WP-CLI’s wp core verify-checksums compares core files against WordPress.org’s checksums without loading WordPress. Add --include-root to flag non-WordPress files in the site root. For directory plugins, wp plugin verify-checksums --all does the same. Neither covers drop-ins, .user.ini files or the database, so check those by hand.
Watch for file changes. WordPress’s Hardening WordPress guide says "When an attack happens, it always leave traces," and suggests file change monitoring with tools like diff, Git or OSSEC. A site kept in Git makes new files easy to spot.
Turn off the file editor. The hardening guide recommends define( 'DISALLOW_FILE_EDIT', true ); in wp-config.php. It is honest about the limit: "This will not prevent an attacker from uploading malicious files to your site, but might stop some attacks."
Set file permissions. The same guide gives 755 for folders and 644 for files, and 400 or 440 for wp-config.php.
Read the logs. Look for requests to the hidden file names and outbound traffic you cannot explain.
When to rebuild instead of clean
If the same site has been reinfected more than once, or nobody can say how the attacker got in, a rebuild may cost less time. That means a fresh WordPress install, plugins and themes downloaded again from their official sources, content exported from a database you have checked, and new credentials everywhere.
WordPress’s FAQ says forensics, the work of finding how attackers got in, is hard for most site owners "due to lack of technical knowledge and / or available data." That is a fair reason to bring in help, and a reason to keep logs and a clean backup. Our posts on backup security and data breach response plans cover both.
Frequently Asked Questions
What causes WordPress reinfection after a cleanup?
Usually a copy of the malware survived somewhere the cleanup did not reach: a drop-in, a must-use plugin, a .user.ini file, the database, a scheduled task or a hidden admin account. The other cause is an open entry point, such as an outdated plugin, that lets the attacker back in.
Is reinstalling WordPress core enough to remove malware?
No. WordPress’s hacked-site FAQ notes that installers often only overwrite existing files, while hacks often add new ones. Malware in wp-content, the database or server settings is untouched by a core reinstall.
Why does the malware come back within seconds?
In the strain Sucuri analyzed, several pieces watch for each other. When one is deleted, a surviving copy rebuilds it on the next page load. That is why Sucuri’s cleanup order disables the loader and clears the off-disk copies before deleting files.
What is auto_prepend_file, and why is it risky to delete its target?
It is a PHP setting that runs a file before every PHP request. Attackers set it in .user.ini or .htaccess. PHP caches .user.ini settings for 300 seconds by default, so deleting the target first can break every PHP request on the account until the cache expires.
How do I find a hidden admin account?
Check the users and usermeta tables in the database directly, not only the Users screen. Sucuri says the SC payload hides its admin from user lists and counts. Look for accounts with administrator capabilities you cannot match to a real person.
Can I restore from a backup instead of cleaning?
Only if the backup predates the break-in and you close the entry point. Restoring an old backup without fixing the hole leads to WordPress reinfection by the same route.
Do I need to change the WordPress security keys?
WordPress’s hacked-site FAQ says to update the secret keys in wp-config.php to log out anyone still signed in, and to change all passwords again once the site is clean. Sucuri’s write-up says the SC payload can forge login cookies, so this step matters.
Does disabling the theme and plugin editor stop reinfection?
It helps a little. WordPress’s hardening guide says DISALLOW_FILE_EDIT will not stop malicious uploads but might stop some attacks. Updates and strong sign-in matter more.
How long should I watch for WordPress reinfection after cleanup?
WordPress does not set a period. Watch closely for a few weeks: rerun scans, check for new files and review logs. If anything returns, a copy is still on the server or the entry point is still open.