• BUUCTF-warmup


    靶场首页

    只看到一个滑稽的表情,查看源码,提示了source.php

     

    代码审计

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

    这里告诉我们需要满足三个条件:

    01.$file的值必须为非空;

    02.$file是字符串;

    03.$file传入checkFile()可以通过检验;

    04.全部满足后,引用相应的文件


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

    首先需要了解一下两个函数:

    mb_strpos($string, $a):查找字符串a在字符串string中首次出现的位置,起始位置以0开始;

    mb_substr($string, $start, $end):在字符串string中截取以start开始,以end结尾的子串;

    01.白名单中有source.phphint.php

    02.$page的值必须为非空且是字符串

    03.判断$page是否在白名单中

    04.对$page ‘?’之前进行截取赋值给$_page,判断是否在白名单中

    05.再对编码之后的$_page进行判断是否在白名单中

     

    构造payload

    访问代码中提示的hint.php发现

    flag not here, and flag in ffffllllaaaagggg

    所以flag在ffffllllaaaagggg

    这里有一个知识点:双重编码,比如你将?双重编码的话,经过包含时你包含的文件会被当成一个目录

    http:``//xxxx:xxxx/source.php?file=source.php%253f../../../../../ffffllllaaaag

    ../是向上回退目录

  • 相关阅读:
    python中取列表的后半部分元素
    python中列表分片
    python中统计列表中元素出现的次数
    python中range()函数用法
    pyhton中实现列表元素顺序颠倒
    python中列表元素求交集和并集
    python中编写抽奖小游戏
    python中删除列表元素
    python中列表的去重复和取重复
    欲为Java技术大牛所需的25个学习要点
  • 原文地址:https://www.cnblogs.com/zesiar0/p/12643084.html
Copyright © 2020-2023  润新知