This is a discussion on PHP security exploit with GIF images within the PHP Programming forums, part of the Web Development category; PHP security exploit with GIF images The problem that was discovered is that you can insert PHP code in the ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| PHP security exploit with GIF images The problem that was discovered is that you can insert PHP code in the middle of a GIF image. That would not be a problem if it was not for the insecure ways some developers use to serve images upload by their users. Usually, uploaded files are moved to a given directory. If the site then serves the images directly from that directory and preserve the original file name, the site may be open for security exploits. For instance, lets say the attacker uploads an image named image.gif.php . The image may be moved to the images directory. If the the Web server is configured as usual to process requests with files .php extension, and the site serves the image with the following URL, the request will execute the PHP code inside the image. Avoiding the problem he basic solution to avoid this problem is to either serve images only with actual extensions of image files (.gif, .png, .jpeg), or protect the upload directory to avoid direct requests to where the images are located. Depending on your PHP setup, it may or may not be easy to protect your uploaded images directory. In Apache it can be done using a .htaccess file with lines like this: <Files images> Deny from all </Files> Alternatively you can use other PHP functions to serve image files as images, and so, avoid triggering the execution of PHP scripts embedded in image files like these readfile. $file = 'image.gif.php'; Header('Content-Type: image/gif'); readfile('images/'.basename($file)); Note the use of basename function to avoid injection of malicious paths. This way, only files from inside the images directory will be served, even if the original file named was forged to steal server sensitive files like /etc/passwd |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
| |
LinkBacks (?)
LinkBack to this Thread: http://www.discussweb.com/php-programming/2044-php-security-exploit-gif-images.html | |||
| Posted By | For | Type | Date |
| hosting image - PHP security exploit with GIF images | This thread | Refback | 07-18-2007 08:55 AM |
| hosting php web - PHP security exploit with GIF images | This thread | Refback | 07-18-2007 08:51 AM |
| hosting php - PHP security exploit with GIF images | This thread | Refback | 07-18-2007 08:51 AM |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Security in PHP | rekhaa | PHP Programming | 153 | 09-24-2008 07:56 AM |
| PHP security | jegan | PHP Programming | 1 | 08-29-2007 04:52 AM |
| Sql Security | vadivelanvaidyanathan | Database Support | 1 | 08-09-2007 08:51 AM |
| Security for ASP.net | nhoj | ASP and ASP.NET Programming | 0 | 04-09-2007 09:19 AM |
| VB.net Security | nhoj | VB.NET Programming | 1 | 04-06-2007 01:50 AM |