文件包含+DVWA

文件包含漏洞原理

服务器执行PHP文件时,可以通过文件包含函数加载另一个文件中的PHP代码,并且当PHP来执行。在通过PHP的函数引入文件时,由于传入的文件名没有经过过滤,导致执行了非预期的代码。

<?php
    $a  = $_GET['a'];
    include($a);
?>

1.本地文件包含漏洞。网站服务器本身存在恶意文件,然后利用本地文件包含使用

2.远程文件包含漏洞。调用其他网站的恶意文件进行打开

需要php.ini

allow_url_fopen = On(是否允许打开远程文件)

allow_url_include = On(是否允许include/require远程文件)

PHP中文件包含函数 :

require():找不到包含文件只警告

include():找不到包含文件则停止

require_once():只运行一次

include_once()

https://www.freebuf.com/articles/web/182280.html

DVWA - File Inclusion

low

<?php

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

?>

对输入的page没有过滤

能直接进本地的文档
在这里插入图片描述
在这里插入图片描述

可以连接远程的phpinfo
在这里插入图片描述

应该也可以连菜刀,但是不知道怎么在蚁剑里改DVWA难度(迷之错误。
在这里插入图片描述

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://"防止远程包含漏洞的产生

过滤"../", "..\"防止进行目录切换的包含

可以使用双写绕过
在这里插入图片描述

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

?> 

if( !fnmatch( "file*", $file ) && $file != "include.php" )限制file必须为 file* 或 include.php

可以利用file协议进行包含本地的文件

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

?>

if( $file != "include.php" && $file != "file1.php" && $file != "file2.php" && $file != "file3.php" )确定file必须为include.php、file1.php、file2.php、file3.php之一(白名单过滤)。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值