Back to Blog
Cloud IAM Security

Bypassing ASLR and DEP: Modern Exploit Mitigations and Counter-Mitigations

OffSec Research Team
10 June 2026 • 09:00 AM16 min
Bypassing ASLR and DEP: Modern Exploit Mitigations and Counter-Mitigations
TL;DR — DEP (no-execute memory) and ASLR (randomised addresses) are the two foundational exploit mitigations, and they are designed to be complementary: DEP stops you running injected code, ASLR stops you knowing where existing code lives. Defeating one without the other is usually useless. This article explains how each works, why they reinforce each other, and the counter-mitigation playbook — information leaks to defeat ASLR, ROP/JIT-spray to defeat DEP — plus how partial-ASLR gaps, non-PIE modules, brute force on 32-bit, and the newer layers (CFG, CET, PAC) reshape the fight.

Executive Summary

For roughly a decade, the central question of binary exploitation has been: how do I get arbitrary code execution on a target protected by DEP and ASLR? These two mitigations, shipped together on every modern OS, attack the two halves of a classic exploit.

A pre-mitigation exploit did two things: it placed shellcode somewhere in memory, and it redirected execution to a known address where that shellcode lived. DEP breaks the first half by making the memory where you placed data non-executable. ASLR breaks the second half by randomising the addresses of everything, so you don't know where anything is — not your data, not the system functions you'd want to call.

The reason they are deployed as a pair is that each plugs the other's hole:

  • DEP alone is weak: if you knew addresses, you could reuse existing executable code (ROP) instead of injecting your own.
  • ASLR alone is weak: if you could execute injected data, you wouldn't need to know addresses — you'd just spray and jump roughly into your own shellcode.

Together they force the attacker to solve both problems at once: find executable code to reuse (ROP) and discover where it currently lives (an information leak). That dual requirement is the entire modern exploitation workflow, and everything below is an elaboration of it.

DEP / NX: You Cannot Execute Data

diagram — rendering…
flowchart LR
    A["Memory page"] --> B{"W^X:<br/>Writable XOR eXecutable"}
    B -->|Stack / heap<br/>= writable| C["Marked NX<br/>(non-executable)"]
    B -->|Code segment<br/>= executable| D["Read-only,<br/>cannot be written"]
    C --> E["Jump into stack/heap shellcode → fault"]
    style E fill:#0c2a22,stroke:#21d48e,color:#d1fae5

Data Execution Prevention enforces W^X (write-xor-execute): a page may be writable or executable, never both. The hardware NX/XD bit traps any attempt to fetch an instruction from a non-executable page. Practically:

  • The stack and heap — where attacker input lands — are writable, therefore non-executable.
  • The code segment is executable, therefore read-only — you can't overwrite it with shellcode either.

So injecting shellcode and jumping to it is dead. The counter is code reuse: don't inject new code, repurpose code that is already executable. That is precisely what Return-Oriented Programming does — chain existing gadgets to call a memory-protection API (VirtualProtect, mprotect) and flip a region executable, then run real shellcode. DEP is not bypassed so much as persuaded to bypass itself using legitimate, already-executable instructions.

The other DEP counter is JIT spraying: abuse a runtime that legitimately generates executable code (a JavaScript/Flash JIT) to emit attacker-chosen bytes into executable pages — DEP can't object because those pages are supposed to be executable.

ASLR: You Do Not Know Where Anything Is

text
WITHOUT ASLR (predictable)          WITH ASLR (randomised each run)kernel32.dll @ 0x77E40000           kernel32.dll @ 0x7ffb_3a210000  (varies)ntdll.dll    @ 0x77F00000           ntdll.dll    @ 0x7ffb_3c8e0000  (varies)stack        @ 0x0012FF00           stack        @ randomisedheap         @ 0x00340000           heap         @ randomised

ASLR randomises the base addresses of the executable, libraries, the stack, and the heap at load time. A hard-coded address that worked on one run points at garbage on the next. This is what kills both classic "jump to my shellcode at fixed address" and naive ROP ("return into the gadget at this fixed address"), because ROP gadgets are referenced by address too.

The strength of ASLR is a function of entropy — how many random bits go into the base. This is where 32-bit vs 64-bit matters enormously:

32-bit64-bit
Usable address bits~8–16 bits of entropy28–47+ bits of entropy
Brute force feasible?Often yes (esp. forking servers)Practically never
"Spray everywhere" viable?SometimesNo — too much space

