TryHackMe - Brainpan 1 (Hard)

Summary

On port 10000, we can download a Windows executable in a hidden directory. This is an OSCP-like Windows Buffer Overflow exploit development challenge. Note that the victim machine is running Linux, not Windows.

In the privilege escalation, sudo -l allows us to open man page as root. Here we can spawn a root shell using a privesc payload from GTFOBins.

IP

  • RHOST: 10.10.180.215

  • LHOST: 10.13.12.2

Nmap

Nmap

Asset Discovery

Run Gobuster against port 10000:

Gobuster finds /bin:

Gobuster

Visit http://brainpan1.thm:10000/bin and download the executable:

/bin

User Shell (Windows buffer overflow)

Step 1: Fuzzing (Locally)

Write a script:

We learn that the offset is less than 1000 bytes:

Fuzzing

Step 2: Finding the Offset (Locally)

Generate a pattern of 1000 bytes:

Update the script:

Run this script and brainpan crashes. Note that the EIP is overwritten:

EIP

Compute the offset:

Offset

Step 3: Overwritting the EIP (Locally)

EIP is overwritten by 0x42424242, as expected:

EIP overwrite

Step 4: Finding Bad Characters (Locally)

Generate a list of badchars:

Update the script:

Find badchars:

There is no badchar:

No badchar

Step 5: Finding the Right Module (Locally)

Find a JMP ESP gadget:

Mona finds one possible gadget:

JMP ESP

Step 6: Generating Msfvenom Payload and Gaining Root (Remotely)

Generate a Linux reverse shell payload using Msfvenom:

Update the script:

Now we get an user shell as Puck:

User shell

Privlege Escalation (sudo man)

sudo -l:

sudo -l

Try executing this command:

anansi_util

Run sudo /home/anansi/bin/anansi_util manual ls. This is essential the same as man ls, but we are openning this man page as root:

ls

Grab a privesc payload from GTFOBins:

GTFOBins

Spawn a root shell with !/bin/bash:

root shell

Last updated