Bashed Writeup
Reconnaissance:
First thing first, we run a quick initial nmap scan to see which ports are open and which services are running on those ports.
We get back the following result showing that port 80 is open with Apache HTTP Server running on it.
Before we start investigating port 80, let’s run more comprehensive nmap scans in the background to make sure we cover all bases.
Similarly, we run an nmap scan with the -sU flag enabled to run a UDP scan.
We get back the following result. As can be seen, the top 1000 ports are closed. Our only avenue of attack is port 80, so let’s check it out.
Enumeration:
The arrow on the first page leads us to http://10.10.10.68/single.html
There, you can find a link to a GitHub repository explaining that this is a script used to create a semi-interactive web shell. Interesting! If we find the phpbash.php file, we can potentially get a web shell!
Let’s do more enumeration on the web server. Run gobuster to enumerate directories.
The directories /images, /uploads, /php and /css lead us nowhere. So let’s move on to the /dev directory. We found the phpbash.php script and clicking on it gives us a web shell!
Foothold:
What exactly does this shell do and in what context does it run?
We’re running in the context of an Apache default user www-data. For this machine, we already have a low privileged shell that allows us to run linux commands on the web server, so we don’t necessarily need to get our own reverse shell. However, in a real penetration test, you would place your own shell in the system just in case the creator notices his insecure configuration and takes down the php script. This way you’ll have consistent access to the system by a shell that you control.
Since we’re modelling a real penetration test, let’s get a reverse shell going. In the attack machine (kali) set up a listener.
In the target machine (bashed) send a reverse shell to the attack machine.
Unfortunately, the connection keeps terminating. Let’s try sending a reverse shell in a different way.
pentestmonkey has a comprehensive list of reverse shells. Check if python exists on the target machine.
Since we get back a result, python is installed on the machine! Copy the python command from the list and change it to your attack machine’s ip address and listening port.
Yes! We have a reverse shell going.
Let’s find the user flag. Change to the home directory and view its contents.
I have execute privileges on both arrexel and scriptmanager directories. Let’s look in the arrexel directory first.
Privilege Escalation:
Next, I need to figure out what other privileges I have or can easily get. The following command lists the allowed commands for my user.
User www-data may run the following commands on bashed:
The last two lines are particularly interesting because they say that the user I’m running in the context of (www-data) can run as the user scriptmanager without having to provide the user’s password. This might come in handy later on.
For the time being, let’s do some more enumeration.
Everything in the root directory seems to be owned by root except for the scripts directory which is owned by scriptmanager. In the previous step we found out that we can run as scriptmanager without a password.
The above command changes the user to scriptmanager.
Now that we’re running in the context of scriptmanager, we have read/write/execute privileges in the scripts directory.
We have two files; one owned by us (test.py) and the other owned by root (test.txt). Let’s print out the content of test.py.
Interesting! It’s a simple python program that writes to the file test.txt. However, we saw in the previous image that test.txt is running as root! Running the python program also seems to be something that is scheduled since the last access time of the test.txt file is very recent. In fact, the script seems to be executing every minute! It’s probably a cron job that is owned by root.
Why is that great news for us? If I change the contents in the test.py file to send a reverse shell, that reverse shell will run as root!
Changing the file on the shell was unbelievably difficult and glitchy. Therefore, I decided to transfer the file from my attack (kali) machine.
In the kali machine, create a test.py file and add the reverse shell code to it.
Change the file permission to rwx for everyone.
In the same directory, start a simple HTTP server.
In the target (bashed) machine under the scripts directory, download the file.
OR
Now, go back to your attack (kali) vm and start up a listener with the same port specified in the test.py script.
Wait for a minute or so for the cron job to execute and voila! We have a shell running as root!
Change to the root directory and get the root flag.
Last updated