Easier to read with cream paper, a tint, more contrast or larger text? Choose your colours and text, once, for every page.

Free lesson

Reading email headers to spot phishing

After this lesson: I can read the headers of an email and name the signs that it is phishing.

65 min lesson5 commandsDHCP and DNS lab: configure dnsmasq for a small network in your browser

A quick check that you are not a bot, then your own lab opens on the interactive lesson.

Already have an account? Sign in

The mailbox is full, says an email

Email headers are the lines above a message that record where it came from and how it was checked. Reading them is how an analyst tells a phishing email from a real one.

It matters because phishing is still the most common way into a college or a company, and the body is written to fool you. The headers are harder to fake.

By the end of this lesson

Note

I can read the headers of an email and name the signs that it is phishing.

Key words

WordWhat it meansExample
Received linea header each mail server adds as it passes a message on
Hopone step from one server to the next
Authentication-Resultsthe header where the receiver writes its SPF, DKIM and DMARC results
Display namethe words shown before the address in From"IT Service Desk"
Lookalike domaina domain spelt to look like anotherexamp1e.test

The cells students fill in are left blank in this preview.

Starter

Have a go

Starter

4 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Analyse, and test only with permission

Warning

This lesson reads a sample made up for the lab. Sending a test phishing email to real people needs the organisation's written permission. In the UK, misusing someone's account or system can be a crime under the Computer Misuse Act 1990.

Received lines are read from the bottom up

Every server that passes a message on adds a Received line at the top. So the oldest hop is at the bottom, and the newest is at the top.

Each says "from" one machine "by" another, with a time. Only the top line, written by your own server, is certain. Lines below it were written by servers you do not control.

Worked example: two Received lines

Order in the filefrombyRead as
First (top)mail.examp1e.test [203.0.113.66]mx.example.testHop 2: our server took it from theirs
Secondlaptop [192.168.1.20]mail.examp1e.testHop 1: a laptop sent it to their server

The cells students fill in are left blank in this preview.

Check

Have a go

Check

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Write the sample message

Command
mkdir -p mail && printf '%s\n' 'Authentication-Results: mx.example.test; spf=pass smtp.mailfrom=examp1e.test; dkim=pass header.d=examp1e.test; dmarc=pass header.from=examp1e.test' 'Received: from mail.examp1e.test (mail.examp1e.test [203.0.113.66])' ' by mx.example.test with ESMTPS id 7QxT2; Mon, 16 Nov 2026 07:58:12 +0000' 'Received: from laptop (unknown [192.168.1.20])' ' by mail.examp1e.test with ESMTPSA id 91kd; Mon, 16 Nov 2026 07:58:09 +0000' 'Return-Path: <[email protected]>' 'From: "IT Service Desk example.test" <[email protected]>' 'Reply-To: <[email protected]>' 'To: [email protected]' 'Subject: Your mailbox is full: act within 24 hours' 'Date: Mon, 16 Nov 2026 07:58:05 +0000' 'Message-ID: <[email protected]>' '' 'Your mailbox is full. Sign in at http://examp1e.test/reset to keep your mail.' > mail/phish.eml

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Show the Received lines

Command
grep -A1 '^Received' mail/phish.eml

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

All three checks can pass for a phish

Authentication-Results says what your server found. Here SPF, DKIM and DMARC all pass, but for examp1e.test, with the digit 1 in place of the letter l.

The checks prove the mail came from that domain. They say nothing about whether that domain is honest. A lookalike domain passes everything, so the reader has to notice the name.

Write the header reader, part 1

Command
mkdir -p mail && printf '%s\n' 'import sys' 'from email import message_from_file' 'from email.utils import parseaddr' '' 'OWN = ["example.test"]' 'msg = message_from_file(open(sys.argv[1]))' '' '' 'def domain(header):' '    return parseaddr(msg.get(header, ""))[1].rpartition("@")[2].lower()' '' '' 'def plain(name):' '    for a, b in [["1", "l"], ["0", "o"], ["rn", "m"], ["vv", "w"]]:' '        name = name.replace(a, b)' '    return name' '' '' 'hops = msg.get_all("Received", [])' 'hops.reverse()' 'for number, hop in enumerate(hops, 1):' '    words = hop.split()' '    where = words[words.index("from") + 1] + " -> " + words[words.index("by") + 1]' '    print("hop " + str(number) + ": " + where + "  (" + hop.rpartition(";")[2].strip() + ")")' 'print("Authentication-Results: " + " ".join(msg.get("Authentication-Results", "").split()))' 'sender = domain("From")' 'print("From " + sender + ", Return-Path " + domain("Return-Path") + ", Reply-To " + domain("Reply-To"))' > mail/headers.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Write the header reader, part 2

Command
printf '%s\n' 'flags = []' 'if domain("Reply-To") and not domain("Reply-To") == sender:' '    flags.append("Reply-To")' 'if sender not in OWN and plain(sender) in OWN:' '    flags.append("lookalike " + sender)' 'name = parseaddr(msg.get("From", ""))[0].lower()' 'for own in OWN:' '    if own in name and not sender == own:' '        flags.append("display name")' 'print("flags: " + ", ".join(flags))' >> mail/headers.py

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

Read the sample's headers

Command
python3 mail/headers.py mail/phish.eml

Shown here, not run. Press Start lab to type it into your own lab’s terminal.

What headers.py printed

LineWhat it saidThe sign
hop 1 and hop 2laptop -> mail.examp1e.test -> mx.example.testSent from a home laptop through the lookalike's server
Authentication-Resultsspf=pass, dkim=pass, dmarc=pass, all for examp1e.testPassing proves the domain, not honesty
From, Return-Path, Reply-Toexamp1e.test, examp1e.test, mailbox.example.comReplies go to a third domain
flagsReply-To, lookalike examp1e.test, display nameThree signs together

The cells students fill in are left blank in this preview.

Check the Run

Have a go

Check the Run

3 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

A common mistake

Warning

Many people think a message that passes SPF, DKIM and DMARC is safe. Those checks prove which domain sent it. Read the domain itself, the Reply-To and where the links go.

What to do about a phish

Report it with the mail client's report button, so the security team can block the domain and remove copies from other inboxes. Never use its link or reply.

A mail gateway can find the same signs at scale. It can flag a Reply-To that differs from From, new lookalike domains and display names that contain your own domain. Multi-factor sign-in limits the harm of a stolen password.

Match each header to what it tells you

Have a go

Loading…

Your answers are marked here and are not kept. An account keeps your marks.

Assignment: flag a message

Write the two parts of a header reader.

hops(received) takes the Received header values in the order they appear in the message (newest first) and returns [from, by] for each hop, oldest first: the word after from and the word after by.

flags(headers, own) takes a dictionary of headers and a list of your own domains, and returns these flags in this order: "reply-to" if a Reply-To's domain differs from From's; "lookalike" if From's domain is not yours but becomes one of yours when 1 is read as l, 0 as o, rn as m and vv as w; "display-name" if the words before < contain one of your domains that is not From's domain; "auth-fail" once if Authentication-Results contains spf=fail, dkim=fail or dmarc=fail. Compare domains in lower case.

Code: python
def hops(received):
    return []


def flags(headers, own):
    return []

Make a free account to save your work and track your progress.

Exit quiz

Have a go

Exit quiz

5 questions
Have a go: your answers are marked here and then forgotten. Sign in if you would like your score kept, and to pick up where you left off.Sign in to keep your score

Teaching a class? Set this module for your students with a teacher guide, marked assignments and a lab for every student.