skills/binary-exploitation/libc-heap/bins-and-memory-allocations/SKILL.md
A skill for understanding and exploiting glibc heap memory management, including tcache, fast bins, unsorted bins, small bins, large bins, and top chunk manipulation. Use this skill whenever working on binary exploitation challenges involving heap vulnerabilities, analyzing malloc/free behavior, debugging heap corruption issues, or when the user mentions heap exploitation, glibc malloc, memory bins, tcache attacks, fastbin attacks, or any heap-related CTF challenges.
npx skillsauth add abelrguezr/hacktricks-skills glibc-heap-exploitationInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
This skill helps you understand and exploit glibc's heap memory management system. The glibc malloc implementation uses several types of bins to efficiently manage freed memory chunks.
| Bin Type | Count | Max Chunks | Size Range (64-bit) | Link Type | |----------|-------|------------|---------------------|------------| | Tcache | 64 per thread | 7 | 24-1032 bytes | Singly-linked | | Fast | 10 | 0x80 | 16-80 bytes | Singly-linked (LIFO) | | Unsorted | 1 | - | - | Doubly-linked | | Small | 62 | - | 16-512 bytes | Doubly-linked | | Large | 63 | - | 512+ bytes | Doubly-linked |
Each heap chunk has a header containing:
When a chunk is freed, it goes through this decision tree:
Tcache check: Is chunk ≤ 512 bytes (64-bit) AND tcache bin not full (7 chunks)?
Fast bin check: Is chunk ≤ 80 bytes (64-bit)?
Unsorted bin: Add to unsorted bin first
Small/Large bins: Based on size thresholds
When to use: When you can control the next pointer in a freed chunk.
Requirements:
Attack pattern:
1. Allocate chunk A (size X)
2. Allocate chunk B (size X)
3. Write fake next pointer to chunk A's content
4. Free chunk A (goes to tcache)
5. Free chunk B (goes to tcache)
6. Allocate chunk C → gets chunk B
7. Allocate chunk D → gets chunk A with fake next
8. Chunk D points to your controlled address
Key insight: Tcache uses singly-linked lists, so you only need to control the next pointer, not prev.
When to use: When tcache is disabled or full, and you can control freed chunk content.
Requirements:
Attack pattern:
1. Allocate chunk A (fastbin size)
2. Allocate chunk B (fastbin size)
3. Write fake next pointer to chunk A
4. Free chunk A (goes to fastbin)
5. Free chunk B (goes to fastbin)
6. Allocate → gets chunk B
7. Allocate → gets chunk A with fake next
Key insight: Fastbins use LIFO, so the last freed chunk is allocated first.
When to use: When you need to manipulate chunk sizes or merge chunks.
Requirements:
Attack pattern:
1. Allocate chunk A (large size)
2. Allocate chunk B (large size)
3. Free chunk A (goes to unsorted bin)
4. Modify chunk A's size field
5. Allocate chunk C (triggers unsorted bin sorting)
6. Chunk A gets sorted with modified size
Key insight: Unsorted bin chunks are sorted into small/large bins on demand, allowing size manipulation.
When to use: When you need precise control over chunk placement.
Requirements:
Attack pattern:
1. Allocate multiple chunks of same size
2. Free them all (go to unsorted, then small bin)
3. Modify chunk pointers in small bin
4. Allocate to get controlled chunk
Key insight: Small bins use doubly-linked lists, requiring control of both next and prev pointers.
When to use: For large allocations where size manipulation matters.
Requirements:
Attack pattern:
1. Allocate large chunk A
2. Free chunk A (goes to unsorted, then large bin)
3. Modify chunk A's size field
4. Allocate large chunk B (triggers large bin search)
5. Chunk A found with modified size
Key insight: Large bins sort by size, so modifying size affects search order.
# View all heap bins
heap bins
# View heap chunks
heap chunks
# View specific arena
heap arena
# View malloc state
heap malloc-stats
# Visualize heap
heap visualize
from pwn import *
# Connect to process
p = process('./vuln')
# Read heap memory
heap_addr = p.libc.symbols['__malloc_hook'] - 0x231000
heap_data = p.read(heap_addr, 0x1000)
# Parse chunk headers
for i in range(0, len(heap_data), 16):
size = u64(heap_data[i:i+8]) & 0xfffffffffffff
print(f"Chunk at {hex(heap_addr + i)}: size={hex(size)}")
Pattern: Free a chunk, then use the pointer without reallocating.
Exploitation:
Pattern: Free the same chunk twice.
Exploitation:
Pattern: Write beyond chunk boundary.
Exploitation:
Pattern: Write one byte beyond boundary.
Exploitation:
# In GEF
gef➤ heap bins
# Look for which bin contains your chunk
# Check tcache
Tcachebins[idx=X, size=0xXX, count=Y]
# Check fastbin
Fastbins[idx=X, size=0xXX]
# Check unsorted
Unsorted Bin for arena at 0xXXXX
# Check small/large
Small Bins for arena at 0xXXXX
Large Bins for arena at 0xXXXX
Use the calculate_bin_index.py script (see scripts/) to determine which bin a chunk will go to based on its size.
# Track malloc/free order
allocations = []
frees = []
# In your exploit
allocations.append(malloc(size))
frees.append(free(ptr))
# Analyze which bin each freed chunk goes to
-g and run with gdb for better analysisLD_PRELOAD carefully, it can affect behaviorSee the scripts/ directory for helper tools:
calculate_bin_index.py - Calculate which bin a chunk size belongs toanalyze_heap_dump.py - Parse and analyze heap memory dumpsgenerate_test_program.py - Generate test programs for specific bin typestesting
How to perform a House of Lore (small bin attack) heap exploitation. Use this skill whenever the user mentions heap exploitation, small bin attacks, fake chunks, glibc heap vulnerabilities, or needs to insert fake chunks into small bins for arbitrary read/write. Trigger for CTF challenges involving heap corruption, glibc 2.31+ exploitation, or when the user needs to bypass malloc sanity checks using fake chunk linking.
testing
How to perform House of Force heap exploitation attacks. Use this skill whenever the user mentions heap exploitation, House of Force, top chunk manipulation, arbitrary memory allocation, malloc manipulation, or wants to allocate chunks at specific addresses. Also trigger for CTF challenges involving heap overflows, top chunk size overwrites, or when the user needs to calculate evil_size for heap attacks. Make sure to use this skill for any binary exploitation task involving glibc heap manipulation, even if they don't explicitly say "House of Force".
tools
How to perform House of Einherjar heap exploitation to allocate memory at arbitrary addresses. Use this skill whenever the user mentions heap exploitation, glibc heap attacks, arbitrary memory allocation, off-by-one overflow exploitation, tcache poisoning, fast bin attacks, or any CTF challenge involving heap manipulation. This is essential for binary exploitation tasks where you need to control malloc() return addresses.
testing
How to identify, analyze, and exploit heap overflow vulnerabilities in binary exploitation challenges and real-world scenarios. Use this skill whenever the user mentions heap overflows, memory corruption, heap grooming, tcache poisoning, fast-bin attacks, or any heap-related vulnerability in CTF challenges, binary analysis, or security research. This skill covers heap overflow fundamentals, exploitation techniques, heap grooming strategies, and real-world CVE analysis.