IT Community - Software Programming, Web Development and Technical Support

PHP security exploit with GIF images

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 ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  3 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 07-17-2007, 11:01 PM
bluesky bluesky is offline
D-Web Analyst
 
Join Date: Jun 2007
Posts: 201
bluesky is on a distinguished road
Default PHP security exploit with GIF images

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

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


All times are GMT -7. The time now is 02:12 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0