skills/binary-exploitation/basic-stack-binary-exploitation-methodology/basic-stack-binary-exploitation-methodology/SKILL.md
A comprehensive methodology for binary exploitation, covering stack overflows, ROP chains, shellcode injection, and bypassing protections like ASLR, PIE, NX, and canaries. Use this skill whenever the user mentions binary exploitation, CTF challenges, buffer overflows, ROP, shellcode, ELF analysis, or any security research involving binary vulnerabilities. Trigger this skill for any task involving reverse engineering, vulnerability analysis, or exploit development on compiled binaries.
npx skillsauth add abelrguezr/hacktricks-skills binary-exploitation-methodologyInstall 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 structured approach to analyzing and exploiting binary vulnerabilities, particularly stack-based buffer overflows and related techniques.
Use this methodology when:
Before attempting exploitation, understand the binary's structure:
# Basic binary info
file <binary>
readelf -h <binary>
# Check for PIE
readelf -d <binary> | grep -i type
# Check for stack canaries
readelf -s <binary> | grep -i __stack_chk
# Check for NX (non-executable stack)
readelf -l <binary> | grep GNU_STACK
# Check for ASLR
readelf -d <binary> | grep FLAGS
| Protection | Check Method | Impact |
|------------|--------------|--------|
| PIE | readelf -h shows DYN type | Addresses are randomized |
| Canary | __stack_chk_fail in symbols | Stack overflow detection |
| NX | GNU_STACK without E flag | Stack is non-executable |
| ASLR | readelf -d FLAGS | Memory addresses randomized |
Stack Overflows
Arbitrary Write Vulnerabilities
Use these tools to identify vulnerabilities:
Scenario: A win() function exists that grants access
Without PIE and Canary:
[buffer][padding][return_address -> win_function]
With PIE: Need to leak an address first to calculate base
With Canary: Need to leak or bypass the canary value
Setting Function Parameters:
Prerequisites: NX disabled or bypassed
Without ASLR and NX:
[shellcode][padding][return_address -> shellcode_location]
With ASLR: Use ret2esp/ret2reg to jump to stack
With NX: Use ROP to call mprotect() and make memory executable
Use case: Call execve() to run arbitrary commands
Requirements:
Use case: Call system("/bin/sh") from libc
Scenarios:
| ASLR | PIE | Binary uses system() | Approach | |------|-----|---------------------|----------| | No | No | Any | Static addresses work | | Yes | No | Yes | Leak GOT entry, calculate libc base | | Yes | No | No | Use ret2dlresolve or leak addresses | | Yes | Yes | Any | Leak 2 addresses, calculate libc base |
ret2libc payload structure:
[padding][return_to_system][fake_return][pointer_to_/bin/sh]
Use case: Off-by-one overflows or alternate EIP control
Technique: Control ESP/RSP through EBP/RBP chain
When a single exploitation attempt isn't enough, create loops:
Write the address of main() or the vulnerable function in the ROP chain to re-execute the vulnerability.
Overwrite exit GOT entry to point back to the vulnerable function.
Store two functions in .fini_array:
__libc_csu_fini (which re-executes .fini_array)Methods:
Methods:
Methods:
mprotect() to make memory executableMethods:
from pwn import *
# Find offset to return address
offset = cyclic_find(pwn.cyclic(1000))
# Test for vulnerabilities
process = process('./binary')
process.sendline(cyclic(1000))
process.wait()
# Leak libc address via GOT
libc_addr = u64(process.read(8).ljust(8, b'\x00'))
libc_base = libc_addr - libc.symbols['function_name']
payload = flat([
cyclic(offset), # Fill to return address
libc.symbols['system'], # Call system
0, # Fake return
next(libc.search(b'/bin/sh')) # /bin/sh address
])
[padding][ret][ret][ret][...][final_ret]
[padding][system_addr][fake_ret][/bin/sh_addr]
[nop_sled][shellcode][padding][return_to_shellcode]
After identifying the vulnerability type and protections:
Remember: Each binary is unique. Adapt this methodology to the specific protections and constraints you encounter.
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.