Site legit file image_upload.php
was used to upload file 89471928047.php.jpg
Which was simple file upload form that copy tmp file to same images fo
Your image_upload.php
is insecure, check the following:
To check if it's an image you can run getimagesize on the file, it will return FALSE if it's not an image.
How is it possible to execute that file? First, how do you know it has been executed? Did you see side effects?
How to look at the logs?
Check the date and time of the uploaded file and start to look around there for suspicious activity (look at strange url parameters). Once you've find one or more IP address, doing evil things, grep the log for that (those) IPs, to see the whole story.
Another important info to know is, did you write the site or use a CMS or similar and in this case what is it and what version? You've to check published vulnerabilities and upgrade in case.
The problem is caused by your server using the default /etc/httpd/conf.d/php.conf:
rpm -ql php-5.1.6-39.el5_8
/etc/httpd/conf.d/php.conf
/usr/lib64/httpd/modules/libphp5-zts.so
/usr/lib64/httpd/modules/libphp5.so
/var/lib/php/session
/var/www/icons/php.gif
The content of /etc/httpd/conf.d/php.conf is:
#
# PHP is an HTML-embedded scripting language which attempts to make it
# easy for developers to write dynamically generated webpages.
#
<IfModule prefork.c>
LoadModule php5_module modules/libphp5.so
</IfModule>
<IfModule worker.c>
# Use of the "ZTS" build with worker is experimental, and no shared
# modules are supported.
LoadModule php5_module modules/libphp5-zts.so
</IfModule>
#
# Cause the PHP interpreter to handle files with a .php extension.
#
AddHandler php5-script .php
AddType text/html .php
Please note the last line AddHandler php5-script .php . This is causing that problem and needs to be replaced with a more secure configuration
You can read more about it and how to apply a fix here ( see last reply):
http://core.trac.wordpress.org/ticket/11122
also see this:
https://bugzilla.redhat.com/show_bug.cgi?id=885839
Using AddType in your .htaccess file, you can add many other extensions from which PHP can be ran. This is generally how .html
extensions can be used while still using PHP within themselves. So, yes, it's possible:
AddType application/x-httpd-php .jpg
You can test this if you like.
AddType application-x-httpd-php .jpg
<?php echo 'foo'; ?>
If all goes as planned, "foo" will be output to your screen. You could expand upon this to move /tmp
files around if you like.
Definitely something you want to be very careful with.
Another way this could have been done is through a call to require()
or include()
(or any of the _once()
methods) where by the hacker was able to load in his badfile.php.jpg
file that had been uploaded under the guise of an innocent image:
<?php
include $_GET["file"];
?>
In the above case (simplified example), the hacker could pass in a path to his .php.jpg
file and have its contents loaded in and processed as PHP code.
Require, Include, and their related methods aren't the only ways you can process external scripts - unfortunately you can use eval()
as well. I would hope that you have none of this going on though. If you did have any scripts on your server that were using any one of the file functions to read the contents of another script, and then eval()
to evaluate that content as PHP, this could also provide a gaping security hole in your website.