Jump to content

[SOLVED] Having problem with IMAGE UPLOAD (hack)


andz

Recommended Posts

When creating an image upload.

 

I found this code on the internet and said that this can trigger a javascript on IE browser.

 

Here's the code.

 

\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0DPHCK\x00\x00\x00\x01\x00\x00\x00\x01

<html><body><script>alert(window.document.cookie);</script></body></html>

 

save it as image-name.jpg

 

Is there any solution on php side to prevent that from being uploaded on the server?

 

Thanks.

I want users to upload pictures on server specifically the file will reside on uploaded/ folder.

 

Now, i want them to only upload true images and not this codes that will cause problem to me.

 

\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0DPHCK\x00\x00\x00\x01\x00\x00\x00\x01

<html><body><script>alert(window.document.cookie);</script></body></html>

 

Are there any remedy for this one?

\x89\x50\x4E\x47\x0D\x0A\x1A\x0A\x00\x00\x00\x0DPHCK\x00\x00\x00\x01\x00\x00\x00\x01

<html><body><script>alert(window.document.cookie);</script></body></html>

 

is the PE Header for PNG file so it tricks the browser thinking it's loading a PNG file.. i think i'd use  header() for this..

 

header("Content-type: image/png");

it passed the CONTENT-TYPE: image/png

 

i have the solution.

 

by using getimagesize();

 

$upload = getimagesize($_FILES['upload']['tmp_name']);

 

if (!intval($upload[0]) || !intval($upload[1])) {

// render error message here.

}

else {

// upload

}

 

 

even it bypass the content-type, still when checking its width and height, it returned null so that's my basis for my solution.

 

any better solution?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.