Overview
The House of Roman is a sophisticated leakless heap exploitation technique that achieves remote code execution through a combination of:- Fastbin manipulation with relative overwrites
- Unsorted bin attack on
__malloc_hook - Relative overwrite to point
__malloc_hookto system/one_gadget
Glibc Version Compatibility
Compatible with: glibc 2.23 - 2.28
Requirements
- UAF or Overflow: Ability to edit fastbin and unsorted bin pointers
- Heap Control: Good control over allocation sizes and freeing
- Brute Force: Willingness to brute force 12 bits (0.02% success rate)
- No Leaks Required: Technique is completely leakless
What It Achieves
The House of Roman allows an attacker to:- Point a fastbin chunk to
__malloc_hookwithout knowing its address - Write a libc pointer to
__malloc_hookvia unsorted bin attack - Overwrite the libc pointer to point to system or a one-gadget
- Gain code execution on the next malloc call
Technical Details
Three-Stage Attack
Stage 1: Point Fastbin to __malloc_hook
Create a fastbin chain that eventually points to
__malloc_hook using relative overwrites:- Allocate chunks with careful alignment
- Create a fastbin chunk that points to a heap chunk containing a libc pointer
- Use a single-byte relative overwrite to redirect the fastbin chain
- Overwrite the libc pointer to point near
__malloc_hook(requires 4-bit brute force)
Stage 2: Unsorted Bin Attack
Write a libc address to
__malloc_hook using the unsorted bin attack:- Allocate and free a chunk into the unsorted bin
- Overwrite the chunk’s
bkpointer to point to__malloc_hook - 0x10 - Trigger the unsorted bin attack by allocating the same size
- This writes
main_arena + 0x68to__malloc_hook
Source Code
The following code demonstrates the House of Roman technique. For educational purposes, the exploit sets random values to make it consistent, but in a real attack, 12 bits would need to be brute-forced.
Walkthrough
Stage 1: Fastbin Manipulation (Detailed)
Stage 1: Fastbin Manipulation (Detailed)
The first stage creates a fastbin chain that eventually points to
__malloc_hook:- Heap Layout Setup: Allocate chunks with specific offsets to enable single-byte overwrites
- Create Libc Pointer: Free a chunk into unsorted bin, then split it to get a chunk with main_arena pointers
- Fastbin Chain: Create a fastbin chain:
fastbin_victim -> relative_offset_heap - First Relative Overwrite: Change last byte of fastbin_victim’s fd pointer to point to fake_libc_chunk
- Second Relative Overwrite: Change fake_libc_chunk’s fd (which points to main_arena) to point near
__malloc_hook - Brute Force: The second overwrite requires 4-bit brute force for the upper nibble
Stage 2: Unsorted Bin Attack (Detailed)
Stage 2: Unsorted Bin Attack (Detailed)
The unsorted bin attack writes a large value (main_arena address) to an arbitrary location:
- Allocate and Free: Get a chunk into the unsorted bin
- Overwrite bk: Change the chunk’s
bkpointer to__malloc_hook - 0x10 - Trigger Attack: Allocate the same size chunk
- Result: The unsorted bin code writes
main_arena + 0x68to__malloc_hook
__malloc_hook contains a libc address, but it points to main_arena, not system.Stage 3: Final Overwrite (Detailed)
Stage 3: Final Overwrite (Detailed)
The final stage converts the main_arena pointer into a system/one_gadget pointer:
- Calculate Offset: Determine the byte difference between main_arena and system
- Relative Overwrite: Overwrite 2-3 bytes of the
__malloc_hookvalue - Brute Force: This requires 8 additional bits of brute force (total: 12 bits)
- Trigger: Next malloc call executes system or one_gadget
/bin/sh as the malloc size argument. For one_gadget, just call malloc with any size.Entropy and Success Rate
CTF Challenges
No specific CTF challenges listed for this technique, but it can be applied to challenges requiring leakless exploitation on glibc 2.23-2.28.References
- Original House of Roman Write-up
- Ret2 Wargames Interactive Demo
- [Unsorted Bin Attack Explanation/techniques/bins/unsorted-bin-attack)
Related Techniques
- [Fastbin Dup/techniques/fastbin/fastbin-dup) - Basic fastbin manipulation
- [Unsorted Bin Attack/techniques/bins/unsorted-bin-attack) - Write-what-where primitive
- House of Orange - Another technique targeting
__malloc_hook
