By Waseem Akram on 7/16/2021
Bashed is a retired HackTheBox machine, rated easy and rightfully. We'll start by finding a hidden web shell to quickly gaining root level access due to misconfigured...
Bashed is a retired HackTheBox machine, rated easy and rightfully. We'll start by finding a hidden web shell to quickly gaining root level access due to misconfigured permissions to users.
Starting the reconnaissance with an initial Nmap scan.
sC: run default nmap scripts
sV: detect service version
oA: output all formats and store in file nmap/bashed
We get the following result showing that port 80 is open with Apache HTTP Server running on it.
Looks like the developer Arrexel, has created a PHP web shell for their own pentesting purposes, and states that it was "developed on this exact server!" This indicates that there's a high possibility that this web shell is present somewhere on the server. Interesting! If we find the phpbash.php
file, we can potentially get a web shell!
Fun fact: Arrexel is the creator of this machine.
Let's do more enumeration on the web server and find what's inside the website.
The flags breakdown as follows:
after checking all the directories with 200 status code
, found something interesting in /dev directory.
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.
The Pentestmonkey website has a list of reverse shells. Let's Check if python exists on the target machine.
Since 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.
In the attack machine (kali) set up a listener.
we can find the user flag in /home/arrexel
directory.
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.
The last two lines are particularly interesting because it says 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.
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.
Let's change the user to scriptmanager.
Also setup Interactive Shell for better interaction.
Now that we're running as the scriptmanager, we have read/write/execute privileges in the scripts directory.
Most interesting is that the test.txt
file is owned by root, and seems to be the result of the test.py
script, which is writable by scriptmanager. First, I tried moving test.txt to test.txt.old. A few minutes later, it's back:
Something is running that test.py
script from the /scripts directory creates a test script that writes to a different file, and it writes the different file. So any .py file seems to be run. Also, since test.py doesn't have a #! at the start, it seems that whatever is running this (maybe a cron?) is calling python.
It is possible to just write a script that reads /root/root.txt
and writes it elsewhere, but it's better to get a shell!
Let's create the exploit:
On Kali, set up a listener, and get root shell:
ls -la
instead of simple ls
command. I was also having difficulty to know whether the python script is run by a cron job.Thanks for reading this post, if you like my work you can support me on Patreon. ❤️ Read other posts
This course is designed to be hands-on and beginner-friendly, so even if you’re new to the world of network security, you’ll be able to follow along with ease. By the end, you'll have a
Read MoreToday we’re going to see how real malware protect themselves from being analyzed using a technique called Api Hashing. First of all we should...
Read MoreToday we’ll dump LSASS.EXE process memory to obtain credentials and we also will be using some evasion techniques. During red team...
Read MoreToday we’re gonna see an effective technique to mantain access in Windows systems during red team operations just by modifying a registry key...
Read MoreToday we’ll learn an advanced shellcode injection technique used by Lazarus group which uses UuidFromStringA API call. In this technique, the malware..
Read MoreInstahack is a security tool officially designed to test the password strength of Instagram accounts using termux and kali with a brute force attack...
Read More