473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

securing

hello

Is there a method to forbid an attacker to exploit download.php
in grabbing some "sensitive" file ?

I mean using that kind of trick

download.php?filename=../../../../../../../../../../../../etc/passwd

thanks you
Mar 29 '06 #1
4 1413
Frank Mutze wrote:
hello

Is there a method to forbid an attacker to exploit download.php
in grabbing some "sensitive" file ?

I mean using that kind of trick

download.php?filename=../../../../../../../../../../../../etc/passwd

thanks you


1. Validate the path and filename being downloaded
2. Don't run the webserver as root
3. Let Unix security help you.

Or, better yet - don't let them input the filename being downloaded. Rather,
give them a list of files and let them select. But don't give them the
filenames themselves - just descriptions. Look up the filenames when they
select which file they want to download.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 29 '06 #2
On Wed, 29 Mar 2006 11:31:46 +0200, Frank Mutze wrote:
hello

Is there a method to forbid an attacker to exploit download.php in
grabbing some "sensitive" file ?

I mean using that kind of trick

download.php?filename=../../../../../../../../../../../../etc/passwd


Use http://uk.php.net/realpath to convert it to a normal path and then use
one of the many string comparing functions to check it's within your
acceptable path.

Cheers,
Andy

--
Andy Jeffries MBCS CITP ZCE | gPHPEdit Lead Developer
http://www.gphpedit.org | PHP editor for Gnome 2
http://www.andyjeffries.co.uk | Personal site and photos

Mar 29 '06 #3
"Frank Mutze" <no****@all.net> wrote in message
news:e0**********@s1.news.oleane.net...
hello

Is there a method to forbid an attacker to exploit download.php
in grabbing some "sensitive" file ?

I mean using that kind of trick

download.php?filename=../../../../../../../../../../../../etc/passwd

thanks you


Jerry already suggested a good way, but you can also try it with a checksum
to see that you did generate the filename by recalculating the check.

Say you'r filename is 'validfile.pdf'. You calculate a checksum for it, for
example by prepending a static password and md5'ing it.

$filename = 'validafile.pdf';
$checksum = md5($filename.'supercalifragislisticexpialidocious ');

Then echo the link:

download.php?filename=$validfile.pdf&checksum=$che cksum

In download.php before outputting the file, you recalculate the checksum the
same way and compare it to given checksum
if($_GET[checksum] ==
md5($_GET[filename].'supercalifragislisticexpialidocious'))
if they match, it was indeed a link you generated and a file you generated,
but if it was changed to something like
filename=../../../../../../../../../../../../etc/passwd then the checksums
do not match (or at least the possibility of a false file name matching is
near to non-existing)

I used a scrambler 'supercalifragislisticexpialidocious' here, because
simply md5'ing the filename can be reproduced, but by adding the secret
scrambling key you also ensure that a hacker doesn't outsmart you by also
md5'ing his filename. Without the correct scrambling key the md5 will be
different, and since it's one-way function, you can not reproduce the
scrambling key from the md5 hash.

They way Jerry suggested is easier, but this is another way to achieve it.

--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviö
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
Mar 29 '06 #4
d
"Frank Mutze" <no****@all.net> wrote in message
news:e0**********@s1.news.oleane.net...
hello

Is there a method to forbid an attacker to exploit download.php
in grabbing some "sensitive" file ?

I mean using that kind of trick

download.php?filename=../../../../../../../../../../../../etc/passwd

thanks you


The easiest way is to remove any path elements that navigate up the
directory structure:

$path=str_replace("../", "", $path);

that would at least keep it within your documentroot. Comparing the
realpath() is the most secure, however.

dave
Mar 29 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: David McNab | last post by:
Hi, I'm writing a web app framework which stores pickles in client cookies. The obvious security risk is that some 5cr1p7 X1ddi35 will inevitably try tampering with the cookie and malforming...
1
by: Bruno Desthuilliers | last post by:
Hi everyone ! Could someone point me to infos about securing python for use as CGI or mod_python for a shared hosting environnement ? I searched google, but did not find anything specific :( ...
0
by: atl-jcd | last post by:
Does anyone have a HTML or PDF copy of the old Al Stevens article: "Passing the C++ Test: Securing success in an interview" from Dr. Dobbs Journal (I know I can get it from the DDJ site if I...
2
by: byrocat | last post by:
I'm chasing after a documetn that was available on one of the Microsoft websites that was titled somethign like "MS SQL Server Best Practices" and detailed a nyumber of best practices about...
2
by: James | last post by:
What's the best way of securing online databases and web services? At present I am using a database password, which of course is not hard-coded into the web service, but this means re-submitting it...
11
by: Susan Bricker | last post by:
Greetings. I am looking for some advice on making a database secure. By secure, I mean that I want only certain people to have write access to the database and I want the updates to be permitted...
11
by: Wm. Scott Miller | last post by:
Hello all! We are building applications here and have hashing algorithms to secure secrets (e.g passwords) by producing one way hashes. Now, I've read alot and I've followed most of the advice...
1
by: Mark Goosen | last post by:
Hi ive installed wse 2.0 SP3 and was running throught the demo downlaoded on the Securing the Username Token with WSE 2.0 page the Securing the Username Token with WSE 2.0. Im spose to change...
4
by: KJ | last post by:
Hello All, I have to secure my first real B2B web service. Could you please provide some guidance as to which method of security I should use. One caveat is that we will not be using SSL on the...
10
by: Les Desser | last post by:
In article <fcebdacd-2bd8-4d07-93a8-8b69d3452f3e@s50g2000hsb.googlegroups.com>, The Frog <Mr.Frog.to.you@googlemail.comMon, 14 Apr 2008 00:45:10 writes Not sure if I quite follow that. 1....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.