BUUCTF-Web刷题记录

0x01 WarmUp

做法: 查看网页源代码发现注释<!--source.php-->,于是尝试打开/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 not here, and flag in ffffllllaaaagggg,审计代码出现字符截取

            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );

由于include $_REQUEST['file'];,PHP解析时,hint.php?被当成一个文件,然后结合../进行目录穿越,目录穿越之后的地址才是include包含的文件地址,造成任意文件包含漏洞,可以查看目录下任意文件了。于是构造?file=hint.php?/../ffffllllaaaagggg,发现值为空,构造?file=hint.php?/../../../../ffffllllaaaagggg,穿越4层后得到flag{3ffe90a2-13d7-4e3b-8287-aa9fd723c766},估计这也是每个字母重复4次的理由...

BUUCTF-Misc刷题记录
BUUCTF-Crypto刷题记录
已开启邮件提醒回复功能