The approach is the same for every case
- Get a first point of contact: something concrete you can see or test.
- Replicate it yourself, so you have a “before” picture.
- Trace it to the exact location: a file, a database row, a user, or a cron job.
- Clean it with permission, taking a backup first.
- Retest the same way you replicated it.
Keep in mind: a clean curl result doesn’t prove the site is clean, since some malware only fires for Google visitors, first visits, certain countries, or after a tap. Broad patterns like eval and atob also appear in legitimate plugins, so treat a hit as a lead, not proof. An unknown domain is a much stronger signal.
Before any case
Run these first on every case. WP-CLI acts on whatever site is in your current folder, so confirm you are on the right one.
Go to the site folder and confirm it
cd ~/domains/example.com/public_html wp option get siteurlSet the mobile user agent used in later blocks
UA='Mozilla/5.0 (Linux; Android 14; SM-S918B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Mobile Safari/537.36'
Redirects and pop-ups
See the page as an anonymous mobile visitor (no login cookies)
curl -s -L -A "$UA" "https://example.com/?nc=$RANDOM" \ | grep -oiE '<script[^>]*src=[^>]*>|window\.open|location\.(href|replace)|atob\(|fromCharCode|eval\('List external script domains and look for one you don't recognise
curl -s -L -A "$UA" "https://example.com/?nc=$RANDOM" \ | grep -oiE 'src=["'\'']https?://[^/"'\'']+' | sed -E 's/.*:\/\///' | sort -uIf it only happens from Google, add a referrer
curl -s -L -A "$UA" -e "https://www.google.com/" "https://example.com/?nc=$RANDOM" | grep -i 'script'Find where the unknown domain is stored
wp db search 'bad-domain' --all-tables grep -rl 'bad-domain' wp-content/ .htaccess 2>/dev/nullCheck common injection spots
wp option list --search='*header*' --fields=option_name wp option list --search='*footer*' --fields=option_name wp option list --search='*custom*js*' --fields=option_name cat .htaccess | grep -iE 'Rewrite|http'Read the bad script as text (never open it in your browser)
curl -s -A "$UA" "https://bad-domain/path.js" | head -c 3000
Retest: Rerun the first command several times and check DevTools mobile emulation in incognito. The bad domain should no longer appear.
SEO / Japanese keyword spam
In Google, search the site to see what is indexed
site:example.comSee the site as Googlebot (spam is often shown only to Google)
curl -s -A "Googlebot/2.1 (+http://www.google.com/bot.html)" "https://example.com/" | head -100 curl -s -A "Googlebot/2.1 (+http://www.google.com/bot.html)" "https://example.com/spam-url-from-google"Compare with a normal visitor (different output means cloaking)
curl -s "https://example.com/spam-url-from-google" | head -100Look for spam posts and pages
wp post list --post_type=any --post_status=any --orderby=date --order=DESC \ --posts_per_page=30 --fields=ID,post_type,post_title,post_date wp db search 'viagra|casino|slot|コピー|激安' --all-tables --regexLook for bot-targeting rules and spam generator files
grep -iE 'googlebot|bing|RewriteCond.*HTTP_USER_AGENT' .htaccess find . -name "*.php" -mtime -14 -not -path "./wp-content/cache/*" -ls ls -la | grep -vE 'wp-|index.php|\.htaccess|license|readme'Check for a sitemap planted by the attacker
ls -la *.xml 2>/dev/null
Retest: Rerun the Googlebot fetch; it should match the normal visitor view. The customer then requests a review in Search Console. Old spam URLs take time to drop out of Google, so tell the customer.
Defaced site, missing or changed index.php
Compare core and plugin files to the official copies
wp core verify-checksums wp plugin verify-checksums --allLook at index.php directly
ls -la index.php head -30 index.phpRecently changed files
find . -type f -mtime -7 -not -path "./wp-content/cache/*" -ls | head -50Extra index files that shouldn't be there
find . -maxdepth 2 -name "index.*" -ls
Retest: Open the site in incognito and rerun wp core verify-checksums, which should report success.
Unknown admin users or unknown files
All admins, with emails and creation dates
wp user list --role=administrator --fields=ID,user_login,user_email,user_registeredHidden admins (role granted directly in the database)
wp db query "SELECT user_id, meta_value FROM $(wp db prefix)usermeta WHERE meta_key='$(wp db prefix)capabilities' AND meta_value LIKE '%administrator%';"PHP files in uploads (almost always malicious)
find wp-content/uploads -name "*.php" -lsPlugins nobody installed, or must-use plugins (often hidden)
wp plugin list --fields=name,status,version ls -la wp-content/mu-plugins/ 2>/dev/null
Next: Confirm each user and file with the customer before removing anything. Unknown admins mean the attacker may have left more behind, so also run the backdoor and reinfection checks.
Backdoors and webshells
Common obfuscation patterns in PHP (check each hit; some plugins use these legitimately)
grep -rlE 'eval\(base64_decode|eval\(gzinflate|gzinflate\(base64|str_rot13\(|assert\(\$_(POST|GET|REQUEST)|preg_replace\(.*/e' \ --include=*.php . 2>/dev/nullFiles changed after wp-config.php was last touched
find . -name "*.php" -newer wp-config.php -not -path "./wp-content/cache/*" -lsOdd file names and locations
find . -name "*.php" -path "*/uploads/*" -ls find . -name ".*.php" -ls # hidden PHP files find . -name "*.ico" -size +10k -ls # PHP disguised as iconsCode added to wp-config.php or the theme's functions.php
head -20 wp-config.php grep -nE 'eval|base64|include.*\$' wp-content/themes/*/functions.php
Next: Compare suspicious files to a clean copy of the same plugin or theme. If you're unsure, offer the backup restore or paid cleanup from the flow rather than guessing.
Reinfection after cleaning
Scheduled tasks that might re-add the code
crontab -l wp cron event list --fields=hook,next_run_relative,recurrenceAccess that survived the cleanup
wp user list --role=administrator --fields=ID,user_login,user_email,user_registered cat ~/.ssh/authorized_keys 2>/dev/nullBackdoors
# Run the Backdoors and webshells checks againOutdated or vulnerable plugins (the likely entry point)
wp plugin list --update=available --fields=name,version,update_version wp theme list --update=available --fields=name,version,update_versionOther sites on the same account (one infected site can reinfect the others)
ls ~/domains/
Next: Follow the close-out: the customer changes every password and turns on 2FA, you remove unknown access, and the customer updates or replaces vulnerable plugins.
Spam emails sent from the account
Scripts that send mail
grep -rlE 'mail\(|wp_mail\(|PHPMailer' --include=*.php wp-content/uploads wp-content/themes 2>/dev/nullRecently added PHP files (mailers are often new, random-named files)
find . -name "*.php" -mtime -7 -not -path "./wp-content/cache/*" -lsContact forms that could be abused
wp plugin list --fields=name,status,version | grep -iE 'form|contact'
Also check: The email sending logs in hPanel, and whether any email account password needs changing.
High CPU or slow server (possible cryptominer)
What's using CPU right now
ps aux --sort=-%cpu | head -15Files in temporary and odd folders
ls -la /tmp ~/tmp 2>/dev/null find ~ -type f -perm -u+x -mtime -7 -not -path "*/node_modules/*" -ls 2>/dev/null | headScheduled tasks that restart the process
crontab -l
Cleanup template
These change data. Take a backup and get the customer's approval first. Adapt each one to where you actually found the problem.
Back up first, always
wp db export ~/backup_before_cleanup_$(date +%F).sql wp option get <option_name> --format=json > ~/backup_<option_name>.jsonRemove injected code from an option
wp option patch update <option_name> <key> ''Reinstall a plugin from a clean copy (keeps its settings)
wp plugin install <plugin-slug> --forceReinstall core files without touching content
wp core download --force --skip-contentFlush caches
wp cache flush wp litespeed-purge all # only if LiteSpeed Cache is installedLog out every session (warn the customer first)
wp config shuffle-salts
Close-out
Every scenario ends here.
- RetestUse the same method you replicated with and report the result.
- Customer securesHostinger account (+2FA), account email, FTP/SFTP/SSH, WP/CMS admin, and database credentials.
- Revoke other accessReview every WP admin on every site, and check SSH key changes and cron jobs.
- UpdatesUpdate vulnerable plugins and themes. Other site types: follow the scanner’s recommended steps.