|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-01-10 05:22 UTC] zyyang at fortinet dot com
Description: ------------ Subject: [FG-VD-18-005] PHP GD Denial of Service Vulnerability Notification ------- Vulnerability Notification Jan 09, 2018 Tracking Case #: FG-VD-18-005 Dear PHP, The following information pertains to information discovered by Fortinet's FortiGuard Labs. It has been determined that a vulnerability exists in PHP GD. To streamline the disclosure process, we have created a preliminary advisory which you can find below. This upcoming advisory is purely intended as a reference, and does not contain sensitive information such as proof of concept code. As a mature corporation involved in security research, we strive to responsibly disclose vulnerability information. We will not post an advisory until we determine it is appropriate to do so in co-ordination with the vendor unless a resolution cannot be reached. We will not disclose full proof of concept, only details relevant to the advisory. We look forward to working closely with you to resolve this issue, and kindly ask for your co-operation during this time. Please let us know if you have any further questions, and we will promptly respond to address any issues. If this message is not encrypted, it is because we could not find your key to do so. If you have one available for use, please notify us and we will ensure that this is used in future correspondence. We ask you use our public PGP key to encrypt and communicate any sensitive information with us. You may find the key on our FortiGuard center at: http://www.fortiguard.com/pgpkey. Type of Vulnerability & Repercussions: Denial of Service Affected Product: PHP 5.6.32 (cli) (built: Oct 29 2017 19:00:01) GD Version bundled (2.1.0 compatible) FreeType Version 2.3.11 libPNG Version 1.2.49 libXpm Version 30411 Upcoming Advisory Reference: http://www.fortiguard.com/advisory/UpcomingAdvisories.html Credits: This vulnerability was discovered by Zhouyuan Yang of Fortinet's FortiGuard Labs. Proof of Concept & Additional Information: The issue exists in the "imagecopyresampled" function. To reproduce, 1. Attacker modify an image file, for example, a gif file, set the Logical Screen Descriptor value to FF FF FF FF. Shown in figure 1. 2. Execute this image file (test.gif) with the PoC test.php. Then the server CPU goes to 100% (for a better result, we can set the test server to single core processor or do it multiple times in a short time, like upload it 100 times in 5 seconds.) Shown in figure 2. For example, when an upload program using this function, with multi-thread uploading a tiny file (like 100 threads at the same time with the same payload, see figure 3, tested in the latest WordPress). Would cause a long time 100% usage with a quad-core processor. Even after the client side stops the attack. The error log shows: [Tue Jan 09 21:17:20 2018] [error] [client 192.168.56.1] PHP Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/html/uploads/test.php on line 18 Not sure how to upload attachments. Test script: --------------- <?php // The file $filename = 'test.gif'; // Content type header('Content-Type: image/gif'); // Get width height list($width, $height) = getimagesize($filename); // Resample $image_p = imagecreatetruecolor(180, 180); $image = imagecreatefromgif($filename); // The issue imagecopyresampled( $image_p, $image, 0, 0, 0, 0, 180, 180, $width, $height ); ?> Expected result: ---------------- Server CPU goes to 100% Error Log: [Tue Jan 09 21:17:20 2018] [error] [client 192.168.56.1] PHP Fatal error: Maximum execution time of 30 seconds exceeded in /var/www/html/uploads/test.php on line 18 Actual result: -------------- For example, when an upload program using this function, with multi-thread uploading a tiny file (like 100 threads at the same time with the same payload, see figure 3, tested in the latest WordPress). Would cause a long time 100% usage with a quad-core processor. Even after the client side stops the attack. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 07:00:01 2025 UTC |
Thanks for reporting this issue. The issue is not really related to GD, but rather to getimagesize() which always returns the size given in the logical screen descriptor of GIFs. imagecreatefromgif(), however, creates an image with the size given in the first image descriptor. So in this case $width and $height equal 65535, while the image has only a size of 200✕200. The following imagecopyresampled() consequently takes a lot of time to downsize the image. Actually, one might argue that this is not even a security issue, since the proper script would be: <?php // The file $filename = 'test.gif'; // Content type header('Content-Type: image/gif'); // Resample $image_p = imagecreatetruecolor(180, 180); $image = imagecreatefromgif($filename); // Get width height $width = imagesx($image); $height = imagesy($image); // The issue imagecopyresampled( $image_p, $image, 0, 0, 0, 0, 180, 180, $width, $height ); I'm not sure whether getimagesize() should be "fixed" to return the size given in the first image descriptor of GIF files, or whether this issue should merely be documented.