[Zer0pts2020]Can you guess it?1

打开题目

看到信息随便输入一个数,显示错误

查看源代码

看到php代码,代码审计

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

basename()

会返回路径重的文件名部分。比如/index.php/config.php使用basename()之后返回config.php
basename()会去掉文件名开头的非ASCII值。

看到提示,有config.php目录,跳转一下看看。

得到

我们要想访问config,但是config.php被正则过滤了

本题目利用的是basename()漏洞

用不可显字符绕过正则(后面加 %80 -- %ff 的任意字符)

我们构造payload:/index.php/config.php/%ff?source

访问得到flag

相关推荐
通玄3 小时前
Jetpack Compose 入门系列(十):Paging 3 分页加载
android
hunterandroid3 小时前
DataStore 工程化实践:迁移、并发更新与异常恢复
android·前端
程序员-珍5 小时前
报错下载android sdk失败
android·java
齊家治國平天下6 小时前
AAOS 电源管理深度解析:休眠/唤醒/功耗优化
android·车载系统·aaos·aosp·电源管理·休眠唤醒·carpowermanager
qq3621967056 小时前
安卓大版本升级后APK不兼容怎么办?2026跨版本更新指南
android
Xzaveir7 小时前
企业号码展示不可观测怎么办:状态机、拨测事件与异常回放
android·人工智能
2501_916007477 小时前
iOS和macOS应用程序性能分析和优化工具使用综合指南
android·macos·ios·小程序·uni-app·iphone·webview
黄林晴7 小时前
Nearby Connections 重大变更:不再自动开启 Wi-Fi / 蓝牙,适配指南
android
恋猫de小郭8 小时前
Flutter 全新真 3D 实现,用 flutter_scene 能开发一个「我的世界」
android·前端·flutter
止语Lab8 小时前
从 PHP 到 Go:真正迁移的是复杂度的归属
android·golang·php