Phishing and Social Engineering
Most of the attacks in this section break a machine. Social engineering breaks a decision. The attacker does not need a vulnerability in the mail server when an employee will type their password into a convincing page, approve a login prompt they did not start, or pay an invoice to a new bank account because "the CEO" asked. The on-ramp lesson Social Engineering and Phishing covers the psychological levers and checking a link; this lesson maps the forms of the attack, shows what an analyst can read from the message itself, and puts most of the weight on the defences that work even when someone is fooled.
Mechanism: a story, a channel and a request
Every social-engineering attack has three parts: a pretext (a believable story: IT support, a supplier, a parcel service, the boss), a channel (email, text message, phone, chat, a QR code on a poster, a video call) and a request (click, sign in, approve, pay, send a file, install something). The levers that make the request feel reasonable are authority, urgency, scarcity, helpfulness and fear of getting into trouble.
| Form | Channel | Typical request | Main warning sign |
|---|---|---|---|
| Phishing (bulk) | "sign in to keep your account" | generic greeting, link to an unfamiliar domain | |
| Spear phishing | email or chat, researched target | open a document that fits the target's real work | correct details but an unexpected sender or channel |
| Business email compromise (BEC) | email from a lookalike or a hijacked real mailbox | change bank details, pay an urgent invoice | a payment change requested by email, pressure to skip the usual process |
| Vishing / smishing | voice call / text message | read out a code, call back a number, follow a link | the caller asks for a one-time code or a password |
| MFA fatigue (push bombing) | repeated push prompts after a stolen password | tap "Approve" to make it stop | login prompts you did not start, often at night |
| Pretexting in person | front desk, phone | let someone in, reset an account | no way to verify the person's identity |
Impact. A stolen password and an approved session lead to a mailbox takeover, data theft or a foothold for ransomware (the attack map shows how one category leads to the next). BEC goes straight to money: the attacker never touches malware, so many technical controls never see it.
What the message itself tells you
An analyst who receives a reported message reads its headers before its text. The receiving mail server records the results of three checks in an Authentication-Results header:
- SPF asks: was the server that delivered the message allowed to send for the envelope sender's domain (
smtp.mailfrom)? - DKIM asks: does a valid signature from domain
header.dcover the message? - DMARC asks: did SPF or DKIM pass for a domain aligned with the visible
From:address, and what does that domain's owner want done when not?
DMARC matters most, because the From: line is what the human reads. SPF can pass for an attacker's own domain while From: claims to be yours. The program below parses two synthetic messages received by a lab mail server and flags the classic BEC signs: failed DMARC, a Reply-To that leads somewhere else, and pressure words in the subject.
from email import message_from_string
# Two synthetic messages received by the lab mail server mx.lab.test
raw = {
"invoice": """\
Authentication-Results: mx.lab.test; spf=pass smtp.mailfrom=billing.lab.test;
dkim=pass header.d=lab.test; dmarc=pass header.from=lab.test
From: Billing <billing@lab.test>
Reply-To: billing@lab.test
Subject: Your November statement
""",
"urgent": """\
Authentication-Results: mx.lab.test; spf=pass smtp.mailfrom=1ab.test;
dkim=none; dmarc=fail header.from=lab.test
From: CEO <ceo@lab.test>
Reply-To: ceo.private@1ab.test
Subject: URGENT: wire transfer before 3 pm, keep this confidential
""",
}
URGENT = ("urgent", "immediately", "confidential", "wire", "gift card", "password")
def checks(msg):
ar = " ".join(msg["Authentication-Results"].split())
res = dict(part.split("=")[:2] for part in ar.replace(";", " ").split() if "=" in part
and part.split("=")[0] in ("spf", "dkim", "dmarc"))
from_dom = msg["From"].split("@")[1].rstrip(">")
reply_dom = msg["Reply-To"].split("@")[1]
flags = []
if res.get("dmarc") != "pass":
flags.append(f"dmarc={res.get('dmarc')}")
if reply_dom != from_dom:
flags.append(f"reply-to goes to {reply_dom}")
words = [w for w in URGENT if w in msg["Subject"].lower()]
if words:
flags.append("pressure words: " + ", ".join(words))
return res, flags
for name, text in raw.items():
res, flags = checks(message_from_string(text))
print(f"{name:8} spf={res['spf']} dkim={res['dkim']} dmarc={res['dmarc']}")
print(" " + ("; ".join(flags) if flags else "no warning signs"))invoice spf=pass dkim=pass dmarc=pass
no warning signs
urgent spf=pass dkim=none dmarc=fail
dmarc=fail; reply-to goes to 1ab.test; pressure words: urgent, confidential, wire
The second message passes SPF, but for 1ab.test (a digit one, not a letter l), the attacker's own domain. DMARC fails because nothing that passed is aligned with lab.test in the From: line, and the replies would go to the attacker. If lab.test publishes a DMARC policy of p=reject, a receiving server refuses this message outright; with p=none it is delivered and only reported.
Lookalike domains
A message can also come from a domain the attacker really owns and that passes every check: a lookalike such as labs.test, 1ab.test, or a name with a Unicode letter that looks like an ASCII one (an IDN homograph). The DNS only ever sees the ASCII "punycode" form starting with xn--, which is a useful thing to show users and log. A simple screen combines an edit distance with a table of confusable characters:
def distance(a, b):
# Levenshtein edit distance: insertions, deletions and substitutions
prev = list(range(len(b) + 1))
for i, ca in enumerate(a, 1):
cur = [i]
for j, cb in enumerate(b, 1):
cur.append(min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (ca != cb)))
prev = cur
return prev[-1]
CONFUSABLE = str.maketrans({"1": "l", "0": "o", "а": "a", "ā": "a", "е": "e"})
def lookalike(domain, ours="lab.test"):
if domain == ours:
return "ours"
skeleton = domain.translate(CONFUSABLE).replace("rn", "m")
d = distance(domain, ours)
if skeleton == ours:
shown = domain.encode("idna").decode() # what the DNS really sees
return "LOOKALIKE (confusable characters" + (f", really {shown})" if shown != domain else ")")
if d <= 2:
return f"LOOKALIKE (edit distance {d})"
return f"unrelated (edit distance {d})"
for dom in ["lab.test", "1ab.test", "labs.test", "lāb.test", "lab-test.test", "example.test"]:
print(f"{dom:14} {lookalike(dom)}")lab.test ours
1ab.test LOOKALIKE (confusable characters)
labs.test LOOKALIKE (edit distance 1)
lāb.test LOOKALIKE (confusable characters, really xn--lb-dla.test)
lab-test.test unrelated (edit distance 5)
example.test unrelated (edit distance 6)
lab-test.test slips through with an edit distance of 5, although a human would happily read it as "lab test". Real lookalike monitoring adds keyword rules ("contains lab"), newly registered domain feeds and certificate-transparency logs, and still misses some. Treat it as one signal, never as proof that a message is safe.
How it is detected
- User reports. The best phishing sensor is a "Report phishing" button that people use without fear. Measure the report rate and the time to the first report, not only who clicked.
- Mail gateway signals: DMARC, SPF and DKIM failures, first-time senders, lookalike and newly registered domains,
Reply-Tomismatch, links whose text and target differ, archives and macro documents. - Identity signals after a click: a sign-in from a new device or country right after a reported email, many MFA prompts denied in a row, a new inbox rule that forwards or hides mail (a classic sign of mailbox takeover).
- Finance signals: a change of supplier bank details requested by email.
How it is prevented
- Phishing-resistant MFA. Passkeys and FIDO2 security keys bind the login to the real site's origin, so a fake page cannot replay them. One-time codes and push approvals can be relayed or nagged out of people. Turn on number matching for push MFA, and limit or alert on repeated prompts.
- Publish SPF, DKIM and DMARC for your own domains and move DMARC from
p=nonetoquarantineandrejectonce the reports show all legitimate senders are aligned. It stops exact-domain spoofing; it does nothing against lookalikes. - Process controls for money and accounts: any change of bank details or urgent payment is confirmed by calling a number already on file, never one from the message; help desks verify identity before a password or MFA reset.
- Make reporting easy and blameless. People who report a click within minutes give the security team time to reset a password and revoke sessions. Punishing them teaches everyone to stay quiet.
- Short, frequent training on real warning signs of the kind above. Simulated phishing campaigns run by your own organisation, with its written approval, are a measurement tool; they are part of the Blue Team and awareness programmes, never something to run against people outside your scope.
Pitfalls
- "SPF passed, so it is genuine." SPF passes for whatever domain the attacker controls. Read the DMARC result and the alignment.
- The padlock myth. Phishing pages use HTTPS too; a valid certificate proves who owns the domain, not that the domain is the one you meant.
- Training as the only control. Even trained people click on a well-made spear-phishing message. Assume someone will, and make the next step (MFA, payment checks, fast reporting) catch it.
- Blaming the clicker. It kills the reporting culture that detection depends on.
Practice
1. An email shows spf=pass smtp.mailfrom=mailer.lab.test; dkim=pass header.d=lab.test; dmarc=pass header.from=lab.test, but asks you to approve a new supplier bank account. Is it safe?
Not necessarily. The authentication says the message really came from lab.test infrastructure, which is exactly what a compromised real mailbox looks like. Payment changes are confirmed out of band (a call to a known number), whatever the headers say.
2. Add "lab.test.example" and "iab.test" to the domain list. What does the screen say, and why?
iab.test has edit distance 1 and is flagged. lab.test.example has edit distance 8 (eight extra characters) and is "unrelated", although it starts with the real name. A rule that checks whether our domain appears as a label prefix would catch it.
3. A user gets 14 push prompts between 01:00 and 01:10 and approves the last one. What happened, and what should be reset?
The password was already stolen and the attacker pushed prompts until one was approved (MFA fatigue). Reset the password, revoke all sessions and refresh tokens, review MFA methods and inbox rules for changes, and turn on number matching.
Test yourself
Which check ties the result to the domain in the visible From: line?
- SPF
- DKIM
- DMARC
- TLS
An attacker sends from their own domain 1ab.test with valid SPF. What does DMARC on lab.test protect against here?
- Everything: the message is rejected
- Only messages whose From: line claims lab.test
- Nothing at all, ever
- Only phone calls
Which MFA method can a fake login page not relay?
- SMS code
- Authenticator-app code
- Push approval
- A passkey (FIDO2/WebAuthn)
What is the best response to an urgent emailed request to change a supplier's bank details?
- Reply to the email and ask if it is real
- Call the supplier on a number already on file
- Check that SPF passed
- Pay a small amount first