Skip to content

New Advisory: 0wning with Gimp

It’s advisory time again:

This one’s nice because you can do your exploit development in Gimp. The idea is to plant your exploit code (in this case, PHP code) in a file with a valid GIF header and the file extension .php. Papoo CMS only sees the valid GIF header and let’s the user upload the file, as it is deemed harmless. The web server on the other hand will parse the file as PHP code because of the file extension -> instant remote code execution. The PoC in the advisory only creates a file with a minimal GIF header content, but if you need a valid GIF, just add the PHP code to the GIF comment section. You’ll be limited to 240 characters though.

Adding PHP code to a GIF comment in Gimp

Adding PHP code to a GIF comment in Gimp

The idea of embedding code in GIFs is not new but still works surprisingly well. So remember: always make sure that you look at both the header and the file extension when dealing with untrusted files (at least if your web server decides by file extension how to parse files).

BTW, another neat exploit along the lines of the above is the GIFAR attack which was presented at last year’s BlackHat.

[Update]
HD Moore adds in reply to windexh8er’s tweet the fun fact that Apache treats files like file.php.gif as PHP code and not as a GIF. Very true.

[2nd Update]
As you can see, HD also added his remark to this blog’s comments, which unfortunately got caught in the spam filter so I didn’t see it when posting the first update. I guess I’ll have to whitelist you HD ;).

{ 2 } Comments

  1. HD | 2009-Aug-10 at 16:29 | Permalink

    Keep in mind apache will process the first extension in the file, not the last, so just checking for ending “.gif” doesn’t work if the file is called “exploit.php.gif” — the PHP extension is detected and the file is processed as PHP instead of GIF.

  2. bob | 2009-Aug-14 at 17:19 | Permalink

    HD, you have it backwards.
    a.php.gif will not process as php.
    a.gif.php will.

{ 1 } Trackback

  1. [...] I happened to post this one earlier in the day and it got quite a bit more attention than I had expected.  The RedTeam blog has some Gimp pwnage fun that shows you how to embed some sneaky PHP in a GIF.  That and @hdmoore pointed out to me some extra fun to go along with the ’sploit. Double whammy! [0wning with Gimp] [...]

Post a Comment

Your email is never published nor shared.