ASLR Bypass Methods
Exploit Mitigation Bypass Techniques · Exploit Development track
6 min read
In this module
Defeating Randomisation
ASLR (Address Space Layout Randomisation) randomises where code and data land in memory, making hardcoded addresses useless. On 64-bit systems, libraries and the stack get 28+ bits of entropy — brute-forcing that isn't a realistic option. So attackers developed other routes.
Information Leaks
The most reliable ASLR bypass is an information leak - any mechanism that discloses a memory address to the attacker. A single leaked pointer from any loaded module reveals that module's base address, because the offset of any symbol within a module is fixed at compile time.
Common information leak sources:
Format string vulnerabilities: An attacker-controlled format string like %p.%p.%p.%p dumps values from the stack, which often include return addresses (code pointers) and saved frame pointers (stack pointers).
Out-of-bounds reads: Reading past the end of a buffer can disclose adjacent data, including pointers. The Heartbleed bug in OpenSSL was an out-of-bounds read that leaked heap contents, including cryptographic keys and pointers.
Uninitialised memory: Variables that are not initialised before use may contain stale pointers from previous operations. Sending this uninitialised data to the attacker (through a network response, for example) leaks addresses.
Use-after-free with info leak: Free an object, reallocate the memory with attacker-controlled data, then read through the old pointer. The overlapping data can contain pointers that the attacker can observe.
// Format string leak exampleprintf(user_input); // If user_input is "%p.%p.%p.%p"// Output might be: 0x7ffff7a2d830.0x7fffffffe120.0x400756.0x7ffff7dd4e80// These are leaked stack values, likely including return addressesLeaking a single code pointer reveals the base address of the module it belongs to. From there, the attacker can calculate the address of every gadget in that module by adding the known offset. If the leaked address is from libc, the attacker has access to the entire libc gadget catalogue, which is more than enough for a full ROP chain.
Partial Overwrites
ASLR randomizes page-aligned base addresses. On x86-64, pages are 4 KB (0x1000 bytes), so the lower 12 bits of any address within a page are always the same regardless of ASLR. A partial overwrite exploits this by modifying only the lower bytes of a pointer.
Single-byte overwrite: Changes only the lowest byte, redirecting the pointer to a different offset within the same 256-byte range. Those 8 bits sit inside the 12 fixed page-offset bits, so there's no randomness to beat at all: it works first time, every time, but only reaches 256 bytes.
Two-byte overwrite: Changes the lowest two bytes, reaching anywhere in a 64 KB window. The second byte's upper nibble is randomised, so you have to guess 4 bits: a 1-in-16 chance per attempt. A three-byte overwrite needs 12 bits (1 in 4096), which is usually where brute force stops being practical.
The address below is a made-up library pointer, 0x7f3a5c21d6a0, in the 48 bits that x86-64 user space actually uses. The coloured strips show which bits ASLR randomises: on Linux x86-64 the default mmap randomisation is 28 bits, which lands on bits 12 to 39. Press each overwrite button and count how many outlined bits fall inside the randomised strip. That count is the number of bits you're guessing.
| Field | Bits | Hex | Decimal |
|---|---|---|---|
| high bits (almost constant) | 47-40 | 0x7F | 127 |
| randomised by ASLR (28 bits) | 39-12 | 0x3A5C21D | 61194781 |
| page offset (never randomised) | 11-0 | 0x6A0 | 1696 |
This technique is particularly useful for redirecting return addresses or function pointers to nearby code without needing to know the full address. For example, redirecting a return address from the end of function A to the beginning of function B in the same library.
Return-to-PLT
On Linux, the Procedure Linkage Table (PLT) provides stubs for calling shared library functions. In non-PIE executables, the PLT is at a fixed address (because the executable is not randomized). Even with full ASLR for libraries, the attacker can return to PLT entries to call library functions like system() or mprotect(), provided the binary imports them: the PLT only has stubs for functions the program itself calls.
; PLT stub for system() at a fixed address in non-PIE binary0x400520 <system@plt>: jmp [0x601028] ; Jump through GOT entry push 0x3 ; Push relocation index jmp 0x4004e0 ; Jump to PLT resolverThis technique is why PIE (Position Independent Executables) is important - without PIE, the executable's code and PLT are at known addresses, providing a foothold even with full library ASLR.
Brute Force
On 32-bit systems or in specific scenarios, brute-forcing ASLR is feasible:
32-bit systems: Libraries typically have only 8-12 bits of entropy on 32-bit Linux. This means 256 to 4096 possible base addresses - easily brute-forceable with automated attempts.
Forking servers: Fork preserves the parent's memory layout. Each child process has the same ASLR layout. The attacker gets unlimited attempts against the same layout until the parent restarts.
Stack spraying: On 32-bit systems, the stack has limited entropy. Spraying a large ROP chain or NOP sled on the stack can cover enough of the randomized range to land a hit.
Format String Leaks in Detail
Format strings deserve special attention because they provide both read and write primitives:
// Read: leak stack values with %pprintf(attacker_input); // "%7$p" leaks the 7th value on the stack
// Read arbitrary address: %s dereferences a pointer on the stackprintf(attacker_input); // Put target address at position N, use "%N$s"
// These leaks reveal ASLR layout with a single interactionA format string vulnerability in a network-facing service is about the cleanest ASLR bypass you can get: send a format string, read the leaked values, calculate addresses, send the exploit. One connection, no crash, no retries.
Every ASLR bypass technique suggests a defensive countermeasure. Info leaks can be reduced by initialising all memory, using memory-safe languages, and minimising exposed interfaces. Partial overwrites can be mitigated by increasing randomisation granularity. PLT-based attacks are defeated by PIE. Brute force is slowed by giving each new child process a fresh layout (fork-then-exec rather than plain fork, so crashes don't keep sharing one layout) and by throttling processes that keep crashing, as grsecurity's GRKERNSEC_BRUTE feature does. Understanding the bypass landscape helps defenders prioritise which mitigations matter most.