On 32-bit, the entropy is small enough that an attacker can brute force it — repeatedly trying the same guess until the randomised base happens to match — particularly against a server that fork()s child processes which inherit the parent's layout (so each crash-and-retry tests against the same randomisation). On 64-bit, brute force is hopeless and the attacker must learn the layout instead of guessing it.

The Master Key: Information Leaks

The single most important counter-mitigation is the information disclosure primitive: any bug that lets you read a pointer out of the target's memory. One leaked pointer collapses ASLR.

diagram — rendering…
sequenceDiagram
    participant A as Attacker
    participant T as Target process
    A->>T: Trigger info-leak (OOB read, format string, uninit mem, type confusion)
    T-->>A: Returns a pointer, e.g. a libc/ntdll address
    Note over A: leaked - known_offset = module_base
    A->>A: gadget_addr = module_base + gadget_offset
    A->>T: Send ROP chain built on real, current addresses
    T-->>A: Code execution (DEP defeated by ROP, ASLR by the leak)

How you leak depends on the bug class:

  • Out-of-bounds read — read past a buffer to disclose adjacent pointers (saved return addresses, vtable pointers, heap metadata).
  • Format string (printf(user_input)) — %p/%s to dump stack and memory contents directly.
  • Uninitialised memory — an object field never set, returned to the attacker, reveals whatever pointer last occupied that memory.
  • Type confusion / UAF read — interpret attacker-controlled bytes as an object whose "length" or "pointer" field you then read out of bounds.
  • Side channels — timing or speculative-execution leaks in extreme cases.

Once you have any address inside a known module, you subtract that symbol's static offset to recover the module base, then every gadget and function in that module is addressable again. Leak → base → ROP is the universal modern shape. This is why so much defensive engineering now targets info leaks specifically (see below).

Defeating ASLR Without a Leak

Leaks aren't always available. Other avenues:

  • Non-ASLR / non-PIE modules. If any loaded DLL or the main executable was compiled without /DYNAMICBASE (Windows) or without PIE (-no-pie, Linux), it loads at a fixed address. Its gadgets are reliable forever, no leak required. Mixed-randomisation is a classic real-world gap — one legacy plugin DLL can hand the attacker a stable gadget source. Tools like Microsoft's EMET/exploit-guard and "Mandatory ASLR / Bottom-up ASLR" exist precisely to force-randomise such modules.
  • Partial overwrite. ASLR typically randomises high-order address bits while the low bits (page offset within a module) are fixed. By overwriting only the low byte(s) of a saved pointer, you can redirect execution within the same page/region without knowing the full base — a precise, leak-free pivot in some bugs.
  • Brute force (32-bit / forking). As above: against a 32-bit forking server, retry until the small entropy is hit. The child's crash doesn't re-randomise the parent.
  • Heap spray to a probable band (32-bit). With low entropy, a massive spray still lands at a predictable address with high probability (the historical 0x0c0c0c0c), giving a known-enough target without a precise leak.

Defeating DEP Without ROP

ROP is the standard DEP counter, but alternatives exist:

  • `ret2libc` — the precursor to full ROP: overwrite the return address with the address of a libc function (system) and lay out its arguments, no gadget chain needed for simple goals.
  • JIT spraying — emit executable bytes via a JIT engine (constants in JS arithmetic become instruction bytes), sidestepping DEP because the JIT page is legitimately executable.
  • Disabling DEP via API — on some Windows configs, a ROP call to NtSetInformationProcess/ZwSetInformationProcess could flip the process DEP policy off (largely mitigated by permanent DEP).
  • Data-only attacks — never execute new code at all; corrupt data (function pointers already pointing at executable code, configuration, is_admin flags) to achieve the goal within existing control flow. These dodge both DEP and CFI.

The Combined Modern Exploit

text
STAGE 0  Trigger info-leak bug          -> defeat ASLR (recover module base)STAGE 1  Compute gadget & API addresses -> from leaked baseSTAGE 2  Build ROP chain                -> VirtualProtect/mprotect region -> RWXSTAGE 3  ROP returns into shellcode      -> defeat DEP, run native payload         (or skip 2-3 with a data-only / JIT-spray path)

Every line corresponds to defeating one mitigation. Remove the leak and Stage 0–1 collapse (ASLR holds). Remove ROP and Stage 2 collapses (DEP holds). This is the precise sense in which DEP and ASLR are co-dependent defences — and why the attacker must field co-dependent primitives.

The Next Layers: CFG, CET, PAC, MTE

