直接给了源码:

 <?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.';
  }
}
?>
<!doctype html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>Can you guess it?</title>
  </head>
  <body>
    <h1>Can you guess it?</h1>
    <p>If your guess is correct, I'll give you the flag.</p>
    <p><a href="?source">Source</a></p>
    <hr>
<?php if (isset($message)) { ?>
    <p><?= $message ?></p>
<?php } ?>
    <form action="index.php" method="POST">
      <input type="text" name="guess">
      <input type="submit">
    </form>
  </body>
</html>

分析源码,结合过往做的爆破随机数题目的经验可以看出随机数是个幌子,直接忽略.随后百度$_SERVER['PHP_SELF']发现文章:[红日安全]代码审计Day15 – $_SERVER[‘PHP_SELF’]导致的防御失效问题

而且源码中还用到了basename(),可以获取到最后的文件名,而get请求source可以显示basename($_SERVER['PHP_SELF'])文件的内容,结合之前找到的文章构造payload,/index.php/config.php/?source.但是这里使用了正则对config.php是否为$_SERVER[‘PHP_SELF’]的结尾进行了判断,若config.php是结尾则程序结束.所以我们还需要绕过该正则.basename()函数会去掉非ascii字符,所以我们在config.php后面再加上非ascii字符然后get请求source.最终payload:/index.php/config.php/%ff?source

Categories:

Tags:

No responses yet

发表评论

邮箱地址不会被公开。 必填项已用*标注

闽ICP备19027300号