skills/binary-exploitation/common-binary-protections-and-bypasses/libc-protections/SKILL.md
How to understand and bypass modern libc memory protections including chunk alignment, pointer mangling, safe-linking, and pointer guard. Use this skill whenever working on heap exploitation, binary exploitation challenges, CTF heap tasks, analyzing glibc vulnerabilities, or when you need to understand how to leak and demangle pointers in modern glibc versions (2.32+). Make sure to use this skill when you mention heap, glibc, malloc, fastbin, tcache, pointer guard, safe-linking, or any binary exploitation context.
npx skillsauth add abelrguezr/hacktricks-skills libc-protectionsInstall 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 practical guide to understanding and bypassing modern glibc memory protections for binary exploitation and CTF challenges.
Use this skill when:
Malloc allocates memory in 8-byte (32-bit) or 16-byte (64-bit) groupings. The security feature checks that each chunk aligns correctly before using a pointer from a bin.
__malloc_hook: No longer viable due to strict alignment requirementsWhen crafting fake chunks, ensure the address ends in:
0x0 (16-byte aligned)0x8 (8-byte aligned)Note: Since glibc 2.34, legacy hooks (
__malloc_hook,__free_hook) are removed from the exported ABI. Modern exploits target tcache per-thread structs, vtable-style callbacks, or usesetcontextand_IO_list_allprimitives.
New_Ptr = (L >> 12) XOR P
Where:
Pointer mangling prevents:
If you have a heap leak, you can recover the original pointer:
def demangle(leaked_fd, storage_location):
return leaked_fd ^ (storage_location >> 12)
When both the corrupted chunk and victim chunk share the same 4KB page, you can recover the original pointer using just the page offset. If they're on different pages, brute-forcing the 12-bit page offset (0x1000 possibilities) becomes necessary.
// leaked_fd is the mangled Fd read from the chunk on the same page
uintptr_t l = (uintptr_t)&chunk->fd; // storage location
uintptr_t original = (leaked_fd ^ (l >> 12)); // demangle
Pointer guard scrambles function pointers by XORing them with a secret from thread data (fs:0x30) and applying a left rotation of 0x11 bits.
__pthread_attr_destroy)secret = (mangled >> 0x11) XOR known_addressdef demangle_pointer_guard(mangled, secret):
# Reverse the rotation
rotated = ((mangled << 0x11) | (mangled >> (64 - 0x11))) & 0xFFFFFFFFFFFFFFFF
# XOR with secret
return rotated ^ secret
The dynamic loader parses GLIBC_TUNABLES before program startup. Mis-parsing bugs here affect libc before most mitigations kick in.
An overlong GLIBC_TUNABLES value overflows internal buffers in ld.so, enabling privilege escalation on many distros when combined with SUID binaries.
GLIBC_TUNABLES environment variableCheck glibc version and enabled protections:
ldd --version # Check glibc version
Use unmangled pointers from unsorted, small, or large bins.
Apply the demangling formula with your leaked values.
Account for alignment requirements and pointer mangling in your fake chunks.
(L >> 12) XOR P, not L XOR (P >> 12)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.