Skip to content

Lesson 2 of 9 · 21m

Reading Binary Protections Correctly

Use checksec, ELF headers, symbols, and runtime inspection to determine exactly which exploitation constraints are in force.

Most bad exploit assumptions are visible before the first payload. The binary and its loader tell you whether addresses move, whether the stack executes, whether relocation entries are writable, and whether the compiler inserted stack cookies. Learn to read that evidence properly; guessing from a CTF filename is not analysis.

Start with checksec, then verify

checksec is a map, not the territory:

pwn checksec ./target
readelf -h ./target | grep Type
readelf -lW ./target | grep GNU_STACK
readelf -dW ./target | grep -E 'BIND_NOW|FLAGS'

Typical output tells you several distinct things:

Arch:     amd64-64-little
RELRO:    Full RELRO
Stack:    Canary found
NX:       NX enabled
PIE:      PIE enabled

Full RELRO affects GOT overwrite strategy. NX removes trivial shellcode execution. PIE means code and data base addresses move under ASLR. A canary changes linear stack overwrite economics. None of these is a binary pass/fail label.

Symbols and build artifacts matter

A stripped PIE binary is harder to navigate than an unstripped one, but difficulty is not impossibility. Dynamic symbols, exception frames, constructors, imported functions, and compiler-generated scaffolding remain useful:

file ./target
nm -an ./target 2>/dev/null | head
objdump -T ./target | grep -E 'system|puts|read|write'

If libc is supplied with the challenge or target environment, version-match it exactly. A Debian glibc 2.36 and Ubuntu glibc 2.35 differ enough to break offsets, one-gadget constraints, and heap behavior assumptions.

Runtime state beats static folklore

/proc answers questions your notes will eventually ask anyway:

./target &
pid=$!
cat /proc/$pid/maps | grep -E 'target|libc|stack|heap'
cat /proc/$pid/auxv 2>/dev/null | od -Ax -tx8 | head

Look at where the binary, heap, libc, stack, and vDSO landed. If addresses do not move between executions, ASLR may be disabled in the environment, the process may be run under a debugger personality, or the exploit lab may be lying to you. In real assessments, container configuration and kernel settings matter.

Mitigations compose

A binary can have a canary but not PIE, NX but partial RELRO, or static linkage with no writable GOT. Controls compose into strategy constraints. For example, no PIE may make ROP gadget addresses stable while a canary still forces you to leak or bypass the cookie. Full RELRO may redirect you toward return addresses, hooks, vtables, or application-specific function pointers.

Field notes

  • checksec cannot tell you whether the process is actually launched with ASLR enabled; inspect runtime maps.
  • Partial RELRO and full RELRO are not close cousins for exploit planning. Treat them as different targets.
  • Static binaries remove libc-leak convenience but often contain abundant gadgets; tradeoffs cut both ways.
  • Rebuild artifacts from source when available. Compiler flags and optimization level can remove the bug or change layout.

Was this lesson helpful?

Sign in to rate