Frontend Labs
⋯

Chapter 40 — Hands-on: seeing the network

Why this chapter exists

Every claim in Parts 7–9 is checkable with a packet capture. Being able to capture, filter, and read traffic — and to run a safe attack in your own lab — turns theory into intuition.

tcpdump — capture anywhere

# interfaces
sudo tcpdump -D

# basic: interface, no name resolution, snap full packets
sudo tcpdump -i any -n -s0

# write to a file for Wireshark; rotate to keep size sane
sudo tcpdump -i any -n -w /tmp/cap.pcap -C 100 -W 5   # 5 x 100MB ring

# read back with a display filter
tcpdump -n -r /tmp/cap.pcap 'tcp port 443'

# --- filters you'll actually use (BPF syntax) ---
sudo tcpdump -i any -n 'host 10.0.0.5'
sudo tcpdump -i any -n 'tcp port 443 and host example.com'
sudo tcpdump -i any -n 'udp port 53'                       # DNS
sudo tcpdump -i any -n 'tcp[tcpflags] & (tcp-syn|tcp-fin) != 0'   # conn setup/teardown
sudo tcpdump -i any -n 'icmp'
sudo tcpdump -i any -nA 'tcp port 80'                      # ASCII payload (plaintext HTTP)
sudo tcpdump -i any -n 'not port 22'                       # exclude your ssh session
sudo tcpdump -i any -n 'net 10.0.0.0/8 and not net 10.0.20.0/24'

Wireshark / tshark — read deeply

# terminal Wireshark
tshark -i any -f 'tcp port 443' -Y 'tls.handshake.type == 1'   # ClientHellos
tshark -r /tmp/cap.pcap -Y 'http.request' -T fields \
       -e ip.src -e http.request.method -e http.host -e http.request.uri
tshark -r /tmp/cap.pcap -q -z conv,tcp        # conversation summary
tshark -r /tmp/cap.pcap -q -z io,phs          # protocol hierarchy

# decrypt YOUR OWN TLS with a key log
SSLKEYLOGFILE=/tmp/keys.log curl -s https://example.com -o /dev/null
tshark -r /tmp/cap.pcap -o tls.keylog_file:/tmp/keys.log -Y http2

# Wireshark GUI display filters worth memorising:
#   tls.handshake            ip.addr == 10.0.0.5
#   http.response.code >= 400 dns.flags.rcode != 0
#   tcp.analysis.retransmission   tcp.flags.reset == 1
#   tls.record.version == 0x0301  (probes for old TLS)

nmap — discovery and service inspection (your hosts / lab only)

nmap -sn 10.0.20.0/24                      # host discovery (ping sweep)
nmap -sS -T4 --top-ports 1000 10.0.20.5    # SYN scan, common ports
nmap -sV -sC -p 22,80,443 10.0.20.5        # version + default scripts
nmap --script ssl-enum-ciphers,ssl-cert -p 443 shop.securesh.op
nmap --script ssh2-enum-algos,ssh-auth-methods -p 22 app-01.internal
nmap -sU --top-ports 50 10.0.20.5          # UDP (slow)
nmap -A -oA scan_result 10.0.20.5          # everything; save 3 formats

Chapter 0.6, restated: nmap against systems you don't own or have written permission to test can be a criminal offence. Lab, HTB/THM, and your own infrastructure only.

A safe MITM lab (isolated, VMs you own)

   Setup: two VMs (victim, gateway-sim) + one attacker VM on a HOST-ONLY
   network with no route to anything real.

   1. On attacker: enable IP forwarding, then:
        sudo bettercap -iface eth1
        > set arp.spoof.targets 192.168.56.10
        > arp.spoof on
        > net.sniff on
   2. On victim: browse to the plaintext test app you host on gateway-sim.
      Watch credentials appear in bettercap's log.
   3. Now serve the app over HTTPS with a cert from your Ch 29 mini-CA
      (trusted on the victim). Repeat -- bettercap sees only TLS records.
   4. Try `set https.proxy on` (sslstrip-style). It works UNTIL you add an
      HSTS header (Ch 31) -- then the browser refuses the downgrade.
   5. On gateway-sim's switch/bridge, add static ARP entries (or enable
      DAI on a real managed switch) and watch step 1 stop working.

   Deliverable: ~/sec-lab/reports/part9-mitm.md -- what each layer of
   defence (TLS, cert validation, HSTS, DAI) removed from the attacker.

