note 69438 added to function.readdir
| From: | runt at osu1 dot php dot net | Date: | Wed, 06 Sep 2006 05:46:42 +0000 |
| Subject: | note 69438 added to function.readdir | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-116745@lists.php.net to get a copy of this message | ||
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>
----
Server IP: 216.194.113.175
Probable Submitter: 68.112.124.211
----
Manual Page -- http://www.php.net/manual/en/function.readdir.php
Edit -- https://master.php.net/note/edit/69438
Del: integrated -- https://master.php.net/note/delete/69438/integrated
Del: useless -- https://master.php.net/note/delete/69438/useless
Del: bad code -- https://master.php.net/note/delete/69438/bad+code
Del: spam -- https://master.php.net/note/delete/69438/spam
Del: non-english -- https://master.php.net/note/delete/69438/non-english
Del: in docs -- https://master.php.net/note/delete/69438/in+docs
Del: other reasons-- https://master.php.net/note/delete/69438
Reject -- https://master.php.net/note/reject/69438
Search -- https://master.php.net/manage/user-notes.php