Use After Free / Double Free
Two common bugs seen in heap
Use After Free
Occurs when a program frees the memory but accesses it again because of certain misconfigurations (E.g No NULL ptr). Combined with the First-Fit logic of allocators, this can potentially let attackers manipulate which memory blocks are reused.
Double Free
Occurs when a memory address is freed twice which opens up possibilities for other attacks. The allocator might allocate memory and give two different pointers pointing to the same memory location.
To bypass fasttop
, free another chunk in between the double free.
For malloc() memory corruption
, make sure that the size parameter in the chunk is valid.
Example 1 (From ironstone's gitbook) :
Goal of this binary is to obtain a arbitrary stack variable write via double free.
Solution:
Trigger double free vulnerabilityusing the
create()
anddelete()
functions, then proceed to allocate another chunkAllocating another chunk after the double free causes us to reference the freed chunk, and we know that freed chunks contain the fd (addr to next chunk to be allocated) in the user data section instead, we can use this to determine the address of our fake stack chunk to be allocated later (address of admin variable)
We can then allocate two more buffer chunks so that eventually our allocation will point to the stack variable as seen below.
We also need to add appropriate padding/alignment for the fake_metadata variable
This gives us our solve script.
Last updated