HTB: PermX

PermX is an easy Linux box, which is running a vulnerable version of Chamilio CMS which leads to a initial shell. Running linpeas reveals a password, which seems to be the password of the user mtz. Mtz has sudo permissions to run a custom bash binary, which can be exploited by making a symlink of /etc/sudoers and giving ourself ALL permissions to get root access.
Enumeration
I run my normal nmap scan. Port 80 and port 22 are open.
The SSH banner shows it is an Ubuntu machine. Port 80 redirects to http://permx.htb
, so I add that to my /etc/hosts
file.
permx.htb is just a static website.
Virtual hosts enumeration with ffuf reveals the following endpoints: http://lms.permx.htb
and http://www.permx.htb
. I add this to my /etc/hosts
file.
http://lms.permx.htb
contains a login portal.
The footer also contains interesting information
Clicking on I lost my password
redirects to http://lms.permx.htb/main/auth/lostPassword.php
, so now we know we’re dealing with PHP.
It is also interesting there is the option to change the language, which makes me think about possible file inclusion. Tried this, but no luck.
Googling for chamilo exploit
instantly shows a github repository with an exploit link, which leads to unauthenticated code execution. The exploit looks the following (I only changed the HOST variable). The CMD variable is the command to be ran on the server.
Running this gives the output
Now I change it to a reverse shell payload
This doesn’t work, so I made a little change, by adding
/bin/bash -c
before the reverse shell, which executes the command inside the single quotes.Running the exploit, gives a shell as www-data
.
Running linpeas reveals a password
Testing this password on mtz
(the only user) gives us SSH access and the user flag!
Running sudo -l
shows that we can run /opt/acl.sh
.
This file contains the following code, this clearly is a self made bash script.
The script first checks if 3 arguments are passed in, if this is not the case, it exits. After that it sets the variable user to the first argument, perm variable to the second argument and target to the third argument.
It then checks that the target is /home/mtz/*
and does not contain *..*
(against directory traversal).
After that, one more check is done to verify that the path is a file. After all these checks are passed, it runs /usr/bin/setfacl
(used to set file access control list) as sudo. It grants the user
the permissions specified by perm
onto the target
.
Also, it is good to check who is the owner of the /opt/acl.sh
binary, since otherwise I might have been possible to modify it.
symlink to /etc/sudoers
Set permissions
I then change the following line in the file /home/mtz/sudoerslink
to be able to run all commands as sudo.
Which gives me all the permissions
With that, I can change to root and read the final flag.