Binary Exploitation (Pwn)
A core hacking pillar focusing on exploiting low-level vulnerabilities in compiled binaries. This guide covers memory corruption, control flow hijacking, and modern mitigation bypasses.
Advanced Topic
Exploit Development Workflow
Recon
Binary analysis
Find Bug
Fuzzing, audit
Trigger
Crash, control
Exploit
Bypass, execute
Shell
Code execution
Core Topics
Understanding stack-based buffer overflows, EIP control, and shellcode execution.
Return Oriented Programming to bypass NX/DEP protections.
Attacking the heap allocator, use-after-free, and heap grooming.
Exploiting format string vulnerabilities for memory reads and writes.
Techniques for defeating address randomization protections.
Process Memory Layout
Process Address Space (High → Low)
Which of those bands move depends on the ELF type and on randomize_va_space.
Stack Frame
Buffer overflows occur when local variables overflow into return address.
Security Mitigations
| Protection | Description | Bypass | Covered in |
|---|---|---|---|
| NX/DEP | Stack not executable | ROP chains, ret2libc | ROP Chains |
| ASLR | Randomize memory addresses | Info leak, brute force | ASLR & PIE Bypass |
| Stack Canary | Detect stack overflow | Leak canary, format string | Format Strings |
| PIE | Position Independent Executable | Leak base address | Format Strings, ASLR & PIE Bypass |
| RELRO | Read-only relocations (GOT) | Partial: GOT overwrite | Format Strings |
| CFI | Control Flow Integrity | Out of scope for this section | — |
Checking Binary Protections
# Using checksec (pwntools)
checksec ./binary
# Example output:
# Arch: amd64-64-little
# RELRO: Partial RELRO
# Stack: Canary found
# NX: NX enabled
# PIE: No PIE (0x400000)
# Using file
file ./binary
# Check ASLR status (Linux)
cat /proc/sys/kernel/randomize_va_space
# 0 = Off, 1 = Conservative, 2 = Full
# Disable ASLR for testing
echo 0 | sudo tee /proc/sys/kernel/randomize_va_spaceEssential Tools
pwntools
ExploitationCTF framework and exploit development library. Essential for writing exploits in Python.
Installation
pip install pwntoolsGDB + pwndbg
DebuggingEnhanced GDB with exploit development features, heap analysis, and better visualization.
Installation
git clone https://github.com/pwndbg/pwndbg && ./setup.shGhidra
Reverse EngineeringNSA's reverse engineering suite. Excellent decompiler for static analysis.
Installation
# Download from websiteROPgadget
ROPFind ROP gadgets in binaries. Essential for building ROP chains.
Installation
pip install ropgadgetone_gadget
ExploitationFind one-shot RCE gadgets in libc for instant shell.
Installation
gem install one_gadgetradare2
Reverse EngineeringAdvanced commandline reverse engineering framework.
Installation
# Install from package managerQuick Start: Pwntools
from pwn import *
# Set architecture
context.arch = 'amd64'
context.log_level = 'debug'
# Connect to binary or remote
# p = process('./vuln')
p = remote('pwn.ctf.com', 1337) # replace with your target
# Create payload
payload = b'A' * 72 # padding to the return address on x86-64
payload += p64(0xdeadbeef) # placeholder: a real address from your build
# Send payload
p.sendline(payload)
# Interactive shell
p.interactive()Practice Resources