freizyk/ctfd-parser
GitHub: freizyk/ctfd-parser
一款基于 Flask 的 Web 应用,用于从 CTFd 平台批量抓取 CTF 题目、下载附件并自动同步归档至 Notion 与 Backblaze B2 存储。
Stars: 7 | Forks: 0
# CTFd 解析器与 Notion 上传器
一个用于从 CTFd 平台解析 CTF 题目、将任务文件上传到 Backblaze B2 存储并在 Notion 中创建有序任务页面的 Web 应用程序。
## 功能特性
- 🔐 **用户认证** - 安全登录与用户管理
- 📥 **CTF 解析** - 使用 Cookie 或凭据从 CTFd 平台解析题目
- 📁 **文件下载** - 下载任务文件,包括 Google Drive 链接
- ☁️ **B2 上传** - 将文件上传到 Backblaze B2 存储(最大 10GB)
- 📝 **Notion 集成** - 创建带有内联任务数据库的 CTF 页面
- 🔄 **验证与同步** - 检查 Notion 缺失的任务并上传
- 📊 **实时进度** - 基于 SSE 的实时进度更新
- 🧹 **自动清理** - 上传成功后删除本地文件
## 环境要求
- Python 3.10+
- Backblaze B2 账户及 S3 兼容 API 密钥
- Notion integration token
## 部署说明
### 1. 克隆仓库
```
git clone https://github.com/YOUR_USERNAME/ctfd-parser.git
cd ctfd-parser
```
### 2. 创建虚拟环境
```
python3 -m venv venv
source venv/bin/activate # Linux/Mac
# 或
.\venv\Scripts\activate # Windows
```
### 3. 安装依赖
```
pip install -r requirements.txt
```
### 4. 配置环境
创建 `web_parser/.env` 文件:
```
SECRET_KEY=your-secret-key-here-generate-random
# Notion API
NOTION_TOKEN=ntn_your_notion_token
CTF_TEMPLATE_DB_ID=your-template-database-id
CTF_TEMPLATE_PARENT_PAGE_ID=your-parent-page-id
# Backblaze B2 (S3-compatible)
B2_KEY_ID=your-b2-key-id
B2_APP_KEY=your-b2-app-key
B2_BUCKET_NAME=your-bucket-name
B2_ENDPOINT=https://s3.us-east-005.backblazeb2.com
```
### 5. 初始化数据库
```
# 从项目根目录 (ctfd-parser/) 运行,而不是 web_parser/
python -c "
from web_parser.app import create_app
from web_parser.extensions import db
app = create_app()
with app.app_context():
db.create_all()
print('Database initialized!')
"
```
### 6. 创建管理员用户
```
# 从项目根目录 (ctfd-parser/) 运行
python -c "
from web_parser.app import create_app
from web_parser.extensions import db
from web_parser.models import User
app = create_app()
with app.app_context():
admin = User(username='admin', is_admin=True)
admin.set_password('your-secure-password')
db.session.add(admin)
db.session.commit()
print('Admin user created!')
"
```
### 7. 运行开发服务器
```
python -m web_parser.app
```
访问地址:http://localhost:5000
### 8. 生产环境部署
```
pip install gunicorn
cd /path/to/ctfd-parser
gunicorn -w 4 -b 0.0.0.0:5000 'web_parser.app:create_app()'
```
### Systemd 服务(可选)
创建 `/etc/systemd/system/ctfd-parser.service`:
```
[Unit]
Description=CTFd Parser Web App
After=network.target
[Service]
User=your-user
WorkingDirectory=/path/to/ctfd-parser
Environment="PATH=/path/to/ctfd-parser/venv/bin"
ExecStart=/path/to/ctfd-parser/venv/bin/gunicorn -w 4 -b 0.0.0.0:5000 'web_parser.app:create_app()'
Restart=always
[Install]
WantedBy=multi-user.target
```
```
sudo systemctl enable ctfd-parser
sudo systemctl start ctfd-parser
```
## Notion 设置
1. 在 https://www.notion.so/my-integrations 创建一个 Notion integration
2. 创建一个模板数据库,包含以下属性:
- `Project name` (Title)
- `Type` (Multi-select): web, pwn, reverse, crypto, forensics, misc 等
- `Status` (Select): To Do, In Progress, Done, Stuck
- `People` (People)
- `Dates` (Date)
3. 将父页面与你的 integration 共享
4. 复制数据库 ID 和父页面 ID 到 `.env`
## 使用方法
1. **添加 CTF** - 输入 CTFd URL 和认证信息(Cookie 或凭据)
2. **检查连接** - 验证登录是否有效
3. **解析题目** - 下载所有任务和文件
4. **上传到 Notion** - 将任务上传到 Notion,文件存放在 B2
5. **验证与同步** - 重新检查并上传任何缺失的任务
## 技术栈
- **后端**: Flask, SQLAlchemy
- **存储**: Backblaze B2 (S3 兼容)
- **数据库**: Notion API
- **认证**: Flask-Login
- **进度**: Server-Sent Events (SSE)
## 许可证
MIT
标签:Backblaze B2, CTFd, Flask, Notion集成, Python, S3兼容存储, SSE实时进度, 云存储, 数据同步, 文件解析, 无后门, 用户认证, 知识管理, 竞赛辅助, 网络安全, 逆向工具, 隐私保护