HTB Obscurity Write-up
Foothold
Nmap scan provides:
1 | PORT STATE SERVICE VERSION |
Browsing the page at http://10.10.10.168:8080
, I found a note for developers saying:
Server Dev
Message to server devs: the current source code for the web server is in ‘SuperSecureServer.py’ in the secret development directory.
To find the corresponding directory, I guess gobuster could work but since we have the name of the file, I’m adopting a slightly different approch by using wfuzz
with wordlists from dirb
instead of dirbuster
since it’s an orange box.
1 | $ wfuzz -t20 -w /usr/share/dirb/wordlists/big.txt --hc 404 -u http://10.10.10.168:8080/FUZZ/SuperSecureServer.py |
That gave away the develop
directory and the content of the SuperSecureServer.py
is
1 | import socket |
I immediately spotted the exec
function call at line 139.
We can do a RCE with it! We just need to provide the command as part of the request path like we do with SQL Injection. Note that we need to close the single quote opened just before Document:
then we can chain any command. We finish by making a random string assignation to match the end quote. I tried directly to obtain a reverse python shell appending the code to index.html';
in the path and of course, all URL encoded. I put it all in a script so I can recall how I did it next time.
1 | #!/usr/bin/env python3 |
And I caught a shell first try this time! NICE!
User Flag
Exploring around the /var
directory, I didn’t found anything interesting. After jumping to the robert
home dir, I found a bunch of stuff.
1 | $ ls -la /home/robert |
As expected, the user flag is not readable by www-data but what we can read is an encrypted password reminder text file and the python script used to encrypt it. Also we have two text files representing a cleartext and its cipher using the script.
From my experience with crypto challenges, sometimes when you face a symetric encryption based on “character masking” like xor, ordinal addition, …, decrypting the encrypted text using the cleartext as the key gives the key used during the encryption. I bet their is a term in crypto for such ciphers but I don’t know it by now. So I tried aaaaaaaannnndddd it works, I GOT LUCKY.
1 | $ python3 SuperSecureCrypt.py -i out.txt -o key.txt -k "Encrypting this file with your key should result in out.txt, make sure your key is correct!" -d |
Using the same process on the passwordreminder.txt
file with our new key gives SecThruObsFTW
.
All we have to do now is spawn a TTY shell and switch to user robert.
1 | www-data@obscure:/home/robert$ python3 -c 'import pty; pty.spawn("/bin/bash")' |
Root Flag
sudo -l
shows we can execute sudo /usr/bin/python3 /home/robert/BetterSSH/BetterSSH.py
. That’s probably the secure replacement to SSH they were talking about in their homepage.
Reading the script, it seems that it dumps part of the /etc/shadow
file in a temp file in /tmp/SSH
folder, checks if the user is in the dump with the corresponding password before deleting that temp file. It became clear we need to have a look at that temp file before it gets deleted. In a nutshell, a race!
Using the watch
command, let’s concatenate in a new session the content of whatever file inside the /tmp/SSH
folder to a custom file.
1 | # ================== Session 1 ===================== |
And there is the root hash! Pass it to hashcat and it produces the password mercedes
.
Congratulations, you just rooted the box.