当前位置:网站首页>[Net Ding Cup 2020 Qinglong Group] AreUSerialz
[Net Ding Cup 2020 Qinglong Group] AreUSerialz
2022-07-30 06:34:00 【Wanfeng 129】
Open the range link to see the code given

代码审计,分析得到This topic needs to be passed in个序列化之后的类对象

Basically, it filters the input characters a little bit,然后进行反序列化.
然后,Reanalyze the section in the class.去掉了__construct(),因为它在unserialize()时是不会自动调用的.Deserialization will be called first__destruct()这个魔术方法,Let's start with the analysis.And our goal is to read what it containsflag.php文件.

From here we can analyze this string of code pairsop进行了过滤,如果你op等于2,will be forced to convert to 1再输出,The last value is given toprocess
我们再看process代码

从这里我们可以看到op值等于1输出write,op值等于2则输出read,
So we're going to readflag,所以要op等于2
总结:我们要绕过__destruct()The filtering of this magic method,op值对比 === 类型 值
我们可以使用op=’ 2’,Add a space to bypass.
来到read代码

我们可以看到变量filename,我们查看的是file.php这个文件,So we have to read this filefilename=file.php就行
Because the beginning code has given three variables,So our constructed serialization code is

这里解释下为什么用public而不是protected,Because we wrote spaces around there,protectedThere will be in serialization%00符号,而public则不会有,所以用public.变量$contentFeel free to give a value.
Serialize this code

得到O:11:"FileHandler":3:{s:2:"op";s:2:" 2";s:8:"filename";s:8:"flag.php";s:7:"content";s:2:"ly";}
Go back to the title page to enter?str=O:11:"FileHandler":3:{s:2:"op";s:2:"
2";s:8:"filename";s:8:"flag.php";s:7:"content";s:2:"ly";}
![]()
回车,按F12查看,得到flag

PHP反序列化
原理:未对用户输入的序列化字符串进行检测,导致攻击者可以控制反序列化过程,从而导致代码执行,SQL注入,目录遍历等不可控后果.在反序列化的过程中自动触发了某些魔术方法.当进行反序列化的时候就有可能会触发对象中的一些魔术方法.
serialize() //将一个对象转换成一个字符串
unserialize() //将字符串还原成一个对象

首先我们要了解phpMagic method for deserialization
构造函数和析构函数
- __construct()
具有构造函数的类会在每次创建新对象时先调用此方法,所以非常适合在使用对象之前做一些初始化工作. - __destruct()
析构函数会在到某个对象的所有引用都被删除或者当对象被显式销毁时执行.
new出一个新的对象时就会调用__construct(),而对象被销毁时,例如程序退出时,就会调用__destruct()
涉及:反序列化魔术方法调用,弱类型绕过,ascii绕过
使用该类对flag进行读取,这里面能利用的只有__destruct函数(析构函数).
__destruct函数对$this->op进行了===判断并内容在2字符串时会赋值为1,
process函数中使用==对$this->op进行判断(为2的情况下才能读取内容),
因此这里存在弱类型比较,可以使用数字2或字符串' 2'绕过判断.
is_valid函数还对序列化字符串进行了校验,因为成员被protected修饰,
So it will appear in the serialized stringascii为0的字符.经过测试,在PHP7.2+的环境中,
使用public修饰成员并序列化,反序列化后成员也会被public覆盖修饰.
边栏推荐
猜你喜欢
随机推荐
jsonpath
js方法 reduce 用法
第一篇博客
函数解剖——深挖printf()与scanf()
P3 元宝第三天的笔记
C语言(字符串,转义字符,关键字)
C语言自定义类型一网打尽(结构体、位段/位域、枚举、联合体)
The operations engineer interview experience
目前主流浏览器以及对应的内核
盲注、报错注入、宽字节注入、堆叠注入学习笔记
MySQL存储引擎
封装Cookie API
easyexcel使用教程-导出篇
Qt通过QSttings类读取*.ini配置文件
P3 元宝序列化笔记
Qt设置窗口可拖动
awd总结
cJSON开源项目详细解剖
函数(c语言)
一类SMS漏洞的防御思路



![[Mini Program Project Development--Jingdong Mall] Classification Navigation Area of uni-app](/img/cb/b0b79444dc90980cd2220ff9e68549.png)




