WordPress Malware Scan Over SSH: WP-CLI Checksums, find and grep Commands, and a Daily Scan Script

By Information Security Asia · November 28, 2026 · 7 min read

Short answer: with SSH access, run wp core verify-checksums and wp plugin verify-checksums --all to find modified or unexpected core and plugin files, then use find to list PHP files in uploads and recently changed files, grep to search for obfuscation patterns such as eval( and base64_decode(, and WP-CLI to list administrators, cron events and suspicious database content. Command-line scanning is faster and harder for malware to hide from than dashboard plugins.

When we cleaned our own compromised WordPress site in November 2026, command-line checks found the malicious files in wp-content/mu-plugins quickly. Security plugins running inside WordPress can be disabled or fooled by malware that loads first, so scanning from the server is a valuable second line. Run these commands from the WordPress root directory, as the site’s user rather than root where possible.

How to Scan WordPress for Malware From the Command Line

1. Verify core files

wp core verify-checksums compares every WordPress core file with official checksums from WordPress.org for your version. It reports files that were modified, and files in wp-admin and wp-includes that should not exist. Any warning deserves investigation. To replace core files without touching your content, run wp core download --force --skip-content.

2. Verify plugins

wp plugin verify-checksums --all does the same for plugins hosted on WordPress.org. Premium and custom plugins are skipped because no public checksums exist; for those, compare with a fresh download from the vendor. List plugins with wp plugin list and look for unfamiliar names, and wp plugin list --status=must-use plus ls -la wp-content/mu-plugins for must-use plugins.

3. Find PHP files in uploads

The uploads folder should contain media, not code. Run find wp-content/uploads -type f \( -name "*.php" -o -name "*.phtml" -o -name "*.phar" \). Any result is suspicious unless a known plugin documents it.

4. List recently modified files

find . -type f -mtime -7 -printf '%TY-%Tm-%Td %TH:%TM %p\n' | sort shows files changed in the last seven days. Change the number for a different window. Attackers can fake modification times, so also try -ctime, which records when file metadata changed and is harder to forge.

5. Search for suspicious code patterns

A starting search: grep -rnE --include=*.php "eval\(|base64_decode\(|gzinflate\(|str_rot13\(|assert\(|shell_exec\(|create_function" wp-content. Legitimate plugins sometimes use these functions, so review results in context. Malicious code tends to combine them with long encoded strings, variable function names or request parameters (for example, executing data from $_POST or $_COOKIE). Also search for unfamiliar external domains.

6. Check configuration files

Inspect wp-config.php, .htaccess and any .user.ini or php.ini files for unexpected includes, auto_prepend_file directives and redirect rules. Find stray .htaccess files with find . -name ".htaccess".

How to Scan WordPress for Malware From the Command Line

7. Review users and sessions

wp user list --role=administrator --fields=ID,user_login,user_email,user_registered lists admins. Compare with what you expect; malware sometimes hides users from the dashboard. Check application passwords with wp user application-password list <user>.

8. Check cron

wp cron event list shows scheduled WordPress events; look for unfamiliar hooks. Check the server’s crontab (crontab -l for the site user) and your hosting panel’s cron page for jobs that download or execute files.

9. Search the database

Use wp db search '<script' --all-tables and similar searches for eval(, iframe or unfamiliar domains. Check wp option get siteurl and wp option get home. Review the options table for unusually large autoloaded entries.

After scanning

If you find malware, back up the infected state, remove malicious files, replace core, plugins and themes with fresh copies, clean the database, change all passwords and salts, and fix the entry point. See how we cleaned a hacked WordPress site and our malware removal checklist.

Automate the basics

Running these commands once is useful; running them every day is far better. A simple shell script scheduled with cron (or your hosting panel’s cron feature) can run the core and plugin checksum commands, list PHP files in uploads and files changed in the last 24 hours, count administrator accounts, and email you the output. Keep the script outside the web root so it cannot be reached from a browser, and have it write results to a log you review. If the output suddenly shows new files in mu-plugins, a new administrator or checksum failures you did not cause with an update, you will know within a day instead of discovering the problem weeks later through a Google warning or angry visitors.

Command cheat sheet: what each check catches

Command Catches Misses
wp core verify-checksums --include-root Changed core files, extra files in wp-admin and wp-includes, and (with --include-root) unknown files in the site root Anything in wp-content
wp plugin verify-checksums --all Changed or added files in WordPress.org plugins Premium, custom and must-use plugins, and all themes
find wp-content/uploads -name "*.php" Web shells dropped into media folders Code hidden in image files or in the database
find . -ctime -7 Recently written files, even if the attacker faked the modification time Changes older than the time window
grep for eval/base64 Common obfuscation in themes and custom plugins Heavily encoded or split-up code, and many false positives
wp db search Injected scripts and iframes in posts and options Encoded payloads that don’t contain your search terms

No single command covers everything, which is why you run them together. Themes have no public checksum command. Compare a theme with a fresh copy from WordPress.org or the vendor using diff -r, or just reinstall it after cleaning.

Reading the output

wp core verify-checksums prints “Success: WordPress installation verifies against checksums.” when every core file matches. Any line saying “File doesn’t verify against checksum” names a changed core file. “File should not exist” names an extra file in wp-admin or wp-includes, a common hiding place for backdoors such as a fake wp-includes/class-wp-*.php. With --include-root, extra files in the root folder show up as warnings. Your own files (a robots.txt, a Google verification file, an .htaccess) will show up too, so list what you expect before you panic.

For plugins, the summary line shows how many plugins verified and how many failed or were skipped. A skipped plugin usually just isn’t hosted on WordPress.org. A failed one has altered files and should be reinstalled with wp plugin install <slug> --force once you’ve saved a copy for investigation.

Add a signature scanner

Pattern searches find suspicious code. A signature scanner adds known-malware detection. ClamAV is a free, open-source antivirus engine that many Linux hosts already include. Run freshclam to update signatures, then clamscan -ri --exclude-dir=cache wp-content for a recursive scan that lists only infected files. ClamAV catches well-known web shells and mailers but misses a lot of custom PHP malware. Treat a clean result as one data point, not a clean bill of health.

A minimal daily scan script

Save this outside the web root, for example as ~/bin/wp-scan.sh, make it executable and schedule it with cron:

#!/bin/bash
cd /path/to/wordpress || exit 1
echo "== Core ==";     wp core verify-checksums --include-root 2>&1
echo "== Plugins ==";  wp plugin verify-checksums --all 2>&1 | tail -n 5
echo "== PHP in uploads =="; find wp-content/uploads -type f -name "*.php"
echo "== mu-plugins ==";     ls -la wp-content/mu-plugins 2>/dev/null
echo "== Changed in 24h =="; find . -type f -ctime -1 -not -path "./wp-content/cache/*"
echo "== Admins ==";   wp user list --role=administrator --field=user_login

A crontab line such as 15 3 * * * ~/bin/wp-scan.sh | mail -s "WP scan" [email protected] sends the report each night, as long as the server can send mail. You can also send the output to a log file and compare it with yesterday’s using diff. After the first few days you’ll know what “normal” looks like, and any change will stand out.

Frequently asked questions

Do I need root access?

No. Most commands work as the site’s user. Root helps for server-wide cron and log checks.

Can I run WP-CLI from aaPanel or cPanel?

Yes, through the panel’s terminal if available, or via SSH.

Will grep find all malware?

No. Heavily obfuscated code may evade simple patterns, which is why checksums and file-change checks matter too.

How often should I run these checks?

Automate checksums and recent-file checks daily, and run a full manual scan after any suspicious event.

Sources

Keep reading