HTB - Bashed

Bashed

Getting Root:

  1. Start with nmap and noticed that port 80 is the only port opened

  2. Using gobuster we discover a directory called /dev which contains a phpwebshell

  3. We get a reverse shell using python

  4. Simple enumeration shows we can execute any commands as scriptmanager

  5. Used sudo -u to become scriptmanager and create a reverse shell script in python which gets executed by root every 1 minute.

Nmap

Gobuster

Gobuster discovered a directory named /dev which includes a phpwebshell.

Getting a Reverse Shell

Using a python reverse shell

Started the listener

Improving the shell

Privilege Escalation

Using linpeas.sh, the following is very interesting: linpeas.sh GitHub: https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite

That means we can run any command as user scriptmanager

The user scripmanager can access the /scripts directory (this shows on the linpeas.sh but www-data couldn't access it)

There are two files there. It seems like something is executing the test.py script with root privileges because if you mv test.txt test.bkp, after some time, the file gets created again and is owned by root.

You can modify the test.py script (this script is owned by user scriptmanager, which is our user) and see if you can get a reverse shell with root privileges. As you can see below, I reused the same exact reverse python shell I used to get user but this time I changed the formatting a little bit.

We get a shell as root

Investigating a little bit into what was executing the test.py on the /scripts directory, we noticed that root had a cron job running which executes all python scripts every minute

If you want to learn a little bit more about crontab, check out this site below:

Last updated