[Zer0pts2020]Can you guess it?

题目场景
在这里插入图片描述
可以读到源码

<?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.';
  }
}
?>

想绕过下面的比较却卡了很久,所以把目标转移到上面
在这里插入图片描述
base()可以返回路径中的文件名部分 如果传入/index.php/config.php/,则$_SERVER['PHP_SELF']返回/index.php/config.php/basename($_SERVER['PHP_SELF'])返回config.php
验证:
在这里插入图片描述
成功了,接下来就是绕过正则过滤,测试过换行符但是没有效果,这里用basename()的第二个特性
https://bugs.php.net/bug.php?id=62119

var_dump(basename("xffconfig.php")); // => config.php
var_dump(basename("config.php/xff")); // => config.php

basename()会去掉非ascii字符。
payload:

index.php/config.php/%ff/?source

参考
https://blog.csdn.net/qq_43801002/article/details/105835367

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值