Buffer Oveflow
Buffer Oveflow
OVERFLO
W
(BOF)
KEY CONCEPTS
• This error occurs when there is more
data in a buffer than it can handle,
causing data to overflow into adjacent
storage.
Genaral purpose: EAX, EBX, ECX, EDX, EDI, ESP, and EBP. (ESP is the Address for the top of the stack,
EBP is Stack Base Address)
1- Disassembly,
2- Registers,
3- Dump,
4- Stack.
PREPAIRING
&
ATTACKING
PREPAIRING
● Fuzzing is sending random data to the application and monitor for a crash.
○ We need to know how many characters caused the overflow, and which four
overwrite the EIP.
PREPAIRING
● How many characters caused the overflow? We can copy the payload “AAAAA…”
and use the following command to count them for us:
echo -e "AAAAAAA….." |wc –c lets assume the result is 513 character
● Now we know how many characters in the payload. We need to check which four
“A”s overwrite the EIP using the following steps:
Using Metasploit: ./pattern_create.rb -l 513 this will create 513 random non-
repeated characters . Result is “Aa0Aa1Aa2……”
○ We execute the attack again using the new characters using: echo –e
“Aa0Aa1Aa2…” | ncat “IP” “port”. Results on targeted machine is EIP =
0x69413269, now we use Metasploit to find the offset of the given value:
./pattern_offset.rb -q 69413269, results is 247.
PREPAIRING
● This means that if we send 247 characters then any four characters (e.g., BBBB), this
will overwrite the EIP with 0x42424242 (42 is the HEX representation of “B”).
● Any extra characters sent after that, will be placed in the ESP.
○ A = architecture
○ Lhost = IP of Kali
○ Lport = any port you wish to assign to the listener
○ P = Payload
○ E = Encoder
○ B = avoid adding the following characters as they may crash
○ F = use the format of the following language (in this case C)
○ windows/shell_reverse_tcp = make the victim initiate the connection
○ shikata_ga_nai = encoder to pypass any antiviruses, IPs, IDs, and firewalls..