Part 6 · Real networks: infrastructure, security and operations
Network security: attacks and defenses at every layer
Course contents
The Internet’s base protocols were designed for a world where everyone trusted everyone. Almost every lower-layer protocol (ARP, DHCP, IP, BGP, DNS) has no authentication by default; security was added later, by the layers above. This lesson is a map of attacks and defenses, from the bottom of the stack to the top.
Layer 2: the local network
| Attack | How it works | Defense |
|---|---|---|
| ARP spoofing | Forged ARP reply (“the gateway’s IP is at my MAC”); traffic flows through the attacker (MITM) | Dynamic ARP Inspection on the switch; end-to-end encryption (TLS) |
| MAC flooding | Fill the switch’s MAC table so it floods everything, like a hub | Port security (limit the number of MACs per port) |
| Rogue DHCP | A fake DHCP server hands out the attacker’s gateway and DNS | DHCP snooping |
| VLAN hopping | Double tagging, or posing as a trunk | An unused native VLAN; disable automatic trunking (DTP) |
| Evil twin (Wi-Fi) | A fake access point with the same SSID | WPA2/3-Enterprise with certificate checks; never trust public Wi-Fi |
The general fix for all of these is 802.1X (authenticate every device before it gets access to a switch port or to Wi-Fi), plus the assumption that the local network is not safe.
Layers 3 and 4
- IP spoofing: forging the source address. That’s enough for one-way attacks (reflected DDoS), but hard to use against TCP, because the replies go to the forged address. Defense: BCP 38 (RFC 2827, ingress filtering), where ISPs only pass packets from a customer whose source address really belongs to that customer, plus uRPF on routers.
- BGP hijacks and route leaks: covered in the BGP lesson; the defense is RPKI.
- Port scanning: finding open services.
nmap -sSruns a SYN scan: send a SYN; a SYN-ACK means open, an RST means closed, no answer means filtered. Defense: a small attack surface, a default-deny firewall, and monitoring. - SYN flood: defended with SYN cookies and capacity at the network edge.
- TCP reset injection: a forged RST with the right sequence number kills the connection (some filtering systems do exactly this). TLS doesn’t solve it, because the TCP header isn’t encrypted; QUIC partly does.
DDoS
| Category | Target | Example |
|---|---|---|
| Volumetric | Saturate the bandwidth | UDP amplification |
| Protocol | Exhaust state in network devices | SYN flood, fragment flood |
| Application (L7) | Exhaust server resources | HTTP floods, expensive requests; “HTTP/2 Rapid Reset” in 2023 |
Amplification and reflection: using the victim’s IP as a forged source address, the attacker sends small UDP requests to thousands of public servers (open DNS resolvers, NTP, Memcached, CLDAP, SSDP), and they send replies tens to thousands of times larger to the victim. Today’s DDoS records are in the tens of Tbps.
Defenses: anycast and enormous capacity at the edge (CDNs and scrubbing services such as Cloudflare and Akamai), rate limiting, shutting down open UDP services on the Internet, BCP 38, and, in the worst case, blackholing the target through a BGP community.
The application layer
- MITM: any place where someone can get into the path (ARP, fake Wi-Fi, DNS, BGP, a proxy) is a risk. The main defense is TLS with correct validation; HSTS (and the HSTS preload list) so that not even the first request goes over plain HTTP; and certificate pinning in sensitive apps (used with care).
- TLS downgrade and SSL stripping: forcing the client onto HTTP or a weak protocol version. Defended by HSTS and TLS 1.3, which resists downgrades.
- DNS attacks: cache poisoning, domain hijacking and subdomain takeover (see the DNS lesson).
- SSRF: your application takes a URL from the user and makes a request to it, and the attacker supplies internal addresses (
169.254.169.254for cloud metadata,localhost:6379). It’s a “network” vulnerability that lives in your code. Defense: an allowlist; resolving the name and checking the IP before connecting (and again after every redirect); and IMDSv2 on AWS. - Services that should never be directly reachable from the Internet: databases (3306, 5432, 27017, 6379, 9200), SMB (445), RDP (3389), the Docker API (2375), the kubelet (10250), and admin panels. Device search engines such as Shodan and Censys scan the whole IPv4 space every day; any open port gets found within minutes.
Principles of secure design
- Defense in depth: several independent layers, because no single layer is perfect.
- Segmentation: split the network into separate parts (VLANs, subnets, security groups, NetworkPolicy) so that a breach in one part doesn’t open up the whole network. This limits lateral movement.
- Zero trust: being “inside the network” is no reason to trust anything. Every request is authenticated and authorized based on identity (user and device), device posture and context, and internal traffic is encrypted too (mTLS). The best-known example is Google’s BeyondCorp.
- Bastion / jump host, or better, identity-aware access (such as SSM, IAP or Teleport) instead of exposing SSH to the Internet.
- IDS / IPS (Suricata, Snort, Zeek): detecting (and blocking) attack patterns in traffic. Flow logs and NetFlow support analysis after an incident.
- Least privilege in firewall rules: use
0.0.0.0/0only for services that really are public.