WordPress malware investigationCommands by symptom

Find the symptom, replicate it, trace it to where it lives, clean with permission, then retest the same way. Every block except the cleanup template only reads and changes nothing.

Fills the domain into every command.

The approach is the same for every case

  1. Get a first point of contact: something concrete you can see or test.
  2. Replicate it yourself, so you have a “before” picture.
  3. Trace it to the exact location: a file, a database row, a user, or a cron job.
  4. Clean it with permission, taking a backup first.
  5. 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.

  1. Go to the site folder and confirm it

    cd ~/domains/example.com/public_html
    wp option get siteurl
  2. Set 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

Signs
Visitors are sent to ad or scam sites, or new tabs open. Often mobile-only or intermittent, and the scanner is often clean.
Ask the customer
Which browser, typed address or Google, every time or sometimes, the URLs that open, and a video.
  1. 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\('
  2. 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 -u
  3. If 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'
  4. Find where the unknown domain is stored

    wp db search 'bad-domain' --all-tables
    grep -rl 'bad-domain' wp-content/ .htaccess 2>/dev/null
  5. Check 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'
  6. 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

Signs
Google shows spam titles (Japanese, pharma, casino) for the site, or there are pages the customer never made, but the site looks normal to them.
Ask the customer
A screenshot of the Google results and any Search Console “Security issues” warning.
  1. In Google, search the site to see what is indexed

    site:example.com
  2. See 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"
  3. Compare with a normal visitor (different output means cloaking)

    curl -s "https://example.com/spam-url-from-google" | head -100
  4. Look 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 --regex
  5. Look 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'
  6. 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

Signs
The homepage shows a hacker message or a blank page, or index.php is missing or altered.
  1. Compare core and plugin files to the official copies

    wp core verify-checksums
    wp plugin verify-checksums --all
  2. Look at index.php directly

    ls -la index.php
    head -30 index.php
  3. Recently changed files

    find . -type f -mtime -7 -not -path "./wp-content/cache/*" -ls | head -50
  4. Extra 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

Signs
The customer, the scanner, or the admin panel shows users or files nobody recognises.
  1. All admins, with emails and creation dates

    wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
  2. Hidden 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%';"
  3. PHP files in uploads (almost always malicious)

    find wp-content/uploads -name "*.php" -ls
  4. Plugins 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

Signs
Malware keeps coming back, the scanner flags obfuscated PHP, or there are files with random names.
  1. 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/null
  2. Files changed after wp-config.php was last touched

    find . -name "*.php" -newer wp-config.php -not -path "./wp-content/cache/*" -ls
  3. Odd 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 icons
  4. Code 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

Signs
The site was clean, then the malware came back hours or days later.
  1. Scheduled tasks that might re-add the code

    crontab -l
    wp cron event list --fields=hook,next_run_relative,recurrence
  2. Access that survived the cleanup

    wp user list --role=administrator --fields=ID,user_login,user_email,user_registered
    cat ~/.ssh/authorized_keys 2>/dev/null
  3. Backdoors

    # Run the Backdoors and webshells checks again
  4. Outdated 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_version
  5. Other 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

Signs
Bounce messages, a blocklist notice, or the customer's mail being rejected.
  1. Scripts that send mail

    grep -rlE 'mail\(|wp_mail\(|PHPMailer' --include=*.php wp-content/uploads wp-content/themes 2>/dev/null
  2. Recently added PHP files (mailers are often new, random-named files)

    find . -name "*.php" -mtime -7 -not -path "./wp-content/cache/*" -ls
  3. Contact 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)

Signs
The server is slow or resource limits keep being hit, with no traffic spike to explain it.
  1. What's using CPU right now

    ps aux --sort=-%cpu | head -15
  2. Files 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 | head
  3. Scheduled 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.

  1. Back up first, always

    wp db export ~/backup_before_cleanup_$(date +%F).sql
    wp option get <option_name> --format=json > ~/backup_<option_name>.json
  2. Remove injected code from an option

    wp option patch update <option_name> <key> ''
  3. Reinstall a plugin from a clean copy (keeps its settings)

    wp plugin install <plugin-slug> --force
  4. Reinstall core files without touching content

    wp core download --force --skip-content
  5. Flush caches

    wp cache flush
    wp litespeed-purge all     # only if LiteSpeed Cache is installed
  6. Log out every session (warn the customer first)

    wp config shuffle-salts

Close-out

Every scenario ends here.

  1. RetestUse the same method you replicated with and report the result.
  2. Customer securesHostinger account (+2FA), account email, FTP/SFTP/SSH, WP/CMS admin, and database credentials.
  3. Revoke other accessReview every WP admin on every site, and check SSH key changes and cron jobs.
  4. UpdatesUpdate vulnerable plugins and themes. Other site types: follow the scanner’s recommended steps.