skills/binary-exploitation/libc-heap/double-free/SKILL.md
How to identify, understand, and exploit double-free heap vulnerabilities in C programs. Use this skill whenever the user mentions double-free, heap corruption, memory allocator attacks, fast bin dup, tcache poisoning, or any heap-based vulnerability in C code. Also trigger when users are working on CTF challenges involving heap exploitation, analyzing malloc/free patterns, or debugging memory corruption issues.
npx skillsauth add abelrguezr/hacktricks-skills double-free-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.
A skill for understanding and exploiting double-free vulnerabilities in C programs.
A double-free occurs when the same memory block is freed more than once. This corrupts the heap allocator's internal data structures and can lead to:
// Fill tcache with 7 freed chunks
free(a); free(b); free(c); free(d); free(e); free(f); free(g);
// Double-free with intervening free
free(h); // First free of h
free(i); // Intervening free (bypasses double-free check)
free(h); // Second free of h - now h is in fast bin twice!
// Reallocate - i1 and i2 get the SAME address
char *i1 = malloc(10); // Gets h's address
char *i2 = malloc(10); // Also gets h's address (duplicate!)
When tcache is involved, you can use null-byte overflows to corrupt size fields:
// Pattern 1: Direct double-free
void *ptr = malloc(100);
free(ptr);
// ... some code ...
free(ptr); // VULNERABLE
// Pattern 2: Conditional double-free
if (condition) {
free(ptr);
}
// ... code that might free ptr again ...
free(ptr); // VULNERABLE if condition was true
// Pattern 3: Function call double-free
void process(void *data) {
// ... uses data ...
free(data); // Frees it
}
// Caller also frees data - VULNERABLE
# Set breakpoints on free
break free
# Watch for suspicious patterns
watch *(void **)ptr
# Use pwndbg heap analysis
heap
heap chunks
vmmap
When you can't directly overwrite __malloc_hook:
__malloc_hook)__malloc_hook#include <stdio.h>
#include <stdlib.h>
int main() {
char *a = malloc(10);
char *b = malloc(10);
char *c = malloc(10);
free(a);
free(b);
free(a); // DOUBLE FREE - a is now in fast bin twice!
char *a1 = malloc(10); // Gets a's address
char *a2 = malloc(10); // Also gets a's address!
// Now a1 and a2 point to same memory
strcpy(a1, "controlled"); // Also modifies a2!
return 0;
}
free(ptr) called twice on same pointer__malloc_hookmain_arena offset to reach __malloc_hook// Always NULL out pointers after freeing
void *ptr = malloc(100);
free(ptr);
ptr = NULL; // Prevents double-free
// Use smart pointers in C++
std::unique_ptr<char[]> ptr(new char[100]);
// Automatically freed, can't double-free
free() calls and trace pointer ownership| Technique | When to Use | Key Requirement | |-----------|-------------|------------------| | Fast Bin Dup | Classic double-free | 7 freed chunks to fill tcache | | Tcache Poisoning | Modern glibc | Tcache enabled, size field corruption | | Address Disclosure | PIE binaries | Need to leak addresses first | | Code Execution | Full control | Can overwrite function pointers |
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.