[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.';
}
}
?>
<!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’],这个是返回PHP当前目录与根目录的相对路径,但是访问路径被修改的话这个变量的内容也会对应的更改,如果我们访问的内容是url/index.php/config.php的话,$_SERVER[‘PHP_SELF’]的内容就是index.php/config.php,然后再用basename()获取到config.php,但是这样子过不了正则