Security 6 min read

Check WordPress for Hacked Files with WP-CLI Checksums

The fastest honest check on a suspect WordPress site is to ask WordPress which files differ from the official release. WP-CLI does it in one command.

By BashPilot Team
BashSecure Malware & vulnerability protection Scan, find and remove malware across every hosted account. Explore BashSecure

When you suspect a WordPress site has been tampered with, the quickest honest check does not need a scanner. WP-CLI can compare every core file against the checksums WordPress.org publishes for that exact version, and tell you which ones differ. It will not tell you what is malware, but it narrows a site with thousands of files down to a short list you can read.

Run the core check

Run WP-CLI as the site's own user rather than as root, and point it at the WordPress directory with --path. That keeps file ownership correct and avoids running code from a possibly compromised site with full privileges.

verify core files for one site
sudo -u USERNAME wp core verify-checksums --path=/home/USERNAME/public_html

A clean site ends with Success: WordPress installation verifies against checksums. A modified file produces a warning naming it, followed by an error that the installation does not verify, for example File doesn't verify against checksum: wp-includes/version.php. Each warning is a file to look at.

Two options solve most surprising results. If the site uses a language other than the default, or your version differs from what you assumed, the WP-CLI documentation says to pass the locale and version shown under Dashboard, then Updates, so the comparison uses the right reference.

compare against a specific version and locale
sudo -u USERNAME wp core version --path=/home/USERNAME/public_html
sudo -u USERNAME wp core verify-checksums --path=/home/USERNAME/public_html --version=6.8 --locale=en_US

Add --include-root to also be warned about files in the site's root directory that are not part of WordPress. Backdoors are often dropped there, next to wp-config.php, with names chosen to look like they belong.

Run the plugin check

verify every installed plugin
sudo -u USERNAME wp plugin verify-checksums --all --path=/home/USERNAME/public_html

WP-CLI verifies plugin files against the checksums published by WordPress.org. A paid or self-hosted plugin is not distributed there, so check each of those separately against a fresh copy from its vendor. By default small changes such as an edited readme.txt are tolerated. Add --strict if you want those reported as errors too.

Decide what each mismatch means

What you findLikely explanationNext step
One core file differs, and it has extra code at the start or endInjected codeRead the file. Treat the site as compromised and look for the backdoor that placed it
Many core files differA wrong version or locale, or a partial updateRe-run with the right --version and --locale before assuming an attack
A plugin file differs from WordPress.orgA local edit, or injected codeDiff it against a clean download of the same version
Plugin cannot be verifiedIt is not distributed through WordPress.orgCompare with a fresh copy from the vendor

For a mismatch you cannot explain, compare the file with a clean copy of the same version, the way the diff method in cPanel Malware Scan False Positive? How to Confirm It does, and look at its modification time against its neighbours.

Check what checksums do not cover

Core and WordPress.org plugin checks leave out the places attackers like best. These short commands fill the gap.

PHP in uploads, administrators, and scheduled events
find /home/USERNAME/public_html/wp-content/uploads -type f -name '*.php'
ls -la /home/USERNAME/public_html/wp-content/mu-plugins
sudo -u USERNAME wp user list --role=administrator --fields=ID,user_login,user_email,user_registered --path=/home/USERNAME/public_html
sudo -u USERNAME wp cron event list --path=/home/USERNAME/public_html

PHP files inside uploads are rarely legitimate, because that folder should only hold media, so treat any you cannot explain as suspicious. The mu-plugins folder loads automatically without appearing in the normal plugin list, so anything unfamiliar there deserves attention. An administrator account you did not create, or a scheduled event with an odd name, are both common ways a compromise keeps its foothold. The full hunt for the entry point is in WordPress Hacked on cPanel? How to Find the Backdoor.

Restore the core files

If core files were altered, replace them from the official release. This leaves wp-content, where your themes, plugins and uploads live, untouched. Be careful with the version: without it the command downloads the latest release, which turns a repair into an unplanned upgrade.

re-download core files for the installed version
cd /home/USERNAME/public_html
sudo -u USERNAME wp core download --force --skip-content --version=$(sudo -u USERNAME wp core version) --locale=en_US

Doing this per site is fine for one suspect. Across a server with dozens of WordPress installs it is slow and easy to skip. BashSecure does the same kind of core comparison for WordPress, Joomla and Drupal against the official release, reports modified files separately from malware findings, and identifies installed plugins with known published vulnerabilities. It also scans file contents rather than trusting names, so a payload saved with an image extension is still examined, and confirmed threats move into reversible quarantine instead of being deleted.

Confirm the result

  • wp core verify-checksums now ends with the Success line.
  • wp plugin verify-checksums --all shows no unexplained differences, and any plugin it cannot verify has been compared with the vendor's copy.
  • The find in uploads returns nothing, the administrator list contains only people you know, and the scheduled events list has no surprises.
  • Passwords for WordPress administrators, the database and the hosting account have been changed, since an attacker who read wp-config.php has those.
Share LinkedIn X
Questions

Frequently asked questions

What does wp core verify-checksums do?

It compares your WordPress core files with the checksums published by WordPress.org for your exact version and reports any file that does not match, for example `File doesn't verify against checksum: wp-includes/version.php`. It does not load WordPress, so it works even if a plugin is broken. It tells you what changed, not whether the change is malicious.

Why does verify-checksums fail on a site I did not hack?

Usual reasons are a locale or version that differs from what the command assumed, a partial update, or a deliberate local edit to a core file. The WP-CLI documentation suggests passing `--locale` and `--version` with the values shown under Dashboard, then Updates. Re-run with those before concluding the site is compromised.

Can WP-CLI check premium or custom plugins?

Not with `wp plugin verify-checksums`. It verifies against the checksums WordPress.org publishes, so a plugin that is not distributed there has no reference to compare with. Download a clean copy from the vendor and compare the files, for instance with `diff -r`.

Is it safe to run WP-CLI on a hacked site?

Run it as the site's own user instead of root, so that nothing from a compromised site runs with full privileges. The checksum command is designed to avoid loading WordPress, which helps. Other WP-CLI commands do load the site, and malicious code in a plugin could run when they do, so be selective.

Will re-downloading WordPress core remove the malware?

Only the part that lives in core files. Backdoors in themes, plugins, `mu-plugins` and the uploads folder survive it, and so does a rogue administrator account or a scheduled event. Replace the core files, then work through the other checks, find the entry point and change every credential.

Put your servers on autopilot.

Connect a server in about a minute. The first week is on us.