• ctfhub-web-warmup


    打开题目链接  是一张图

    查看源代码  提示source.php

    访问这个文件 

     得到源码 

    1.     highlight_file(__FILE__);
    2.     class emmm
    3.     {
    4.         public static function checkFile(&$page)
    5.         {
    6.             $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
    7.             if (! isset($page) || !is_string($page)) {
    8.                 echo "you can't see it";
    9.                 return false;
    10.             }
    11.             if (in_array($page$whitelist)) {
    12.                 return true;
    13.             }
    14.             $_page mb_substr(
    15.                 $page,
    16.                 0,
    17.                 mb_strpos($page '?''?')
    18.             );
    19.             if (in_array($_page$whitelist)) {
    20.                 return true;
    21.             }
    22.             $_page urldecode($page);
    23.             $_page mb_substr(
    24.                 $_page,
    25.                 0,
    26.                 mb_strpos($_page '?''?')
    27.             );
    28.             if (in_array($_page$whitelist)) {
    29.                 return true;
    30.             }
    31.             echo "you can't see it";
    32.             return false;
    33.         }
    34.     }
    35.     if (! empty($_REQUEST['file'])
    36.         && is_string($_REQUEST['file'])
    37.         && emmm::checkFile($_REQUEST['file'])
    38.     ) {
    39.         include $_REQUEST['file'];
    40.         exit;
    41.     } else {
    42.         echo "
      "
      ;
    43.     }  
    44. ?>

     进行代码审计

    首先看到  设置的一段白名单

    进入hint.php看看

    果然后面的代码不会白瞎  安心分析源码咯

    先看最后一个if

    1.     if (! empty($_REQUEST['file'])
    2.         && is_string($_REQUEST['file'])
    3.         && emmm::checkFile($_REQUEST['file'])
    4.     ) {
    5.         include $_REQUEST['file'];
    6.         exit;
    7.     } else {
    8.         echo "
      "
      ;
    1. 传入的变量file不为空   为string类型  并执行checkFile()函数
    2. 三个条件为真则执行include
    3. 三个条件为假则输出滑

    查看checkFile()函数

    1. public static function checkFile(&$page)
    2. {
    3. $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
    4. if (! isset($page) || !is_string($page)) {
    5. echo "you can't see it";
    6. return false;
    7. }
    8. if (in_array($page, $whitelist)) {
    9. return true;
    10. }
    11. $_page = mb_substr(
    12. $page,
    13. 0,
    14. mb_strpos($page . '?', '?')
    15. );
    16. if (in_array($_page, $whitelist)) {
    17. return true;
    18. }
    19. $_page = urldecode($page);
    20. $_page = mb_substr(
    21. $_page,
    22. 0,
    23. mb_strpos($_page . '?', '?')
    24. );
    25. if (in_array($_page, $whitelist)) {
    26. return true;
    27. }
    28. echo "you can't see it";
    29. return false;
    30. }
    31. }

        四个if分析:

        $page不为空或不为字符串  返回false
        $page在$whitelist数组中  返回true
        mb_substr()函数截取字符串
        mb_strpos()函数返回在$page中?前的内容  没有则返回$page的值
        截取后$page在$whitelist数组中  返回true
        对$page进行URL解码
        执行与之前相同的截取操作
        解码截取后$page在$whitelist数组中   返回true

    checkFile()函数会匹配?前的内容是否在数组whitelist中  因为不知道在哪个目录  多次添加../

    构造payload

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

    底部找到flag

  • 相关阅读:
    视听杂志视听杂志社视听编辑部2022年第11期目录
    vue打包优化
    迅为iTOP-2K1000开发板龙芯中科国产64位Loognix系统工业核心主板
    AxGlyph矢量绘图软件 | 绘图软件
    基于springboot实现应急救援物资管理系统项目【项目源码】计算机毕业设计
    疫苗预约管理系统,疫苗预约系统,新冠疫苗预约系统毕业设计作品
    C语言回顾(指针篇)
    GitHub标星65k,阿里面试核心技术手册,我不允许还有人没看过!
    2023数维杯数学建模C题思路+代码+论文
    JavaWeb之Servlet-----(2)
  • 原文地址:https://blog.csdn.net/m0_57954651/article/details/127934002