Brainpan 1
Room Link: https://tryhackme.com/room/brainpan
Scanning
nmap -A $VICTIM

Abyss/TCP port 9999
Abyss appears to have a program running but we can't interact.


http/TCP port 10000


brainpan.exe file found.

Initial Shell
Test Machine
As we have the .exe we're going to test on our Windows lab machine.

Crash Replication & Controlling EIP
I crashed the program by sending 1000 As
fuzzer.py
Fuzzer was able to crash the program around 1000 bytes so we got really lucky when we sent our As

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 524.
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. We found no bad characters so we'll just add \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. 0x311700000 is the only possible address to use.
Immunity Debugger

We find that brainpan.exe has only one possible JMP ESPs to use. So we will try 0x311712f3 but when we add it to our code we need it in little endian format so it becomes \xf3\x12\x17\31.
Immunity Debugger

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.
exploit.py - Code Changes #4
Kali #1
Kali #2

Exploit - Production #1
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
Kali #2

Exploit - Production #2
Shortly after exploring the Victims OS it had the directory of a Linux server. I realized that it was running.
exploit.py - Code Changes #4
Kali #1
Kali #2
Victim

Transfer LinPeas
I tried transfering LinPeas but it didn't end up really using anything from the output.
Kali
Victim
Privilege Escalation
We discovered we can run the command anansi_util as sudo without a password. gtfobins showed a way to become root if we can run manual which the program allowed us to do.
Exploit: https://gtfobins.github.io/gtfobins/man/



We are able to run the commands mentioned on gtfobins and get a root shell.

Last updated