WordPress core file integrity: how to detect and repair tampered core files

By TurnUpHosting Web Services LLC · · #wordpress #malware #incident-response

In short: WordPress publishes a checksum for every core file. Comparing against them finds injected code with certainty, and replacing the file fixes it without breaking the site.

Attackers love WordPress core files. Code hidden inside wp-includes or wp-admin runs on every page load, survives theme and plugin changes, and is easy to miss because the file name looks legitimate. The good news: core files are the one part of a WordPress site you can check with complete certainty.

WordPress publishes a fingerprint for every file

For every release, WordPress.org publishes an MD5 checksum of each core file through its checksums API (api.wordpress.org/core/checksums/1.0/). If a file in wp-admin, wp-includes or the root (wp-login.php, wp-settings.php, ...) doesn't match the checksum for your version, it has been changed, whether by an attacker, a careless edit or a failed update.

Your own content lives in wp-content (themes, plugins, uploads), which has no official checksums and needs a malware scanner instead.

Checking by hand with WP-CLI

wp core verify-checksums

It lists every core file that differs from the official release and any unexpected files in core folders. Plugins from WordPress.org can be checked the same way with wp plugin verify-checksums --all.

Repairing safely

  1. Keep a copy of each modified file before you touch it; it's evidence, and you may need to compare.
  2. Replace with the official copy for your exact version: wp core download --version=X.Y.Z --skip-content --force reinstalls core without touching wp-content or wp-config.php.
  3. Look for the way in. A modified core file means the attacker could write to the site. Check plugins, themes, admin users, cron jobs and credentials, and fix the vulnerability, or the change will come back.
  4. Check unexpected files. PHP files in wp-includes or wp-admin that aren't part of the release are almost always malicious.

Why replacing beats quarantining here

Quarantining a malicious upload is harmless: the site never needed it. Quarantining an infected wp-includes/load.php takes the whole site down. For core files the right fix is to put the official copy back, which removes the injected code and keeps the site running.

Doing it automatically

TurnUpSecurity Shield checks every WordPress install on a server against the official checksums on each full scan. Modified core files are replaced with the official copy (verified against the checksum before it's used), the infected version is kept in quarantine so nothing is lost, and the change is reported in the console and the customer's dashboard.