Last Minute Notes

Network Security

Network security for engineers: the CIA triad, firewalls (stateless, stateful, WAF), network segmentation and zero trust, VPNs (IPsec, WireGuard, SSL VPN), common attacks by layer (sniffing, spoofing, MITM, DNS attacks, DDoS, SSRF), DDoS mitigation, and a practical hardening checklist.

📘 Network Security

This page covers how networks are attacked and defended, at the level an application or platform engineer needs. For application-layer security (authentication, OWASP, injection) see Authentication and Security.

Table of Contents

  1. Security Goals
  2. Firewalls
  3. Segmentation and Zero Trust
  4. VPNs
  5. Attacks by Layer
  6. Man in the Middle
  7. DDoS
  8. SSRF and Internal Network Exposure
  9. Monitoring and Detection
  10. Hardening Checklist
  11. Questions

1. Security Goals

GoalMeaningNetwork example
ConfidentialityOnly intended parties can read dataTLS, VPN encryption
IntegrityData is not altered undetectedAEAD tags, signed DNS (DNSSEC)
AvailabilityService stays reachableDDoS protection, redundancy
AuthenticationYou know who you are talking toCertificates, mTLS, SSH keys
Non-repudiationSender cannot deny sendingDigital signatures, audit logs

Defense in depth: assume every single control will fail sometime, and layer them so one failure is not a breach.


2. Firewalls

TypeDecides onNotes
Stateless packet filterEach packet alone: IPs, ports, protocolFast; must allow return traffic explicitly (AWS network ACLs)
Stateful firewallTracks connections; return traffic allowed automaticallyMost firewalls, AWS security groups, Linux conntrack
Next-generation firewallApplication identity, users, intrusion preventionPalo Alto, Fortinet; deep packet inspection
WAF (web application firewall)HTTP requests: SQL injection patterns, bad bots, rate limitsCloudflare, AWS WAF, ModSecurity with the OWASP Core Rule Set
Host firewallTraffic on one machinenftables / iptables, ufw, Windows Firewall

Rule design:

  • Default deny, then allow what is needed.
  • Filter egress too: a compromised server that cannot call out cannot exfiltrate data or reach a command and control server easily.
  • Rules are evaluated in order in ACLs; the first match wins.
  • Reference groups or tags, not IPs, in cloud rules (a security group can allow traffic "from the app tier security group").

Linux example with nftables:

nft add table inet filter
nft add chain inet filter input '{ type filter hook input priority 0; policy drop; }'
nft add rule inet filter input ct state established,related accept
nft add rule inet filter input iif lo accept
nft add rule inet filter input tcp dport { 22, 443 } accept

3. Segmentation and Zero Trust

Perimeter model: a hard shell (firewall) around a soft inside where everything trusts everything. One phished laptop or one vulnerable server gives the attacker the whole network (lateral movement).

Segmentation limits the blast radius:

TechniqueExample
Subnets and tiersPublic subnet for load balancers, private for apps, isolated for databases
DMZInternet-facing servers in a zone that cannot reach the internal network freely
MicrosegmentationPer-workload policies: Kubernetes NetworkPolicies, security groups per service
Bastion / jump hostSingle hardened entry for admin access, or better, identity-aware access (AWS SSM Session Manager, Teleport)

