hctf2018

打开题目,f12发现

<!--source.php-->

以及hint和link:http://warmup.2018.hctf.io/index.php?file=hint.php
网页内容:

hint.png

访问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)) {  //in_array(search,array,type)   函数搜索数组中是否存在指定的值。
                return true;
            }

            $_page = mb_substr(  //mb_substr — 获取部分字符串
                $page,
                0,
                mb_strpos($page . '?', '?') //mb_strpos — 查找字符串在另一个字符串中首次出现的位置
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page); //urldecode — 解码已编码的 URL 字符串
            $_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\" />";
    }  
?>
  • 思路
    发现checkFile函数$_page取file参数第一个问号之前的字段检查文件名是否在白名单内
    是构造file参数为hint.php?/../../../../../ffffllllaaaagggg
  • 原理
    原理是hint.php?/被当作目录,之后上跳目录就好了(这个只适用于linux)


    image.png
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容