|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
Patchesphar69324.diff (last revision 2015-04-05 22:11 UTC by stas@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
[2015-03-29 03:34 UTC] emmanuel dot law at gmail dot com
[2015-04-01 06:54 UTC] emmanuel dot law at gmail dot com
[2015-04-01 06:59 UTC] kaplan@php.net
-CVE-ID:
+CVE-ID: 2015-2783
[2015-04-05 08:16 UTC] stas@php.net
[2015-04-05 08:53 UTC] stas@php.net
[2015-04-05 08:54 UTC] emmanuel dot law at gmail dot com
[2015-04-05 09:07 UTC] emmanuel dot law at gmail dot com
[2015-04-05 20:54 UTC] stas@php.net
[2015-04-05 20:55 UTC] stas@php.net
[2015-04-05 20:56 UTC] stas@php.net
[2015-04-05 22:11 UTC] stas@php.net
[2015-04-06 05:20 UTC] stas@php.net
-Assigned To:
+Assigned To: stas
[2015-04-06 11:14 UTC] emmanuel dot law at gmail dot com
[2015-04-06 15:26 UTC] stas@php.net
[2015-04-06 15:41 UTC] stas@php.net
[2015-04-07 01:54 UTC] emmanuel dot law at gmail dot com
[2015-04-14 07:29 UTC] stas@php.net
[2015-04-14 07:29 UTC] stas@php.net
-Status: Assigned
+Status: Closed
[2015-04-14 08:31 UTC] stas@php.net
[2015-04-15 08:43 UTC] jpauli@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 22 13:00:02 2025 UTC |
Description: ------------ The nature of this vulnerability is CWE-126: Buffer Over-read. It is possible to read beyond a buffer. The vulnerability can be triggered when parsing a PHAR file at phar.c:623 if (!php_var_unserialize(metadata, &p, p + buf_len, &var_hash TSRMLS_CC)) { "buf_len" is obtained from the phar file and passed into php_var_unserialize() as the max argument. Under normal php_var_unserialize() circumstances, YYCURSOR will always be <= max. This however can be bypassed when processing a malform phar with a buf_len that is shorter then the string to be unserialized. It should be noted that YYCURSOR >max should never happen due to lines like var_unserializer.c:893 if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2); However since YYFILL() does nothing, it is optimized away by the compiler and thus never called. This is also a weakness in itself even though the vulnerable point is trigger via phar parsing. Thus by carefully crafting the string to be unserialize, we can produce a condition where YYCURSOR>max When YYCURSOR > max, a buffer over-read conditions occurs and the php_var_unserialize() is in a unstable and vulnerable state. For example var_unserializer.c:906 leads to an integer underflow(or wrap around): maxlen = max - YYCURSOR; I've created a POC that triggers the buffer over-read condition resulting in a memory info leak. This was done by unserializing a "s:<len>:<data>" string object. Using other serialized objects might lead to other possible attacks.I'm still in the process of analysing those. Test script: --------------- I've created a POC that leaks chunks of memory ala heart-bleed style. https://www.dropbox.com/s/tl0o9ekjpsn4s1u/php-buffer-over_read-poc.zip?dl=0 $php POC.php !!!!!!!!!!!!!!!!!!!! MEM LEAK Found !!!!!!!!!!!!!!!! 0 : 00 00 00 4d 45 54 41 44 41 54 41 5f 31 32 33 34 [...METADATA_1234] 10 : 35 36 37 38 39 30 31 32 33 34 35 36 37 38 22 30 [56789012345678"0] 20 : 31 32 33 22 3b 0b 00 00 00 a5 61 13 55 0b 00 00 [123";.....a.U...] 30 : 00 82 b7 29 4b b6 01 00 00 00 00 00 00 00 81 01 [...)K...........] 40 : 00 00 00 00 00 00 79 00 00 00 00 00 00 00 00 24 [......y........$] ............. 2CA0 : d9 01 01 00 00 00 00 00 01 00 00 00 00 00 49 00 [..............I.] 2CB0 : 00 00 00 00 00 00 59 00 00 00 00 00 00 00 48 c3 [......Y.......H.] 2CC0 : 5c 02 01 00 00 00 08 09 0a 0b 0c 0d 0e 0f 10 11 [\...............] 2CD0 : 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 [.............. !] ####### Mem info leak found(11488 bytes leaked). Continuing to find more...... ###### Actual result: -------------- Backtrace from parsing the phar file to php_var_unserialize #0 0x00000000007342db in php_var_unserialize (rval=0x7ffff7fc02a0, p=0x7fffffff9f78, max=0x7ffff7fc001e "77777:\"MY_METADATA_\";\b", var_hash=0x7fffffff9f68) at /home/elaw/php-5.6.7/ext/standard/var_unserializer.c:914 #1 0x000000000062ccac in phar_parse_metadata (buffer=0x7fffffffa128, metadata=0x7ffff7fc02a0, zip_metadata_len=0x0) at /home/elaw/php-5.6.7/ext/phar/phar.c:622 #2 0x000000000062ddcf in phar_parse_pharfile (fp=0x7ffff7fc0a38, fname=0x7ffff7fc0f40 "/home/elaw/php-5.6.6-afl-asan/sapi/cli/Phar4-Crash-0.phar", fname_len=0x39, alias=0x0, alias_len=0x0, halt_offset=0x1f, pphar=0x7fffffffa868, compression=0x0, error=0x7fffffffa8a8) at /home/elaw/php-5.6.7/ext/phar/phar.c:1038 #3 0x0000000000630c11 in phar_open_from_fp (fp=0x7ffff7fc0a38, fname=0x7ffff7fc0f40 "/home/elaw/php-5.6.6-afl-asan/sapi/cli/Phar4-Crash-0.phar", fname_len=0x39, alias=0x0, alias_len=0x0, options=0x8, pphar=0x7fffffffa868, is_data=0x0, error=0x7fffffffa8a8) at /home/elaw/php-5.6.7/ext/phar/phar.c:1716 #4 0x000000000062f8a2 in phar_create_or_parse_filename (fname=0x7ffff7fc0f40 "/home/elaw/php-5.6.6-afl-asan/sapi/cli/Phar4-Crash-0.phar", fname_len=0x39, alias=0x0, alias_len=0x0, is_data=0x0, options=0x8, pphar=0x7fffffffa868, error=0x7fffffffa8a8) at /home/elaw/php-5.6.7/ext/phar/phar.c:1346 #5 0x000000000062f7b0 in phar_open_or_create_filename (fname=0x7ffff7fc1c78 "Phar4-Crash-0.phar", fname_len=0x12, alias=0x0, alias_len=0x0, is_data=0x0, options=0x8, pphar=0x7fffffffa868, error=0x7fffffffa8a8) at /home/elaw/php-5.6.7/ext/phar/phar.c:1315 #6 0x000000000063b5e6 in zim_Phar___construct (ht=0x2, return_value=0x7ffff7fbe3b0, return_value_ptr=0x7ffff7f874b8, this_ptr=0x7ffff7fbe4a0, return_value_used=0x0) at /home/elaw/php-5.6.7/ext/phar/phar_object.c:1189