Email Authentication Assessment (SPF, DKIM, DMARC)
A single-file skill: assess whether a mail domain's published authentication policy
would actually stop an unauthenticated sender from using that domain in the From:
header, and produce evidence a receiving operator or the domain owner can act on.
A. Skill Metadata
| Field | Value |
|---|---|
| Skill name | Email Authentication Assessment |
| Identifier | email-authentication-assessment@1.0.0 |
| Version | 1.0.0 |
| Category | email-security |
| Domain | Internet mail authentication: SPF, DKIM, DMARC, ARC |
| Intended agent | A coding or security agent with shell access, DNS resolution, and written authorization for the assessed domain |
| Required knowledge | SMTP envelope vs header identity, SPF evaluation, DKIM signing and canonicalization, DMARC alignment and reporting, DNS basics |
| Required tools | dig or kdig, openssl, python3; optionally swaks, opendkim-testkey, dkimverify, checkdmarc, parsedmarc |
| OS compatibility | Linux, macOS, Windows (Git Bash or WSL for the shell examples) |
| Permissions | Outbound DNS; authorization to send test mail from the assessed domain to a mailbox you control |
| Dependencies | Standard-library Python 3.10+ for the bundled checker; no runtime third-party packages |
| CWE | CWE-290, CWE-345, CWE-347, CWE-287 |
| OWASP | OWASP Top 10 2021 A07 (identification and authentication failures) |
| MITRE ATT&CK | T1566, T1566.001, T1566.002, T1656, T1585.002 |
| Reference documentation | See section P |
The YAML frontmatter above is the machine-readable source of truth. The table
repeats it for readers who receive the file without a frontmatter-aware tool.
The bundled checker (mailauth check SKILL.md) enforces both.
B. Executive Overview
SPF, DKIM and DMARC answer three different questions, and a domain only resists
impersonation when all three answers agree. SPF asks whether the connecting host
was authorized to use the envelope sender. DKIM asks whether a cryptographic
signature over selected headers and the body is valid for a stated signing
domain. DMARC is the only one of the three that binds either result to the
From: header a human actually sees, and it is the only one that tells a
receiver what to do when neither result aligns.
Most real-world failures are not exotic. They are a record that silently exceeds
SPF's ten-query budget, a DKIM key that was rotated without the old selector
staying published, a DMARC record at p=none that everyone believes is
enforcement, or an ESP whose envelope domain never aligned with the From domain
so the domain has never once passed DMARC on its own mail. Each of these produces
the same business outcome: a third party can send mail that a recipient's client
displays as the organization's own domain.
The agent's goal is narrower than "improve email security". It is to establish,
with reproducible evidence, whether an unauthenticated sender can use the
assessed domain in From: today, why not or why so, and what the smallest
staged change is that closes the gap without breaking legitimate mail flows.
In scope: record retrieval and parsing, SPF term accounting, DKIM selector and key inventory from mail you are authorized to inspect, DMARC policy and alignment analysis, aggregate-report review, controlled send tests, evidence collection, and remediation sequencing.
Out of scope: sending mail that impersonates a domain you do not own, testing third-party domains without authorization, content filtering or spam scoring, mailbox compromise investigation, and deliverability tuning that is not about authentication. This skill does not authorize any action; section K defines the boundary that must already exist.
C. Technical Foundations
Two identities per message
A message carries an envelope identity and a header identity, and they are not
required to match. The envelope is what SMTP negotiates (RFC 5321): MAIL FROM
becomes the return-path, and the sending host names itself in EHLO. The header
block is what the recipient's client renders (RFC 5322): From:, Reply-To:,
Subject:. SPF authenticates the envelope. DMARC compares the authenticated
envelope domain against the header From: domain. That comparison, called
alignment, is the entire reason DMARC exists.
SPF: an authorized-sender list evaluated by the receiver
The domain owner publishes one TXT record beginning v=spf1 at the domain name.
Receivers evaluate it with check_host() (RFC 7208 section 4). Mechanisms are
evaluated left to right and the first match decides the result:
all matches any sender
include: recursively evaluates another domain's SPF record
a matches if the sender IP is in the domain's A/AAAA records
mx matches if the sender IP is in the domain's MX records
ptr reverse-DNS check; deprecated by RFC 7208 and counted as a query
ip4: literal IPv4 address or CIDR
ip6: literal IPv6 address or CIDR
exists: matches if a constructed name resolves to any A record
Each mechanism may carry a qualifier: + pass (default), - fail, ~ softfail,
? neutral. Modifiers redirect= and exp= change control flow and explanation
text; unknown modifiers are ignored. Results are none, neutral, pass,
fail, softfail, temperror, permerror.
Three hard budgets make SPF fragile in practice, all in RFC 7208 section 4.6.4:
at most 10 DNS-querying terms per evaluation (include, a, mx, ptr,
exists, and redirect each consume budget), at most 2 void lookups (a
query that returns no answer), and at most 10 address records for a and
mx. Exceeding any of them yields permerror, and receivers treat permerror
as no authorization at all. Because include nests, a domain can exceed the
limit purely through a vendor's own record.
Macro expansion (%{s}, %{l}, %{o}, %{d}, %{i}, %{p}, %{v}, %{h},
with optional transformers and digits) means a record cannot always be read
literally. When a record uses macros, expand it by hand or with a checker rather
than assuming the literal text is the whole story.
When MAIL FROM is empty, as in a bounce, receivers check the EHLO identity
instead. That is why a domain that only publishes SPF for its sending IPs can
still fail on its own bounces.
DKIM: a signature over headers and body
The signer hashes a canonicalized selection of header fields plus a hash of the
canonicalized body, then signs that with a private key. The signature travels in
DKIM-Signature: with tags: v=1, a= algorithm, c= header/body
canonicalization, d= signing domain, s= selector, h= signed header list,
bh= body hash, b= signature, and optionally t=, x=, i=, l=, q=.
Verification retrieves the public key from <selector>._domainkey.<d> as a TXT
record containing v=DKIM1; k=rsa; p=<base64 SubjectPublicKeyInfo>. An empty
p= means the key was revoked; a missing record means the signature cannot be
verified at all, which for DMARC is equivalent to a failure.
Canonicalization decides what survives transit. simple changes nothing.
relaxed lowercases the header name, unfolds continuation lines, collapses
whitespace runs to one space, strips trailing whitespace, and removes whitespace
around the colon; for the body it collapses whitespace runs, strips trailing
whitespace, and ignores empty lines at the end of the body. Both canonicalizations
ignore trailing empty lines in the body.
The l= tag limits how much of the body is hashed, and anything appended after
that length is unsigned. The h= list must include From; a verifier must
reject a signature that does not. RFC 8301 removed rsa-sha1 for signing and
requires RSA keys of at least 1024 bits, with 2048 recommended.
DKIM survives forwarding only if the intermediary does not rewrite signed content. Mailing lists that add a subject prefix or a footer break the body hash, which is why ARC exists.
DMARC: alignment plus an instruction
DMARC (RFC 7489) is published at _dmarc.<domain> as a TXT record:
v=DMARC1; p=none|quarantine|reject; sp=; pct=; rua=; ruf=; adkim=r|s; aspf=r|s; fo=; rf=; ri=. The record must begin with v=DMARC1; p= is required.
A message passes DMARC when at least one of the following holds for the domain
in the single From: header field:
- SPF produced a
passfor a domain aligned with theFrom:domain, or - a valid DKIM signature carries a
d=value aligned with theFrom:domain.
Alignment is relaxed by default, meaning the organizational domain (public
suffix plus one label) must match; strict requires an exact FQDN match. A
message with multiple From: domains is treated as failing.
Policy discovery walks from the exact domain to the organizational domain.
When the record is found at the organizational domain, sp= governs subdomains
and defaults to p=. pct= samples the fraction of failing messages that get
the quarantine or reject treatment; it does not apply to p=none. rua= names
aggregate-report destinations and ruf= forensic ones, each optionally suffixed
with a size limit such as !10m. A destination outside the reporting domain's
organizational domain must authorize the reports by publishing v=DMARC1 at
<destination-domain>._report._dmarc.<reporting-domain>.
Aggregate reports are gzipped XML with a feedback root containing
report_metadata, policy_published, and one record per source IP with row
(count, disposition, evaluated SPF and DKIM results) and auth_results (the
actual DKIM domains/selectors and SPF domains observed).
Authentication-Results and ARC
Receivers record verdicts in Authentication-Results: (RFC 8601), naming the
authserv-id, the SPF and DKIM results, and a dmarc= result with the evaluated
header.from. This header, from a receiver you control, is the strongest
empirical evidence available: it is the receiving stack's own judgement, not
your reading of DNS.
ARC (RFC 8617) adds three headers at each forwarding hop so a receiving system
can see an intact chain of prior authentication: ARC-Authentication-Results,
ARC-Message-Signature, and ARC-Seal, linked by an instance number i= and a
chain validation result cv=. ARC lets a forwarder preserve the original
authentication verdict; it does not make a broken signature valid again.
Root causes worth naming
- SPF authorizes hosts, not the
From:header, so an SPFpasson a shared ESP domain says nothing about the brand domain. - Alignment is a separate configuration step from authentication; a domain can authenticate perfectly and align never.
p=nonepublishes an instruction to monitor, not to block, and receivers are free to apply their own heuristics.- Records decay: keys rotate, IPs change, vendors change their include trees. A configuration that passed last year can fail today without any edit.
D. Prerequisites and Environment
Operating system and shell
Linux is the reference environment. macOS ships a usable dig and openssl.
On Windows, use WSL or Git Bash; nslookup is present but prints less than dig
and hides TTL and multi-string TXT framing. All commands below are POSIX shell.
Software
# Debian/Ubuntu
sudo apt-get install -y dnsutils openssl python3
# optional analysis helpers
sudo apt-get install -y swaks opendkim-tools
python3 -m pip install --user dkimpy checkdmarc parsedmarc
# macOS (Homebrew)
brew install bind openssl@3 python@3.12 swaks opendkim
python3 -m pip install --user dkimpy checkdmarc parsedmarc
# Fedora/RHEL
sudo dnf install -y bind-utils openssl python3 swaks opendkim
Verification of the environment
dig -v
openssl version
python3 -c "import ssl, sys; print(sys.version.split()[0], ssl.OPENSSL_VERSION)"
Expected: a BIND version line, an OpenSSL 1.1.1 or 3.x banner, and a Python 3.10+
interpreter. A missing dig is not fatal, but every command in this skill that
prints raw TXT framing assumes it.
Network requirements
Outbound UDP/TCP 53 to a resolver, and outbound TCP 25 or 587 only to a mail
server you are authorized to use. No inbound exposure is required. If the
environment forces a specific resolver, pass it explicitly with @resolver so
results are attributable and reproducible.
Safe testing environment
The minimum safe setup is: two domains you control, a mailbox you own at a third-party provider for empirical checks, and a local record of the authorization (who approved the test, which domains, what date range). Never point a send test at an address belonging to someone who has not agreed to receive it.
Query hygiene
Resolvers and authoritative servers are third-party infrastructure. Keep lookups to the handful a diagnosis needs, cache results in a local file rather than re-querying in a loop, and remember that repeated queries against a provider's nameservers are visible to that provider.
E. Detailed Operational Methodology
Run the phases in order. Each phase states what it needs, what it produces, and what must be true before the next phase is meaningful. Phases 2 through 5 are static and need no mail to be sent, so they can run in any environment with DNS.
Phase 0 — Record scope and authority
Objective: establish, in writing, which domains and sending flows are covered. Preconditions: a named approver for the domain owner and a stated window. Inputs: domain list, allow/deny list, contact for the sending infrastructure. Procedure: write the authorization record before the first query. Record the approver, the domains in scope, the mailboxes permitted to receive test mail, the maximum number of test messages, and the stop conditions from section K. Expected output: a short scope note stored with the evidence set. Interpretation: if the approver cannot name the domains, the scope is not yet defined; stop and ask for the list rather than inferring it from a brand name. Error handling: an ambiguous scope is a blocker, not a warning. Validation: every later command must be traceable to a line in this note. Next decision: proceed only when each domain is attributable to the owner.
Phase 1 — Inventory the domains and their sending flows
Objective: enumerate every domain and subdomain that sends mail, and through
which provider, so that a clean SPF on the primary domain does not hide an
unauthenticated subdomain.
Preconditions: Phase 0 complete.
Inputs: apex domain, known subdomains, marketing tool list, ticketing system,
transactional ESP, CRM.
Procedure: collect the apex, every subdomain that appears in a From: header
of historical mail you can read, and the provider named in each message's
Received and Return-Path headers. Then verify each candidate with a DNS
query rather than assuming from the name:
for d in example.com mail.example.com news.example.com; do
printf '%-24s ' "$d"
dig +short TXT "$d" | tr '\n' ' ' | cut -c1-120
echo
done
Expected output: one TXT line per domain, either an SPF record or nothing.
Interpretation: a subdomain with no SPF record and no DMARC inheritance is a
spoofable surface even when the apex is perfect.
Error handling: dig returning nothing at all usually means NXDOMAIN; confirm
with dig +noall +comments before concluding the name does not exist.
Validation: cross-check the list against at least one real message per flow.
Next decision: any domain that sends mail and returns no SPF record goes on
the findings list immediately.
Phase 2 — Retrieve and parse SPF
Objective: obtain the exact record text as a receiver would see it, including multi-string framing. Preconditions: Phase 1 list. Inputs: domain names. Procedure:
dig +noall +answer TXT example.com
dig +short TXT example.com
The first form prints the raw TXT presentation format, which shows whether the record is split across multiple 255-octet character-strings. Receivers concatenate those strings with no separator, so a record split mid-token is still valid but a record split with an added space is not the record the author intended.
Expected output: exactly one record beginning v=spf1. Zero records means no
SPF. Two or more records beginning v=spf1 is a permanent error per RFC 7208 and
must be reported as such, not merged by hand.
Interpretation: read mechanisms left to right; the first match wins. A
terminal -all is enforcement, ~all is soft enforcement, ?all is neutral and
provides no protection, and +all authorizes the entire internet.
Error handling: if the record uses macros, expand them for a known sending IP
before judging the terminal mechanism.
Validation: confirm the retrieved text with a second resolver:
dig +short TXT example.com @1.1.1.1 and @8.8.8.8.
Next decision: proceed to budget accounting; a record that looks correct is
still unauthoritative if it exceeds the query limit.
Phase 3 — Account for the SPF DNS budget
Objective: prove whether the record evaluates within RFC 7208's limits.
Preconditions: Phase 2 record.
Inputs: the record text, plus each included domain's record.
Procedure: count DNS-querying terms. Every include:, a, mx, ptr,
exists:, and a redirect= each consume one unit of the 10-unit budget; an
include brings its whole subtree with it. Walk the tree explicitly:
for d in _spf.provider.example mail.example.com; do
echo "== $d"
dig +short TXT "$d"
done
A checker automates the walk and reports the total:
python3 -m checkdmarc example.com --timeout 8
Expected output: a total of 10 or fewer, with 2 or fewer void lookups.
Interpretation: 10 is the ceiling, not a target. A record at 10 has no room
for a new vendor and will break the day one is added. Void lookups above 2 are a
permanent error on their own, even with a small term count.
Error handling: if the checker and a hand count disagree, trust the hand count
and document the discrepancy; implementations differ on whether redirect is
counted, and a receiver's implementation is the one that matters.
Validation: re-run the count after any vendor record changes.
Next decision: over budget means the domain currently returns permerror on
some paths, which is a finding independent of DMARC.
Phase 4 — Inventory DKIM selectors and keys
Objective: establish which selectors are live, whether their keys are valid
and adequately sized, and whether any selector is revoked or dangling.
Preconditions: at least one message from each flow, with its headers intact.
Inputs: DKIM-Signature header values from authorized mail.
Procedure: read d= and s= from each signature, then query the key:
dig +short TXT selector1._domainkey.example.com
Decode the published key and read its size:
rec=$(dig +short TXT selector1._domainkey.example.com | tr -d '"' | tr -d ' ')
key=$(printf '%s' "$rec" | sed -n 's/.*p=\([^;]*\).*/\1/p')
printf '%s' "$key" | base64 -d | openssl pkey -pubin -inform DER -noout -text | head -2
opendkim-testkey performs the same check in one step:
opendkim-testkey -d example.com -s selector1 -vvv
Expected output: Public-Key: (2048 bit) or larger, and opendkim-testkey
reporting the key as OK.
Interpretation: 1024-bit keys are permitted by RFC 8301 but are below current
practice; a key record with p= empty means the selector was revoked, so any
message still signed with it fails. A selector that no longer resolves means the
key was withdrawn while mail still carries signatures referencing it.
Error handling: a CNAME at the selector is valid delegation, not an error; it
adds a DNS dependency that must be checked separately.
Validation: verify with a real message through dkimverify < message.eml and
confirm the signature reports good.
Next decision: any flow with no valid selector is a DP (DKIM) finding.
Phase 5 — Read the DMARC policy and judge alignment
Objective: determine the effective policy for each sending domain and whether
the domain can actually align.
Preconditions: Phases 2 and 4 results.
Inputs: DMARC TXT at _dmarc.<domain> and at the organizational domain.
Procedure:
dig +short TXT _dmarc.example.com
dig +short TXT _dmarc.example.org
Expected output: a record beginning v=DMARC1 with an explicit p=.
Interpretation: apply the policy to observed mail. A message passes only if an
aligned SPF pass or an aligned DKIM pass exists. With a shared ESP, the envelope
domain is the provider's, so SPF cannot align unless the provider offers a custom
return-path on your domain; DKIM with d=example.com is then the only path to a
pass. p=none means the receiver reports but does not block, which is why a
domain "with DMARC" can still be spoofed successfully.
Error handling: a record at the organizational domain with sp=none leaves
subdomains unprotected even when the apex rejects.
Validation: confirm with a real message's Authentication-Results header from
a receiver you control, which reports dmarc=pass or dmarc=fail with the
evaluated header.from.
Next decision: if no record exists, the finding is "no policy"; if a record
exists but nothing aligns, the finding is "policy that cannot be satisfied".
Phase 6 — Controlled empirical test
Objective: convert static reasoning into an observed receiver verdict. Preconditions: authorization to send, a mailbox you control, a small message limit. Inputs: the sending host or ESP, one recipient address, one message body. Procedure: send one ordinary message through the legitimate flow:
swaks --to test-inbox@your-domain.example \
--from sender@example.com \
--server smtp.example.com:587 \
--tls --auth LOGIN --auth-user sender@example.com \
--header "Subject: authentication check" \
--body "Controlled test, single message."
Then read the full headers at the receiving mailbox and extract the verdicts:
Authentication-Results: mx.receiver.example;
spf=pass smtp.mailfrom=example.com;
dkim=pass header.d=example.com header.s=selector1;
dmarc=pass header.from=example.com
Expected output: dmarc=pass for legitimate mail.
Interpretation: one failing mechanism with the other passing is normal in a
forwarding path and is exactly what alignment is for. Two failures is a
configuration defect.
Error handling: a message that never arrives is a delivery problem, not an
authentication result; do not record it as a failure. A temperror means the
receiver could not complete the check; retry once, later.
Validation: repeat with one message per sending flow, no more.
Next decision: any flow with dmarc=fail on its own legitimate mail is a
blocking finding, because enforcement would break it.
Phase 7 — Review aggregate reports
Objective: see what receivers actually observed, across sources, rather than
what one test message produced.
Preconditions: a rua= destination you can read, with at least a few days of
history.
Inputs: aggregate XML reports (gzipped attachments or provider dashboards).
Procedure: parse reports into per-source rows and separate legitimate flows
from unknown sources:
parsedmarc --input reports/ --output results/ --silent
Expected output: per-day counts keyed by source IP, with dkim and spf
results and the header-from domain.
Interpretation: a source IP that fails both mechanisms and is not a known
vendor is either an unknown legitimate sender or an impersonation attempt; the
report proves the domain's policy let it through, which is the impact statement.
Error handling: reports from a destination outside the domain require the
_report._dmarc authorization record; absence produces no reports at all, which
is easy to misread as "no failures".
Validation: reconcile the report window against the test message timestamps.
Next decision: unknown sources with volume justify escalation in severity.
Phase 8 — Findings, severity and remediation order
Objective: turn observations into a defensible report and a change sequence
that does not break legitimate mail.
Preconditions: Phases 1 to 7 evidence.
Inputs: evidence set, flow inventory, provider capabilities.
Procedure: grade each finding by what an unauthenticated sender gains, not by
which record is missing. Order remediation so monitoring precedes enforcement:
publish or fix rua, reach aligned passes on every flow, then ramp policy.
Expected output: findings with CWE mapping, evidence, and a staged plan.
Interpretation: enforcement applied before alignment exists converts a
spoofing problem into a delivery outage.
Error handling: when a provider cannot align, the fix is provider-shaped
(custom return-path, dedicated subdomain) rather than a DNS edit.
Validation: each finding must cite a command output captured today.
Next decision: proceed to Phase 9 only after a change is published.
Phase 9 — Verify after change
Objective: confirm the change took effect from the receiver's perspective.
Preconditions: change published and TTL elapsed.
Inputs: the same queries and the same test flow as before.
Procedure: re-run Phases 2 to 6 and diff the results against the baseline
capture.
Expected output: identical records except the intended change, and a
dmarc=pass on every flow.
Interpretation: a record that has not propagated is not a failed fix. Check
TTL before concluding anything.
Error handling: negative caching at the resolver can hold the old answer;
query the authoritative server directly to separate propagation from caching.
Validation: keep the before/after pair as the verification artifact.
Next decision: close the finding only when the observed verdict changed.
Decision tree
Is a DMARC record published for the From domain?
no -> finding: no policy (spoofable From), severity by mail volume
yes -> does it parse and is p= present?
no -> finding: malformed policy, receivers ignore it
yes -> does at least one mechanism align on real mail?
no -> finding: policy cannot be satisfied; enforcing breaks mail
yes -> what does p= say?
none -> finding: monitoring only; spoofing still delivers
quarantine/reject -> check pct, sp, and subdomain coverage
F. Practical Technical Examples
All domains below use the reserved example.com/example.org names from
RFC 2606. Values are illustrative; the commands are real and the observed output
shape is what a receiver returns.
F1. Basic: one domain, one sender, correct configuration
$ dig +short TXT example.com
example.com. 300 IN TXT "v=spf1 ip4:192.0.2.10 -all"
$ dig +short TXT _dmarc.example.com
example.com. 300 IN TXT "v=DMARC1; p=reject; rua=mailto:dmarc@example.com"
$ dig +short TXT mail._domainkey.example.com
mail._domainkey.example.com. 300 IN TXT "v=DKIM1; k=rsa; p=MIIBIjANBg..."
Reading: one SPF record, two DNS-querying terms (none, in fact: ip4: is not a
query), terminal -all, DMARC at p=reject with a reporting address, and a key
that decodes to 2048 bits. A test message through this configuration returns
dmarc=pass with both spf=pass and dkim=pass. This is the reference case; any
deviation found later is a finding.
F2. Intermediate: shared ESP, correct DKIM, broken SPF alignment
Return-Path: <bounce@em1234.provider.example>
DKIM-Signature: v=1; a=rsa-sha256; d=example.com; s=provider; ...
From: Example <news@example.com>
SPF passes for em1234.provider.example because the provider authorized its own
sending IPs. DMARC evaluates the From: domain, example.com, and finds no
aligned SPF pass. The message still passes DMARC, because the DKIM signature
carries d=example.com and verifies. This is the correct design, and it is also
the fragile one: rotate the DKIM key without publishing the new selector and the
domain loses its only aligned path, at which point enforcement starts blocking
its own newsletters.
F3. Advanced: enforcement that is not enforced
dig +short TXT _dmarc.example.com
"v=DMARC1; p=quarantine; pct=10; sp=none; adkim=s; aspf=s"
Three separate weaknesses in one line. pct=10 applies quarantine to one message
in ten, so nine in ten spoofed messages are delivered as if no policy existed.
sp=none explicitly declines to protect subdomains, which is where staging and
ESP-hosted senders usually live. adkim=s and aspf=s demand exact-FQDN
alignment, which many ESP flows cannot satisfy because the signing domain is a
subdomain of the brand domain. The correct read is not "DMARC is configured" but
"policy exists and covers roughly a tenth of traffic, on one label".
F4. Edge case: multiple SPF records
dig +short TXT example.com
"v=spf1 include:_spf.provider.example ~all"
"v=spf1 ip4:198.51.100.0/24 -all"
Two records is a permanent error (RFC 7208), not an additive configuration. Some
receivers pick the first, some return permerror; both outcomes are wrong for the
owner and the ambiguity itself is the finding. The fix is a single record holding
the union of mechanisms, which almost always pushes the term count closer to the
limit and must be re-accounted afterwards.
F5. Edge case: the record that is over budget
v=spf1 include:_spf.a.example include:_spf.b.example include:_spf.c.example
include:_spf.d.example include:_spf.e.example include:_spf.f.example ~all
Six includes look modest, but each vendor's record commonly contains two to four
nested includes of its own. The total routinely lands at 11 or 12, producing
permerror for every message, which most receivers treat as "no SPF". checkdmarc
reports the count and the offending subtree; the remedy is flattening or per-vendor
subdomains, not removing a vendor.
F6. Edge case: revoked and dangling selectors
$ dig +short TXT old._domainkey.example.com
old._domainkey.example.com. 300 IN TXT "v=DKIM1; k=rsa; p="
$ dig +short TXT 2023._domainkey.example.com
# (no answer)
p= empty is a deliberate revocation; a signature naming that selector must fail.
A selector that does not resolve at all means mail still carries signatures whose
key no longer exists. Neither is exploitable by itself, but both indicate a
rotation process without a verification step, which is how a live flow silently
loses its aligned DKIM path.
F7. False positive: dmarc=pass with spf=fail
A forwarded message commonly shows spf=fail (the forwarder's IP is not in the
original domain's SPF) and dkim=pass (the body hash survived because the
forwarder did not rewrite signed content), so DMARC passes. Reporting this as a
spoofing success would be wrong. The finding, if any, is that the forwarder does
not implement ARC, which matters only for flows that rewrite content.
F8. False positive: a reporting domain you do not control
An rua= address at a third-party monitoring vendor looks like data leaving the
organization. It is a normal and RFC-sanctioned arrangement, authorized by the
vendor's _report._dmarc record. It becomes a finding only when the vendor is
unapproved by policy, or when the authorization record is missing and reports are
silently dropped.
F9. Failure condition: enforcement before alignment
The most damaging real-world sequence is raising p= to quarantine on a domain
whose only aligned mechanism is a DKIM key that one ESP flow does not use. The
spoofing surface closes and that flow's mail starts landing in spam, usually
discovered days later from a business complaint rather than from monitoring. The
pair of evidence to capture before any change is: a dmarc=pass for every flow
in the inventory, and a non-zero rua volume reporting those passes.
G. Tools and Commands
Every tool below is a real, maintained program. Flags are the ones documented for
the version ranges noted; verify with <tool> --help on the machine you are on
rather than trusting this table blindly, because flags do drift between releases.
G1. dig (BIND 9 dnsutils)
Purpose: query authoritative and recursive DNS and print TXT records with their
framing. Source: ISC BIND, distributed by every major Linux distribution and by
Homebrew (brew install bind). Example and interpretation:
dig +noall +answer TXT example.com
dig +short TXT example.com
dig +noall +answer +comments TXT example.com
dig +dnssec TXT _dmarc.example.com
+noall +answer prints the answer section with TTL and class; +short prints
just the data, which is convenient but hides multi-string framing; +comments
shows rcode, so NXDOMAIN is distinguishable from an empty answer; +dnssec sets
the DO bit and shows RRSIG records when the zone is signed. Limitations: dig
does not validate DNSSEC (use delv for that), and it resolves through the
system resolver by default, so a cached answer may be older than it looks. Pass
@server to attribute results to a specific resolver.
G2. kdig (Knot DNS utils)
Purpose: an alternative resolver client with cleaner multi-line TXT output and
TLS support. Source: Knot DNS project (apt install knot-dnsutils). Useful for
confirming that a result is not a quirk of BIND's presentation:
kdig +short TXT _dmarc.example.com
kdig +tls TXT example.com @1.1.1.1
Limitation: not installed by default on most systems; and like dig it does not
validate signatures.
G3. delv (BIND 9)
Purpose: perform DNSSEC validation and report secure/insecure/bogus. Source:
BIND 9.12 and later, same package as dig.
delv TXT _dmarc.example.com
Expected output includes fully validated on a signed zone, or unsigned answer
on an unsigned one. Interpretation: an unsigned DMARC record can be replaced by
an on-path attacker, so DNSSEC is the integrity control; absence is a hardening
observation, not an authentication bypass by itself.
G4. openssl
Purpose: decode a published DKIM key and read its size and algorithm.
rec=$(dig +short TXT mail._domainkey.example.com | tr -d '"' | tr -d ' ')
key=$(printf '%s' "$rec" | sed -n 's/.*p=\([^;]*\).*/\1/p')
printf '%s' "$key" | base64 -d | openssl pkey -pubin -inform DER -noout -text | head -3
Expected: Public-Key: (2048 bit) and a modulus. Interpretation: the p= value
is base64 of a DER SubjectPublicKeyInfo, which is why -pubin -inform DER is the
correct decode. Limitations: openssl pkey on some 1.0.x builds rejects the
input; use a 1.1.1+ or 3.x binary.
G5. opendkim-testkey
Purpose: fetch the selector's public key and check that it parses and matches an
optional local private key. Source: OpenDKIM (apt install opendkim-tools).
opendkim-testkey -d example.com -s mail -vvv
Expected: a line reporting the key as OK with its size. Interpretation: a failure
here means signatures with that selector cannot verify, regardless of what the
signing software believes. Limitation: it reads the resolver configuration from
the system and can be affected by a stale cache; add -C if your build supports
it to bypass the cache.
G6. dkimverify (dkimpy)
Purpose: verify signatures on a stored message, end to end, including canonicalization.
python3 -m pip install --user dkimpy
dkimverify < message.eml
Expected: <signature ok> per valid signature, with the signing domain and
selector. Interpretation: body hash did not verify means the body was modified
after signing; no key for signature means the selector does not resolve.
Limitation: it verifies only what is in the file; it does not tell you whether the
receiver's stack agreed.
G7. checkdmarc
Purpose: parse SPF and DMARC for a domain, count SPF terms, report alignment and policy problems in a machine-readable form.
python3 -m pip install --user checkdmarc
checkdmarc example.com --timeout 8
Expected: JSON on stdout with spf, dmarc, valid_domains, and a list of
warnings and errors. Interpretation: SPF record lookup limit exceeded is a
permerror condition; DMARC policy is p=none is reported as a warning. Limitation:
it is a static checker; it cannot know which hosts legitimately send for the domain.
G8. parsedmarc
Purpose: parse DMARC aggregate and forensic reports into JSON or a database, so per-source failures become visible.
python3 -m pip install --user parsedmarc
parsedmarc --input reports/ --output results/ --silent
Expected: one JSON file per report plus a summary. Interpretation: aggregate rows
are counts, not individual messages, so a single failing source with count=400
represents 400 messages in that window. Limitation: it needs real report files;
there is no offline substitute for a domain that publishes no rua.
G9. swaks
Purpose: send one controlled test message through a specific server with TLS and authentication.
swaks --to you@your-domain.example --from sender@example.com \
--server smtp.example.com:587 --tls --auth LOGIN \
--auth-user sender@example.com --header "Subject: test" --body "one message"
Expected: a transcript ending in 250 OK per recipient. Interpretation: a 5xx at
MAIL FROM is usually a policy rejection, not an authentication failure; read the
SMTP reply text before drawing conclusions. Limitation: sending is a state change
at a third party; keep it to the number of messages the authorization allows.
G10. Tool selection
Use dig for retrieval, checkdmarc for accounting, openssl or
opendkim-testkey for keys, dkimverify for a stored message, swaks only when
an empirical verdict is required, and parsedmarc only when reports exist. Do not
install a tool that is missing without recording that it was unavailable; a
skipped check is a declared gap, not a pass.
H. Vulnerability Discovery and Validation
H1. Attack surface identification
The surface is every domain that (a) appears in a From: header of mail the
organization sends, and (b) has no aligned, enforced policy. Enumerate it from
three directions: DNS (records exist), mail history (headers show what is used),
and provider inventory (the ESP console lists sending domains). Any domain found
by one method and missing from another is worth a second look.
H2. Reconnaissance without touching the target
All of Phases 2 to 5 are read-only DNS queries against public data. They are still traffic: keep them minimal, do not enumerate large subdomain lists, and do not query a provider's authoritative servers in a loop. If the assessment has access to the zone file or the DNS provider's API, prefer that source and treat live queries as confirmation only.
H3. Weakness identification
Classify each observation into one of five shapes, because they have different fixes and different severities:
no-policy no DMARC record at or above the From domain
unsatisfiable policy exists; no flow can produce an aligned pass
unenforced p=none, or pct<100, or sp=none over the sending subdomains
broken-mechanism SPF permerror/over-budget, or DKIM key revoked/missing
hygiene DNSSEC absent, 1024-bit key, no rua, no MTA-STS
H4. Test-case development
Each test case is a claim plus the observation that would falsify it. Examples:
"an unauthenticated host can use this domain in From: and be delivered" is
falsified by an enforced aligned policy; "the domain's own newsletters pass
DMARC" is falsified by a dmarc=fail row in an aggregate report for that flow.
Write the falsifier before running the check, or the check becomes a search for
con
…(truncated)