CTF [HCTF 2018]WarmUp writeup mb_substr()函数

滑稽镇楼,哈哈。
在这里插入图片描述
一进来就是个大滑稽,有点意思,审计看元素。
在这里插入图片描述
访问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\" />";
   }  
?> 

一段一段的看,先看最后一段

    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\" />";
    }  

如果有提交file并且file为字符串,则调用类当中的checkFile()函数进行检查,检查通过就包含file,反之输出滑稽。

再看第一个if语句

$whitelist = ["source"=>"source.php","hint"=>"hint.php"];
if (! isset($page) || !is_string($page)) {
    echo "you can't see it";
    return false;
}

如果没有提交参数,或者参数不是字符串,则return一个false,并输出"you can't see it"。没啥用,再看一个并列的if

if (in_array($page, $whitelist)) {
    return true;
}

如果提交的参数在白名单里面,则返回true,即可以包含参数。白名单在一段当中,有两个source.phphint.php,目前访问的就是source.php,那现在送个hint.php看看会有什么。
在这里插入图片描述
提示结果在ffffllllaaaagggg里面,没法用,继续看,下一个if走起。

$_page = mb_substr(
    $page,
    0,
    mb_strpos($page . '?', '?')
);
if (in_array($_page, $whitelist)) {
    return true;
}

截取参数中的?之前的一部分,如果没有?则,截取所有参数。
mb_strpos()是用来截取汉字的。。。

这样的话就有提示了阿,构造参数file=hint.php?ffffllllaaaagggg即可。
在这里插入图片描述
执行以后,发现没有echo那行讨厌的字you can't see it,说明确实returntrue,也就是已经成功绕过,但是ffffllllaaaagggg并不在此目录下,接着构造file=hint.php?../ffffllllaaaagggg,接着不停的加../即可,如果这样还不行,那就只能换方法了,好在第五个../的时候flag就出来了。
在这里插入图片描述
后面的其实可以不需要,大概是用于post提交方式的payload吧。。。

发布了265 篇原创文章 · 获赞 266 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/u014029795/article/details/105232104