Hacking Shocker (hackthebox)
I first of all did an Nmap scan and found an SSH and Apache server open.
I decided to start by enumerating the website using Gobuster.
I like to use Gobuster before dirbuster as it is faster. It did not take long for it to find an interesting directory called /cgi-bin/
This, along with the name of the box, led me to thinking about Shellshock bugs. One Shellshock exploit uses shell scripts in the Command Gateway Interface to work. I therefore decided to use dirbuster to dig deeper to see if I could find an available .sh file in the /cgi-bin/ directory.
I had to try a couple of wordlists before I found the right one. I kept on trying as I was sure the way to pwn this machine would be via a Shellshock exploit. Sure enough, with a little perseverance and experimentation with wordlists, I found an .sh script which could potentially be used:
I fired up msfconsole and did a search for shellshock:
Number 1 looked interesting, so I checked out its info:
This seemed good, so I set the various options. The path to the .sh script is an important one! I then ran the exploit and gained a meterpreter shell - lovely! I then started a regular shell as I am more comfortable using one. The user flag was now easy to find.
In order to find a way to escalate my privileges, I ran sudo -l and discovered that shelly could run perl scripts as root without needing a password. This led to a simple perl script to open a root shell.
sudo /usr/bin/perl -e 'exec "/bin/bash"'
The root flag was then soon found and the machine pwned! :-)
I find it interesting that the Shellshock bugs have been around for so long - since 1989! Of course, Apache recommends that CGI scripts are not used to handle web server requests as they are so dangerous. Nevertheless, machines were historically pwned using exploits developed to take advantage of the Shellshock bugs. Lots of machines were affected by it as recently as 2014. It is not a trivial problem - large scale DDos attacks utilised Shellshock.
I enjoyed learning more about Shellshock during my work hacking this box. Thanks to mrb3n for creating it, and thank you for reading my write up - I hope it was useful.
If you would like to see how Shellshock can be exploited manually (by malforming the User-Agent header) please check out the last part of my post about hacking the beep machine on hackthebox... :-)