Can a php shell be injected into an image? How would this work?

GStock picture GStock · Feb 24, 2011 · Viewed 30.7k times · Source

I remember seeing an exploit for an image uploading function, which consisted of hiding malicious php code inside a tiff image.

I'm making my own image uploading script, and I assume I'll have to protect myself from this possibility. Except, that I have no idea how it would work. Does anyone know how a php shell hidden inside an image would execute itself? Would it need to be loaded in a certain way?

Thanks.

Answer

Marty picture Marty · Jun 5, 2012

Re encoding the image will not stop someone from uploading a shell. The only sure way to prevent it is to re-encode and scan the image for the presence of php tags.

For an example of a PHP PNG shell that will survive re-encoding