|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2022-07-19 14:30 UTC] ohseungju5 at gmail dot com
Description: ------------ follow below url https://github.com/php/php-src/blob/2f5295692fde289f99aa9701528dcde4c78b780f/ext/phar/phar.c#L1623 in line 1652, php execute while statement until the file pointer returns eof. while(!php_stream_eof(fp)) { if ((got = php_stream_read(fp, buffer+tokenlen, readsize)) < (size_t) tokenlen) { MAPPHAR_ALLOC_FAIL("internal corruption of phar \"%s\" (truncated entry)") } after entering the while statement, value of test variable is set to \1. However, we can set value of test variable to \0 after passing if statements in line 1660, 1720. https://github.com/php/php-src/blob/2f5295692fde289f99aa9701528dcde4c78b780f/ext/phar/phar.c#L1718 https://github.com/php/php-src/blob/2f5295692fde289f99aa9701528dcde4c78b780f/ext/phar/phar.c#L1756 If we can constantly set value of test variable to \0, then we can make php fall into an infinite loop. Of course, we have to upload a gzip payload for the attack on the victim's server. However, this is not a problem because many php servers support upload. Test script: --------------- test_dos.php <?php file_exists($_GET['file']); ?> exploit.py import requests SERVER = "" while True: try: requests.get(SERVER+"/test_dos.php?file=phar://2xq.gz",timeout=1) except: pass 2xq.gz hxxp://ssrf.kr/2xq.gz Expected result: ---------------- I don't know correct result of this. Maybe, there is no problem with the implementation. But no one would have expected that decompressing gzip file could make strange file that would return gzip file again. Actual result: -------------- An infinite loop occurs in all files with php extensions PatchesPull Requests
Pull requests:
HistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 30 18:00:02 2025 UTC |
To clarify, this issue does not only affect the phar stream wrapper, but also the PharData class, which is not supposed to cause such issues, and is likely not rarely used to deal with .tgz files. A simple new PharData(__DIR__ . "/quine.tgz"); causes an infinite loop. > Isn't once enough? Maybe, but at least wrt. backwards compatibility I wouldn't disallow multiple passes for now; after all, a gzip compressed file might have been gzip compressed again (maybe accidentially), and that is handled fine.