Web & servers
Hacked website triage for WordPress and PHP sites
Hacked website triage for WordPress and PHP: snapshot first, read the access logs, hunt webshells, check admins and cron, rotate keys, then rebuild or clean.
Your WordPress site is redirecting visitors to a pharmacy, Google has flagged it, or the host has suspended it for sending spam. This is hacked website triage in an order that avoids the usual mistake: cleaning up first and finding out how they got in afterwards, or never.
Hacked website triage starts with a snapshot
Before you update a plugin, restore a backup or delete a single file, copy everything as it is. Updating a vulnerable plugin overwrites the exact files that would have shown you the entry point. Deleting the obvious webshell removes the filename you were going to search the logs for.
If your host offers snapshots, take one. Otherwise, from a shell:
mkdir -p /root/ir
tar -czpf /root/ir/site-$(date +%F).tar.gz /var/www/example.com
mysqldump --single-transaction -u root -p wordpress > /root/ir/db-$(date +%F).sql
find /var/www/example.com -type f -printf '%TY-%Tm-%Td %TT %C+ %p\n' > /root/ir/file-times.txt
Copy the web server logs as well: /var/log/nginx/ or /var/log/apache2/ on your own server, the access-logs directory on a cPanel host. Logrotate compresses and eventually deletes old logs on its normal schedule, and the oldest days are often the ones you need. Get the copies off the server.
What the access logs can tell you
The logs answer two questions: when the attacker first got code onto the site, and what they did just before that. Start broad:
zgrep -h '"POST ' access.log* | awk '{print $7}' | sort | uniq -c | sort -rn | head -50
zgrep -h 'wp-content/uploads/.*\.php' access.log*
Thousands of POSTs to wp-login.php or xmlrpc.php mean someone was guessing passwords. POSTs to admin-ajax.php with an unusual action parameter, or straight to a file inside a plugin directory, often point at a vulnerable plugin. Any request at all to a PHP file under uploads is a webshell being used.
Once you have a suspicious filename, find its first appearance in the logs. That gives you a timestamp and usually an IP address. Pull every request from that address, and everything in the few minutes before the shell appeared, and read them in order. The entry point is usually sitting right there.
Where webshells and injected code hide
WordPress has no reason to execute PHP from the uploads directory, so start there:
find wp-content/uploads -type f \( -iname '*.php*' -o -iname '*.phtml' -o -iname '*.phar' \)
find . -type f -name '*.php' -ctime -30
grep -rlE 'eval\(|base64_decode\(|gzinflate\(|str_rot13\(|assert\(' --include='*.php' .
The second command uses change time rather than modification time on purpose. Attackers routinely backdate modification times so their files blend in, and ctime is much harder to fake without root. The grep will be noisy, because legitimate plugins call base64_decode constantly. Treat its output as a reading list, not a verdict.
WP-CLI will tell you which core and plugin files differ from the published versions:
wp core verify-checksums
wp plugin verify-checksums --all
Plugin checksums only exist for plugins from the WordPress.org directory, so premium plugins and your theme need a manual comparison against a clean download. Then check the places people forget:
wp-content/mu-plugins/, which loads automatically and doesn’t show up in the normal plugin list..htaccessand.user.iniin every directory, for redirects keyed on search-engine referrers and forauto_prepend_file.- The first and last lines of
wp-config.php, the theme’sfunctions.phpand the rootindex.php. - The database:
siteurlandhomeinwp_options, widget content, and<script>tags injected intowp_posts.
Field note: Plenty of injected redirects fire only for visitors who arrive from a search engine, on a phone, for the first time. “The site looks fine when I open it” proves nothing. Test with a clean browser profile, a mobile user agent and a search referrer, or better, read the code.
Admin users, scheduled tasks and the server itself
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
wp cron event list
crontab -l -u www-data
cat /etc/cron.d/* /root/.ssh/authorized_keys /home/*/.ssh/authorized_keys
ps -u www-data -f
An administrator you don’t recognize, or one registered on the day the shell appeared, is a backdoor. So is a WordPress cron hook with a random-looking name. At the server level, look for cron entries that download and run something, SSH keys nobody can account for, and processes running as the web user that aren’t PHP-FPM or Apache. Crypto miners and reverse shells tend to show up in that last list.
If you find changes outside the web root (root’s crontab, new system users, altered binaries), this is no longer a WordPress problem. It’s a server compromise, and the server gets rebuilt. On shared hosting, check every other site in the same account. One infected site there usually means all of them.
Rotate the secrets, at the right moment
Assume the attacker read wp-config.php. That covers the database password, the authentication keys and salts, and anything else in that file or in an .env. They may also have read API keys stored in plugin settings: payment gateway, SMTP relay, CRM, backup service.
Rotate all of it, along with every administrator password and the hosting panel, SFTP and SSH credentials. wp config shuffle-salts replaces the keys and salts and logs everyone out. Timing matters here. Rotate after the site is clean or rebuilt. Rotating while a webshell is still in place just hands the attacker the new values.
Rebuild or clean in place?
Both are legitimate choices. What decides it is how confident you can be that you’ve found everything.
| Factor | Cleaning in place is reasonable | Rebuild |
|---|---|---|
| Entry point | Identified and fixed, such as a specific plugin version | Unknown |
| Depth | Limited to WordPress files and the database | Shell commands run, cron or SSH keys changed, root involved |
| Time on site | Days, with logs covering the whole period | Weeks, months, or unknown |
| Clean source | Heavily customized theme with no clean copy anywhere | Theme in version control, plugins from official sources |
| What the site handles | Brochure content | Customer logins, orders or payment pages |
A rebuild means a fresh server or container, current WordPress core, plugins downloaded again from their source, and the theme from version control. Bring content across, not code: export the database and review users, options and posts for injected content before importing, and copy uploads through a filter that lets only media file types pass. Then rotate credentials and switch DNS.
The WordPress project’s own “My site was hacked” FAQ is a sensible checklist to run alongside this one. Outdated and vulnerable components have featured on the OWASP Top 10 for years, and the plugin nobody remembers installing is the WordPress version of that problem.
After the site is back
Watch it closely for a while. File integrity monitoring on the web root, an alert on new administrator accounts, and a daily look at the access log for the first couple of weeks will tell you whether you missed something. If Google flagged the site, request a review in Search Console once you’re confident it’s clean.
If the site held customer accounts or orders, the database contents may make this a personal data breach, with deadlines attached; see breach notification timelines across jurisdictions. Keep the snapshot and log copies you made at the start, and handle them carefully, as described in preserving evidence without slowing recovery.
If the site is still serving malware, or you can’t tell how deep the compromise goes, take the snapshot, stop changing things, and send us the details through the incident report page. Our website and server compromise response works from the copies while the live site stays in maintenance mode, so the evidence and the fix don’t compete.
Dealing with this right now?
A responder will acknowledge your report within 15 minutes, 24/7.
Related service: Website & Server Compromise