Lion Cipher Lab

Exploit a format string vulnerability (in your own lab)

Why it matters

This is the third rung of binary exploitation, and it is a genuinely different beast from an overflow. An overflow smashes memory by writing PAST a buffer; a format string bug needs no overflow at all — it hands attacker-controlled text straight to `printf` as the FORMAT argument, and printf will faithfully do whatever that text says: dump the stack with `%p`, read arbitrary memory with `%s`, and — the crown jewel — WRITE to an arbitrary address with `%n`. One missing `"%s",` turns a harmless log line into a read/write primitive over the whole process. The class is old and still very much…

What you'll learn

Steps in this lab

  1. Read this first: still your own machine, still authorized-only
  2. What a format string actually is (the mechanism the bug abuses)
  3. Why `printf(buf)` is catastrophic and `printf("%s", buf)` is safe
  4. Get Linux and the toolchain
  5. Write the vulnerable program — with a global that gates access
  6. Compile with mitigations off for teaching — and watch the compiler warn you
  7. Leak: dump the stack with %p and find WHERE your input lands
  8. Read: use %s at that offset to dereference memory (the read primitive)
  9. Write: use %n to flip the global and grant yourself access
  10. Why short writes exist: %hn and %hhn (don't print four billion bytes)
  11. The defenses that make this hard — and watch a hardened build reject your payload

Open the full interactive lab →