Heap Exploitation Techniques
You'll learn how to exploit dynamic memory management flaws that bypass traditional stack-based protections.
What Is Heap Exploitation?
While stack overflows target function call frames, heap exploitation attacks the dynamic memory allocation system where programs store long-lived data structures. The heap is like a shared warehouse where programs request storage bins of various sizes at runtime. When developers mismanage these bins—freeing them incorrectly, reusing freed memory, or overflowing their boundaries—attackers can manipulate heap metadata to achieve code execution or information disclosure.
Core Heap Vulnerabilities
Use-After-Free (UAF)
When a program frees a heap chunk but keeps a pointer to it (a "dangling pointer"), that memory can be reallocated for something else. If the original pointer is used again, you're accessing data you shouldn't. It's like selling your storage unit but keeping the key—the new owner's belongings are now accessible to you.
Double-Free
Freeing the same memory twice corrupts the heap's internal free-list data structures. Attackers exploit this to trick the allocator into returning overlapping chunks, allowing one allocation to overwrite another's contents.
Heap Overflow
Similar to stack overflows, but overwriting adjacent heap chunks. Because heap chunks often store size metadata and pointers, corrupting these can redirect control flow or leak information when the heap manager processes them.
Exploitation Approach
Unlike stack exploitation with predictable frame layouts, heap exploitation requires understanding the specific allocator (glibc malloc, jemalloc, Windows LFH). Attackers manipulate allocator metadata—forward/backward pointers in free chunks, size fields, or bins—to achieve arbitrary writes or code execution when allocation/free operations occur.
Key Takeaway: Heap exploitation leverages memory management vulnerabilities to corrupt allocator metadata, enabling attackers to control which memory gets allocated where—ultimately achieving arbitrary read/write primitives that lead to code execution.