当前位置:网站首页>php反序列化结构知识点实例分析
php反序列化结构知识点实例分析
2022-07-29 21:22:00 【亿速云】
php反序列化结构知识点实例分析
本篇内容主要讲解“php反序列化结构知识点实例分析”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“php反序列化结构知识点实例分析”吧!

简介
序列化的目的是方便数据的传输和存储,在PHP中,序列化和反序列化一般用做缓存,比如session缓存,cookie等。
反序列化中常见的魔术方法
__wakeup() //执行unserialize()时,先会调用这个函数
__sleep() //执行serialize()时,先会调用这个函数
__destruct() //对象被销毁时触发
__call() //在对象上下文中调用不可访问的方法时触发
__callStatic() //在静态上下文中调用不可访问的方法时触发
__get() //用于从不可访问的属性读取数据或者不存在这个键都会调用此方法
__set() //用于将数据写入不可访问的属性
__isset() //在不可访问的属性上调用isset()或empty()触发
__unset() //在不可访问的属性上使用unset()时触发
__toString() //把类当作字符串使用时触发
__invoke() //当尝试将对象调用为函数时触发
反序列化绕过小Trick
php7.1+反序列化对类属性不敏感
我们前面说了如果变量前是protected,序列化结果会在变量名前加上\x00*\x00
但在特定版本7.1以上则对于类属性不敏感,比如下面的例子即使没有\x00*\x00也依然会输出abc
<?phpclass test{ protected $a; public function __construct(){ $this->a = 'abc'; } public function __destruct(){ echo $this->a; }}unserialize('O:4:"test":1:{s:1:"a";s:3:"abc";}');绕过_wakeup(CVE-2016-7124)
版本:
PHP5 < 5.6.25
PHP7 < 7.0.10
利用方式:序列化字符串中表示对象属性个数的值大于真实的属性个数时会跳过__wakeup的执行
对于下面这样一个自定义类
<?phpclass test{ public $a; public function __construct(){ $this->a = 'abc'; } public function __wakeup(){ $this->a='666'; } public function __destruct(){ echo $this->a; }}如果执行unserialize('O:4:"test":1:{s:1:"a";s:3:"abc";}');输出结果为666
而把对象属性个数的值增大执行unserialize('O:4:"test":2:{s:1:"a";s:3:"abc";}');输出结果为abc
绕过部分正则
preg_match('/^O:\d+/')匹配序列化字符串是否是对象字符串开头,这在曾经的CTF中也出过类似的考点
利用加号绕过(注意在url里传参时+要编码为%2B)
serialize(array(a ) ) ; / / a));//a));//a为要反序列化的对象(序列化结果开头是a,不影响作为数组元素的$a的析构)
<?phpclass test{ public $a; public function __construct(){ $this->a = 'abc'; } public function __destruct(){ echo $this->a.PHP_EOL; }}function match($data){ if (preg_match('/^O:\d+/',$data)){ die('you lose!'); }else{ return $data; }}$a = 'O:4:"test":1:{s:1:"a";s:3:"abc";}';// +号绕过$b = str_replace('O:4','O:+4', $a);unserialize(match($b));// serialize(array($a));unserialize('a:1:{i:0;O:4:"test":1:{s:1:"a";s:3:"abc";}}');利用引用
<?phpclass test{ public $a; public $b; public function __construct(){ $this->a = 'abc'; $this->b= &$this->a; } public function __destruct(){ if($this->a===$this->b){ echo 666; } }}$a = serialize(new test());上面这个例子将$b设置为$a的引用,可以使$a永远与$b相等
16进制绕过字符的过滤
O:4:“test”:2:{s:4:“%00*%00a”;s:3:“abc”;s:7:“%00test%00b”;s:3:“def”;}
可以写成
O:4:“test”:2:{S:4:“\00*\00\61”;s:3:“abc”;s:7:“%00test%00b”;s:3:“def”;}
表示字符类型的s大写时,会被当成16进制解析。
到此,相信大家对“php反序列化结构知识点实例分析”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!
边栏推荐
- [HDLBits brush questions] Verilog Language (4) Procedures and More Verilog Features section
- IDEA 快捷键
- 网络通信编程基础,BIO,NIO
- HMS Core音频编辑服务音源分离与空间音频渲染,助力快速进入3D音频的世界
- Get the Qiniu cloud address file and save it locally
- GBASE 8s 如何并行执行update statistics
- 1. Promise usage in JS, 2. The concept and usage of closures, 3. The difference between the four methods and areas of object creation, 4. How to declare a class
- mdnice-test
- 刘畊宏男孩女孩看过来!运动数据分析挖掘!(附全套代码和数据集)
- 全自动化机器学习建模!效果吊打初级炼丹师!
猜你喜欢

相亲信息

爽朗的一天

程序员自由工作的三大痛点?一文教你统统解决

解决reudx中的异步问题 applyMiddleware thunk
![LeetCode 593 Valid Squares [Math] HERODING's Road to LeetCode](/img/c2/34624c9c7693ba40d0b3724c0db611.png)
LeetCode 593 Valid Squares [Math] HERODING's Road to LeetCode

2022了你还不会『低代码』?数据科学也能玩转Low-Code啦!

【ORM框架:Sequelize的查询】

Add a logo to the upper left corner of the picture, add time and address to the lower left corner, and wrap the line when the address reaches the specified length

leetcode-593:有效的正方形

小程序预览pdf
随机推荐
ALBERT: A Lite BERT for Self-supervised Learning of Language Representations
GBASE 8s 通过临时表提升排序性能
获取七牛云地址文件保存到本地
在Ferora35中安装oracle-database-xe-21c
给pdf添加已作废标识
Panorama Tutorial丨How to shoot sunrise and sunset scenes in VR panoramic shooting?
【点云】M3DeTR: Multi-representation, Multi-scale, Mutual-relation 3D Object Detection with Transformers
mdnice-test
小程序预览pdf
亚马逊登录参数metadata1,encryptedPwd逆向分析
SQL教程之性能不仅仅是查询
GBASE 8s自定义存储过程和函数介绍
解决报错 WARNING: IPv4 forwarding is disabled. Networking will not work.
【无标题】
Numpy数组处理(二)
APM电机输出逻辑(Motors类详解)
WeChat Mini Program 31 Subcontracting Mechanism
刚重装的win7系统不能上网(深度系统安装步骤)
GBASE 8s 数据库的恢复
全球都热炸了,谷歌服务器已经崩掉了