Day 5 · HTML email, images, code & security

Email security: phishing, spoofing, BEC, S/MIME and account protection

lesson 17 / 1914 min1 labpublished
Course contents
On this page
  1. Spoofing: four ways to fake a sender
  2. The attacks
  3. Defenses in layers
  4. When an account is compromised
  5. Encryption: what protects what

Email is still the most common way into an organization. It reaches every employee, anyone on the Internet can write to it, and a convincing message needs no technical exploit at all, only a person who believes it. This lesson maps the attacks from the cheapest to the most targeted, then the defenses in layers: authentication (which you already know), filtering, account security, user habits, and encryption. The lab signs and encrypts mail with S/MIME.

Spoofing: four ways to fake a sender

TechniqueExampleWhat stops it
Exact-domain spoofingFrom: ceo@yourcompany.com, sent from a random serverDMARC at p=reject on your domain (lesson 10). This is solved, if you finish your DMARC rollout
Lookalike (cousin) domainyourcompany-invoices.com, yourc0mpany.com, yourcompany.co, Unicode homographs (уourcompany.com with a Cyrillic у)Domain monitoring, registering the obvious variants, filters that flag new and lookalike domains, user training
Display-name spoofingFrom: "Jane Smith, CEO" <jane.smith.ceo@gmail.com>Filters that flag display names of executives from outside, external-sender banners, users who check the address
Compromised accountA real message from a real supplier’s mailbox, which an attacker controlsNothing in authentication: everything passes. Process controls (call-back verification for payment changes) and the supplier’s own security

Authentication protects your exact domain. Every other technique works around it, which is why the other layers exist.

The attacks

  • Mass phishing: a fake login page (“your mailbox is full”, “shared document”, “missed delivery”) sent to thousands. The goal is passwords, and often the session cookie behind them (adversary-in-the-middle kits that relay a real login page can steal sessions even past one-time codes).
  • Spear phishing: the same, written for one person or team, using details from LinkedIn and the company website.
  • Business Email Compromise (BEC): no link, no attachment, just a request: “Can you process this urgent wire transfer?”, “Our bank details have changed”, “Please buy gift cards for the client event”. According to the FBI’s Internet Crime Complaint Center, it causes billions of dollars in reported losses every year, which makes it one of the costliest kinds of cybercrime it tracks. Its best variant comes from a compromised supplier account in an existing email thread (thread hijacking), with correct names, real invoice numbers and perfect authentication.
  • Malicious attachments: documents with macros (Microsoft has blocked macros in files from the Internet by default since 2022, so attackers moved on), HTML attachments that open fake login pages locally, ISO and other disk images, archives with passwords to evade scanning, shortcut (.lnk) files.
  • QR-code phishing (“quishing”): the link is in an image of a QR code, so URL filters don’t see it, and the victim scans it with a personal phone outside company protection.
  • Links through trusted services: phishing pages hosted on well-known file-sharing, form and document services, whose domains have excellent reputations.

Defenses in layers

1. Authentication of your own domains. SPF, DKIM and DMARC at p=reject for every domain you own, including the ones that never send mail (lesson 5). MTA-STS and TLS-RPT for transport. Then BIMI if you want the logo.

2. Inbound filtering. Your provider’s built-in protection (Microsoft Defender for Office 365, Gmail’s filtering) or a secure email gateway, configured, not left on defaults:

  • Anti-impersonation for your executives’ names and your own domains and lookalikes.
  • Attachment sandboxing (opening attachments in a disposable VM) and blocking of risky file types.
  • Link protection: URL rewriting and time-of-click checks (Safe Links in Microsoft 365), because a link that was clean at delivery can become malicious an hour later.
  • External sender warnings (“This message came from outside your organization”) and first-contact warnings.
  • Treat inbound mail that fails DMARC according to the sender’s policy, and quarantine mail that fails your own domain’s DMARC.

3. Account security. Most damage happens after an account is taken over.

  • MFA for everyone, phishing-resistant where possible: FIDO2 security keys and passkeys can’t be relayed by a fake login page; codes by SMS or app can.
  • Turn off legacy authentication (basic auth for IMAP, POP, SMTP AUTH), which bypasses MFA (lesson 4).
  • Block automatic forwarding to external addresses by default, and allow it only by exception. Attackers’ first move in a compromised mailbox is a rule that forwards or hides mail. In Microsoft 365 that’s the outbound spam policy’s auto-forwarding setting; in Google Workspace the “automatic forwarding” setting under Gmail end-user access.
  • Alert on new inbox rules, suspicious sign-ins and sending spikes.

4. People and process.

  • A “Report phishing” button in every mail client, and someone who actually looks at the reports. Reported messages are your earliest warning.
  • Call-back verification for every change of bank details and every unusual payment request, using a phone number you already had, never one from the email. This single process stops most BEC.
  • Short, regular, realistic training, without humiliation: people who feel safe reporting mistakes report them quickly.

When an account is compromised

Speed matters: an attacker in a mailbox reads conversations about payments and sends replies inside them.

  1. Contain: reset the password, revoke all sessions and tokens (a password reset alone doesn’t end existing sessions everywhere), check and re-register MFA methods (attackers add their own).
  2. Find what they changed: inbox rules (forwarding, moving, deleting messages that contain “invoice” or “payment”), mailbox forwarding, delegates, app consents (OAuth apps granted access to the mailbox), and sent items. In Exchange Online PowerShell, for example:
Get-InboxRule -Mailbox jane@example.com | Format-List Name, Enabled, ForwardTo, ForwardAsAttachmentTo, RedirectTo, MoveToFolder, DeleteMessage
Get-Mailbox jane@example.com | Format-List ForwardingSmtpAddress, DeliverToMailboxAndForward
  1. Find what they sent: message trace for messages from the account during the compromise, especially to external recipients and to finance contacts. Warn the recipients.
  2. Find how they got in: the phishing message (and everyone else who received it), the sign-in logs, the IP addresses.
  3. Learn: was MFA missing? Legacy auth still on? Forwarding allowed? Fix the gap for everyone.

Encryption: what protects what

ProtectionProtectsDoesn’t protect
TLS between servers (STARTTLS, MTA-STS, DANE)The message in transit between each pair of serversThe message on each server, from the providers, from a compromised mailbox
Encryption at rest (the provider’s disks)Stolen disksAnyone with access to the account or the provider’s systems
Provider message encryption (Microsoft Purview Message Encryption, Gmail’s confidential mode)Access control and expiry for the recipient, often via a web portalIt is not end-to-end; the provider can read it. Gmail’s confidential mode prevents forwarding and printing, but doesn’t encrypt end to end
End-to-end encryption: S/MIME or OpenPGPThe content from everyone except the recipient, plus a signature proving the sender and integrityMetadata: From, To, Subject (in most implementations), dates, sizes

S/MIME (RFC 8551) uses X.509 certificates from certificate authorities, much like TLS. It’s built into Outlook, Apple Mail and most corporate clients, and certificates can be managed centrally, which makes it the usual choice inside and between organizations. Public CAs issue S/MIME certificates under the CA/Browser Forum’s S/MIME Baseline Requirements. OpenPGP (RFC 9580) uses keys that people exchange and vouch for themselves; it’s common among developers and in open-source projects, and Proton Mail uses it internally. Both encrypt with the recipient’s public key and sign with the sender’s private key, so before you can send someone encrypted mail, you need their certificate or key.