Excuse the ads! We need some help to keep our site up.
House of Force
malloc () allocates memory using Top chunk in the following way.
Store the value of main_arene → top in "victim" and the size of the top chunk in "size".
malloc () uses the space in Top chunk if the value of "size" is greater than or equal to "Newly requested memory size (nb) + minimum chunk size (MINSIZE)".
Store the value stored in "size" minus the size of the newly requested memory (nb) in "remainder_size" and the value stored in "victim" plus the size of the newly requested memory(nb) in "remainder" It is.
"remainder" is stored in main_arene → top.
Using set_head () saves the newly requested memory size(nb) in "victim→size" and stores the value of "remainder_size" in "remainder→size".
malloc() calls chunk2mem(), returns the address(p + 2 * SIZE_SZ).
- House of Force can overwrite the value stored in the size of the top chunk with another value and implement it if it can request the allocation of memory of the desired size.
- After requesting memory allocation to malloc(), the value of Top chunk is overwritten with 0xffffffffffffffff.
- In order to allocate the desired memory area, the calculated value is passed as the argument value of Mallo () function.
- "Address of memory you want to allocate"-"Chunk header size (16 or 8)"-Top chunk address-"Chunk header size (16 or 8)"
- After the memory allocation request, the address of the memory to be allocated is stored in the top chunk.
- Requesting memory allocation to malloc () returns that memory.
- For example, allocate one memory and overwrite the top chunk's size with 0xffffffffffffffff:
- To allocate 0x601010, it asks malloc () to allocate memory of size 0xffffffffffffeee0.
- 0x601010 - 0x10 - 0x602110 - 0x10 = 0xffffffffffffeee0
- After allocating memory, 0x601000 is stored in "main_arena→top".
- And request malloc() for memory allocation, it returns 0x601010.
- This code behaves like the previous example.
- Allocate one memory and change the value of the top chunk.
- The next memory allocation request asks malloc() for memory allocation of size 0xffffffffffffeee0 to get the desired memory address.
- Requests memory allocation to malloc() and stores the returned value in buf3.
- Store 0x4141414141414141 in buf3 and call the free() function.
- At 0x40062d, Check the allocated memory address and the value stored in the main_arena→top.
- At 0x40063b and 0x400649, note the change in the value stored in the main_arena → top.
- Check the address of the newly allocated memory at 0x400657.
- See how the data stored at 0x400672,0x40067c affects the flow of code.
- The address of the first allocated memory is 0x602010, the top chunk is 0x602110 and the size is 0x20ef1.
- Store 0xffffffffffffffff in main_arena→top→size.
- After asking malloc() for an allocation of memory of size 0xffffffffffffeee0, the Top chunk changes to 0x601000.
- This causes the next memory allocation request to be allocated an area of 0x601010.
- The program stores 0x4141414141414141 in 0x601018.
- The value stored at 0x601018 is the free@plt.
If you call the free() function at 0x40067c, the function calls free@plt(0x4004b0).
- The code moves to the address stored in 0x601018.
- An error occurs because the value stored in the area is 0x4141414141414141.
- If you enter the address of One-gadget instead of 0x4141414141414141 at 0x601018, you will get a shell.