ASLR and DEP are necessary but no longer sufficient; the platform vendors stacked further mitigations specifically targeting the ROP/leak workflow:

diagram — rendering…
flowchart TD
    A["Attacker still has<br/>leak + ROP"] --> B["CFG/CFI: indirect CALL targets<br/>must be valid function entries"]
    A --> C["CET Shadow Stack: RET must match<br/>protected return-address copy"]
    A --> D["CET IBT / ARM BTI: indirect branches<br/>must hit landing pads"]
    A --> E["ARM PAC: pointers are<br/>cryptographically signed"]
    A --> F["MTE: memory tagging catches<br/>OOB/UAF that enable leaks"]
    B & C & D & E & F --> G["ROP chains break; leaks get harder"]
    style G fill:#0c2a22,stroke:#21d48e,color:#d1fae5
  • CFG (Control Flow Guard) / CFI validate indirect call targets, breaking fake-vtable hijacks.
  • CET shadow stack independently records return addresses; a ROP ret to a gadget mismatches and faults — a direct kill for return-oriented chains.
  • CET IBT / ARM BTI force indirect branches onto landing-pad instructions, breaking jump-oriented programming.
  • ARM PAC signs pointers cryptographically, so a corrupted/forged return address fails authentication.
  • ARM MTE tags allocations so the out-of-bounds and use-after-free reads that produce leaks are caught at the source.

The pattern repeats: each new mitigation targets a specific step of the leak+ROP recipe, and attackers respond with the next technique (JOP, data-only attacks, counterfeit-object-oriented programming, leak primitives that survive MTE). The arms race never ends; it just raises the cost.

Practical Guidance

For exploit developers:

  • Always plan for a leak first. On 64-bit, no leak usually means no exploit. Identify your disclosure primitive before you design the control-flow hijack.
  • Hunt for non-ASLR modules; one fixed module is worth more than a clever leak.
  • Build chains that survive the mitigations actually present on the target — check for CFG/CET, and if present, pivot to JOP or data-only strategies.

For defenders / builders:

  • Compile everything with /DYNAMICBASE /NXCOMPAT (Windows) and -fPIE -pie -Wl,-z,relro,-z,now plus stack protectors (Linux). One non-PIE dependency undoes the whole scheme.
  • Enable CFG/CET on Windows, CET/CFI on Linux, PAC/BTI/MTE on ARM where available — these target the bypass, not just the original bug.
  • Treat any information-disclosure bug as high severity even if it "only reads memory" — it is the master key to ASLR.
  • Prefer memory-safe languages for new attack-surface code; the most durable bypass-defeat is having no memory-corruption bug to leak or hijack in the first place.

ASLR Entropy: Quantifying What You Need to Beat

The practical strength of ASLR is a direct function of the number of random bits it applies to each region's base address. Understanding the entropy is how an attacker determines whether brute force, a leak, or a partial overwrite is the right strategy.

Entropy by Platform and Region

PlatformBinary/ELF PIEShared LibrariesStackHeap
Linux x86 (32-bit)8 bits (256 positions)8 bits8–24 bits~13 bits
Linux x86-6428 bits28 bits30 bits30 bits
Windows 32-bit8 bits (/DYNAMICBASE)8 bits5–14 bits5–8 bits
Windows 64-bit19 bits (ASLR base)up to 17 bits33 bits (HEASLR)24 bits
macOS ARM64 (M-series)32 bits (slide)shared cache slidehighhigh

