OSCP BOF
Buffer Overflow (PEN-200 Edit)
All you need to know about the BOF challenge for OSCP exam preparation.
1. Determine EIP Offset
Generate a unique pattern and feed it to the vulnerable application.
#!/usr/bin/env python3
import socket
# msf-pattern_create -l 5000
buf = b'<UNIQUE_PATTERN>'
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('10.10.13.37', 1337))
s.send(buf)
s.close()Calculate the offset from buffer to EIP overwrite point:
$ msf-pattern_offset -l 5000 -q <EIP_VALUE>
[*] Exact match at offset <EIP_OFFSET>2. Confirm BOF
Confirm that you can actually control the EIP value - if true, it will be overwritten with d34dc0d3.
3. Enumerate the Bad Characters
Send all the possible byte values to the application. Then in the Immunity Debugger: right click on ESP -> "Follow in Dump" -> check what characters are missing or misinterpreted - they are the bad characters that should be excluded when generating the shellcode.
4. Build the Exploit
I. Find the Return Address
List all loaded modules in process memory space with mona:
Choose a module with no memory protections enabled and look for jmp esp instruction in that module:
Discovered pointer is the needed value for EIP to force the execution flow into the shellcode.
II. Generate a Shellcode
Build a shellcode providing bad characters set from (3):
5. Exploit!
Start a netcat listener, feed the shellcode to the application and catch your shell.
Last updated