The idea
Email has no built-in proof of who sent it: the From line is text the sender types. A domain can publish three records in its DNS for receiving servers to check. SPF lists its sending servers, DKIM signs its mail, and DMARC says what to do with mail that fails both.
Steps
-
The From line is only text
Ruth captains the Millpond Rowing Club,
rowclub.lab. She mails the members from the club's own mail server,clubMail. Lotte, a member, keeps her mailbox at a big provider,postbox.lab, whose server ispostboxMail.A forger on the internet wants the members' money. He has his own machine,
forger, and no account at the club. He writes a message in Ruth's name, asking for this season's fee at a new bank account, and hands it straight topostboxMail.Send it from
forger, then open Lotte's newest message onpostboxMail.forger:~# curl -sS smtp://postboxMail.lab --mail-from captain@rowclub.lab --mail-rcpt lotte@postbox.lab -T ~/fees.eml postboxMail:~# curl -sS "imap://localhost/INBOX;UID=*;SECTION=HEADER" -u lotte:harbour-gull-3
-
SPF lists the club's senders
SPF is the first record. It's a TXT record on the domain that lists the addresses allowed to send its mail. A receiving server compares the connecting address with that list.
The club sends from one place:
clubMail, 10.25.1.25.dnsHostserves rowclub.lab's zone from/etc/bind/zones/rowclub.lab.zone, which already holds the zone's basics (how long answers may be kept, which server answers for the zone, the MX pointing atclubMail) and an$INCLUDEline you'll meet in step 4.The SPF record is one more line,
@ IN TXT "v=spf1 ip4:10.25.1.25 -all".@is the zone's own name, and the value reads: version 1, that one address, and-all, "everyone else fails".Add it to the zone file on
dnsHost, look it up fromforger, and send the forgery again.forger:~# dig +short TXT rowclub.lab forger:~# curl -sS smtp://postboxMail.lab --mail-from captain@rowclub.lab --mail-rcpt lotte@postbox.lab -T ~/fees.eml postboxMail:~# curl -sS "imap://localhost/INBOX;UID=*;SECTION=HEADER" -u lotte:harbour-gull-3
-
SPF checks the envelope
SMTP carries a message like a letter in an envelope. The servers read the envelope: who it's from (
MAIL FROM, the address given with--mail-from, where bounces go back to) and who it's for.People read the letter's own lines, From: and To:. Nothing makes the two agree, and a mailing list's envelope rarely matches its From line.
SPF checks the domain of the envelope sender. It never looks at the From line Lotte reads.
The forger owns a throwaway domain,
quickparcel.lab, whose SPF record lists his own address. He sends the same message with--mail-from billing@quickparcel.lab, leaving the From line as Ruth's.Look up quickparcel.lab's record, send the message that way, and read Lotte's newest message.
forger:~# dig +short TXT quickparcel.lab forger:~# curl -sS smtp://postboxMail.lab --mail-from billing@quickparcel.lab --mail-rcpt lotte@postbox.lab -T ~/fees.eml postboxMail:~# curl -sS "imap://localhost/INBOX;UID=*;SECTION=HEADER" -u lotte:harbour-gull-3
-
DKIM signs what the club sends
DKIM is the second record.
clubMailadds a signature made with the club's private key to every message from the club's network, in aDKIM-Signature:header. The public key sits in rowclub.lab's DNS, where any receiver can fetch it and check.In DNS, the key lives at
<selector>._domainkey.<domain>. A domain can have several keys, one per service that sends its mail, and the selector names the one that signed.Have Ruth send a real message from
captainLaptop, read it onpostboxMail, and look up the key fromforger.captainLaptop:~# curl -sS smtp://clubMail.lab --mail-from captain@rowclub.lab --mail-rcpt lotte@postbox.lab -T ~/training.eml postboxMail:~# curl -sS "imap://localhost/INBOX;UID=*;SECTION=HEADER" -u lotte:harbour-gull-3 forger:~# dig +short TXT mail._domainkey.rowclub.lab
-
DMARC ties the checks to the From line
DMARC is the third record, a TXT record at
_dmarc.rowclub.lab. It ties the two checks to the From line.SPF counts only if the envelope's domain matches the From line's domain, and DKIM only if
d=does. That match is called alignment; by default a subdomain of the same domain matches too, sobounce.rowclub.labwould. DMARC passes if either aligned check passed.p=says what to do with mail where neither did:none(deliver it, and send reports if the record asks for them),quarantine(junk folder) orreject.The club's real mail passes both checks for rowclub.lab, so it can afford
v=DMARC1; p=reject. Publish it, send the quickparcel forgery again, and readpostboxMail's log. Then have Ruth send once more.forger:~# curl -sS smtp://postboxMail.lab --mail-from billing@quickparcel.lab --mail-rcpt lotte@postbox.lab -T ~/fees.eml postboxMail:~# grep reject /var/log/mail.log captainLaptop:~# curl -sS smtp://clubMail.lab --mail-from captain@rowclub.lab --mail-rcpt lotte@postbox.lab -T ~/training.eml postboxMail:~# curl -sS "imap://localhost/INBOX;UID=*;SECTION=HEADER" -u lotte:harbour-gull-3
Run these steps on real machines