WordPress security
The backdoor comes back after removal. How to find the mechanism that restores a WordPress infection
Deleting a malicious file doesn’t finish the repair if code that can recreate it remains somewhere else. In that case the file comes back on the first page visit, when a task runs or after another operation the attacker planned for. Below we describe an anonymised case from our support work. It shows why, after removing a backdoor, you need to find the mechanism that restores it, establish how access was originally obtained and monitor the environment after the repair.
Next step
A file reappearing means a persistence mechanism may still be running in the environment. Diagnosis should cover files, the database, tasks, logs and the other sites on the same account.
01
How to tell that the infection is still active
The first investigation revealed not only traces of an earlier break-in, but also active changes during our analysis. One of the files was created and then overwritten several times at intervals of a few dozen minutes.
The account also showed traces of a file browsing tool being used. Their names indicated that someone was opening directories of the same site while our check was in progress.
File dates are an important clue, but they shouldn’t be the only evidence. Malicious code can change modification times, and a backup or an automated deployment can also create many files in a short time. You need to cross-reference dates with logs, account activity and specific code changes.
In the logs we noticed a series of requests to the login screen coming from many IP addresses and made by automated clients. An example filter can help find similar entries:
zgrep "POST /wp-login.php" /path/to/logs/*.gz
| grep " 302 "
| grep -Ei "curl|wget|python|go-http"A 302 response code after submitting the login form often accompanies a successful login to the admin panel, but on its own it isn’t sufficient confirmation. The redirect may also be generated by a security measure, a plugin or the server configuration. The result needs to be confirmed via the redirect target, the session created, the user ID and the neighbouring log entries.
In this case, the combination of many signals pointed to compromised administrator credentials. We removed unknown accounts, invalidated sessions, deleted unnecessary application passwords, changed credentials and quarantined the backdoors we found.
02
Why the deleted file appeared again
After about forty minutes, one of the deleted files came back. It had the same content and the same hash. That meant a restore mechanism was still running in the environment.
A useful clue was the permissions of the new file. On the hosting we examined, files uploaded via FTP and files created by PHP received different access modes. The restored backdoor matched the local pattern of files created by the PHP process.
This conclusion is valid only if you have first learned how the particular server behaves. Permissions depend on the process owner, the umask, ACLs and the hosting configuration. In another environment FTP, SSH and PHP may create files with the same mode. Permissions are therefore a diagnostic clue, not a universal way of attributing the source of a change.
After ruling out the simplest scenarios, we checked, among other things:
- system tasks and WP-Cron,
- the mu-plugins directory,
- .user.ini files and the auto_prepend_file setting,
- active plugins and the theme,
- unusual accounts and application passwords,
- other installations running on the same account.
None of these places explained the recurrence.
03
A restore mechanism hidden in a plugin file
The breakthrough was verifying the plugin checksums:
wp plugin verify-checksums --all
--path=/path/to/wordpress
--skip-plugins
--skip-themesThe command compares the installed plugin files with the checksums published by WordPress.org. In our case it flagged a modified main file of a popular forms plugin.
Between legitimate fragments there was a short piece of code working much like the example below:
$data = base64_decode('encoded_file_contents');
file_put_contents($_SERVER['DOCUMENT_ROOT'] . '/i2.php', $data);The encoded string contained the body of the deleted backdoor. The plugin’s main file was loaded while handling WordPress requests, so an ordinary page visit could recreate the malicious file. A check run after cleaning therefore triggered the recurrence mechanism itself.
This wasn’t a vulnerability in that plugin. An attacker with administrative access or the ability to write files could modify any code the site loads. The chosen file was a convenient hiding place because its presence raised no suspicion.
04
Why a single scanner may not be enough
The fragment we found contained none of the typical functions associated with webshells, such as eval(), system() or shell_exec(). It used two legitimate PHP functions that are also used by ordinary integrations and libraries.
Signature-based scanning tries to answer whether code resembles a known threat. A checksum check answers a different question: is the file identical to the officially published version? In this case the second method immediately pointed to two added lines.
This doesn’t mean security plugins are ineffective. Some of them also compare files with the originals and could detect such a change. But you need to keep in mind the limits of a particular tool and its configuration:
- a scanner may cover only a specified directory, not the whole hosting account,
- some tools analyse files but not every place in the database,
- an attacker with administrator rights may try to disable the protection or change its settings,
- an exhausted file or space limit can prevent the configuration and report from being saved,
- a custom or paid plugin may have no public checksums.
Application passwords also need a separate check. They are independent credentials intended for integrations and can be revoked individually in the user profile. After an incident, don’t assume that changing the regular password alone closed every route of access.
The best result comes from combining checks from inside WordPress with analysis performed outside the application. You need checksums, logs, the database, scheduled tasks, the PHP configuration and every site in the same environment.
05
How to check core, plugins and recent changes
A basic check can start with three steps:
# Core files and unknown files in the root directory
wp core verify-checksums --include-root
--path=/path/to/wordpress
--version=$(wp core version --path=/path/to/wordpress)
# Plugins available in the WordPress.org repository
wp plugin verify-checksums --all
--path=/path/to/wordpress
--skip-plugins
--skip-themes
# PHP files with a recently changed inode state
find /path/to/wordpress -type f -name "*.php" -ctime -30
-printf "%CY-%Cm-%Cd %CT %m %10s %pn"
| sort -rEvery checksum mismatch must be explained. Don’t automatically dismiss changes in JavaScript files, translations or image assets. They may result from an incomplete update or a local modification, but they may also be part of the incident.
The ctime value shows a change to the inode metadata, for example the content, owner or permissions. An ordinary process can’t set it arbitrarily with touch, but the result still doesn’t prove who changed the file. Copying, restoring and updating also affect ctime.
The absence of public checksums doesn’t mean an infection. WP-CLI may skip paid, custom and plugins not available on WordPress.org. Such files must be compared with the vendor’s licensed package or replaced with a fresh, verified copy. A manual review is a supplement, but doesn’t give the same certainty as comparing the whole package.
06
How to confirm the backdoor isn’t coming back
After replacing the modified plugin with a clean package, we deleted the recreated file and started monitoring. In this case we ran a check every five minutes for thirty minutes:
find /path/to/wordpress -type f -name "*.php"
-newermt "2026-08-14 10:00:00"
! -path "*/cache/*"This period is not a universal standard. It was enough to confirm a mechanism triggered on every request, because during observation we repeatedly opened the site and performed controlled operations. A task triggered once a day would require much longer monitoring.
Acceptance criteria should match the persistence method. After the repair, it’s worth:
- Repeating the core and plugin checksums.
- Checking that the deleted file hasn't been recreated.
- Making controlled page visits and admin panel operations.
- Watching for new and changed files.
- Reviewing the access and error logs.
- Confirming there are no unknown accounts, sessions, application passwords or tasks.
- Checking the other sites on the same account.
07
Key takeaways
A deleted backdoor may only be the product of another piece of code. If it comes back, look for the process that creates it rather than deleting the same file again.
Permissions, dates and logs help narrow the search, but they need a local reference point. No single signal should decide the source of the infection on its own.
Checksum verification is especially valuable because it doesn’t judge what the code looks like. It shows every difference from the official package, even when the added fragment uses only legitimate PHP functions.
The repair is complete only when the original access has been closed, the persistence mechanisms removed and the results confirmed by sufficiently long monitoring.
Is the backdoor coming back, or don't you know the source of the infection?
We’ll check files, the database, logs, accounts, tasks and the other sites in the same environment. You’ll get a description of the source of the problem, the changes made and the tests confirming that the restore mechanism has been stopped.
Only 3 required fields · reply within 1 business day · no obligation
