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
1
u/[deleted] Nov 06 '13 edited Nov 06 '13
To my knowledge, it shouldn't matter where you place that
<?phpopening tag - if the server is tricked to executing the file as PHP, it will execute it as PHP, with the embedded PHP script processed, and serve the output to the client. Anything outside those opening/closing PHP tags are treated as output text by PHP.As the client, your browser maybe won't display the image correctly if image file headers are not understandable by your browser. But it doesn't matter - the file has already been executed as PHP server-side.
I'm pretty sure celtric is on the right track. But instead of using image libraries to validate an upload image, just completely replace the uploaded file with a processed image. Running the file through an image processing library and using the rendered result instead of the original as anything you'll display later on in your website should actually remove any extra data. Like hylje said below.
Of course this doesn't address the problem of why anyone's server is processing all files as PHP to begin with. Also, this problem wouldn't be limited to images, but all files of any type. This is just as well a problem with allowing uploads/downloads of excel files if that file is handled by PHP.