I'm working in a PHP system where the user can upload files.
I'm trying to protect the system from malicious codes, so I'm thinking about some type of blacklist of files that I've to block from upload.
I know that a Whitelist is better than a Blacklist and this is my common approach, but in this case I need to do a blacklist of files for many reasons (out of my control), but I still looking for safety (if possible).
This is my current script (I'm checking the MIME type to get the file type):
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$check= finfo_file($finfo,$file["tmp_name"]);
finfo_close($finfo);
$dangerMime = array('application/x-bsh', 'application/x-sh', 'application/x-shar', 'text/x-script.sh');
if (in_array($check, $dangerMime)) {
//block upload
}
else {
//allow upload
}
The current list of MIME types to block is:
- 'application/x-bsh', 'application/x-sh', 'application/x-shar', 'text/x-script.sh'
I'm trying to block any .sh
file, since the system is running in a CentOS under Apache. Are there any other filetype that I also should block?
Following are some importante information:
The Server is a CentOS 7.2 with Apache 2.4.6. Following are the permissions of the uploads directory:
drwxr-xr-x 4 apache apache 4096 Jan 8 12:23 uploads
Note: In this project, I'm acting just as developer, so I can't change the file permissions.