Executable PHP in a GIF image

Status
Not open for further replies.

On_The_Edge

Newbie
Joined
Nov 16, 2007
Messages
23
Reaction score
3
Ok, I'll ask the first coding question.

Is it possible to place an executable PHP script,within the middle of a GIF image? Is it possible to still have the file appear as an image to a server without detecting the php? I though I read about this action somewhere earlier this year.
 
Afaik, it's impossible. The server only executes PHP scripts when the extension is defined as PHP script. So for this, GIF has to be defined as PHP script. But then it still won't be able to handle a PHP script in the middle of a GIF image, because GIF is binary and PHP isn't.

It is possible to create a PHP script that outputs a GIF image, but that's not what you want, is it? :)
 
Ok, I'll ask the first coding question.

Is it possible to place an executable PHP script,within the middle of a GIF image? Is it possible to still have the file appear as an image to a server without detecting the php? I though I read about this action somewhere earlier this year.

This is used in those invisible 1x1 pixel tracking. So your code is

HTML:
<img src="http://www.site.com/script.php"></img>

Your script then records all the referer, ip, and any other info you want and saves it to a database and streams a 1x1 pixel transparent gif.

If you want to execute code on the users machine through an image tag then you should be learning about xss expliots.





http://tubeautomator.com/squeeze.php​
 
Thanx for the valuable information. Thought this might have worked for a project I have been considering.

"If you want to execute code on the users machine through an image tag then you should be learning about xss expliots." I plan to look into this further because this sounds like possibly more what I need.
 
Ok, I'll ask the first coding question.

Is it possible to place an executable PHP script,within the middle of a GIF image? Is it possible to still have the file appear as an image to a server without detecting the php? I though I read about this action somewhere earlier this year.

PHP is a server side language so it gets executed on the server, not on the user's machine. You can link to a PHP script disguised as an image using modrewrite, for example:

<img src="image.gif">

Use modrewrite to rewrite this to "script.php". The script then does whatever you want it to do (on the server, not on the user's machine) and then outputs an image which gets displayed on the user's machine. The only use for this, as far as I can see, is to prevent anyone knowing you're using an image tag to link to a PHP script. I don't think that's what you were after though, I only posted this because the forum is so empty and somebody might find the above info useful...
 
Ok, I'll ask the first coding question.

Is it possible to place an executable PHP script,within the middle of a GIF image? Is it possible to still have the file appear as an image to a server without detecting the php? I though I read about this action somewhere earlier this year.

i dont know whether it is patched now
but one year ago what you are saying was possible, watch it
milw0rm.com/video/watch.php?id=57
 
it can be done in a folder create a custom .htaccess file and then add the following
This is adding a custom mime header that tell how the file is run and makes a PNG file be run through the php binary

AddType application/x-httpd-php .PNG

This is how people create the dynamic php signatures that show your ip address and such,
 
Here is a file called sig.png that I use and it displays a image and a random quote

PHP:
<?php 
function ImageStringWrap($image, $font, $x, $y, $text, $color, $maxwidth) 
{ 
   $fontwidth = ImageFontWidth($font); 
   $fontheight = ImageFontHeight($font); 

   if ($maxwidth != NULL) { 
       $maxcharsperline = floor($maxwidth / $fontwidth); 
       $text = wordwrap($text, $maxcharsperline, "\n", 1); 
     } 

   $lines = explode("\n", $text); 
   while (list($numl, $line) = each($lines)) { 
       ImageString($image, $font, $x, $y, $line, $color); 
       $y += $fontheight; 
     } 
} 
// 
header("Content-type: image/png"); 
$h_array = file("homer.txt"); 
srand((double) microtime() * 10000000); 
$h = array_rand($h_array); 
     
// Calculate vertical position//put your image name here (must be a png) 
$im = imagecreatefrompng("homer.PNG"); 
//change your text color here ( must be the hex value) ex. 255,255,255 would be white 
$color = imagecolorallocate($im, 255, 255, 255); 

//change your X & y coordinates here to place the text on your image where you want it 
//(these will center the text on a 400x100 image) 
$px=80; 
$py=50; 

//no need to touch this unless you know what your doing 

ImageStringWrap($im, 3, $px, $py, rtrim($h_array[$h]), $color, 550 ); 

imagepng($im); 
imagedestroy($im); 

?>
 
there was a gif php injection attck a while back.....
but i dont think it will work anymore ! :1244:
 
With jpeg's in the exif metadata field. The gif file format doesn't have that.
 
it is possible to hide a php shell backdoor script inside an image file with a little bit of editing.
the best workaround is to have all image files in the same directory and disable php from processing files inside the image folder.
 
Hate to burst some bubbles


but make a php file.

Code in it.

<?php

echo"hello";
?>

now name it something.php

Add .jpg

something.php.jpg

The server will infact execute it as php script. try it yourself.

TJ
 
Hate to burst some bubbles


but make a php file.

Code in it.

<?php

echo"hello";
?>

now name it something.php

Add .jpg

something.php.jpg

The server will infact execute it as php script. try it yourself.

TJ

Nope .. Tried it. IE simply prints the code from the file and FF prints the URL of the file ..
 
to get php to execute that file you would have to get a script to call it with something like
Code:
include()
. at that point the extension doesn't matter. I'm guessing what the orig poster is getting at is he wants to execute code on someone's machine when they view an image on a site. This is possible against unpatched machine via a GDI exploit but good luck finding machines to infect.

Also, it would never be php code you would be embedding in an image. it would be some sort of client side scripting. Im not sure if it's still possible i recall visiting images before that execute vb script.

If your intention is to upload a php script named as a gif to a server in order to gain access to the server, you would want to try to do something like manipulate the value of a variable called in an include(). so like...
lets say its a forum and you rename yourscript.php to yourscript.gif then upload it to the forum as your avatar or an attachment.. you would then want to look for something in the forum code like
Code:
include($file)
; then try to alter the value of $file via the browser to point to yourscript.gif.

Note: there are some pretty neat PHP trojans out there that you can use to intrude upon any server that you can get the things uploaded to. A popular one is called c99.
 
Ok, I'll ask the first coding question.

Is it possible to place an executable PHP script,within the middle of a GIF image? Is it possible to still have the file appear as an image to a server without detecting the php? I though I read about this action somewhere earlier this year.

Yes it is possible dont hae the time to code it right now but heres a hint of what I did last time I did it.

-Use htaccess to interprate that particular file as a php script i.e. first.gif is actually just a php file with gif as an extension.
-Execute your php script careful not to echo or print anything to the browser
-Finally open you gif with your php file i.e. first.gif opens real.gif and print the correct stuff to the browser.
 
Yes it is possible dont hae the time to code it right now but heres a hint of what I did last time I did it.

-Use htaccess to interprate that particular file as a php script i.e. first.gif is actually just a php file with gif as an extension.
-Execute your php script careful not to echo or print anything to the browser
-Finally open you gif with your php file i.e. first.gif opens real.gif and print the correct stuff to the browser.

LOL!

"I have a truly marvellous proof of this proposition which this margin is too narrow to contain."
~Pierre de Fermat
 
Status
Not open for further replies.
Back
Top