Forum Moderators: coopster

Message Too Old, No Replies

removing directory traversal security threat

         

dmmh

8:27 am on Sep 27, 2005 (gmt 0)

10+ Year Member



somehow this will still output any files specified to get via the 2 $_GET variables, allowing people to actaully access all my files using directory traversal, which needless to say isnt a pretty thing. Can't find the error :(

$name = $_GET['name'];
$id = $_GET['id'];
$banned = array("../","./","..\\",".\\");

foreach($banned as $str){
if(strpos($id, $str!== false) ¦¦ strpos($name, $str!== false)){
die("sod off hacking #*$!");
}else{
$url = "../../images/tmp/$id/$name";
etc
etc
}
}

dhardisty

11:54 am on Sep 27, 2005 (gmt 0)

10+ Year Member



try using the absolute file location -- for example, use $_SERVER['DOCUMENT_ROOT']."/images/tmp/$id/$name" instead of "../../images/tmp/$id/$name"

I don't know if it will succeed in preventing the hacks, but it's worth a shot.