HCTF 2018 Warmup(函数理解)

0x01 题目描述

先看hint
在这里插入图片描述
urlfile参数,感觉可能要用伪协议啥的,试了下,没出东西
扫一下目录,发现./source.php源码文件
源码如下

<?php
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST['file'])
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    }  
?>

0x02 题解

看了下是文件包含,checkFile函数$_page取file参数第一个问号之前的字段检查文件名是否在白名单内于是构造file参数为hint.php?/../../../../../ffffllllaaaagggg

原理是hint.php?/被当作目录,之后上跳目录就好了(这个只适用于linux)
include函数不一样, mkdir函数,如果不存在目录就会报错

发布了47 篇原创文章 · 获赞 2 · 访问量 3135

猜你喜欢

转载自blog.csdn.net/a3320315/article/details/102961772