Use this skill when the user says 'heap exploitation', 'use-after-free', 'tcache', 'ROP chain', 'CFG bypass', 'PAC', 'CET', 'memory corruption mitigation'. Explains modern memory-corruption mechanics so engineers can write memory-safe code and design compiler/allocator hardening. Defensive and educational only. Do NOT use for: generating working exploits, or for general secure-coding reviews (use security/sast-dast) or detection logic (use security/detection-engineering).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Advanced Binary Exploitation?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/j4flmao-advanced-binary-exploitation)
---
name: advanced-binary-exploitation
description: >
Use this skill when the user says 'heap exploitation', 'use-after-free', 'tcache', 'ROP chain', 'CFG bypass', 'PAC', 'CET', 'memory corruption mitigation'. Explains modern memory-corruption mechanics so engineers can write memory-safe code and design compiler/allocator hardening. Defensive and educational only. Do NOT use for: generating working exploits, or for general secure-coding reviews (use security/sast-dast) or detection logic (use security/detection-engineering).
version: "1.0.0"
author: "j4flmao"
license: "MIT"
tags: [security, binary-exploitation, memory-safety, mitigations, defensive]
---
# Advanced Binary Exploitation
## Purpose
Explain the deep mechanics of memory corruption (heap metadata, ROP/JOP, modern mitigation internals) for the purpose of building defenses: hardened allocators, compiler mitigations, and memory-safe design. This is reference material for defenders and secure-code authors, not an exploit generator.
## Agent Protocol
### Trigger
User phrases: "heap use after free", "tcache poisoning", "bypass CFG", "SROP", "glibc malloc internals", "PAC/CET hardening".
### Input Context
- Target platform/architecture (x86-64, ARM64) and toolchain.
- Which mitigation the user wants to understand or strengthen.
### Output Artifact
Explanatory analysis plus hardening recommendations. No weaponized code.
### Response Format
```
Mechanism: {what corruption class}
Why it works: {root cause}
Defense: {compiler flag / allocator hardening / code change}
```
> [!WARNING]
> **DISCLAIMER: EDUCATIONAL & DEFENSIVE PURPOSES ONLY**
> Explains the deep mechanics of memory corruption specifically for developing compiler-level mitigations, writing secure code, and understanding exploit theory. Do not generate weaponized exploits.
## 1. Skill Context
**Focus**: Heap exploitation, advanced ROP (ret2libc, SROP, JOP), modern mitigation bypasses (CFG, PAC, CET).
**Triggers**: heap use after free, tcache poisoning, bypass cfg, srop, glibc malloc exploit
## 2. Deep Memory Corruption Mechanics
Moving beyond basic stack overflows into modern, highly mitigated environments.
### The Glibc Heap (ptmalloc) Exploitation
- **Heap Chunks**: Understanding the metadata of a malloc chunk (`prev_size`, `size`, `fd`, `bk`).
- **Use-After-Free (UAF)**: A pointer is freed but not set to NULL. The attacker allocates a new object of the same size, overwriting the old object's data. If the program re-uses the dangling pointer, the attacker controls the execution flow (e.g., overwriting a function pointer inside a C++ object).
- **Tcache Poisoning**: In modern glibc, the thread-local caching mechanism (tcache) lacks robust security checks. Overwriting the `fd` pointer of a freed tcache chunk allows the attacker to trick `malloc()` into returning an arbitrary memory address (like the `__free_hook` or GOT entry), leading to write-what-where primitives.
### Advanced ROP & JOP
- **ret2libc / ret2csu**: Bypassing NX by calling system APIs (`system("/bin/sh")`) directly from the dynamically linked `libc` library. Using `__libc_csu_init` gadgets to control specific registers.
- **Sigreturn Oriented Programming (SROP)**: Exploiting the `sigreturn` system call to pop an entire hardware context (all registers) directly from the stack, requiring only a single `syscall` gadget.
- **Jump Oriented Programming (JOP)**: Bypassing shadow stacks (CET) by chaining gadgets that end in `jmp reg` or `call reg` instead of `ret`.
### Modern Mitigation Bypasses
- **Control Flow Guard (CFG)**: Bypassing Windows CFG by targeting un-guarded function pointers, modifying the return address on the stack (which CFG doesn't protect), or targeting the PEB.
- **Pointer Authentication Codes (PAC - ARM64)**: Bypassing iOS/macOS PAC by finding memory disclosure vulnerabilities to forge valid signatures or exploiting race conditions.
## 3. Output Format
- Diagram the heap metadata corruption step-by-step (e.g., visual layout of chunks before and after corruption).
- Detail the exact mathematical offsets and memory alignments required.
- Focus heavily on how memory allocators (like jemalloc, ptmalloc) can be hardened.