Lion Cipher Lab

Build a minimal userspace TCP/IP stack over a Linux TUN device (stdlib Python, real 3-way handshake)

Why it matters

Almost everyone in security can recite the TCP three-way handshake and nobody has ever emitted the bytes themselves. That gap is why packet captures feel like hieroglyphics, why 'the checksum is wrong' or 'the client sent a RST' turns into hours of flailing, and why so many people can't reason about what a firewall, a NAT, or an IDS is actually looking at. This lab closes the gap the only way that sticks: you BUILD a minimal TCP/IP stack in userspace, over a Linux TUN device, in nothing but stdlib Python, and you make a real, unmodified curl/nc complete a handshake against code you wrote.…

What you'll learn

Steps in this lab

  1. The mental model: a TUN device is a layer-3 pipe, and you are the stack behind it
  2. Create the TUN interface, give the subnet an address, and route it at your process
  3. Open the TUN from Python and read one raw packet (prove there's no Ethernet header)
  4. Hand-parse the IPv4 header — use IHL*4, never a hardcoded 20
  5. Hand-parse the TCP segment — ports, seq, ack, flags, window
  6. The checksums: IPv4 header AND TCP-with-a-pseudo-header (RFC 1071)
  7. The money shot: drive a real 3-way handshake, echo a byte, and close
  8. Cross-check on the wire with tcpdump, and walk the named failure modes
  9. The judgment: build-to-understand only — where userspace TCP is actually real

Open the full interactive lab →