A WordPress homepage replaced by “Hacked by XYZ Team” or a pro-political banner is dramatic but rarely the worst case. Defacement is the visible symptom; the attacker who replaced the homepage also dropped a backdoor file somewhere in the install. The cleanup that “fixes” the defacement by overwriting index.php and goes back to bed is the same site that gets defaced again 48 hours later because the backdoor is still there. The recovery below removes both the defacement and the persistence.
What’s happening
A defacement attack on WordPress typically arrives through one of three vectors: an admin account compromise (credentials brute-forced or stolen, attacker logs in and edits the homepage post or the theme), a plugin or theme vulnerability that allowed arbitrary file write (attacker overwrites wp-content/themes/active-theme/index.php or drops a new file), or a server-level compromise that gave file system access outside WordPress (attacker overwrites index.php at the document root). Each vector leaves different artifacts and requires different cleanup.
The artifact you always find: a backdoor file. The attacker who got in once will get in again unless you remove the way back. The defacement is bait — it draws attention to one file while the actual persistence is in a different location.
How to verify
Confirm the defacement scope before cleaning:
# What does the homepage actually serve - is it the homepage or every page?
curl -s https://example.com/ | head -20
curl -s https://example.com/about/ | head -20
curl -s https://example.com/wp-json/ | head -5
# Find recently-modified files
find /var/www/html -name "*.php" -mtime -3 -ls
# Find recently-modified HTML files in the doc root
find /var/www/html -maxdepth 2 -name "*.html" -mtime -3 -ls
# Compare core file checksums
wp core verify-checksums 2>&1 | head
# Compare theme files (if the theme is in WordPress.org directory)
wp theme verify-checksums --all 2>&1 | head
# Look at the actual content of the defaced page
curl -s https://example.com/ > /tmp/defaced.html
file /tmp/defaced.html
grep -oE '<title>[^<]+</title>' /tmp/defaced.html
The location of the defacement tells you the vector:
- Homepage replaced but other pages normal → likely a homepage post or page replacement, attacker had admin access.
- All pages show the defacement → theme template was replaced.
index.htmlexists at doc root and is being served beforeindex.php→ server-level access, attacker dropped a static file.- Defacement is in the database, not the files → admin compromise, attacker edited content via the editor.
The fix
Run the 60-minute IR playbook first if you have not already (separate KB). Then proceed with the defacement-specific cleanup.
-
Preserve evidence before cleaning. The 60-minute playbook covers this; restate to make sure. Snapshot the database, the filesystem, the access logs. Store them off the compromised server. The temptation to “just fix it fast” is highest with a visible defacement — resist for ten minutes while you preserve.
-
Identify the backdoor before removing the defacement. Search the install for common backdoor signatures:
# PHP files in directories that should not contain them find /var/www/html/wp-content/uploads -name "*.php" -ls # PHP files with random or suspicious names find /var/www/html -name "*.php" -size +50k -ls find /var/www/html -name "*.php" -ls | awk '{print $11}' | grep -E '/[a-f0-9]{8,}\.php$|/(wp-[a-z]{4,})\.php$' # Obfuscated payloads grep -rE 'eval\(base64_decode|eval\(gzinflate|eval\(str_rot13|preg_replace.*/e' \ /var/www/html --include='*.php' -l 2>/dev/null # Files using these PHP functions are usually attackers grep -rlE '(eval|assert)\(\$_(POST|GET|REQUEST|COOKIE)' \ /var/www/html --include='*.php' 2>/dev/null # Recently-modified .htaccess files (attackers use these for redirects) find /var/www/html -name ".htaccess" -mtime -7 -lsList every suspicious file. Do not delete yet — review each. A
eval()in a legitimate plugin is rare but possible (older WooCommerce had some); confirm before removing. -
Identify the entry point. Cross-reference the file modification times with the access logs:
# Get the timestamp of the earliest modified file stat -c '%y %n' /var/www/html/index.php # Find what was happening in the access log around that time awk '$4 ~ /\[15\/Mar\/2026:14:[23]/' access.log | \ awk '{print $1, $7, $9}' | sort | uniq -c | sort -rn | head -20The IP that hit unusual paths (the vulnerable plugin’s admin endpoint, an upload endpoint, a known exploit URL) just before the file modification is the attacker. Their user-agent and the path they exploited tell you which vulnerability you need to patch.
-
Remove the backdoor and the defacement. Now that you have the entry point identified:
# Remove the backdoor files identified in step 2 rm /var/www/html/wp-content/uploads/random-shell.php # Restore the defaced files from core wp core download --force # Restore the defaced theme template # If theme is from WordPress.org: wp theme install <theme-slug> --force # If theme is custom: # Restore from version control or a known-clean backup # Restore any defaced posts/pages wp post update <id> --post_content="<original content>" -
Rotate every secret. Even if you did not find admin compromise, rotate as if you did:
# WordPress salts in wp-config.php wp config shuffle-salts # All user passwords (admin first) wp user list --role=administrator --field=ID | xargs -I {} wp user reset-password {} --skip-email # Application passwords for all users wp db query "DELETE FROM wp_usermeta WHERE meta_key = '_application_passwords';" # Database user password (if you control the DB credentials) # Update via MySQL, then wp config set DB_PASSWORD -
Patch the entry point. If a vulnerable plugin was exploited:
wp plugin update vulnerable-plugin --version=fixed-version wp plugin verify-checksums vulnerable-pluginIf a theme was the entry point, the same — update or replace. If the entry was a credential compromise (admin password guessed or stolen), the rotation in step 5 closes that loop; add 2FA enforcement before you reopen.
-
Verify the cleanup before going public. Run the same searches from step 2. Zero hits is the goal. Restore from a clean snapshot if you find more backdoors after the first pass — at some point, surgical cleanup costs more than rebuild.
-
Reopen with monitoring tightened. When the WAF unblocks and the site goes live again:
- File integrity monitoring on a daily schedule for the next two weeks.
- WAF rate-limiting tightened on the entry point.
- Audit log alerts on every administrator login for the next two weeks.
The attacker who got in once may try again with stored credentials, with knowledge of which plugins are vulnerable, or with the backdoor they think is still there.
A defacement that is cleaned up correctly does not return. A defacement that is cleaned up by overwriting the visible damage returns within 48 hours. Stack Harbor runs the defacement cleanup as part of managed enterprise WordPress hosting incident response, including the post-incident hardening pass and the two-week heightened monitoring. If your WordPress site has just been defaced or has been defaced more than once in the last quarter, book the cleanup and rebuild.