My understanding of this is it just gets a file on the web server, and prints the contents to the webpage.
Within this script, I don't think you're going to need many security features - no harm such as the harm done to NDFJay could be done using such a script that just simply read files.
Your main security problems will arise from the upload file script - this is the one where you need to focus your security efforts.
Couple of suggestions:
- Use
and
(without the spaces) in your post to make the PHP code look nice
- Don't use HTTP get. Use HTTP post. Then people can't access any files by visiting the PHP script in their web browser (it also prevents people from spamming your upload script by mashing the refresh button in their browsers)
- Don't bother with checking the file extension and reading from it. This is useless because if people know the location of the file in your web server, they can just visit the file themselves, running it. They don't need your PHP script to download the file. Say you have the file
www.example.com/hello/test.php. Using your script you could get it, or people could just get the file by visiting it in their browser. Just make the assumption when reading a file from your web server that it will not be malicious - let the upload script handle malicious files.
- When you don't pass a variable to a PHP script, it will be null, not an empty string. Just do something like:
$location = $_GET["filename"];
if ($location != null) {
// Code
} else {
echo "Invalid Parameters";
}
And a last note: You don't need a download script :P/>
You can just download files by using (in Lua):
local res = http.get("http://www.example.com/Files/" .. filename)
local content = res.readAll()
res.close()
TL;DR: A download script cannot be used to exploit a server (from my knowledge). And, a download script is useless.