Zero trust (Google's BeyondCorp, NIST SP 800-207): network location grants no trust.

  • Every request is authenticated and authorized, based on user identity, device health, and context.
  • Service-to-service traffic uses mTLS with workload identities (SPIFFE).
  • Access is least privilege and short lived.
  • Everything is logged.

Practical zero trust replaces "VPN into the office network" with an identity-aware proxy in front of each internal app (Cloudflare Access, Google IAP, Tailscale with ACLs).


4. VPNs

A VPN creates an encrypted tunnel so remote traffic behaves as if it were on a private network.

TypeLayerNotes
IPsec3Site-to-site standard; IKEv2 for key exchange; ESP encrypts packets; tunnel vs transport mode; complex to configure
SSL / TLS VPN4 to 7OpenVPN, corporate remote access; passes firewalls easily on 443
WireGuard3Modern, tiny codebase (about 4,000 lines), fixed modern crypto (Curve25519, ChaCha20-Poly1305), UDP, in the Linux kernel; basis of Tailscale
Mesh VPN / overlay3Tailscale, ZeroTier, Nebula: peer-to-peer tunnels with central identity and ACLs
UseSetup
Remote accessLaptop to corporate network
Site to siteOffice or data center to cloud VPC
Split tunnelOnly corporate traffic goes through the VPN; the rest goes direct
Full tunnelAll traffic through the VPN; more control, more load

Consumer VPNs move trust from your ISP to the VPN provider; they do not make you anonymous.


5. Attacks by Layer

LayerAttackWhat happensDefense
L1Wiretap, rogue devicePhysical access to trafficPhysical security, encryption
L2MAC floodingFill switch table so it floods frames everywherePort security
L2ARP spoofingClaim the gateway's IP, intercept LAN trafficDynamic ARP inspection, TLS
L2VLAN hoppingDouble tagging or switch spoofing to reach other VLANsDisable auto-trunking, unused native VLAN
L2Rogue DHCPHand out attacker's gateway or DNSDHCP snooping
L2Evil twin Wi-FiFake access point with a trusted nameWPA3-Enterprise, certificate validation, TLS
L3IP spoofingForged source address (for reflection DDoS)Ingress filtering (BCP 38), uRPF
L3BGP hijackAnnounce someone else's prefixRPKI, monitoring
L3ICMP floods, smurfOverwhelm with ICMPRate limits, no directed broadcast
L4SYN floodExhaust half-open connection tableSYN cookies, scrubbing
L4Port scanningDiscover open services (nmap)Minimize exposed ports, detection
L4TCP reset injectionForge RSTs to kill connectionsRandom sequence numbers, encryption (QUIC hides most metadata)
L7DNS poisoning / spoofingForged DNS answersDNSSEC, encrypted DNS, random ports
L7HTTP floods, SlowlorisMany or slow requests exhaust serversRate limits, timeouts, CDN / WAF
L7SSL strippingDowngrade HTTPS to HTTP on first visitHSTS with preload
L7Credential stuffingLeaked passwords tried at scaleMFA, rate limits, bot detection

6. Man in the Middle

A MITM sits between two parties and can read or modify traffic.

Getting in the middle is often easy on a shared network. What stops the attack is authentication of the endpoint:

  • TLS certificate validation (and never disabling it with verify=False or InsecureSkipVerify).
  • SSH host key verification (the "authenticity of host can't be established" prompt exists for this).
  • HSTS so the browser never tries plain HTTP.
  • mTLS inside the network.

Corporate TLS inspection is a deliberate MITM: the company installs its own root CA on devices so a proxy can decrypt traffic. It breaks certificate pinning and mTLS, and is why some tools fail with "self-signed certificate in certificate chain" on work laptops.


7. DDoS

A distributed denial of service attack floods a target from many sources, often botnets of compromised IoT devices.

CategoryTargetExamplesMeasured in
VolumetricBandwidthUDP floods, amplification (DNS, NTP, memcached, CLDAP)Tbps
ProtocolConnection state in servers, firewalls, LBsSYN floods, fragmented packetsPackets per second
Application (L7)App servers and databasesHTTP floods, expensive search queries, HTTP/2 Rapid ResetRequests per second

Amplification: the attacker sends small requests with the victim's IP as the (spoofed) source to open servers that reply with much larger responses. Amplification factors range from tens (DNS) to tens of thousands (memcached). Record attacks have passed 20 Tbps and billions of packets per second, mostly absorbed by large CDN and cloud networks.

Mitigation layers:

  1. Absorb: anycast CDN or scrubbing service with more capacity than the attack (Cloudflare, AWS Shield, Akamai).
  2. Filter: drop obviously bad traffic at the edge (unused ports, malformed packets, known reflector protocols).
  3. Rate limit: per IP, per token, per route; challenge suspicious clients.
  4. Protect the origin: only accept traffic from the CDN's IP ranges, hide the origin IP.
  5. Design for it: autoscaling with limits, caching, cheap rejection paths, expensive endpoints behind auth.

8. SSRF and Internal Network Exposure

Server-side request forgery: the attacker makes your server fetch a URL they choose, reaching things only the server can reach.

TargetImpact
http://169.254.169.254/latest/meta-data/iam/...Cloud credentials (the 2019 Capital One breach)
http://localhost:6379, internal admin panelsUnauthenticated internal services
file:///etc/passwd, gopher://Local files, crafted protocol payloads

Defenses: allowlist destinations, resolve DNS once and block private and link-local ranges (watch for DNS rebinding and redirects), disable unused URL schemes, send outbound fetches through an egress proxy, and enforce IMDSv2 (token required, hop limit 1) on AWS.

Other exposure to avoid:

  • Databases, Redis, Elasticsearch, Docker API (2375), and Kubernetes kubelet ports reachable from the Internet; scanners find them within minutes.
  • Management interfaces (SSH, RDP) open to 0.0.0.0/0.
  • Debug endpoints (/actuator, /debug/pprof) exposed publicly.

9. Monitoring and Detection

ToolWhat it shows
Flow logs (VPC Flow Logs, NetFlow, IPFIX)Who talked to whom, when, how much; no payloads
IDS / IPS (Suricata, Zeek, Snort)Signature and anomaly detection, optionally blocking
Packet captureFull detail for investigation (tcpdump, Wireshark)
DNS logsEarly sign of malware and exfiltration
WAF and LB logsAttack patterns on HTTP
SIEMCorrelates logs across sources and alerts
eBPF tools (Cilium Hubble, Falco)Kernel-level visibility of connections per process or pod

10. Hardening Checklist

  • Encrypt everything in transit, including internal traffic (TLS 1.2+ or mTLS).
  • Default-deny ingress and restrict egress.
  • Expose only 80 and 443 publicly, behind a CDN or WAF; nothing else.
  • Admin access through identity-aware proxies or SSH with keys and MFA, never passwords.
  • Private subnets for apps and data; no public IPs on databases.
  • Segment by environment (prod, staging) and by tier.
  • Enable DDoS protection and rate limiting on public endpoints.
  • Enforce IMDSv2 and block metadata access from containers that do not need it.
  • Rotate certificates automatically and alert on upcoming expiry.
  • Turn on flow logs and DNS logs, and keep them long enough to investigate.
  • Patch network devices and VPN appliances fast; they are prime targets for exploits.
  • Run periodic external scans of your own address space.

11. Questions

QuestionShort answer
Stateless vs stateful firewall?Judges each packet alone vs tracks connections and allows return traffic
Security group vs network ACL?Stateful, instance-level, allow-only vs stateless, subnet-level, allow and deny, ordered
What is zero trust?No implicit trust from network location; authenticate and authorize every request
How does a SYN flood work and how is it stopped?Fills half-open queue; SYN cookies, scrubbing
What is a DNS amplification attack?Spoofed small queries to open resolvers produce large replies to the victim
How does HTTPS stop MITM?Certificate validation authenticates the server; attacker cannot present a valid cert
What is SSRF?Tricking the server into making requests to internal targets such as the metadata service
IPsec vs WireGuard?Flexible but complex standard vs small, modern, fixed-crypto tunnel
How do you protect against DDoS?Absorb at the edge with anycast CDN, filter, rate limit, hide origin, design cheap failure paths
Why restrict egress?Limits exfiltration and command and control after a compromise

Next: Troubleshooting and Tools.

On this page