skills/binary-exploitation/libc-heap/heap-memory-functions/unlink/SKILL.md
How to analyze and exploit the unlink operation in glibc heap management. Use this skill whenever the user mentions heap exploitation, unlink attacks, glibc malloc, heap chunks, double-linked lists, heap leaks, libc leaks, or any CTF challenge involving heap memory corruption. This skill helps understand the unlink mechanism, security checks, and how to leak addresses from unlinked chunks.
npx skillsauth add abelrguezr/hacktricks-skills heap-unlink-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 the unlink operation in glibc's heap management system. The unlink function is critical for heap exploitation because it's where many vulnerabilities manifest.
Use this skill when:
When a chunk is freed, glibc removes it from its bin list using the unlink_chunk function. This operation manipulates the doubly-linked list pointers (fd and bk) to remove the chunk from the list.
mchunkptr fd = p->fd;
mchunkptr bk = p->bk;
fd->bk = bk;
bk->fd = fd;
This is the dangerous part: unlink writes to memory at fd and bk without verifying they point to valid locations. If you can control these pointers through heap corruption, you can write arbitrary values to arbitrary addresses.
Before unlink:
[fd] <-> [P] <-> [bk]
| | |
v v v
bk P fd
After unlink:
[fd] <-> [bk]
| |
v v
bk fd
Modern glibc versions include several checks to prevent exploitation:
if (chunksize(p) != prev_size(next_chunk(p)))
malloc_printerr("corrupted size vs. prev_size");
prev_size field in the next chunkif (fd->bk != p || bk->fd != p)
malloc_printerr("corrupted double-linked list");
if (p->fd_nextsize->bk_nextsize != p || p->bk_nextsize->fd_nextsize != p)
malloc_printerr("corrupted double-linked list (not small)");
Unlinked chunks don't clean their pointers, making them valuable for information leaks.
| Chunk Position | Pointer | Leaks |
|----------------|---------|-------|
| Head of list | bk | malloc_state in libc |
| End of list | fd | malloc_state in libc |
| Only chunk in list | fd and bk | malloc_state in libc |
| Chunk Position | Pointer | Leaks |
|----------------|---------|-------|
| Head of list | fd | Next available heap chunk |
| End of list | bk | Previous available heap chunk |
| Middle of list | fd and bk | Adjacent heap chunks |
If you can corrupt fd and bk pointers:
fd to point to target_addr - 8bk to point to target_addr - 16target_addr gets overwritten with controlled valuefd or bk pointermalloc_state addressfd/bk to discover other heap addressesLook for:
chunksize matches prev_size in next chunk# Load the binary
gdb ./vulnerable_program
# Enable heap debugging
set follow-fork-mode child
# Use heap tools
heap
heap chunks
heap bins
from pwn import *
# Connect to the target
p = process('./vulnerable')
# Use heap analysis
from pwn import heap
heap(p)
Challenge: A program has a use-after-free vulnerability in a heap-allocated buffer.
Goal: Leak libc address to bypass ASLR.
Approach:
fd/bk through B's overflowRemember: Heap exploitation is complex and version-dependent. Always verify your assumptions against the target's glibc version and configuration.
testing
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.