Catalog My learning Blog
Computer Networking for Developers: TCP, DNS, HTTP, TLS · Phase 3 · Lesson 20 · 4 min read

Network Attacks: Spoofing, MITM and DDoS

On this page
  1. Three shapes of attack
  2. IP, ARP, DNS and email spoofing
  3. Man-in-the-middle attacks and TLS
  4. DDoS attacks: volumetric, protocol and Layer 7
  5. How to spot a SYN flood
  6. DDoS defenses that work
  7. Check yourself

Three shapes of attack

Network protocols were designed for cooperating machines, so many fields are trusted without proof. Attackers exploit that in three broad ways: pretend to be someone (spoofing), intercept traffic (man in the middle), or overwhelm a target (denial of service).

Man-in-the-middle interception, address spoofing and a botnet DDoS flood side by side, each with its target and main defense.
Man-in-the-middle interception, address spoofing and a botnet DDoS flood side by side, each with its target and main defense.

IP, ARP, DNS and email spoofing

  • IP spoofing: forging the source address of a packet. The attacker never sees replies, so it's mostly used in floods and reflection attacks, not for logging in. Providers that filter outgoing packets with source addresses that aren't theirs (BCP 38) make it harder, but not everyone does.
  • ARP spoofing: on a local network, an attacker answers ARP requests for the gateway with its own MAC (Day 6), so victims send it their traffic. Defenses: Dynamic ARP Inspection on managed switches, and encrypting everything.
  • DNS spoofing and cache poisoning: tricking a resolver into caching a fake answer, so a whole network is sent to the attacker's server. Random query ids and source ports make this hard; DNSSEC makes answers verifiable.
  • Email spoofing: forged "From" addresses, countered by SPF, DKIM and DMARC records (Day 12).

Man-in-the-middle attacks and TLS

An attacker positioned between client and server (through ARP spoofing, a rogue Wi-Fi access point, or a compromised router) can read and change unencrypted traffic.

TLS defeats this when certificates are verified properly (Days 16 and 17). The attacker can't present a valid certificate for your domain. What's left are the gaps:

  • SSL stripping: intercepting the first plain http:// request before the redirect to HTTPS. HSTS tells browsers to use HTTPS only, and HSTS preloading covers even the first visit.
  • Clients that skip verification: code with verify=False or "trust all certificates" is wide open. Search your codebase for it.
  • Users clicking through certificate warnings.

DDoS attacks: volumetric, protocol and Layer 7

A DDoS (distributed denial of service) uses many machines, often a botnet of compromised devices, to exhaust a target's capacity.

TypeTargetExample
VolumetricNetwork bandwidthUDP floods; reflection and amplification, where small spoofed requests to open DNS, NTP or memcached servers trigger large replies to the victim
ProtocolConnection state in servers and firewallsSYN floods: many SYNs, no final ACK, filling the half-open connection table
Application (Layer 7)Expensive application workFloods of search queries, logins or uncached pages that look like real traffic

Real scale: the 2016 Mirai botnet of compromised cameras and routers took down the DNS provider Dyn, making many major sites unreachable, and the 2018 memcached amplification attack on GitHub peaked at 1.35 Tbit/s. Attacks have grown much larger since; providers now report attacks of many Tbit/s.

How to spot a SYN flood

On a Linux server, count half-open connections and compare with normal:

Shell
ss -tan state syn-recv | wc -l       # half-open: SYN received, no final ACK yet
ss -tan state established | wc -l    # normal connections

Thousands of SYN-RECV connections, from many sources, with established connections not growing, is the signature. Linux SYN cookies (net.ipv4.tcp_syncookies = 1, on by default) let the server answer without storing state until the final ACK, which defeats basic SYN floods.

DDoS defenses that work

  • Absorb volume upstream: a CDN or DDoS protection service (Cloudflare, AWS Shield, Google Cloud Armor) has far more capacity than your servers. Keep your origin's IPs private so attackers can't bypass it.
  • Rate limiting and challenges for Layer 7 floods, plus caching so attacks hit cheap responses.
  • Autoscaling helps with application floods, at a cost; set limits so an attack doesn't become a huge bill.
  • Encrypt and verify everything, including internal traffic, to make spoofing and interception useless.

Check yourself

Replies go to the forged source address, so the attacker never receives the SYN-ACK with the server's sequence number. Without it they can't complete the handshake or read any responses, so spoofing mainly enables floods and reflection.

The attacker can't present a valid certificate for the site, so a verifying client refuses the connection; HSTS prevents downgrade to HTTP.

The attacker sends small requests with the victim's spoofed address to open servers whose replies are much larger, so the servers flood the victim.

The server encodes the connection details in its SYN-ACK sequence number and stores nothing until the final ACK arrives, so spoofed SYNs can't fill its connection table.

A resolver tricked into caching a fake answer sends every user who asks to the attacker's address. DNSSEC and randomized ports and query ids make it much harder.