Overview
The House of Gods is an arena hijacking technique for glibc < 2.27 that supplies attackers with arbitrary write capability against thethread_arena symbol of the main thread. By hijacking the arena pointer, attackers gain complete control over heap allocation behavior, enabling trivial escalation to arbitrary code execution.
The technique demonstrates how to replace main_arena with a carefully crafted fake arena within only 8-11 allocations.
Glibc Version Compatibility
Requirements
- 8 Allocations: 8 allocations of arbitrary size to hijack arena (+2 for ACE)
- Chunk Control: Control over first 5 quadwords of chunk userdata
- Write-After-Free: Single WAF bug on an unsorted chunk
- Heap Leak: Need heap address leak
- Libc Leak: Need libc address leak
What It Achieves
The House of Gods enables:- Arena Hijacking: Replace
thread_arenawith fake arena - Complete Heap Control: Control all malloc operations
- Arbitrary Allocation: Return any pointer from malloc
- Fast ACE: Trivial escalation to code execution
- Efficient: Only 8-11 allocations needed
Technical Details
The Binmap Attack
The core of House of Gods is the “binmap attack” - allocating a fake chunk that overlaps thebinmap field within main_arena.
Craft Fake Size via Binmap
Allocate and bin a smallchunk (e.g., 0x90) into smallbin. This triggers
mark_bin(m, i) which sets the binmap. The value 0x200 at offset 0x855 in main_arena serves as a valid size field for a fake chunk at offset 0x850.Link Binmap Chunk to Unsorted Bin
Use a write-after-free bug to redirect the unsorted bin to the binmap-chunk at
main_arena + 0x850. The main_arena.next pointer at offset 0x868 acts as a valid bk pointer, passing the partial unlink check.Allocate Binmap Chunk
Request a chunk of size 0x1f8 (matching the fake size). This allocates the binmap-chunk, giving control over
main_arena.next at offset 0x868.Unsorted Bin Attack on narenas
Perform unsorted bin attack targeting the
narenas variable, writing a large value to exceed narenas_limit. This forces subsequent allocations to reuse arenas.Inject Fake Arena
Write the address of a fake arena into
main_arena.next. This fake arena will be in the arena list traversal.Source Code
Walkthrough
Understanding the Binmap
Understanding the Binmap
The When a chunk is binned, For a 0x90 chunk, this sets binmap to 0x200 at offset 0x855.By reading memory at offset 0x850:This forms size 0x0200, valid for unsorted bin!
binmap is a bitmap in main_arena that tracks which bins contain chunks:mark_bin(m, i) sets a bit:The reused_arena() Traversal
The reused_arena() Traversal
When narenas exceeds narenas_limit, malloc calls The arena list is:By controlling
reused_arena():main_arena.next, we control where the second call goes!First call:- Starts at
next_to_use(=main_arena) - Returns
main_arena
- Starts at
main_arena(from first call) - Traverses to
main_arena.next(our fake arena!) - Returns fake arena
- Sets
thread_arena = fake_arena
Why Invalid Size Triggers reused_arena()
Why Invalid Size Triggers reused_arena()
When you request 0xffffffffffffffc0 bytes:
- Malloc adds header size:
0xffffffffffffffc0 + 0x10 = 0xffffffffffffffd0 - Checks if size >
PTRDIFF_MAX(maximum valid size) - Fails size check, returns NULL
- Before returning, tries to find working arena
- Calls
reused_arena()to get a different arena - Retries with new arena
Fake Arena Requirements
Fake Arena Requirements
The fake arena only needs minimal setup:For fastbin-based arbitrary allocation:
- Set
fastbinsY[index]to target address - Ensure target has valid size field
- Call malloc(size) to get target back
Visual Representation
CTF Challenges
No specific challenges listed, but applicable to:- CTF challenges on Ubuntu 16.04 (glibc 2.23)
- Old challenges on glibc 2.24-2.26
- Historical heap exploitation challenges
References
Related Techniques
- House of Mind - Another arena manipulation technique
- House of Orange - File stream exploitation with arena
- [Unsorted Bin Attack/techniques/bins/unsorted-bin-attack) - Used in this technique
