[Zer0pts2020]Can you guess it? 1

打开题目

点击souce,出来页面源代码

<?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>

查看发现flag在flag在config.php中。但是hash_equal函数没有漏洞也没有错误,没办法从这里入手

但是源码的逻辑部分没有使用简洁的__FILE__而是采用basename函数

截取$_SERVER['PHP_SELF'],本题的利用点也就在此处

$_SERVER['PHP_SELF']会获取我们当前的访问路径,并且PHP在根据URI解析到对应文件后会忽略掉URL中多余的部分,即若访问存在的index.php页面,如下两种UR均会访问到。

/index.php

/index.php/dosent_exist.php

basename可以理解为对传入的参数路径截取最后一段作为返回值,但是该函数发现最后一段为不可见字符时会退取上一层的目录,即:

$var1="/config.php/test"

basename($var1) => test

$var2="/config.php/%ff"

basename($var2) =>  config.php

接下来构造URI让其包含config.php这个文件名再让basename函数截取出来,之后通过请求参数source就能显示config.php的源码,也就能得到flag了

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值