Lion Cipher Lab

Exploit a use-after-free with tcache reuse (in your own lab)

Why it matters

The first three rungs of this arc all lived on the STACK. This one steps onto the HEAP — the region where `malloc` hands out memory at runtime — and it is where the hardest, highest-impact real-world bugs live: the memory-safety flaws that dominate the critical CVEs in browsers, kernels and every large C/C++ codebase are overwhelmingly heap use-after-free and heap overflow. A use-after-free is deceptively simple: you `free` a pointer, the allocator reclaims that memory, but your code still holds — and later uses — the stale pointer. If an attacker can get their OWN data allocated into that…

What you'll learn

Steps in this lab

  1. Read this first: still your own machine, still authorized-only
  2. The heap, free(), and what a use-after-free actually is
  3. The tcache: why reuse is so predictable (LIFO free-list)
  4. Get Linux and the toolchain
  5. Write the vulnerable program — an object with a function pointer
  6. Compile with mitigations off for teaching — and read win()'s address
  7. Prove the reuse in gdb: watch the chunk go into and out of the tcache
  8. Fire the exploit: overwrite the dangling function pointer
  9. The glibc hardening that does NOT save you here — and the one that hints at the bug
  10. Do it better: how the industry actually kills this class — and where it goes next

Open the full interactive lab →