Buffer Overflow Prep
Room Link: https://tryhackme.com/room/bufferoverflowprep
oscp.exe - OVERFLOW1
fuzzer.py
Slightly modified version of the script given.
#!/usr/bin/env python3
import socket, time, sys
try:
ip = str(sys.argv[1])
port = int(sys.argv[2])
print (ip+":"+str(port))
timeout = 5
prefix = "OVERFLOW1 "
string = prefix + "A" * 100
while True:
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(timeout)
s.connect((ip, port))
s.recv(1024)
print("Fuzzing with {} bytes".format(len(string) - len(prefix)))
s.send(bytes(string, "latin-1"))
s.recv(1024)
except:
print("Fuzzing crashed at {} bytes".format(len(string) - len(prefix)))
sys.exit(0)
string += 100 * "A"
time.sleep(1)
except:
print ("\nCould not connect!")
sys.exit()
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.


Crash Replication & Controlling EIP
Program crashed at 2000 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 1978.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\x07\x2e\xa0
exploit.py - Code Changes #3


Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW2
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program. The only difference we need to do is change our scripts prefix variable to point to OVERFLOW2
Crash Replication & Controlling EIP
Program crashed at 700 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 634.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\x23\x3c\x83\xba
exploit.py - Code Changes #3

Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll at 0x62500000 meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW3
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 1300 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 1274.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\x11\x40\x5f\xb8\xee
exploit.py - Code Changes #3

Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll at 0x62500000 meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. I started with the first one but later found out that it does not work, neither did most of the other ones. When I was ready to have my listener running to catch a shell nothing was returned. I decided to go down this list until I found one that had enough space for our payload. The one that worked was 0x62501203 but when we add it to our code we need it in little endian format so it becomes \x03\x12\x50\x62. We could have also tried with a smaller payload if none of the JMP ESPs worked.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW4
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 2100 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 2026.
Kali
Immunity Debugger

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\xa9\xcd\xd4
exploit.py - Code Changes #3


Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW5
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 400 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 314.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\x16\x2f\xf4\xfd
exploit.py - Code Changes #3

Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW6
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 1100 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 1034.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\x08\x2c\xad
exploit.py - Code Changes #3


Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW7
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 1400 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 1306.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\x8c\xae\xbe\xfb
exploit.py - Code Changes #3


Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW8
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 1800 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 1786.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00
exploit.py - Code Changes #3


Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW1
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 1600 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 1514.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\x04\x3e\x3f\xe1
exploit.py - Code Changes #3


Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

oscp.exe - OVERFLOW10
fuzzer.py
Slightly modified version of the script given.
exploit.py
Slightly modified version of the script given.
Kali
Login the the Windows box then open the oscp.exe within Immunity Debugger. Press the play button to start the program.
Crash Replication & Controlling EIP
Program crashed at 600 bytes with fuzzer.py

exploit.py - Code Changes #1
I added the pattern_create output into the payload variable.
On kail run the exploit again then in mona run the following to get the offset for EIP. We were able to find the offset was 537.
Kali
Immunity Debugger

exploit.py - Code Changes #2
Kali
After running the program again we now can fill EIP with our Bs so we now have control of EIP.

Finding Bad Characters
Kali
Now we changed the program to look for bad characters so we don't later use those bad characters when generating our payload. We do this by setting our payload to all possible characters, than follow EIP to see which characters aren't showing up. To do this we just have to keep running our exploit and removing the bad characters one by one. The bad characters found were: \x00\xa0\xad\xbe\xde\xef
exploit.py - Code Changes #3


Finding a Jump Point
Now we need to find a place to jump to to run our payload. We find there is only one place that will meets our conditions that we need which is an address with SafeSEH, ASLR, and NXCompat disabled and the memory address doesn't start with 0x00. ex: 0x0040000 won't work, 0x100000 will work. essfunc.dll meets this criteria.
Immunity Debugger

We find that essfunc.dll has 9 possible JMP ESPs to use. So we will start with the first one which is 0x625011af but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger

Exploit
Now that we have the return address to use, we just need to generate our payload without using the bad characters found previously. I also added 16 NOPs before the payload as suggested in the room. All that is left is to is to update our code with our payload and run it against the program.
exploit.py - Code Changes #4
Kali #1
Kali #2

Last updated