DVWA 黑客攻防实战(四)文件包含 File Inclusion

文件包含(file Inclusion)是一种很常见的攻击方式,主要是通过修改请求中变量从而访问了用户不应该访问的文件。还可以通过这个漏洞加载不属于本网站的文件,比如一个 webshell 从而实现网站控制。下面一起来看看 DVWA 中的文件包含漏洞。

低级

原本也不知道是什么意思,然后尝试点击一下 File1 就显示 File1 的内容了。而且发现 url 变成了 http://192.168.31.166:5678/vulnerabilities/fi/?page=file1.php

Hacker 就在浏览器中输入了 http://192.168.31.166:5678/vulnerabilities/fi/?page=/etc/apache2/apache2.conf

代码如下

<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>

觉得主要问题还是对文件路径没有验证吧 看了中级的代码后,才发现还可以这样用,

。。。看了中级代码才知道 低级的还可以这样注入。

中级

<?php

// The page we wish to display
$file = $_GET[ 'page' ];

// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );

?>

中级代码针对上面两种情况会有所改善,但问题依然存在 比如输入的是http://192.168.31.166:5678/vulnerabilities/fi/?page=HTTP://www.baidu.com 比如输入的是全路径 http://192.168.31.166:5678/vulnerabilities/fi/?page=/etc/apache2/apache2.conf

高级

高级代码终于有输入验证了,只有文件名是有 file 开头的文件才能打开

<?php

// The page we wish to display
$file = $_GET[ 'page' ];

// 输入验证
if( !fnmatch( "file*", $file ) && $file != "include.php" ) {
    // This isn't the page we want!
    echo "ERROR: File not found!";
    exit;
}

?>

好像也没什么问题了, http://192.168.31.166:5678/vulnerabilities/fi/?page=/etc/apache2/apache2.conf 之类的也打不开了。 此时 Hacker 输入了 http://192.168.31.166:5678/vulnerabilities/fi/?page=file4.php,就中奖了

DVWA上根本没有列出此文件!这是个隐藏文件来的,这而这代码的漏洞就是能显示隐藏的文件!这与需求不符。

不可能

再看看不可能的代码

<?php

// The page we wish to display
$file = $_GET[ 'page' ];

// Only allow include.php or file{1..3}.php
if( $file != "include.php" && $file != "file1.php" && $file != "file2.php" && $file != "file3.php" ) {
    // This isn't the page we want!
    echo "ERROR: File not found!";
    exit;
}
?>

感觉有点滑稽。哈哈哈哈 这里的文件列表应该从读文件或者读数据库的方式获取比较好吧。这样不够优雅。

猜你喜欢

转载自www.cnblogs.com/jojo-feed/p/10172970.html