Lion Cipher Lab

Write an ELF loader from scratch (map a real binary into memory and jump to its entry point)

Why it matters

Every time you type a command, the kernel performs a small miracle you have never seen: it reads a file off disk, recognizes it as an ELF binary, carves it into memory at exactly the right addresses with exactly the right permissions, builds a stack out of thin air with your arguments and a secret data structure called the auxiliary vector, and jumps into it. That machinery — binfmt_elf in the kernel, and ld.so for dynamic binaries — is the most load-bearing black box in the whole system, and almost nobody has looked inside it. This lab has you REBUILD it in userspace: a ~130-line C program…

What you'll learn

Steps in this lab

  1. The job you're about to steal from the kernel
  2. Set up a scratch box and build two target binaries
  3. Read the ELF with your eyes before you read it with code
  4. Parse the ELF64 header in C (and validate it)
  5. Map each PT_LOAD segment: mmap at the vaddr, copy filesz, zero the BSS
  6. Why even a static binary needs a stack you build by hand
  7. Hand over control: install the stack and jmp to e_entry
  8. Break it #1: forget MAP_FIXED (the segment lands at the wrong address)
  9. Break it #2: map the code W but not X (a W^X violation)
  10. Break it #3: delete the auxv (glibc dies, freestanding survives)
  11. The judgment: when to hand-roll a loader, and the next rung (PIE + ld.so)

Open the full interactive lab →