Hack The Box | Busqueda
A classic CTF box that'll make you feel good about cracking it. If you have a tinkerer's mind, hop in.
This is a classic CTF box. You just need a tinkerer's mind, and of course, Burp Suite. If you don't know how to setup Burp or connect to HTB, please search your way through it.
Reconnaissance
The IP of the machine is 10.10.11.208. First, you should always navigate to the IP and see if it's running a web app on the default port 80 / 443. In this case, it is.
ProTip - If you don't see the site when you navigate to the IP, just add the IP to your hosts
file. In this case, it's going to be 10.10.11.208 searcher.htb
. Again, google your way through it if you don't know how.
Let's start a nmap scan while we look into what the web app actually does.
nmap -sC -sV -oA default.ouput searcher.htb
Here's what the flag in the nmap command actually means. The command is courtesy of Ippsec.Rocks
- -sC : Run default script for fingerprinting the application running the ports.
- -sV : Enumerate the versions of the applications running on the ports.
- -oA : Output the data in all available formats.
The output is pretty simple. There are just 2 ports available, 22, and 80. Running a fairly exploit-free, SSH and a Web Server respectively.
The application however is what should interest us. It allows you to choose a Engine and Search for anything. It even auto-redirects you to whatever engine's website with your search query in there.
Your first thought might be Open Redirect or SSRF. Both those techniques prove pointless in this case. But what you should do is send the POST request to Burp Suite to fuzz with the parameter.
But something even more interesting is there on the site just in plain sight. Look at the footer. "Powered by Flask and Searchor 2.4.0"
.
Giving up the tech behind the website is a definate red flag. And some googling later we find this.
In short, they're using the eval
function, which one should never use. It takes any string argument and runs it as a command.
Looking at the POC, we can see that we can pass additional arguments to the method by placing a "," at the end. Let's try it then.
SUCCESS! We have code injection. You can either grab the user flag via curl
or you can start a shell.
We have a shell. Now we can start the Privilege Escalation process.
Privilege Escalation
A simple ls -a
tells us that the current directory is a .git project. So let's see whats inside the config.
Now we have a username, password, and another host to mess with. gitea.searcher.htb
. Make sure you add this to your hosts file or it won't resolve.
Same password can be used to SSH into the server. Now let's see which files the user is allowed to run as root.
We're allowed to run the system-checkup.py
script as sudo, let's see what it lets us run.
docker-ps lets you see all the running containers. docker-inspect lets you dump the config of those containers, sounds interesting, lets see.
Now we have more usernames and passwords. You can try to SSH into the system with the given passwords but it won't work. So let's go to gitea.searcher.htb.
Unsurprisingly, it's running a gitea server. We already have credentials to login as "cody". Once logged in you can see there's another account called Administrator. Rather than looking for a way to exploit yet another web app, let's try to use one of the usernames and passwords we found to login as Administrator, spoiler alert, it worked.
Now we can see the source code for the system-checkup.py
script in one of Admin's repos.
See the mistake here?
When you run the script with full-checkup
flag, it'll look for a file called full-checkup.sh in whatever directory you're currently in.
So the next steps are pretty simple, go to your $HOME directory. Create a file called full-checkup.sh
#!/bin/sh
cat /root/root.txt
and run the full-checkup flag. This will print out the root flag.