文件包含与任意文件下载

文件包含

相关函数

include() 多次包含

include_once() ⼀次包含

require() 多次包含

require_once() ⼀次包含

漏洞分类

远程文件包含

image-20230228145659303

image-20230228145726514

image-20230228145742060

本地文件包含

如果文件有代码,会将包含文件以php文件的类型解析

image-20230228145822886

任意文件下载

漏洞成因

存在读取⽂件的函数

读取⽂件的路径客户端可控

没有对⽂件类型进⾏校验或者校验不严

没有对⽂件路径进⾏校验或者校验不严

输出了⽂件的内容

1
2
3
4
5
6
7
8
<?php 
$file_path = $_GET['file'];
file_exists($file_path) or die('file not exits');

$file_name = basename($file_path);
$file_size = filesize($file_path);
readfile($file_path);
?>

任意文件读取

与文件包含的区别

以php网站为例

文件包含会把文件当作php文件解析

文件读取,以记事本打开,TXT