House of Force

so much shit

Overview

Requirements

  • The ability to override top chunk size limit with a overflowing limit 0xFFFFFFFFFF, usually done with a heap overflow

  • Be able to control the size of the heap allocation - program specific - usually able to

  • glibc≤2.29 (was patched)

What is the Top Chunk?

It is the chunk which borders the top of an arena. While servicing 'malloc' requests, it is used as the last resort. If still more size is required, it can grow using the sbrk system call. The PREV_INUSE flag is always set for the top chunk.

Steps

  1. Utilizing a heap overflow, overflow the size of the top chunk header

  2. Calculate the distance between the address of the top chunk (get a leak somewhere via UAF)

    1. This is done so that a malloc with that size will be performed which will move the top chunk to that position

  3. Allocate the size of the distance minus 0x24 (64 bits) or 0x10 (32 bits) to account for metadata of the top chunk and new chunk

  4. Do another malloc to get a chunk at the target address

What can you do with this?

  • Overwrite stack/heap variables

  • Pop shells by overwriting hooks __malloc_hook with one_gadget

Example 1 - Initigri CTF 2024 1337UP

  1. Binary has a UAF as it does not null the pointer after freeing and allows for modification of freed memory via edit_note

  2. Binary also has a heap overflow in the edit_note function

Last updated