note 69438 deleted from function.readdir by tularis
| From: | tularis@php.net | Date: | Sun, 13 May 2007 19:00:18 +0000 |
| Subject: | note 69438 deleted from function.readdir by tularis | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-126506@lists.php.net to get a copy of this message | ||
Note Submitter: runt
----
With the help of a clan member from the clan I'm in, I created the following script to give you
a password protected list of files that allows directory traversing. It will not allow you to view
any file not in the path you chose.
<?
define("def_path", 'your path here');
define("def_pass", 'your password here');
$path = def_path;
$pass = "";
foreach ($_GET as $k => $v) {
if ("path"==$k)
$path="$v/";
if ("pass"==$k)
$pass="$v";
}
// make sure they cant get access to other files
if (strpos($path,def_path) != false)
$path=def_path;
if (strpos($path,"..")!=false)
$path=def_path;
if (!is_dir($path))
$path=def_path;
if (rtrim(substr_replace($path, ' ', 2, 1000)) != def_path) // change 2 to be what you
need to get your entire path for the comparison
$path=def_path;
function read_dir($pass, $dirToRead) {
$path4 = opendir($dirToRead);
$dirs = array();
$files = array();
while (false !== ($file = readdir($path4))) {
if($file!="." && $file!="..") {
if(is_dir($dirToRead.$file))
$dirs[]=$dirToRead.$file;
else
$files[]=$file;
}
}
closedir($path4);
// get the next level up for the
$upDir = substr( $dirToRead, 0, strrpos( $dirToRead, '/') );
if( strrpos( $dirToRead, '/') + 1 == strlen("$dirToRead"))
$upDir = substr( $upDir, 0, strrpos( $upDir, '/') );
if($upDir==""){$upDir=def_path;}
echo "<pre>";
echo ltrim(substr_replace($dirToRead, ' ', 0, 1))."\n";
echo "<a href=\"?pass=$pass&path=$upDir\">..</a>\n";
if($dirs) {
natcasesort($dirs);
foreach($dirs as $dir)
echo "<a href=\"?pass=$pass&path=$dir\">" . basename($dir)
. "</a>\n";
}
echo "\n";
if ($dirToRead != def_path) {
if($files) {
natcasesort($files);
foreach ($files as $file)
echo $file."\n";
echo "\n";
}
}
echo "</pre>";
}
?>
<html><head><title>HMT Fast Download</title></head>
<body bgcolor="#E5E5E5" text="#000000" link="#006699"
vlink="#5493B4">
<?
if($pass==def_pass){
if (is_dir($path)) {
read_dir($pass, $path);
}
}else if($pass==""){
echo "<form action=\"\" method=\"get\"
name=\"loginfrm\">";
echo "<input name=\"pass\" type=\"text\"
value=\"$pass\">";
echo "<input name=\"login\" type=\"submit\"
value=\"login\">";
echo "</form>";
}
else{
header('Location:http://hitlersmissingtestie.clanservers.com/forum/');
}
?>
</body>
</html>