This box was an easy level linux box on HTB created by polarbearer and GibParadox, it started with finding a hidden directory in robots.txt named admin-dir, in which we find two txt files namely contacts.txt and credentials.txt using a gobuster scan with -x txt, then we use ftpuser creds obtained from credentials.txt to login to FTP. FTP server had the old source code of the website and on enumerating it we find a reference to using some open source database management utility, for out box it was adminer. On googling adminer exploits we find a exploit that let us read local files, we use that exploit to read index.php file, which had creds, we can use those creds to ssh as user waldo, root part was fun and it was a Python Library Hijacking.
Enumeration
As always let’s start off with nmap script nmap -sC for default scripts Alright, if it isn’t obvious yet I am a IPPSEC fanboi. Aight, firing up nmap to scan all open ports on the box.
And here is our nmap result
Open services are SSH on port 22, webserver on port 80 and a FTP server on port 21. I checked for Anonymous access on the FTP server but it wasn’t allowed, so I am gonna shift my focus on the webserver.
Enumerating the web server
The site looks like an image gallery.
Alright let’s run something on backend and start exploring the website, because we always want to keep some enumeration running while we manually look at that web serverTold ya already, I am a ippsec fanboi. So firing up the gobuster scan to find hidden directories, and I am also looking for txt and php files(incase we find some notes or some hidden webpage).
Initial Foothold
During basic enumeration, I found a hidden directory in /robots.txt named /admin-dir but we can’t browse files in it, as the first gobuster scan wasn’t really fruitful so, I ran another gobuster scan in admin-dir directory and searching for txt and php files. Note : robots.txt also had a username "waldo".
And got two files contacts.txt & credentials.txt, contacts.txt had some emails and names and it was a nice rabbit hole, but in credentials.txt we found the ftp user’s credential.
ftpuser : %n?4Wz}R$tTF7
Foothold
As now we have the creds of the FTP user, lets start enumerating that.
I simply downloaded all the files in the ftp server to analyse them.
And it looks like backup of the code running on the webserver, In it there were many rabbit holes and a lot of passwords of mysql database, I tried using them with username waldo to ssh into the server but none of those passwords worked D:
In this file there is a TODO note, and as db.php is not present on current webserver, I assumed the box has some open source db management utility. After some basic enumeration I figured they are using Adminer, the box name is based on this.
Getting User
I tried the passwords from the ftp directory in the adminer console, that was at http://10.10.10.187/utility-scripts/adminer.php but none of them worked D:
Then I googled for Adminer’s exploit and reached here, It’s a poc of an exploit that can be used to load local files on the server.
For this we also need to allow remote access on mysql in our machine, I used this blog to do it. Also thanks to pop_eax and kreep for giving me a nudge on this part. Ngl mysql part was a bit annoying.
Now we can use that above exploit to load files, I opened up index.php file in the source code and finally got the creds of the user waldo. waldo : &<h5b~yK3F#{PaPB&dA}{H> Now we can simply use these creds to SSH into the box.
Sorry that I didn’t explain this part properly, I didn’t documented this box while initially doing it and I don’t want to solve this box again but I simply followed this blog to setup a remote mysql server and the exploit’s poc to load index.php file which had creds, so I guess writing them again won’t be really helpful.
Rooting the box
Alright, we are on the box as user waldo and we also have his password, so the first thing to check is for sudo perms.
Let’s check what perms on /opt/scripts/admin_tasks.sh file.
Ah.. we don’t have writeperm on that file D:
Alright, let’s read the code and analyse it.
Seems like we can run some simple checks as well as do some basic backup operations, tho intresting part is the web backup, as here we are calling running a python script.
On checking that python script, we can see it is importing an additional library named shutil.
Which means we can do a Python library hijacking, here is two blogs, by rastating and a medium blog by klockw3rk that I refered to, to understand the basic concept.
Alright so first I created a fake library named shutil.py with a function make_archive in /tmp directory which had our reverse shell payload.
Starting the nmap listener on local machine rlwrap nc -lvnp 9889. And then execute our admin_tasks.sh script with option 6 but main point is, we need to export pythonpath as pwd i.e /tmp/temp folder so that the script uses our fake shutil library/module.
Looking at our rev shell, and yes we got a connection.
Hope you learned something new, if you face any issues / have any query, feel free to contact me on social media.