Zero-Day Lab
Interactive studio · 5 steps
Memory-corruption bugs occur when a program loses track of how much space a buffer (a fixed-size memory box) holds and writes data past its edge into neighboring variables or saved return addresses (where the function jumps back to when it finishes). Security and systems engineers study binary vulnerability triage to trace why a crash happened, prove which inputs trigger it, and fix the root cause without breaking normal traffic. In this lab, you follow a classic real-world integer slip: two base-16 network header bytes (fc ff, encoding -4) are read as a signed number (allowing negatives) instead of unsigned (positive-only), slip past a bounds check (len > 64), and widen into a 65,532-byte copy plan—then inspect the exact Apple Silicon 64-bit CPU instructions (arm64) in the macOS debugger (lldb) and check a guard against every two-byte header.
Interactive 3D · Checking a copy
Where does the copy stop?
A function, a small job inside a program, gets temporary space called a stack frame. The eight green spaces form its buffer. Each holds one byte, a unit of data. A bounds check asks whether the whole copy fits. A sanitizer checks each write and stops it if it touches off-limits guard bytes (the red zone). A canary is a secret marker byte the function checks just before it returns. Choose a check and predict when it will stop the job.
The gold tiles are incoming data. Each green space holds one byte. Will the whole request fit?
Lesson 1 · The negative packet header
Welcome. A program has room for 64 bytes, small units of data. An incoming message, or packet, starts with a count that says how many bytes to copy. That first part is the header. A wrong count could put the rest of the message in space reserved for something else.
Try the rule on paper. A count of 64 fits. A count of 65 does not. What should the program do if the count says minus four? After this lesson, you can decide which counts the program should accept before it copies a single byte.
Follow the copy plan in Lesson 1 → (download the revised lesson text)
A 65,532-byte plan in a 32-byte test tray
On Apple Silicon, both the buggy signed guard and the patched unsigned guard run the exact same compare instruction (cmp w0, #0x40), setting four CPU flags—Negative, Zero, Carry, Overflow (N=1, Z=0, C=1, V=0)—on len = -4. The very next conditional-select instruction—csel ... gt (signed greater-than) versus csel ... hi (unsigned higher)—decides whether 0xaa fill bytes overwrite adjacent fields inside a bounded 32-byte diagnostic struct.
Every C (C11 standard) specimen and JavaScript model in this lab is memory-safe by construction: writes stay clamped inside a 32-byte struct so you can measure exact field damage with zero undefined behavior.
Clone and start
You need Git and Node.js 22 or newer (plus Xcode Command Line Tools on Apple Silicon macOS to compile and disassemble native-lab/ with clang and the lldb debugger):
git clone https://github.com/itsHabib/free-to-learn.git
cd free-to-learn
git switch -c my-zero-day-lab 7dba0d743224c10a707307769782b0db3f9a2a1a
cd courses/zero-day-lab
node lab.mjs inspect -4 0 64 65
node lab.mjs flags -4
sh native-lab/verify.shPredict what buggy_plan and fixed_plan return on -4, 64 and 65 before running the commands. Open lesson 1 and the project README, or serve the course folder locally (python3 -m http.server) to use the 5-lesson reader at public/index.html and the Step 0–5 lldb scrub bar at bench/index.html.
From four green tests to all 65,536 headers
Across five lessons, you trace 16-bit little-endian headers (low byte stored first) into arm64 CPU registers, map adjacent C struct fields beside saved caller registers x29 and x30, see why four happy-path tests cover only 1/4 branch edges while missing all 32,768 negative headers, and scrub recorded hardware register states step by step.
The JavaScript model, recorded lldb trace and browser workbench work on any OS; compiling and disassembling the four C11 binaries uses Apple Silicon macOS.
Three Ways In · Layer 3 of 3 · Node.js 22+ · Zero Dependencies
Build With Your Coding Agent — 5 Rungs + Planted Traps
Build a memory-safe packet receiver and branch-coverage auditor with your coding agent across five rungs: unsigned full-frame bounds validation, constant-time tag verification, defensive buffer ownership, path-sensitive coverage selection, and canonical capability grants. Each rung gives you an architect prompt for Claude Code, Codex, or Cursor, a planted bug that unguided agents write, and a deterministic test suite that catches it.
- Unsigned delivery bounds: Validating signed/unsigned header lengths against actual arrived byte count and capacity — Planted trap: Checking
len <= 64on a signed header (-4 <= 64) or trusting claimed length past arrived bytes. - Constant-time seal check: Adjacent-field tripwire preservation and full-length constant-time MAC comparison — Planted trap: Returning on the first mismatched seal byte and leaking valid tag prefixes via byte-count timing.
- Isolated buffer ownership: Copying validated payload bytes before handing slices to downstream async workers — Planted trap: Returning a zero-copy
subarrayview that the caller mutates after validation (TOCTOU). - Path-sensitive coverage: Corpus minimization preserving distinct branch-edge histories including retry paths — Planted trap: Deduplicating traces only by final exit state and discarding the only test exercising a retry edge.
- Canonical capability grants: Authorizing resource access strictly against canonicalized keys with single-use revocation — Planted trap: Checking permissions on raw display text and decoding
%2e%2eor aliases afterward when opening storage.
unzip agent-track.zip && cd zero-day-lab/agent-track
node --test test/*.test.mjs
mkdir -p src/learner
TRACK_IMPL=learner node --test test/rung-01.test.mjs
Download 5-Rung Agent Track (agent-track.zip) Read AGENT-TRACK.md on GitHub Open agent-track/README.md on GitHub