A customer’s mail starts being redirected to a server you don’t recognize. The MX record was changed three hours ago. The change came from a legitimate cPanel API call, signed with a token. The token was on a developer’s laptop that got compromised last week, and the attacker used it to point the MX at their own server to harvest mail. The DNS layer didn’t fail — it did exactly what it was asked. The failure is that nobody monitored for unauthorized changes until users complained.
What’s happening
DNS records on a cPanel host can be changed via:
- cPanel/WHM web UI (with login).
whmapi1API (with token).- Direct edits to
/var/named/*.db(with root). - Cluster sync from a peer.
Any of these can be misused if the credential or root access is compromised. cPanel logs UI logins (/usr/local/cpanel/logs/login_log) and API calls (/usr/local/cpanel/logs/access_log), but the records change without a separate “DNS edit” alarm. A change made via legitimate API looks indistinguishable from a customer adding a record.
Without monitoring, the first signal is a user-visible failure. By the time someone notices, the attacker has had hours of mail interception or DNS-based phishing.
How to verify
Snapshot the zone periodically and diff:
# at scheduled intervals (e.g., every 15 minutes)
mkdir -p /var/local/zone-snapshots/$(date +%Y%m%d-%H%M)
for zone in $(whmapi1 list_zones --output=jsonpretty | jq -r '.data.zone[]'); do
whmapi1 dumpzone domain=$zone --output=jsonpretty > /var/local/zone-snapshots/$(date +%Y%m%d-%H%M)/$zone.json
done
# compare against the previous snapshot
last=$(ls /var/local/zone-snapshots/ | tail -2 | head -1)
prev=$(ls /var/local/zone-snapshots/ | tail -2 | tail -1)
for zone in /var/local/zone-snapshots/$last/*.json; do
diff -q $zone /var/local/zone-snapshots/$prev/$(basename $zone)
done
A diff for a zone you didn’t expect to change is worth investigating.
Cross-check with the API access log:
grep -E 'addzonerecord|editzonerecord|removezonerecord' /usr/local/cpanel/logs/access_log
This shows who called the API and from where. An IP you don’t recognize is a flag.
For high-value zones (apex MX, NS, DKIM at well-known selectors), monitor externally too:
dig +short MX example.com @1.1.1.1
Compare against a known-good value. If it differs, alert.
What to do
- Snapshot zones every 15 minutes via cron. Keep snapshots for at least 30 days for forensic value. The disk cost is low; the diagnostic value is high.
- Run a diff job that compares each snapshot to the previous. Alert on differences. Most changes are legitimate (customer added a record); the few that aren’t, you’ll catch.
- For critical records (MX, NS, A at apex, DKIM), monitor externally too. Use a service like Pingdom, UptimeRobot, or a custom check from an off-host VM. Alert if the record changes unexpectedly.
- Audit API token usage weekly. Any token that’s been used from an unexpected IP, or hasn’t been used in 30 days (so could be revoked), gets reviewed:
whmapi1 api_token_list
grep TOKEN_NAME /usr/local/cpanel/logs/access_log | awk '{print $1}' | sort -u
- Scope API tokens narrowly. A token for a deployment script doesn’t need DNS scope; a token for a DNS automation doesn’t need account-management scope. If a token gets compromised, the blast radius is the scope it had.
- Rotate tokens quarterly. Even if not compromised, fresh tokens limit how long any leak gives access.
- For root-level direct edits to
/var/named/, log them withauditdor a file-integrity tool (AIDE,tripwire). Manualviedits don’t show in cPanel’s API log; only a filesystem audit catches them. - Set up an alert for
named.confchanges specifically. The config file rarely changes; when it does, that’s news.
For a high-value cPanel host where DNS integrity matters more than the host itself (consider: the host runs a registrar’s nameservers), look at hardening beyond monitoring — restricting WHM access to specific IP allowlists, requiring two-factor auth, and externalizing the audit log to a separate system the host can’t write to retroactively.
Stack Harbor monitors zone integrity and audits API token usage as part of cPanel/WHM management.