[Zer0pts2020]Can you guess it?

https://buuoj.cn/challenges#[Zer0pts2020]Can%20you%20guess%20it?https://buuoj.cn/challenges#[Zer0pts2020]Can%20you%20guess%20it?启动靶机

点击链接,出现源码

php 复制代码
<?php
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.';
  }
}
?>

提示我们flag在config.php 里面。并且对我们输入的网址进行正则匹配,如果以 config.php 或 config.php/ 结尾,不区分大小写,就返回"不知道你在想啥,不想让你读"。

然后再传递参数 source ,就能读取我们再网址内输入页面的源码(这里没有其他要求,可为空)

总的来说,就是绕过 waf ,读取 config.php的内容 。

先试试在地址栏输入 /index.php/config.php 回显表明确实是被过滤了

试试 /index.php/config.php/A?source (尝试了空格 单字符 tab键 数字 空字符 test 这些都不行 )

那试一试 非法utf-8字符 比如 %80

成功获得flag。

说明一下:

  • $_SERVER['PHP_SELF']=/index.php/config.php/%80 进行正则表达式的比较,由于这里的结尾处是 %80 不等于 config.php 或 config.php/ 从而实现绕过waf。
  • basename($_SERVER['PHP_SELF']) 这个函数意为:获取路径中的最后一部分。也就是 %80,但由于文件系统不认识这个字符,会认为是乱码,就会回退到上一层,也就是config.php
  • 像这样的字符有许多, 0x80~0xFF 都可以
  • 所以 highlight_file(basename($_SERVER['PHP_SELF'])) 实际上变成了 highlight_file(config.php) 实现读取flag
相关推荐
独自破碎E1 小时前
【BISHI15】小红的夹吃棋
android·java·开发语言
李堇4 小时前
android滚动列表VerticalRollingTextView
android·java
lxysbly5 小时前
n64模拟器安卓版带金手指2026
android
游戏开发爱好者88 小时前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
王码码20358 小时前
Flutter for OpenHarmony 实战之基础组件:第三十一篇 Chip 系列组件 — 灵活的标签化交互
android·flutter·交互·harmonyos
黑码哥9 小时前
ViewHolder设计模式深度剖析:iOS开发者掌握Android列表性能优化的实战指南
android·ios·性能优化·跨平台开发·viewholder
亓才孓9 小时前
[JDBC]元数据
android
独行soc9 小时前
2026年渗透测试面试题总结-17(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
金融RPA机器人丨实在智能9 小时前
Android Studio开发App项目进入AI深水区:实在智能Agent引领无代码交互革命
android·人工智能·ai·android studio
科技块儿9 小时前
利用IP查询在智慧城市交通信号系统中的应用探索
android·tcp/ip·智慧城市