Buffer Overflow and Binary Exploitation: practice machines and key commands

By Daniel Dayan ยท Updated

A classic stack buffer overflow overwrites the saved return address so execution jumps to code you control. The standard workflow is to fuzz the input until the program crashes, find the exact offset with a cyclic pattern, identify bad characters, locate a JMP ESP instruction in a module without protections and generate shellcode with msfvenom. Debuggers such as Immunity, x64dbg or gdb with pwndbg make each step visible. Modern targets add ASLR, DEP and stack canaries, which call for return-oriented programming or information leaks. Practise the manual process until it is repeatable, because exam style tasks reward a clean methodology. Write down offsets and bad characters as you go. These machines include overflow or binary analysis tasks. Restart the vulnerable service between attempts to keep memory layout predictable.

Key commands

Placeholders in braces, such as {TARGET_IP}, are values you fill in for your target.

Check a Binary's Protections

Inspect a binary for NX, PIE, stack canary and RELRO before planning an exploit, since each mitigation changes the approach.

checksec --file=./vulnerable_binary

Find the Crash Offset with a Debugger

Generate a unique byte pattern, crash the binary under a debugger, and read the offset to the saved return address from the resulting register or stack value.

gdb -q ./vulnerable_binary
(gdb) run $(python3 -c 'from pwn import *; print(cyclic(400).decode())')
(gdb) x/wx $rsp
python3 -c 'from pwn import *; print(cyclic_find(0xDEADBEEF))'

Keep going

Buffer Overflow and Binary Exploitation machines (10)

1 of these are machines I solved myself and are listed first within each difficulty. 6 Linux, 4 Windows.

Listed when a machine has a catalog tag that is one of: buffer overflow, binary exploitation, x86, reverse engineering, stack overflow, pwn, rop, shellcode. Capital letters, hyphens and underscores are ignored, and the tags that matched come first in each row.

Buffer Overflow and Binary Exploitation at a glance

Easy (4)

MachinePlatformOSTags
CyberHeroesReverse-EngineeringAuthentication-BypassJavaScriptTHMLinuxReverse-Engineering, Authentication-Bypass, JavaScript
Buff IppSecBuffer-OverflowPort-ForwardingUnauthenticated-RCEHTBWindowsBuffer-Overflow, Port-Forwarding, Unauthenticated-RCE
Reversing ELFReverse-EngineeringGDBRadare2Binary AnalysisTHMLinuxReverse-Engineering, GDB, Radare2, Binary Analysis
Shoppy IppSecReverse-EngineeringNoSQL-InjectionHTBLinuxReverse-Engineering, NoSQL-Injection

Medium (2)

MachinePlatformOSTags
BrainstormBuffer-Overflowx86FTPTHMWindowsBuffer-Overflow, x86, FTP
GatekeeperBuffer-OverflowOscilloscopeTHMWindowsBuffer-Overflow, Oscilloscope

Hard (3)

MachinePlatformOSTags
Brainpan 1Buffer-OverflowBinary ExploitationWineSudoersTHMLinuxBuffer-Overflow, Binary Exploitation, Wine, Sudoers
EarlyAccess IppSecReverse-EngineeringCommand-InjectionLinux-CapabilitiesPHP-filteringHTBLinuxReverse-Engineering, Command-Injection, Linux-Capabilities, PHP-filtering
Overflow IppSecBuffer-OverflowCVE-2021-22204HTBLinuxBuffer-Overflow, CVE-2021-22204

Insane (1)

MachinePlatformOSTags
Bankrobber IppSecBuffer-OverflowCommand-InjectionFile-read-through-SQLiHTBWindowsBuffer-Overflow, Command-Injection, File-read-through-SQLi

Related techniques

Related guides: TJ Null OSCP list, OSCP exam scoring and time budget, OSCP vs CPTS, OSCP report template.

Practise it, then track it.

Log every box and the commands you used in ZeroBox.