my problem is to avoid users loading some malicious files on my web server. Im works in linux (debian) environment.
In fact, the download is done via php using this code:
function checkFile($nomeFile, $myExt = false){ if($myExt != false){ $goodExt = "_$myExt"."_"; }else{ $goodExt = "_.jpg_.bmp_.zip_.pdf_.gif_.doc_.xls_.csv_.docx_.rar_"; } $punto = strrpos($nomeFile, '.'); $ext = "_".substr($nomeFile, $punto, 8)."_"; if(stristr($goodExt, $ext)){ return 1; }else{ return 0; } }
here I can specify the extensions allowed for downloading, and if the file does not meet them, I will delete it as soon as the download is complete. But this method allows the user to change the file extension for free by simply renaming .. and this is bad for me; even if the .exe file (for example) is never executed, if it is renamed to file.jpg (am I right?), I do not want to have potential danger files on my server.
Is there a way, in php, python, or whatelse, to make the unix system run easily to check the true file type?
I tried the python module mimetypes, but it retrieves the ipotetical mime file type .. based on extension -.-
python security types file php
Strae
source share