DVWA靶场-文件包含

文件包含

低级

源码:

<?php

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

?> 

低级什么也没做,直接利用http协议包含文件(可以远程包含):
在这里插入图片描述

中级

查看源代码:

<?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协议绕过

hthttp://tp://127.0.0.1/phpinfo.php

双写绕过
在这里插入图片描述
file协议绕过:
FIle协议也叫本地文件传输协议 ,主要用于访问本地计算机中的文件,就如同在Windows资源管理器中打开文件一样

file:///文件路径

在这里插入图片描述

高级

源代码

<?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;
}

?> 

分析可知:后台将我们输入的文件 f i l e f i l e f file做了匹配,必须包含file,f且 file不等于include.php,此时服务器才不会去包含文件,两个条件只要不满足其中任意一个,就能达到文件包含的目的
绕过:file协议来绕过
FIle协议也叫本地文件传输协议 ,主要用于访问本地计算机中的文件,就如同在Windows资源管理器中打开文件一样

file:///文件路径

直接包含本地php文件
在这里插入图片描述

impossible

查看源码:

 <?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;
}

?>

分析:做的太绝了,对包含文件做了白名单策略,只能包含指定的那三个文件
总结:通过白名单策略可以避免文件包含

猜你喜欢

转载自blog.csdn.net/Mr_helloword/article/details/107709717