Practice / drill (45 min)

  1. Capture your own DNS for 60 s. List every domain your machine looked up. Anything surprising? (Telemetry, ad/track domains, OS phone-home.)
  2. Capture a single curl https://example.com. In Wireshark, identify: the ClientHello (and the SNI), the ServerHello, where handshake bytes stop being readable, and the first Application Data record. Note you cannot read the HTTP.
  3. Re-do (2) with SSLKEYLOGFILE set and Wireshark configured — now read the HTTP/2 request and response.
  4. nmap -sV your own laptop/router. For every open port, name the service and decide: should that be exposed? Close one.
  5. Run nmap --script ssl-enum-ciphers against a site you use. Cross-check the result against Chapter 31's "sane config".
  6. In your MITM lab, produce the defence-by-defence table from the deliverable above.

Common confusions

  • "tcpdump needs root for no reason." Raw packet capture is a privileged operation (you'd otherwise sniff other users/containers). Use capabilities (cap_net_raw) or a capture group instead of full root where possible.
  • "I set a capture filter and a display filter — same syntax." No. tcpdump / -f use BPF (tcp port 443); Wireshark -Y / the GUI use display filters (tls.handshake.type == 1). Different languages.
  • "Wireshark can decrypt any TLS." Only with the session keys — via SSLKEYLOGFILE for traffic you generate, or the server's private key for non-forward-secret RSA handshakes (which barely exist now).
  • "nmap is just information gathering, it's harmless/legal." Unsolicited scanning of third parties is treated as hostile and is illegal in many places.
  • "A clean nmap means the host is secure." It means those ports/scripts found nothing. Says nothing about app logic, auth, or patch level.

Check yourself

  1. Write a tcpdump filter for "DNS traffic or TLS traffic to 10.0.0.5, but not my SSH session".
  2. What's the difference between a capture filter and a display filter?
  3. How do you make Wireshark decrypt your own HTTPS session?
  4. From nmap, which flags give you service versions and which run the default script set?
  5. In the MITM lab, which single defence stops the sslstrip downgrade, and why?

Further reading

  • Book: Practical Packet Analysis (3rd ed.), Chris Sanders — the best hands-on Wireshark book. And Wireshark Network Analysis, Laura Chappell.
  • Book: Nmap Network Scanning, Fyodor (the author) — free chapters online.
  • Site: Wireshark sample captures wiki; packetlife.net cheat sheets (tcpdump, Wireshark, Wireshark display filters).
  • Labs: TryHackMe "Wireshark" and "Nmap" rooms; malware-traffic-analysis.net (real pcaps with exercises — defensive analysis practice).
  • Tool docs: man pcap-filter (BPF syntax), tshark(1), bettercap docs.

End of Part 9 — Milestone check

  • I can classify any network attack by the position it needs (passive on-path / active on-path / off-path) and give the matching defence
  • I can explain ARP spoofing and the switch features that stop it
  • I know exactly what an active attacker needs to MITM TLS, and why HSTS + CT + trust-store control usually prevent it
  • I can explain the Kaminsky attack and why DNSSEC — not port randomisation — is the real fix
  • I know the difference (and the pairing) between DNSSEC and DoH/DoT
  • I can write a default-deny firewall ruleset with egress filtering
  • I can state the zero-trust principle and why a VPN is not it
  • I stood up WireGuard between two machines and confirmed the tunnel is opaque on the wire
  • I built a segmented SecureShop and verified the reachability matrix
  • I ran a MITM lab and documented what each defence layer removed
  • I can capture, filter, and read traffic with tcpdump/Wireshark, and decrypt my own TLS

Generated from real-life-guide.md · 8 Oct 2026 16:36