Skip to content
Tutorials Center
My learning

Topics

Lesson 32 of 53 ยท Network, Wireless and Cloud Security

Email Security and Email Attacks

Understand how email authentication works (SPF, DKIM, DMARC), how PGP and S/MIME protect content, and how spoofing, phishing, BEC and malware attachments work and are stopped.

Email was designed in an era when everyone on the network was trusted. The protocol that moves mail between servers, SMTP, has no built-in way to verify that the sender is who they claim to be: the From address is just text the sending program fills in. Almost everything we now call email security, from SPF to DMARC to filters, is a layer added later to compensate. Because nearly every organization depends on email and nearly every attack campaign starts with it, understanding both the attacks and the controls is essential.

Send simulated phishing or spoofed mail only inside a program your organization has authorized, with written scope and the people responsible informed. Spoofing a real company's domain or sending deceptive mail to third parties can be illegal and harmful. The examples here are in-memory models; they send nothing.

How mail travels

flowchart LR
  A["Sender's mail app"] --> B["Sender's mail server<br/>(SMTP)"]
  B --> C["Receiver's mail server"]
  C --> D["Filters: SPF, DKIM, DMARC,<br/>spam, malware"]
  D --> E["Recipient's inbox"]

The receiving server decides whether to trust the message. Authentication records published in DNS give it evidence.

There are two "from" addresses. The envelope sender (MAIL FROM, also called the return path) is used between servers. The header From is what the user sees. They can differ, and a lot of spoofing relies on that gap. Real-world details also include the Reply-To header, which can send replies elsewhere, and display names, which can say "IT Support" in front of any address.

SPF, DKIM and DMARC

Three DNS-based mechanisms work together. A domain owner publishes records; receiving servers check them. (You can view them on any domain in a passive reconnaissance exercise.)

  • SPF (Sender Policy Framework). A TXT record lists the servers allowed to send mail for the domain, for example v=spf1 ip4:192.0.2.25 include:mail.example.test -all. The receiver checks whether the connecting server's IP is listed for the envelope sender. The ending matters: -all (fail), ~all (softfail) and ?all (neutral) have different strength. SPF breaks on simple forwarding.
  • DKIM (DomainKeys Identified Mail). The sending server signs selected headers and the body with a private key; the public key is published in DNS under a "selector". The receiver verifies the signature. DKIM proves the message was authorized by the signing domain and not altered in transit, and it survives forwarding better than SPF.
  • DMARC (Domain-based Message Authentication, Reporting and Conformance). A policy record (_dmarc.example.test) tells receivers what to do when checks fail (p=none, p=quarantine, p=reject) and where to send reports. Crucially, DMARC requires alignment: the domain that passed SPF or DKIM must match the domain in the visible From header. That closes the gap between envelope and header.

A strong rollout starts at p=none with reports to see all legitimate sources, fixes those, then moves through quarantine to reject. Related standards add more: ARC helps preserve authentication through mailing lists, MTA-STS and TLS-RPT require encrypted delivery between servers, and BIMI shows a verified logo to recipients of authenticated mail.

Protecting the content: PGP and S/MIME

SPF, DKIM and DMARC authenticate the sending domain, but they do not hide message content from servers on the way. For end-to-end confidentiality and personal signatures there are two systems.

  • PGP/OpenPGP (and compatible tools such as GnuPG) uses a web of trust: people exchange public keys, sign and encrypt messages with them. The message content, often armored in PEM-style text blocks (-----BEGIN PGP MESSAGE-----), stays unreadable to the mail servers. PEM originally meant "Privacy-Enhanced Mail", and its ASCII armor format lives on in many key and certificate files.
  • S/MIME uses X.509 certificates from certificate authorities, common in corporate environments and built into many mail clients.

Both are good at confidentiality and signing, and both are awkward in daily use because of key management, which explains why they remain niche while transport encryption and domain authentication are nearly universal. See Cryptography for Hackers for the primitives.

