3 min read

Complete Guide
Advanced

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

Binary exploitation requires understanding of assembly language, memory architecture, calling conventions, and operating system internals. Recommended prerequisites: x86/x64 assembly basics, C programming, GDB fundamentals.

Exploit Development Workflow

Recon

Binary analysis

Find Bug

Fuzzing, audit

Trigger

Crash, control

Exploit

Bypass, execute

Shell

Code execution

Core Topics

Process Memory Layout

Process Address Space (High → Low)

Kernel space - kernel only, never the process
Stack - locals, return addresses, grows down ↓
vDSO - syscall stubs, one mmap base
Libraries - libc, ld.so, same mmap base as the vDSO
Heap - brk, grows up ↑
Program image - .text, .data, .bss

Which of those bands move depends on the ELF type and on randomize_va_space.

Stack Frame

Arguments (passed to function)
Return Address ← Target!
Saved EBP/RBP (frame pointer)
Local Variables (buffers, etc.)
Canary (if stack protection)

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

checksec.sh
# 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_space

Essential Tools

pwntools

Exploitation
Docs

CTF framework and exploit development library. Essential for writing exploits in Python.

Installation

pip install pwntools

GDB + pwndbg

Debugging
Docs

Enhanced GDB with exploit development features, heap analysis, and better visualization.

Installation

git clone https://github.com/pwndbg/pwndbg && ./setup.sh

Ghidra

Reverse Engineering
Docs

NSA's reverse engineering suite. Excellent decompiler for static analysis.

Installation

# Download from website

ROPgadget

ROP
Docs

Find ROP gadgets in binaries. Essential for building ROP chains.

Installation

pip install ropgadget

one_gadget

Exploitation
Docs

Find one-shot RCE gadgets in libc for instant shell.

Installation

gem install one_gadget

radare2

Reverse Engineering
Docs

Advanced commandline reverse engineering framework.

Installation

# Install from package manager

Quick Start: Pwntools

exploit.py
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

Recommended practice platforms: pwnable.kr, pwnable.tw, HackTheBox, TryHackMe, and PicoCTF for beginners. Always practice in legal, authorized environments.