[Intermediate] — the four defences that made the classic exploit stop working, and exactly what each one does and doesn’t stop.
The kid version first
Every simple exploit in the last two notes assumed the defender did nothing. Real systems stack up defences:
- Don’t let the stack run as code (so injected shellcode won’t execute)
- Move everything to a random address each run (so you can’t hard-code where to jump)
- Put a secret guard value in front of the return address (so an overflow is detected)
- Make the program’s own code load at a random address too
None of these fixes the bug. They make it harder to turn the bug into control — and every one has a known bypass, which is what the next note is about.
The four you must know
NX / DEP — no executable stack
Memory is either writable or executable, never both. The stack and heap are writable (you put data there) so they’re marked non-executable. The code section is executable but read-only.
- Stops: injecting shellcode into a buffer and jumping to it. The CPU refuses to execute data pages
- Doesn’t stop: reusing code that’s already executable — which is exactly what ROP and ret2libc do
- Check:
checksecshowsNX enabled. This is why modern exploitation is code-reuse, not code-injection
Stack canaries — a tripwire
The compiler places a random secret value (the canary) just before the saved return address. Before the function returns, it checks the canary is intact; if an overflow clobbered it, the program aborts.
[ buffer ][ CANARY ][ saved RBP ][ return address ]
↑ an overflow reaching the return address MUST cross this first
- Stops: a naive linear stack overflow — you can’t reach the return address without smashing the canary, and the check catches it
- Doesn’t stop: a bug that leaks the canary first (then you overwrite it with its own value), a write that skips over it, or overflows that don’t touch the return address
- Check:
checksec→Canary found. The standard defeat is: leak the canary, then include it in the payload
The canary has a null byte as its low byte on Linux — deliberately, so a string-copy overflow can’t easily leak it, and so it terminates string reads.
ASLR — randomised addresses
Address Space Layout Randomization loads the stack, heap, and shared libraries at a different base address every run. So you can’t hard-code the address of buffer, or of system, or of your shellcode.
- Stops: hard-coding any address
- Doesn’t stop: an information leak that reveals one real address at runtime (from which you compute the rest, since offsets within a library are fixed), or brute force on 32-bit (too little entropy)
- Note: ASLR is an OS feature. Whether the main binary is randomised depends on PIE (below)
PIE — randomise the binary itself
Position-Independent Executable. Without it, the program’s own code loads at a fixed address (e.g. 0x400000) even with ASLR on — so gadgets and functions in the binary are at known addresses. With PIE, the binary is randomised too.
- No PIE: the binary’s own gadgets and functions are at fixed addresses → much easier. Many CTF challenges are compiled No-PIE on purpose
- PIE: you need a leak of the binary’s base before you can use its gadgets
- Check:
checksec→PIE enabled/No PIE
RELRO — protect the GOT
RELocation Read-Only hardens the GOT (Global Offset Table), which holds resolved addresses of library functions. A classic attack overwrites a GOT entry so calling printf actually calls system.
- Partial RELRO (default): the GOT is still writable — GOT overwrite works
- Full RELRO: the GOT is read-only after startup — GOT overwrite is dead, at the cost of slower startup
- Check:
checksec→Full RELRO/Partial RELRO
Reading the defences: checksec
The single most important command before exploiting anything:
$ checksec --file=./vuln
Arch: amd64-64-little
RELRO: Partial RELRO ← GOT overwrite possible
Stack: No canary found ← naive overflow works
NX: NX enabled ← must use ROP, not shellcode
PIE: No PIE ← binary gadgets at fixed addressesRead this like a recipe. “No canary, NX on, No PIE” says: straight overflow, no shellcode, ROP with the binary’s own gadgets, no leak needed. The defences present tell you which technique the challenge wants → bypassing mitigations.
The others, briefly
- CET / shadow stacks (recent Intel/AMD + OS) — a second, protected copy of return addresses; a mismatch aborts. Directly targets ROP, and is rolling out now
- Fortify Source (
_FORTIFY_SOURCE) — compile-time bounds checks on known-size buffers inmemcpy/strcpy - CFI (Control-Flow Integrity) — restricts indirect calls to valid targets; big in browsers and the kernel
- Pointer Authentication (ARM) — signs pointers, so a corrupted one fails verification. Standard on Apple silicon
Key insight
None of these mitigations fix the underlying bug — they raise the cost of turning it into control, and they compose. The exploitation era shifted from “inject and run” to “leak an address, defeat the canary, reuse existing code” precisely because of this stack of defences. checksec first, always — the set of enabled mitigations is the specification of which technique you need, and reading it is the difference between a plan and flailing.
Related
- bypassing mitigations — the counter to each of these
- shellcode — what NX killed
- Spectre — a different class of hardware-level attack
- weak randomness — ASLR’s entropy matters
Source: [reference] — Aug 2026.
Software engineering
Infrastructure & security
Computer science
Hardware & engineering