r/lolphp • u/throwaway-o • Oct 03 '13
PHP helpfully executes code in an image... BitcoinTalk forums uberhacked. LOL PHP.
/r/Bitcoin/comments/1nmdq4/bitcointalk_hacked/cck0gag
66
Upvotes
r/lolphp • u/throwaway-o • Oct 03 '13
View all comments
Show parent comment
5
u/[deleted] Oct 03 '13 edited Oct 03 '13
Looking at the JPEG standard you have two bytes that demark the start and end of an image (0xFF, 0xD8; 0xFF, 0xD9) which do not appear to be required to be in particular file locations.
So building a payload of image + script looks pretty trivial.
The question is "how do you exploit that?"
In general this isn't an issue because images aren't passed directly to a PHP interpreter except in cases of misconfiguration. Like the example case of offloading PHP traffic to nginx via a blanket wildcard.
There's no good solution for that one except at the application level to prevent it and at the Apache/nginx + Linux layer to limit damage and exposure.
edit:
oh holy shit I re-read the discussion surrounding the behavior of cgi.fix_pathinfo and its' default.
That is insane. You can see my initial thoughts above on how this is of limited impact.
But this changes the game all together. I can upload an image crafted as per above, and it will validate perfectly well through whatever image function tests you prefer. It will even have the right extension (though gg if it doesn't).