On October 17, 2026, the tech blog “Ruyou Lexiang” shared a real-life case of a WordPress site that was repeatedly compromised. Over the course of about three months, the site experienced three separate security incidents, includingthe creation of unknown administrator accounts, the injection of suspicious JavaScript scripts into the homepage, an abnormal reset of theme settings, and the appearance of a suspected malicious PHP file in the plugin directory:。
According to the records published by the site administrator, the three incidents occurred on August 1, during the National Day holiday in October, and on October 12. The site administrator has upgraded WordPress multiple times and disabled certain plugins, but the issues continue to recur. This also indicates that,simply updating the WordPress core does not guarantee that the implanted backdoors, malicious database content, and compromised accounts have been thoroughly removed。
Drawing on the official WordPress security hardening documentation, this article uses a Debian 12/13, Nginx, PHP-FPM, MySQL, and the Baota Panel as examples, this article introduces methods for file investigation, database inspection, identification of malicious administrators, system-level backdoor checks, and recovery and hardening after a WordPress site has been compromised.
I. A Real-Life Case of WordPress Being Hacked Three Times in a Row
According to information released by “Youle Xiang,” this security incident primarily unfolded in three stages:
| Timeline | Abnormal Behavior | Mitigation Measures Taken |
|---|---|---|
| August 1, 2026 | A new administrator was created for the website, and two articles were published abnormally | WordPress was upgraded |
| During the National Day holiday in October 2026 | Unknown administrator appears again; theme settings lost | Upgraded WordPress and disabled some plugins |
| October 12, 2026 | Third occurrence of unknown administrator and abnormal theme settings | In-depth investigation of website files, database, and external scripts |
During subsequent checks, the webmaster also discovered suspicious files in the plugin directory; the malicious script loaded on the homepage may have exploited the administrator’s logged-in status to create a new administrator account,wp_optionsScript injection vulnerabilities were also found in the database tables.
The webmaster ultimately took measures such as cleaning up user accounts and the database, localizing third-party static resources, and redeploying the server.
However, publicly available records do not provide complete forensic evidence sufficient to independently confirm the initial point of entry. The third-party CDN referenced in historical posts, anomalies in plugin files, and database script injection should all be treated as key areas for investigation; none of these should be directly identified as the sole source of the initial vulnerability.
II. Common Signs of a WordPress Compromise
Common issues following a WordPress compromise include:
- Unrecognized administrator accounts suddenly appear in the admin panel.
- Regular users have been elevated to administrators.
- Unfamiliar JavaScript appears on the homepage or post pages.
wp-content/pluginsAn PHP file of unknown origin appears in a directory.wp-content/uploadsAn executable script appears in the upload directory.- The theme’s configuration, header, footer, or template files have been tampered with.
- Database
wp_optionsContains unknown scripts or redirect URLs. - The website is continuously and automatically publishing, modifying, or deleting posts.
- Unrecognized tasks have appeared in WordPress scheduled tasks.
- Similar issues reappeared shortly after the website was cleaned up.
Note: Suspicious files are not necessarily Trojans; legitimate files may also have been tampered with. When investigating, make a comprehensive assessment by considering the file’s source, integrity checks, logs, program behavior, and database records.
III. Step 1: Back up Website Files, Databases, and Logs
Before cleaning up, you must first back up the current environment.
It is recommended to back up the following:
- The entire WordPress website directory, including
wp-config.php。 - the MySQL database.
- Nginx access logs and error logs.
- PHP-FPM error logs.
- SSH login and system authentication logs.
- Baota Panel-related operations and login logs.
- Time of anomaly detection, account information, and details of suspicious files.
database can usemysqldumpbackup:
mysqldump -u DB_USER -p \
--single-transaction --quick \
DB_NAME > /root/wp-incident.sql
ReplaceDB_USER、DB_NAMEwith the actual database username and database name.
Backups may contain user information, password hashes, and database connection credentials; they should be stored outside the web directory, and access to them should be restricted.
It is recommended to temporarily isolate the affected website and subsequently analyze it in a trusted, isolated environment.
Do not directly empty database tables such aswp_users、wp_usermeta、wp_optionssuch as database tables.
IV. Check PHP files recently modified by WordPress
Navigate to the website’s root directory, for example:
cd /www/wwwroot/example.com
The actual directory should be adjusted according to the server configuration.
1. Check PHP files modified within the last 30 days.
find wp-content -type f \
-iname "*.php" -mtime -30 -print
Further check other file extensions that may be processed by the PHP environment:
find wp-content -type f \
\( -iname "*.php" -o -iname "*.phtml" \
-o -iname "*.phar" \) \
-mtime -30 -print
Key areas to investigate:
wp-content/plugins/wp-content/themes/wp-content/mu-plugins/wp-content/uploads/wp-content/cache/
Among these,mu-pluginsdirectories require special attention.
“Must-Use” plugins load automatically without requiring the administrator to manually enable them in the regular plugin list; therefore, suspicious files may run for extended periods without being easily detected.
2. Check for executable files in the upload directory
find wp-content/uploads -type f \
\( -iname "*.php" -o -iname "*.phtml" \
-o -iname "*.phar" \) -print
The standard WordPress media upload directory is typically used to store files such as images, audio, and documents. If PHP code of unknown origin is found, it should be investigated thoroughly.
3. Search for suspicious PHP code
grep -RInE --include='*.php' \
'(base64_decode|gzinflate|shell_exec|eval)' \
wp-content/
These functions are not necessarily malicious in themselves; some legitimate plugins also use encoding, decompression, or command execution features.
Search results should only be used as clues; do not delete them in bulk directly.
Further verification is required.wp-contentspecial load files in the root directory:
object-cache.phpadvanced-cache.phpdb.phpsunrise.php
These files may have been created normally by Redis, a caching plugin, or a multisite plugin; you should verify their actual contents and the source of the plugin.
V. Verifying the Integrity of WordPress Core and Plugin Files
Simply checking file modification times has limitations. Attackers may tamper with file timestamps, and legitimate updates can also result in significant file changes.
If a trusted version of WP-CLI is already installed on the server, you can run the following command:
wp core verify-checksums --include-root
For Chinese WordPress sites, specify the language based on the actual installation:
wp core verify-checksums \
--locale=zh_CN --include-root
Next, check plugins from the WordPress.org plugin repository:
wp plugin verify-checksums --all
These commands are used to compare against the official file checksums to help identify missing, modified, or additional files.
Please note:
- Commercial plugins, in-house plugins, and some unofficial plugins may not have official checksum data.
- When using a custom language pack, you must verify the actual WordPress language version.
- Certain WP-CLI commands may load website code; they should be run in an isolated environment whenever possible to avoid executing tampered plugins.
- On servers where WP-CLI is not installed, you can compare files offline using the official installation package; there is no need to forcibly install new tools in a production environment just to troubleshoot.
Once it is confirmed that program files have been tampered with, you should prioritize replacing them with trusted installation packages rather than simply deleting individual suspicious files that have been identified.
VI. Check for Abnormal WordPress Administrator Accounts
Unfamiliar administrator accounts were a recurring and obvious anomaly in this case.
WordPress users are primarily associated with two database tables:
wp_users: Basic user information.wp_usermeta: User roles, permissions, and other metadata.
1. Check for recently created users
SELECT
ID,
user_login,
user_email,
user_registered
FROM wp_users
ORDER BY ID DESC
LIMIT 30;
This query can identify recently added accounts, but it cannot identify users who were created earlier and later had their permissions elevated.
2. Query users with the Administrator role
SELECT
u.ID,
u.user_login,
u.user_email,
u.user_registered,
m.meta_key,
m.meta_value
FROM wp_users AS u
JOIN wp_usermeta AS m
ON u.ID = m.user_id
WHERE m.meta_key = 'wp_capabilities'
AND m.meta_value
LIKE '%"administrator";b:1%'
ORDER BY u.ID DESC;
This query applies to WordPress sites that use the default single-site role storage mechanism.
If multisite, custom roles, or directly assigned special permissions are present, additional checks of user capability fields and role definitions are required.
Additionally,wp_is only an example prefix. The actual database should be adjusted based on the table names and permission metadata key names withinwp-config.phpand$table_prefixAdjust the table names and permission metadata key names.
3. How to securely clean up abnormal accounts?
After confirming that the account is indeed unauthorized, you can first revoke permissions and terminate the session, then determine the deletion method based on the account’s data associations.
Direct execution is not recommended:
DELETE FROM wp_users;
Also, do not delete users in bulk based solely on their registration date.
This is because WordPress users may be associated with historical posts, comments, attachments, orders, membership information, and other plugin data.
Before deleting a user, you must first verify the authorship of posts and the data associations with relevant plugins, and decide whether to reassign the content.
VII. Check for Database Injections and Malicious Scripts in wp_options
On some compromised WordPress sites, malicious code may not necessarily be present directly in the theme’s PHP files; it may also be stored in database configuration fields.
1. Search for script tags
SELECT
option_id,
option_name,
LEFT(option_value, 300) AS preview
FROM wp_options
WHERE option_value LIKE '%<script%'
LIMIT 100;
2. Check for suspicious URLs and script protocols
SELECT
option_id,
option_name,
LEFT(option_value, 300) AS preview
FROM wp_options
WHERE option_value LIKE '%javascript:%'
LIMIT 100;
These queries can help identify suspicious entries, but they do not guarantee the detection of all encoded or obfuscated scripts.
Legitimate plugins may also store JavaScript, HTML, or serialized data in their configuration.
Particular caution is warranted: WordPress plugin configurations frequently use PHP serialization formats. Directly replacing certain strings in the database may result in mismatched serialization lengths, causing configuration corruption.
Therefore, you should first verify the source of the issue in a test environment before fixing it using the corresponding plugin, the WordPress API, or tools that support serialization processing.
VIII. Check Third-Party JavaScript, CSS, and Font Resources
This case study highlights issues with references to legacy themescdn.staticfile.organd other third-party resources.
You can use the following command to locate references in themes and plugins:
grep -RIn "cdn.staticfile.org" \
wp-content/themes \
wp-content/plugins
You can also search for common external resource references:
grep -RInE \
'https?://[^" ]+\.(js|css)' \
wp-content/themes
For third-party scripts with unclear origins, we recommend:
- Verify the current ownership of the domain and the source of the files.
- Verify that the actual content loaded matches the expected version.
- Prioritize the use of trusted, maintainable dependencies.
- Deploy static files locally, if permitted by the license.
- For fixed third-party resources that absolutely require external links, evaluate the use of SRI integrity verification.
The mere existence of historical security controversies surrounding a particular domain name should not lead to the immediate conclusion that it was the initial point of entry for this WordPress compromise.
IX. Nginx: Disable PHP Execution in Upload Directories
For WordPress sites running on Debian 12/13 with Nginx, it is recommended to restrict access to executable scripts in upload directories.
In the Nginx configuration file for the corresponding website server, you can refer to the following rules:
location ~* ^/wp-content/uploads/.*\.(?:php|phtml|phar)(?:/|$) {
return 403;
}
This configuration is used to prevent access to PHP and related executable file extensions in the upload directory via web requests, thereby reducing the risk of malicious code execution through uploaded files.
Note:
- This rule should be at the
serverlevel. - Regular expression rules must be matched before general PHP processing of regular expressions.
- If a higher-priority
location ^~rule with higher priority, ensure that the restrictions are not bypassed. - When a website uses a custom upload directory, the matching paths must be adjusted accordingly.
- The rules must not prevent internal PHP programs on the server from actively reading or executing local files.
Execute after making changes:
nginx -t
Verify there are no errors before executing:
systemctl reload nginx
BaoTower Panel users can add the corresponding rules through the site’s Nginx configuration management interface.
Before going live, you should also conduct external request testing to verify that the corresponding file extensions in the upload directory actually return a 403 error, to avoid assuming that access restrictions are in effect simply becausenginx -tpasses.
10. Disable the WordPress Admin Theme and Plugin Editors
Open the filewp-config.php, and add the following at the appropriate location:
define('DISALLOW_FILE_EDIT', true);
This setting disables the built-in theme and plugin file editors in the admin panel.
However, it does not prevent attackers with server write permissions from modifying files, nor does it prevent all malicious uploads.
Another configuration is:
define('DISALLOW_FILE_MODS', true);
This configuration further restricts operations such as the background installation and updating of plugins, themes, and the core program.
It is not recommended that general websites enable this feature without first conducting an assessment.DISALLOW_FILE_MODS。 If an alternative update mechanism is not established, this may actually prevent security patches from being installed in a timely manner.
For general websites, it is more appropriate to first enableDISALLOW_FILE_EDIT, in conjunction with two-factor authentication and file permission isolation.
XI. Checking for System-Level Backdoors in Debian 12/13
If WordPress has been compromised multiple times, simply checking the website’s PHP files may not be sufficient.
You should also verify whether the server itself contains suspicious accounts, scheduled tasks, or modified runtime configurations.
1. Review current login information
who
last -a
Check for unusual login times, unfamiliar source addresses, and unauthorized SSH sessions.
2. Check system scheduled tasks
crontab -l
View root scheduled tasks:
sudo crontab -l
Check system Cron configuration:
ls -la /etc/cron.*
Check systemd timers:
systemctl list-timers --all
Pay special attention to scripts from unknown sources, executables in temporary directories, and automated download and startup tasks unrelated to business operations.
3. Check SSH and system accounts
You can check recent login and system authentication logs:
sudo journalctl -u ssh --since "7 days ago"
The actual service names and log locations may vary depending on the server environment.
Still needs to be verified:
/root/.ssh/authorized_keys- SSH authorization files for the website’s running user
/etc/passwd/etc/sudoers/etc/sudoers.d/
Verify whether any unknown SSH public keys, users, or privilege escalation configurations exist.
4. Check Nginx and PHP-FPM
Check the actual configuration loaded by Nginx and the PHP-FPM runtime environment, focusing on:
- Check for any new, unknown configuration files or reverse proxy forwarding.
- Check for any unknown
includedirectives. - Has PHP been configured with an unknown setting?
auto_prepend_file。 - Is PHP-FPM running under an unusual user account?
- Does the website code directory have excessive write permissions?
- Are multiple WordPress sites sharing the same PHP-FPM user with cross-site write permissions?
For BaoTower panel environments, you should also review the panel account, API authorizations, scheduled tasks, file management operations, and the panel’s own security updates.
If you suspect that server root privileges have been compromised, do not assume the system is trustworthy again based solely on checking a few files.
A more prudent approach is to retain a forensic copy, reinstall the operating system using a trusted image, and then migrate the verified site data.
XII. Check WordPress Scheduled Tasks and Caching
WordPress scheduled tasks may be used by legitimate plugins for scheduled publishing, cache clearing, email sending, and synchronization operations, but they may also be abused by malicious code.
If Trusted WP-CLI is already installed, you can check it in an isolated environment:
wp cron event list
Verify that the task name matches the installed plugins and business functions.
You should also check:
- WordPress internal scheduled tasks.
- System Cron.
- PHP-FPM and Nginx-related tasks.
- Redis object caching.
- WordPress page cache.
- CDN edge cache.
If the website is configured with:
define('DISABLE_WP_CRON', true);
You must verify that you are using the system Cron or another reliable task execution mechanism.
This configuration only disables WordPress’s default page-request-triggered Cron; it does not automatically clear saved scheduled events, nor does it serve as a security measure to prevent malicious scheduled tasks.
After removing malicious scripts, you should also clear the relevant caches and verify that external visitors no longer receive compromised HTML or JavaScript content.
XIII. WordPress 7.0.7 and 7.1.3 Security Updates
As of October 17, 2026, the latest officially released version in the WordPress 7.1 series is7.1.3, released on October 6, 2026.
At the same time, the 7.0 maintenance branch has also released7.0.7。
This update includes seven security fixes addressing stored XSS, SQL injection, and other security issues.
For sites still using the 7.0 series, it is recommended to evaluate upgrading to 7.0.7 or a newer supported version; For sites using the 7.1 series, you should update to 7.1.3 as soon as possible.
Before upgrading, you need to verify:
- PHP version and plugin compatibility.
- Whether the theme is actively maintained.
- Whether the database backup is complete.
- Are custom plugins affected by version updates?
- Are there any tampered files or malicious configurations?
If a website has been compromised, a standard WordPress update cannot be considered a complete backdoor cleanup process.
XIV. The Correct Recovery Process After Repeated WordPress Compromises
For WordPress sites that have experienced two or even three exceptions, we recommend following the steps below to restore the site.
Phase 1: Isolation and Forensics
Back up all files, the database, and logs, and record the times of the exceptions as well as any suspicious accounts. If necessary, temporarily restrict write operations or access to the administration panel.
Phase 2: Prevent Further Intrusion
Reset the administrator password from a trusted device, revoke permissions for suspicious accounts, terminate related sessions, and rotate the WordPress authentication keys and salts.
Simultaneously change the SSH, Baota Panel, database, and related API credentials.
Phase 3: Investigate Backdoors
Inspect core programs, themes, plugins, Must-Use plugins, upload directories, databases, and scheduled tasks, and review Nginx and PHP logs to identify potential entry points.
Phase 4: Trusted Reconstruction
Rebuild the WordPress environment using the official package or a trusted commercial plugin installer. When restoring themes and plugins, avoid re-introducing files that have already been modified.
Phase 5: Restore Business Data
Verify posts, categories, tags, attachments, users, and site configuration.
Do not assume the system is secure simply by reimporting an unchecked old database and the entirewp-contentdirectory.
Phase 6: Deploy Continuous Protection
Enhance two-factor authentication, least privilege, off-site backups, log retention, file integrity checks, and anomaly alerts.
If there is evidence that server system privileges have been compromised, priority should be given to redeploying a trusted system rather than repeatedly patching the original server.
XV. Long-Term Security Hardening Recommendations for WordPress
| Hardening Project | Recommended Measures | Purpose |
|---|---|---|
| WordPress Core | Install security updates promptly | Fix known vulnerabilities |
| Themes and plugins | Retain Trusted, Actively Maintained Components | Reduce the Attack Surface |
| Administrator Accounts | Two-Factor Authentication, Least Privilege | Reduce the Risk of Account Compromise |
| Backend File Editing | DISALLOW_FILE_EDIT |
Restrict Direct Modification of Programs in the Backend |
| Upload Directory | Nginx Disables PHP Execution | Reducing the Risk of Upload-Based Backdoors |
| File Permissions | Minimum Write Permissions for Core and Plugin Directories | Restricting Modification of Malicious Files |
| Databases | Dedicated Accounts, Least Privilege | Reducing Database Risks |
| Server SSH | Key-based authentication, login restrictions | Protecting System Entry Points |
| System Cron | Periodically Verify Task Sources | Identify Abnormal Persistent Tasks |
| Logging and Monitoring | Anomaly Administrator, File Change Alerts | Timely Detection of Recurring Intrusions |
| Backups | Off-site backups with regular verification and restoration | Minimizing losses from failures and intrusions |
It is recommended to separate write permissions for the WordPress core, plugin, and theme directories from normal media upload permissions to prevent web processes from having unnecessary modification capabilities over all website files.
XVI. Summary
The fact that a WordPress site is repeatedly compromised does not necessarily mean that the WordPress core contains an unpatched vulnerability.
Actual intrusion incidents may involve historical plugin vulnerabilities, outdated themes, leaked administrator credentials, third-party scripts, configuration flaws, or server-level backdoors that have not been completely removed.
For Debian 12/13, Nginx, and PHP-FPM environments, it is recommended to focus on checkingAdministrator privileges, WordPress file integrity, the wp_options database, Must-Use plugins, execution permissions for upload directories, and system Cron jobs。
If the same unknown administrator or malicious script appears on the website multiple times, it indicates that the issue may not have been fully resolved. The most important steps are to identify the intrusion path, revoke the attacker’s existing privileges, restore trusted programs and data, and establish a continuous monitoring mechanism.
References:
Case Source:https://51.ruyo.net/19757.html
Official WordPress Security Hardening Documentation:https://developer.wordpress.org/advanced-administration/security/hardening/
WordPress Compromise Response Guide:https://wordpress.org/documentation/article/faq-my-site-was-hacked/
WordPress Release Notes:https://wordpress.org/download/releases/
Official Nginx Location Documentation:https://nginx.org/en/docs/http/ngx_http_core_module.html#location






