The critical takeaway: Linux 32-bit ASLR has only 8 bits of entropy for the main binary — 256 possible positions. Against a service that fork()s (so the child inherits the parent's layout) and either restarts on crash or doesn't kill the parent, an attacker can brute-force the correct address in at most 256 attempts. In practice this often takes under a minute at network speeds.

On 64-bit Linux, the main binary has 28 bits of entropy for a PIE binary — over 268 million positions. Brute forcing this is infeasible; a leak is required.

Calculating the Exact Entropy

On Linux, ASLR entropy is controlled by kernel parameters:

bash
# View current entropy bitscat /proc/sys/kernel/randomize_va_space   # 0=off, 1=partial, 2=full # More detailed on x86-64: mmap entropycat /proc/sys/vm/mmap_rnd_bits            # default: 28 bitscat /proc/sys/vm/mmap_rnd_compat_bits     # 32-bit compat: 8 bits # Check PIE slide entropy/proc/<pid>/maps  # run the binary twice, compare base addresses

For a PIE binary, the number of possible base addresses is 2^mmap_rnd_bits. For the stack, a typical 2^30 stack offset gives ~1 billion positions — brute force is hopeless on 64-bit, but a single stack pointer leak (e.g., via printf("%p\n", &var)) collapses it entirely.

Entropy Collapse: What Leaking One Pointer Gives You

The decisive insight is that ASLR randomises bases, not offsets within modules. Once you have any pointer into a module:

text
Leaked pointer:  0x7f4a3c1d2a40   (some libc address)Known symbol:    puts = 0x7f4a3c1d2a40 - puts_offset_in_libc                 (from the exact same libc version/build)libc_base =      leaked - puts_offset_in_libc Now known:  system()  = libc_base + system_offset  "/bin/sh" = libc_base + binsh_offset  ALL gadgets in libc at their exact current addresses  ALL gadgets in all other loaded modules if their offsets are known

A single pointer leak — from an out-of-bounds read, a format string, an uninitialised field — completely defeats ASLR for every loaded module whose base you can derive from that leak. This is why ASLR should be seen not as "random addresses" but as "a one-time random secret that collapses if any pointer escapes."

Information Leak Techniques Reference

TechniqueWhat it leaksPrerequisites
Format string (printf(user_input))Stack contents via %p; heap/libc via %s with known pointersFormat string injection
OOB readAdjacent object contents (saved return addresses, vtable ptrs)OOB read primitive
Uninitialised memoryWhatever pointer occupied that slot previouslyAllocation timing control
UAF readContent of the freed object slot — often metadata pointersUAF bug
Heap info disclosurelibc heap metadata (main_arena pointers in freed bins)Heap OOB / UAF
Kernel pointer side-channelKASLR base via proc_show_stack, timing, or speculative leaksPrivileged context or speculative-exec bug
Browser JS engineaddrof() primitive via type confusion gives direct object addressJS engine type confusion

Partial ASLR Overwrite: Bypassing Without a Full Leak

When you can only overwrite a limited number of bytes (e.g., 1–2 bytes of a saved pointer), you may not need the full leaked address — you only need enough to redirect execution to a useful target within the same page or nearby. This is the partial overwrite technique.

How It Works

ASLR randomises the high bits of an address, but the low 12 bits are always fixed (page offset within a 4 KB page). Typically:

text
Full address:  0x7f_4a_3c_1d_2a_40               ^^ ^^ ^^ ^^           <- randomised by ASLR (40+ bits)                              ^^ ^^  <- fixed (page offset, 12 bits = low 3 hex digits)

If your overflow overwrites only the lowest 2 bytes of a saved return address, you cannot change the upper bits (randomised). But you can redirect to any target within the same 64 KB region (16-bit overwrite range). This is enough to jump from a stack return address to a different function in the same binary, if that function happens to be within the reachable range — no leak required.

text
EXAMPLESaved return address:  0x555555401234  (inside .text of the PIE binary)1-byte overwrite:      change last byte to 0x80New address:           0x555555401280  (a different location in the same binary)Result: redirect to a different function/gadget in the same page — no leak, no brute force        (only works if the desired gadget is within the 1-byte overwrite range)

Partial overwrites are particularly useful against stack-based buffer overflows that overwrite a saved return address byte-by-byte (e.g., strcpy stopping at a null byte), or when an off-by-one error gives a single byte of overwrite.

Conclusion and Takeaways

DEP and ASLR are best understood not as two separate features but as a single, interlocking defence: one denies you the ability to run injected code, the other denies you the knowledge of where existing code lives, and neither is worth much without the other being solved too. That symmetry defines modern exploitation. The attacker's answer is equally paired — an information leak to recover addresses (defeating ASLR) and return-oriented programming to reuse existing code and flip memory executable (defeating DEP). Master those two primitives and the canonical leak→base→ROP→shellcode chain falls into place; everything else is adapting to the target's specifics (32-bit brute force, non-PIE modules, partial overwrites, JIT spraying, data-only paths).

The frontier has moved beyond DEP and ASLR to CFG, CET shadow stacks, PAC, and MTE — each precisely engineered to break a step of that recipe — and attackers have moved with it toward JOP and data-only techniques. But the foundational lesson is timeless and worth internalising before any advanced study: on a modern target you must defeat both mitigations, and you do so with cooperating primitives. For defenders, the corollary is unforgiving — randomise and NX-protect everything without exception, layer on the control-flow and pointer-integrity mitigations that attack the bypass itself, and guard information-disclosure bugs as the crown-jewel vulnerabilities they truly are.