Common email attacks

  • Spoofing. Forging the sender address or display name to impersonate a trusted party. Without DMARC enforcement, spoofing an unprotected domain is trivial.
  • Phishing. Messages that trick users into entering credentials or opening something dangerous; spear phishing is targeted and researched, whaling targets executives (see Malware and Social Engineering).
  • Business email compromise (BEC). Impersonating a supplier or executive to request a payment or a change of bank details. There may be no malware or link at all, so technical filters see nothing odd. Process controls (call-back verification, dual approval) are the defense.
  • Malicious attachments and links. Documents with macros, archives, scripts, or links to credential-harvesting pages and malware downloads.
  • Account takeover. After a user is phished, attackers read mail, set up forwarding rules and message the user's contacts from the real account, passing every authentication check.
  • Email bombing and spam, mail relay abuse (open relays), and enumeration of valid addresses (see Service Enumeration).
  • Tracking pixels and data leaks that confirm an address is live and reveal when mail is opened.

An SPF and DMARC checker stand-in

The stand-in below implements a miniature SPF check and DMARC alignment evaluation over invented records and messages. It is deliberately simplified (real SPF has includes, macros and lookup limits), but it makes the idea of "policy plus alignment" concrete.

Node.js Evaluate SPF and DMARC alignment

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

The second message passes nothing and the domain publishes p=reject, so it is rejected. The third shows why a p=none or ~all domain is still spoofable: the check fails, but the policy asks receivers only to monitor.

Spotting phishing signals

Filters combine many weak signals. The second stand-in scores a message the way a simple filter might and prints reasons, which also helps train users to look for the same clues. The rules are illustrative, not complete.

Node.js Score a message for phishing signals

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with node:readline or process.stdin), it gets the next line from this box.

Defender checklist

  1. Publish SPF, sign with DKIM and move DMARC to quarantine and then reject after reviewing reports. Also protect domains you do not send mail from with a null SPF and p=reject.
  2. Use TLS between servers (MTA-STS) and keep mail software patched.
  3. Filter attachments and links; block macros from the internet; use sandboxing for suspicious files.
  4. Require multi-factor authentication, ideally phishing-resistant, so a stolen password is not enough (Authentication Flaws).
  5. Add process controls for payments and bank detail changes.
  6. Train people and give them an easy "report phishing" button, then run authorized simulations and respond to reports quickly (incident response).
  7. Monitor for new inbox forwarding rules, impossible-travel logins and mass mailings.

Why email security also protects privacy

Email security is more than blocking spam. Encryption in transit (TLS between mail servers) and at rest, plus end-to-end options such as S/MIME or PGP for sensitive content, protect privacy: they keep messages from being read on relays, by a compromised mailbox provider or by a misdirected copy. Combined with SPF, DKIM and DMARC they also stop others impersonating your domain, which protects your customers' privacy as well as your reputation.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What does DMARC alignment require?

    Alignment ties authentication to the domain the user actually sees, closing the gap between envelope and header From.
  2. 2. Why is business email compromise hard to stop with technical filters?

    BEC relies on social pressure and process gaps. Verification procedures and dual approval are the main defenses.
  3. 3. What does DKIM provide?

    DKIM signs headers and body so receivers can verify authorization and integrity. SPF is the IP list.
  4. 4. Which statement about PGP and S/MIME is correct?

    They protect message contents and identity, at the cost of managing keys or certificates.

Summary

  • SMTP does not verify senders; SPF (allowed servers), DKIM (signatures) and DMARC (policy plus alignment) add domain authentication.
  • Roll out DMARC gradually from p=none to quarantine and reject.
  • PGP and S/MIME protect content and identity end to end but need key management; TLS between servers protects transport.
  • Main attacks: spoofing, phishing and spear phishing, BEC, malicious attachments and links, account takeover and enumeration.
  • Defenses combine authentication, filtering, multi-factor authentication, payment verification procedures, user reporting and monitoring.

Next: Privilege Escalation Concepts and OS Hardening