Bypassing DEP, ASLR, and Stack Canaries
What you'll learn: How attackers defeat modern memory protection mechanisms using address leaks and advanced exploitation techniques.
The Challenge of Modern Protections
You've learned how to craft memory corruption exploits, but modern systems deploy multiple defensive layers to make exploitation harder. Data Execution Prevention (DEP) blocks code execution from writable memory, Address Space Layout Randomization (ASLR) randomizes memory locations to break hardcoded addresses, and stack canaries detect buffer overflows before they overwrite return addresses. These protections don't eliminate vulnerabilities—they raise the bar for exploitation.
Defeating These Defenses
Against DEP: Since you can't execute your own shellcode, you reuse existing executable code. Return-Oriented Programming (ROP) chains together instruction fragments ("gadgets") already in memory to perform arbitrary operations without injecting new code.
Against ASLR: You need to discover actual runtime addresses. This requires an information leak vulnerability—reading memory contents to reveal where libraries are loaded. Once you leak one address from a library, you can calculate all other addresses in that library since their relative positions stay fixed.
Against Stack Canaries: Canaries are random values placed before return addresses. You must leak the canary value (through format string bugs or read vulnerabilities) before overwriting the stack, allowing you to replace it with the correct value and avoid detection.
The Attack Chain
Real-world exploitation often combines these techniques: leak a canary value and library addresses, build a ROP chain using the now-known gadget locations, overwrite the stack with the leaked canary to avoid detection, then trigger your ROP payload.
Key Takeaway: Modern exploitation requires chaining multiple techniques—information leaks to defeat ASLR and canaries, then code-reuse attacks like ROP to bypass DEP—turning single vulnerabilities into full compromise paths.