• 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

  • 相关阅读:
    Threejs实现一个园区
    C#中的委托
    nuxt.js 进行项目重构-首页
    核货宝:服装店收银系统必备的五大功能
    藻酸盐/PEI/DNA复合载体|脂质-鱼精蛋白-DNA复合物|合成方法
    Zookeeper特性与节点数据类型详解
    c++之泛型算法
    光储直流微电网MATLAB/Simulink仿真
    【微电网优化】基于matlab遗传算法求解微电网经济优化问题【含Matlab源码 2062期】
    RPA机器人在电商领域有哪些应用?
  • 原文地址:https://blog.csdn.net/m0_57954651/article/details/127934002