Jump to content

Recommended Posts

I have a script that allows for anyone to upload a file to my server

 

using this method

 

move_uploaded_file($_FILES["file"]["tmp_name"],
  "m/" . $newname);

 

it lets the user select a file for upload and then uploads the file in a directory named "m"

 

once the file upload it provides a link so they can share and anyone can download the file.

 

can I make this safe using .htaccess premissions?

 

I want them to be able to upload and download EXE files but not execute on my server.

 

Thanks for any tips on how to make this safe?

 

Paul

Link to comment
https://forums.phpfreaks.com/topic/268647-file-upload-script-safety/
Share on other sites

I very much doubt that, as it depends upon what else you're doing to secure your application. Also, I suspect that you'll want to give your users the ability to download the files again, which means you'll have to write a download wrapper if you disallow browsing. (Browsing will execute any files that can be executed by the server.)

 

To start with I'd recommend that you read this article on securing upload forms. Even though it's not exactly what you want, it is a start.

You will also want to write that download wrapper, just to be on the safe side.

That wouldn't confer any real security, I'm afraid, C4U. All it would do is to require the users to have to do some more work, for no apparent benefit on their end. Also, zip/rar files can be made executable quite easily, and even if the file is called "something.zip" doesn't have to mean that it's actually a zip-file. Could be a renamed executable, which still can get executed on the server.

 

Writing a wrapper that serves the file, and saving them outside of the server root, is the proper course of action.

That way you've ensured that an attacker must have access to the server OS itself, before he's able to execute the files. In which case it's game over already, and no amount of security you've added to your PHP scripts is going to matter.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.