版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_37216944/article/details/86207255
Directory Traversal - Directories
function show_file($file)
{
// Checks whether a file or directory exists
// if(file_exists($file))
if(is_file($file))
{
$fp = fopen($file, "r") or die("Couldn't open $file.");
while(!feof($fp))
{
$line = fgets($fp,1024);
echo($line);
echo "<br />";
}
}
else
{
echo "This file doesn't exist!";
}
}
low
case "0" :
show_file($file);
// Debugging
// echo "<br />" . $_GET['page'];
break;
未对输入的目录进行限制,可以访问任意目录。
http://localhost/bwapp/directory_traversal_2.php?directory=documents/../../../../
medium
strpos($data, "../") !== false ||
strpos($data, "..\\") !== false ||
strpos($data, "/..") !== false ||
strpos($data, "\..") !== false)
同目录遍历medium,只限制了目录遍历,仍可使用文件名访问当前目录
任意文件。
http://localhost/bwapp/directory_traversal_2.php?directory=eval
high
$real_base_path = realpath($base_path);
// echo "base path: " . $base_path . " real base path: " . $real_base_path . "<br />";
$real_user_path = realpath($user_path);
使用real user path进行比较。
这里需要比较我们要访问的目录是不是在我们的目录下。从逻辑上解决了目录遍历的问题。
Directory Traversal - Files
http://localhost/bwapp/directory_traversal_1.php?page=666
还可以结合目录遍历访问上层目录文件
http://localhost/bwapp/directory_traversal_1.php?page=../../manual.chm
还可以结合目录遍历访问上层目录文件
http://localhost/bwapp/directory_traversal_1.php?page=../../manual.chm
medium
同目录遍历medium,只限制了目录遍历,仍可使用文件名访问当前目录任意文件。
high
同目录遍历high,使用real user path进行比较。