Module 11 (Widows Buffer OverFlow)

MindMap

Discovering The Vulnerability

  • Source Code Review

    • (is likely the easiest if it is available)

  • Reverse engineering techniqes

  • Fuzzing

We will be covering the following 6 steps in detail for buffer overflow:

  1. Fuzzing

  2. Finding Offset

  3. Finding Bad Characters

  4. Finding Vulnerable Modules

  5. Shellcode generation

  6. Exploitation

Fuzzing

make req using Wireshark

i'll try make request using SOCKT

Finding Offset

(msf-pattern_create)

oFFSET

add + 800 => inputBuffer ="A"*780+'BBBB'+'C'*(1500-780-4)

C = 2C4 =708

Finding Bad Characters

Bad characters:

  • 00 for NULL

  • 0A for Line Feed n

  • 0D for Carriage Return r

  • FF for Form Feed f

Badchar form 1 byte to (0xff)

Generate BadChar from 1 to 0xff

Add badchar in exploit code

Run exploit with attach The Service

Follow Dump ESP

EX:-

After Remove Badchar

Jmp esp

find the dll with out badchar

10090C83

convert address to Latin indin = 0x10090C83

Finding Vulnerable Modules

It's a crucial step. After finding EIP value, we have to find a vulnerable DLL file that gets loaded when our R GUI application starts. Some DLL files don't have protection from buffer overflow attacks. We will find such DLL files using a tool named Mona.

1) Download Mona tool and copy Mona.py into \Immunity Debugger\PyCommands directory.

2)Now, let's fire up the immunity debugger with our vulnerable application again!

3)Input the following command to the command line in Immunity Debugger:

Command:

!mona modules

It will list all the dll files currently in use and their safety flags.

4)Then we will choose R.dll file, which is used by our vulnerable application and doesn't have any protection.

Finding OP code for JMP ESP

Now we will find the address pushed on the stack when R.dll is called in the application. For that, we have to run the following command:

!mona find -s "\xff\xe4" -m R.dll

Generate payload (x86/shikata_ga_nai )

What is NOP sled characters?

A NOP (No Operation) sled is a sequence of NOP instructions in machine code that does nothing when executed. In a buffer overflow attack, a NOP sled is a filler between the injected malicious payload and the return address the attacker wants to overwrite in the vulnerable program's stack.

The purpose of an NOP sled is to provide a predictable and controllable path for the program's execution to reach the injected malicious payload. When a buffer overflow occurs, the excess data written to the buffer can overwrite adjacent data on the stack, including the return address. The attacker can use an NOP sled to increase the chances that the overwritten return address will point to the start of the NOP sled, leading to the execution of the malicious payload.

Here are some examples of NOP sleds for different architectures:

x86 (32-bit): The x86 architecture uses the 0x90 instruction to represent a NOP. A NOP sled for x86 can be represented as a sequence of 0x90 instructions.

\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90

x86-64 (64-bit): The x86-64 architecture also uses the 0x90 instruction to represent a NOP. A NOP sled for x86-64 can be represented as a sequence of 0x90 instructions.

\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90

ARM (32-bit): The ARM architecture uses the 0x01 instruction to represent a NOP. A NOP sled for ARM can be represented as a sequence of 0x01 instructions.

\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01\x01

Reverse shell

Shellcode generation

Exploitation

FULL Exploit

Buffer OverFlow Labs

References

https://anubissec.github.io/Vulnserver-Exploiting-TRUN-Vanilla-EIP-Overwrite/#

https://bufferoverflows.net/exploiting-vanilla-buffer-overflow-in-vulnserver-trun-command/

https://www.purpl3f0xsecur1ty.tech/2019/02/28/Vulnserver.html

https://medium.com/purple-team/buffer-overflow-c36dd9f2be6f

https://www.hackingarticles.in/a-beginners-guide-to-buffer-overflow/

https://steflan-security.com/complete-guide-to-stack-buffer-overflow-oscp/

https://www.google.com/amp/s/boschko.ca/braindead-buffer-overflow-guide-to-pass-the-oscp-blindfolded/amp/

https://github.com/3isenHeiM/OSCP-BoF

https://github.com/CyberSecurityUP/Buffer-Overflow-Labs

https://github.com/johnjhacking/Buffer-Overflow-Guide

Last updated