• [Zer0pts2020]Can you guess it?


    [Zer0pts2020]Can you guess it?
    在这里插入图片描述
    查看源码:

    
    include 'config.php'; // FLAG is defined in config.php
    
    if (preg_match('/config\.php\/*$/i', $_SERVER['PHP_SELF'])) {
      exit("I don't know what you are thinking, but I won't let you read it :)");
    }
    
    if (isset($_GET['source'])) {
      highlight_file(basename($_SERVER['PHP_SELF']));
      exit();
    }
    
    $secret = bin2hex(random_bytes(64));
    if (isset($_POST['guess'])) {
      $guess = (string) $_POST['guess'];
      if (hash_equals($secret, $guess)) {
        $message = 'Congratulations! The flag is: ' . FLAG;
      } else {
        $message = 'Wrong.';
      }
    }
    ?>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22

    提示了flag在config.php中

    $_SERVER用于获取当前执行脚本的文件名,与 document root 有关。例如,在地址为 http://c.biancheng.net/test.php/foo.bar 的脚本中使用 $_SERVER[‘PHP_SELF’]将得到 /test.php/foo.bar

    如果url是:http://xxx/index.php/a.php/a/b/c/d/?a=1
    $_SERVER[‘PHP_SELF’]的值就是index.php/a.php/a/b/c/d/ (忽略传参)

    第一个if做了正则的判断,判断$_SERVER获取到的值是否以config.php/* 结尾。相当于要求config.php/后不能有自读,如果是则退出。
    在这里插入图片描述
    结合提示,猜测我们需要绕过限制,读取到config.php

    第二个if如果传入了source参数,就highlight_file 高亮显示$_SERVER中经过basename后提取到的文件
    在这里插入图片描述
    绕过正则可以使用不存在于ascii码表中的字符,比如中文符号?、《》、中文等,例如index.php/config.php/??source(第一个为中文问号),此时正则就会失效,SERVER获取到的就是index.php/config.php(忽略传参),经过basenmae后就是config.php,这样既可以绕过正则匹配,也可以绕过basename的过滤
    在这里插入图片描述

  • 相关阅读:
    Notepad++--常用的插件
    英集芯推出4串锂电池100W移动电源升降压方案SoC芯片IP5389
    ICM42688笔记
    爬虫之Scrapy框架
    使用扩散模型从文本生成图像
    SSM - Springboot - MyBatis-Plus 全栈体系(三十二)
    GPT-3/ChatGPT复现的经验教训
    数据可视化在监控易中的艺术与实践
    opencv
    虚拟机复制后,无法ping通问题解决
  • 原文地址:https://blog.csdn.net/pakho_C/article/details/126403165