文件包含漏洞案例

一、PHP://INPUT

Example 1:造成任意代码执行

源代码:

复制代码
<meta charset="utf8">
<?php
error_reporting(0);
$file = $_GET["file"];
if(stristr($file,"php://filter") || stristr($file,"zip://") || stristr($file,"phar://") || stristr($file,"data:")){
	exit('hacker!');
}
if($file){
	if ($file!="http://www.baidu.com") echo "tips:flag在当前目录的某个文件中";
	include($file);
}else{
	echo '<a href="?file=http://www.baidu.com">click go baidu</a>';
}
?>

根据源代码来看,filter、zip、phar、data等伪协议都被过滤了。

但php://input这个伪协议没有被过滤,我们可以在这里做文章。

先用dir看看目录,发现有flag,然后直接读取出来就行。

Example 2:文件内容绕过

源代码:

复制代码
<?php
show_source(__FILE__);
include('flag.php');
$a= $_GET["a"];
if(isset($a)&&(file_get_contents($a,'r')) === 'I want flag'){
	echo "success\n";
	echo $flag;
}

最主要的就是if判断语句里的意思,file_get_contents里读取的变量a中要有I want flag,才能走到下面读取flag中,那么我们就需要一个可以接收参数的伪协议,只有php://input可以。

二、PHP://FILTER

Example 1

源代码:

复制代码
<?php
error_reporting(0);
$file = $_GET["file"];
if(stristr($file,"php://input") || stristr($file,"zip://") || stristr($file,"phar://") || stristr($file,"data:")){
	exit('hacker!');
}
if($file){
	include($file);
}else{
	echo '<a href="?file=flag.php">tips</a>';
}
?>

查看过滤掉的伪协议,php://filter没有被过滤,看代码也是可以直接读取。

三、zip://

Example 1

第一部分代码:

复制代码
<?php
error_reporting(0);
$file = $_GET["file"];
if (!$file) echo '<a href="?file=upload">upload?</a>';
if(stristr($file,"input")||stristr($file, "filter")||stristr($file,"data")/*||stristr($file,"phar")*/){
	echo "hick?";
	exit();
}else{
	include($file.".php");
}
?>

这个没有过滤zip的伪协议,然后可以看出会跳转到upload页面,然后还看到include函数,可以知道这里就是漏洞点。

upload代码:

复制代码
<meta charset="utf-8">
<form action="upload.php" method="post" enctype="multipart/form-data" >
	 <input type="file" name="fupload" />
 	<input type="submit" value="upload!" />
</form>
you can upload jpg,png,zip....<br />
<?php
if( isset( $_FILES['fupload'] ) ) {
    $uploaded_name = $_FILES[ 'fupload' ][ 'name' ];         //文件名
    $uploaded_ext  = substr( $uploaded_name, strrpos( $uploaded_name, '.' ) + 1);   //文件后缀
    $uploaded_size = $_FILES[ 'fupload' ][ 'size' ];         //文件大小
    $uploaded_tmp  = $_FILES[ 'fupload' ][ 'tmp_name' ];     // 存储在服务器的文件的临时副本的名称
    $target_path = "uploads\\".md5(uniqid(rand())).".".$uploaded_ext;
    if( ( strtolower( $uploaded_ext ) == "jpg" || strtolower( $uploaded_ext ) == "jpeg" || strtolower( $uploaded_ext ) == "png" || strtolower( $uploaded_ext ) == "zip" ) &&
        ( $uploaded_size < 100000 ) ) {
        if( !move_uploaded_file( $uploaded_tmp, $target_path ) ) {// No
            echo '<pre>upload error</pre>';
        }
        else {// Yes!
            echo "<pre>".dirname(__FILE__)."\\{$target_path} succesfully uploaded!</pre>";
        }
    }
    else {
        echo '<pre>you can upload jpg,png,zip....</pre>';
    }
}
 ?>

文件上传,根据代码可以看出只能上传四种类型,jpg、jpeg、png、zip。

创建一个文档,里面写入命令

<?php system('type flag.php');

再对文件进行压缩,上传zip文件

将这个路径给复制出来,用在后面zip伪协议进行解压

相关推荐
_祝你今天愉快2 小时前
Android 高级绘制:[五] 贝塞尔曲线与计算规则
android
FungLeo17 小时前
FengCMS · PHP+MySQL 升级实录 · 危险默认值之殇:root/123456、认证码 8888 写进配置加载器
android·mysql·php·安全加固·fengcms
yz_aiks17 小时前
Termux 使用教程:把安卓手机变成随身 Linux(装 Python、SSH 远程、跑自动化脚本)
android·linux·python·智能手机·ssh·termux
booboosui1 天前
编号没变,消息还是来了:Mac 端通知读取漏第二条的原因
android
雨白2 天前
单例设计模式:从 Java/Kotlin 实现到 Android 实战
android
hai_android2 天前
一行 asLiveData,背后是一座生命周期的桥
android·java·kotlin
阿杰m2 天前
Android源码第二十三章:Telephony、RIL 与 IMS——来电怎么到应用?
android
booboosui2 天前
没人认领 .md:安卓把报告交给了音乐播放器打开
android
用户60709759149062 天前
AOSP 14 OTA 升级指导(四):update_engine 内部机制——Action 流水线与写盘
android
恋猫de小郭2 天前
Jetpack Compose 1.13 发布,憋了这么久终有交代了
android·前端·flutter