Classic
!mona jmp -r esp => jmp esp
Idea
Since there is no protection on the victim machine, we store a piece of shellcode on the stack and use
JMP ESP
to redirect the control flow for executing this shellcode.Here
JMP ESP
is used since ESP points to somewhere near the beginning of input buffer. Note that ESP may not point to the exact beginning of the buffer.Because of the uncertainty of ESP, NOP sled should be inserted right before the shellcode.
The
pop calc
shellcode is often used as PoC.I recommend the Immunity Debugger + Mona workflow.
Badchars
We assume \x00
is a badchar by default. Note that\x0a
and \x0d
are often badchars as well.
Make sure you only assume \x00
is a badchar. Follow the steps to find bachars one by one. Sometimes assuming other badchars, such as \x0a
and \x0d
, would break the bytestream and you may miss some badchars because of that.
Msfvenom
Generate pop calc shellcode using msfvenom:
Summary
Interact with the application and write a script to verify the existence of stack overflow.
Fuzz the application using pattern and find the offset.
Find a
JMP ESP
gadget from a library without protection.Find all badchars.
Generate shellcode using msfvenom.
Get shell or pop calc.
Make sure NOP sled is added before the shellcode.
Payload
Template
This type of stack overflow senario is often referred as the "OSCP-style" buffer overflow, since it is in the OSCP exam. Many templates exist, and my favorites are:
OSCP Buffer Overflow in 30 minutes -- hyperreality
Automations are integrated into the scripts, for example, pattern, badchars
The scripts contain built-in instructions.
OSCP Buffer Overflow -- V1n1v131r4
This repo contains a step-to-step guide.
Use the guide as cheatsheet during the exploit development process.
Reference
Last updated