Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to safely prevent uploaded file from being run via PHP on any server?

I noticed that it's possible to run a file via PHP even if its extension wasn't .php, for example file test.xyz.php.whatever.zyx can be still run with PHP even when the extension isn't .php! It just happens to have .php. in the filename, and that's enough for my Apache to run the PHP script.

I tried (as someone suggested) to put this in a .htaccess file on that folder:

php_flag engine off

But it didn't work on my machine.

The only solutions I know for now are:

  • Rename to known file extension, which is not run via PHP, such as .txt.
  • Remove all dots from the filename, thus making it extensionless.

But I'm still not sure how these solutions would work on other servers than my Windows server (with Apache).

Is there any other solutions which doesn't need the filenames to be renamed in any way?

like image 624
Rookie Avatar asked Nov 07 '12 14:11

Rookie


1 Answers

for uploading by users I suggest that you upload a folder in a layer above the root path in this case Only You Have Access To upload folder( In direct addressing) and an attacker have not access to any files in this folder Thus you disable an attacker action to run malicious file

like image 132
saeed arab sheybani Avatar answered Sep 21 '22 15:09

saeed arab sheybani