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_binaryFind 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
- Methodology: Phase 04: Foothold Execution & Initial Access
- Cheatsheet: Exploitation & Payloads
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
- By platform: 5 TryHackMe, 5 Hack The Box.
- On these practice lists: OSCP (1).
- Tags that most often appear alongside it: Command-Injection (2).
- Solved by me, with a page here: CyberHeroes (Linux Easy).
Easy (4)
| Machine | Platform | OS |
|---|---|---|
| CyberHeroes | THM | Linux |
| Buff IppSec | HTB | Windows |
| Reversing ELF | THM | Linux |
| Shoppy IppSec | HTB | Linux |
Medium (2)
| Machine | Platform | OS |
|---|---|---|
| Brainstorm | THM | Windows |
| Gatekeeper | THM | Windows |
Hard (3)
| Machine | Platform | OS |
|---|---|---|
| Brainpan 1 | THM | Linux |
| EarlyAccess IppSec | HTB | Linux |
| Overflow IppSec | HTB | Linux |
Insane (1)
| Machine | Platform | OS |
|---|---|---|
| Bankrobber IppSec | HTB | Windows |
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.