Overview
The large bin attack is a powerful heap exploitation technique that leverages the insertion logic of chunks into large bins. Unlike the unsorted bin attack (patched in 2.29), large bin attack still works in modern glibc and allows writing heap addresses to two arbitrary memory locations simultaneously.This technique is based on research by dangokyo’s 2018 blog post and continues to work in the latest glibc versions.
Glibc Version Compatibility
Working Versions
All versions (2.23 - 2.41+)
Status
Still working in modern glibc!
What Does This Technique Achieve?
Large bin attack allows you to:- Write two heap addresses to arbitrary memory locations in a single operation
- Overwrite
global_max_fast- enable fastbin attacks on larger chunks - Corrupt function pointers - prepare for code execution
- Bypass modern protections - still works after unsorted bin attack was patched
The Vulnerability
This attack requires:- Heap overflow or UAF - ability to overwrite large bin chunk metadata
- Three large chunks - to trigger the specific insertion path
- Known target addresses - where you want to write heap pointers
Technical Details
Large Bin Insertion Logic
Large bins are sorted by size, with additionalfd_nextsize/bk_nextsize pointers:
victim->bk_nextsize and fwd->bk, we can write to two arbitrary locations!
The Two Write Primitives
-
First write via
bk_nextsize: -
Second write via
bk:
The offsets (0x20 and 0x10) are for
fd_nextsize and fd positions respectively. On x64: 0x20 = 32 bytes (4 pointers), 0x10 = 16 bytes (2 pointers).Memory Layout
Step-by-Step Exploitation
Move p2 to Large Bin
Allocate a small chunk to trigger sorting:
Now p2 is alone in the large bin, establishing the baseline for our attack.
Trigger Large Bin Insertion
Allocate to move p3 into large bin:When p3 is sorted into the large bin:
- p3 is larger than p2 (0x501 > 0x3f1)
- p3 will be inserted at the head
- This triggers:
p2->bk_nextsize->fd_nextsize = p3 - And:
p2->bk = p3 - Result: Two arbitrary writes!
Full Source Code
View Complete Exploit Code
View Complete Exploit Code
Why This Still Works
Unlike the unsorted bin attack, large bin attack remains unpatched because:- Complex insertion logic - Large bins require sorted insertion by size
- Necessary functionality - The
fd_nextsize/bk_nextsizemechanism is required for performance - Harder to validate - Checking all pointers would significantly impact performance
Common Attack Targets
1. global_max_fast (Most Common)
2. Double Corruption
The unique advantage of large bin attack is two writes:Advanced Techniques
Controlling Written Value
The written value is the address of the newly inserted chunk (p3). You can:- Groom heap layout - allocate p3 at a predictable address
- Use the heap address - if it points to controlled data
- Partial overwrites - on systems with ASLR where lower bytes are known
Chaining with Other Techniques
Related CTF Challenges
0CTF 2018
heapstorm2 - Showcases large bin attack in a realistic CTF scenario
Practice
Try it in your browser
Debug this technique interactively on Ret2 Wargames
Related Techniques
- Unsorted Bin Attack - Similar concept but patched in 2.29
- Tcache Stashing Unlink Attack - Another modern bin-based technique
