文章更新于:2020-04-15
文件包含 File Inclusion
一、安全级别:Low
1.1、源码
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>
1.2、攻击
可以看出,源码中没有做任何防护,这意味着我们有可能能读取到任意文件。
当我们在地址栏构造如下地址时:
http://home.cc/dvwa/vulnerabilities/fi/?page=../../../../../../etc/passwd
可以获得密码文件的内容:
包含远程文件:
二、安全级别:Medium
2.1、源码
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
?>
2.2、攻击
从源码可以看出,对 http
等字符进行了替换。
但大小写却没有校验。
所以我们可以:
三、安全等级:High
3.1、源码
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
if( !fnmatch( "file*", $file ) && $file != "include.php" ) {
// This isn't the page we want!
echo "ERROR: File not found!";
exit;
}
?>
3.2、攻击
源码可以看出,
文件要么是 file
开头,
要么是 include,php
,
否则报文件未找到错误。
那么:
四、安全等级:Impossible
4.1、源码
<?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;
}
4.2、攻击
白名单过滤机制,
攻击没戏。