Horizontall is an easy rated machine on HackTheBox created by wail99. To get user we will abuse 2 CVE’s in a strapi application whichs result in a reverse shell on the machine. There we discover a laravel installation listening on localhost which is vulnerable to phar deserialization. Forwarding it to our machine we are able to exploit this to get a reverse shell as the root user.
User
Nmap
As usual we start our enumeration off with a nmap scan against all ports, followed by a script and version detection scan against the open ones.
All ports
1 |
|
Script and version
1 |
|
Strapi
From the 2 open ports http promises more success, so we add the leaked domain name to our /etc/hosts
and open the page in our browser. Looking at the page it seems to be fully static with almost no functionality.
Fuzzing for additional subdomains we can retrieve two other ones. www
looks the same as the other page, api-prod
is different though.
1 |
|
Password reset | CVE-2019-18818
Opening it in our browser it just displays a short welcome message.
Bruteforcing directories with gobuster we find a /admin
directory which reveals a strapi
login interface.
1 |
|
Looking for vulnerabilities in strapi
there is a CVE which promises authentication bypass by resetting the password of a user. Looking at the PoC for CVE-2019-18818
we need a valid email to make it work. We can do this by checking the password reset functionality on the login. If we enter a likely invalid email it tells us the email does not exist.
Testing the username admin with the domain found earlier there is no error though, indicating this email is valid.
Now we just need to download the script from the PoC and run it with the email, url and new password we want to set on the user.
resetpw.py
1 |
|
1 |
|
After the script successfully completes we are now able to log into strapi
as the admin@horizontall.htb
user.
Command injection | CVE-2019-19609
There is another CVE affecting this version of strapi
. Following this PoC we are able to abuse command injection in the plugin
value of the /admin/plugins/install
functionality.
For this we first intercept an authenticated request with burp for a request with our JWT to build upon and start a ncat listener.
1 |
|
Next we rewrite the request to a similar formatting as the curl request in the blogpost before sending it. We instantly get a reverse shell back which we upgrade and fix the terminal size. Looking a bit around we can now already read the user flag.
1 |
|
Root
Laravel phar deserialization | CVE-2021-3129
Looking for open ports on localhost we see port 8000
and 1337
being open next to mysql on 3306
. Connecting to 1337 it returns the same as the subdomain of the webserver. Checking 8000
though with curl it seems to host a laravel installation.
1 |
|
To take a better look at it we first generate an ssh keypair with ssh-keygen
, copy the public key to /opt/strapi/.ssh/authorized_keys
and connect with our private key to forward the port. On a new line we enter ~C
, which drops us into the ssh command console where we can enter our portforward.
1 |
|
Browsing to port 8001
on localhost now we see the laravel installation.
Looking online for vulnerabilities we stumble accross this blogpost. Testing if the conditions are met, we are able to provoke a stacktrace and prove that debug mode is enabled and ignition
present.
We can now use this PoC which belongs to the blogpost to exploit this. Along the exploit script we also need phpgcc to create our malicious phar
.
First we generate the phar file with phpggc
, specifying a reverse shell as payload and set up a ncat
listener again.
1 |
|
1 |
|
Next we exectue the python script with our previously generated phar.
1 |
|
We almost instantly get a reverse shell back as the root user and are able to add the flag to our collection.
1 |
|