Client workWith a senior developer
Cleaning a hacked site when the backup is infected too
- Problem
- Malicious code on a site where core, plugins and the database had not been updated, and the backup was infected as well, so a restore was not an option.
- Fix
- Took a full copy, replaced core with a fresh download, reinstalled every plugin from the official source, removed PHP files from uploads, searched the database for injected scripts and unknown admins, then reset passwords and security keys.
- Security
- MySQL
- WP-CLI
- Malware removal
The approach in code
# Compare core and plugins with the official copies
wp core verify-checksums
wp plugin verify-checksums --all
# PHP has no business in uploads
find wp-content/uploads -type f -name "*.php"
# Admins nobody recognises
wp user list --role=administrator --fields=ID,user_login,user_registered
# Injected scripts in the database
wp db query "SELECT ID, post_title FROM wp_posts
WHERE post_content LIKE '%<script%' OR post_content LIKE '%eval(%'"
# New security keys log everyone out
wp config shuffle-salts Example of the approach, not the client’s original code