onlygoku/ctf-framework

GitHub: onlygoku/ctf-framework

一个基于 Python/Flask 的生产级 CTF 竞赛平台框架,提供从题目脚手架、Flag 验证、动态积分到 Docker 部署的一站式解决方案。

Stars: 0 | Forks: 0

# 🏴 CTF 框架 一个生产级的 **Capture The Flag 挑战平台**,使用 Python 构建 —— 具备挑战脚手架、带速率限制的 Flag 验证、动态评分、Docker 部署、REST API 以及具有黑客美感的 Web 界面。 ## 🚀 快速开始 ``` # 安装依赖 pip install -r requirements.txt # 初始化新的 CTF 事件 python ctf.py init # 创建一些 challenges python ctf.py create web "SQL Injection 101" --points 100 --difficulty easy python ctf.py create pwn "Buffer Overflow" --points 300 --difficulty hard python ctf.py create crypto "Broken RSA" --points 200 --difficulty medium # 启动 web server python ctf.py server --port 5000 ``` 访问 `http://localhost:5000` 查看 Web 界面。 ## 📁 项目结构 ``` ctf-framework/ ├── ctf.py # CLI entry point ├── ctf_core/ │ ├── challenge_manager.py # Challenge lifecycle & scaffolding │ ├── flag_validator.py # Secure flag validation + rate limiting │ ├── scoreboard.py # Real-time scoring & leaderboard │ ├── docker_manager.py # Container deployment management │ ├── database.py # Thread-safe SQLite abstraction │ ├── config.py # Environment-based configuration │ └── init.py # CTF initialization wizard ├── web/ │ └── app.py # Flask web app + REST API ├── challenges/ # Auto-generated challenge directories ├── tests/ │ └── test_framework.py # Full pytest test suite └── requirements.txt ``` ## 🎮 CLI 参考 ``` # 创建 challenge python ctf.py create "" [--points N] [--difficulty easy|medium|hard|insane] # 分类: web, pwn, crypto, forensics, reverse, misc, osint, network, mobile, blockchain # 列出 challenges python ctf.py list python ctf.py list --category web python ctf.py list --difficulty hard # 提交 flag python ctf.py submit "CTF{...}" --team myteam # Scoreboard python ctf.py scoreboard --top 20 # 启动 server python ctf.py server --host 0.0.0.0 --port 8080 --debug # Docker python ctf.py docker build python ctf.py docker deploy --port 9001 ``` ## 🌐 REST API | Method | Endpoint | 描述 | |--------|----------|-------------| | GET | `/api/v1/challenges` | 列出所有挑战 | | GET | `/api/v1/challenges/:id` | 获取挑战详情 | | POST | `/api/v1/submit` | 提交 Flag | | GET | `/api/v1/scoreboard` | 获取排行榜 | | GET | `/api/v1/feed` | 实时解题动态 | | POST | `/api/v1/teams/register` | 注册团队 | | GET | `/api/v1/teams/:name` | 团队统计与解题记录 | | GET | `/api/v1/stats` | 分类统计 | | GET | `/api/v1/docs` | API 文档 | ``` # 通过 API 提交 flag curl -X POST http://localhost:5000/api/v1/submit \ -H "Content-Type: application/json" \ -d '{"challenge_id": "abc12345", "flag": "CTF{...}", "team": "myteam"}' ``` ## 🏗 挑战脚手架 | 类别 | 生成的文件 | |----------|----------------| | `web` | `app/app.py`, `app/requirements.txt`, Dockerfile | | `pwn` | `src/chall.c`, `src/Makefile`, `solve.py` (pwntools) | | `crypto` | `chall.py`, `solve.py` | | `forensics` | `gen.py`, `dist/` | | `reverse` | `src/chall.py` | ## 🔐 安全特性 - **速率限制 (Rate Limiting)** — 令牌桶算法(每个团队对每个挑战在 60 秒内最多 10 次尝试) - **计时攻击防护 (Timing Attack Protection)** — SHA-256 常量时间 Flag 比对 - **一血追踪 (First Blood Tracking)** — 记录每个挑战的首次解出 - **审计日志 (Audit Log)** — 记录所有提交及其时间戳与 IP - **动态评分 (Dynamic Scoring)** — 随着解出队伍增加,分数衰减 - **Docker 加固 (Docker Hardening)** — `--read-only`, `no-new-privileges`, tmpfs ## ⚙️ 配置 (`.env`) ``` CTF_NAME=HackThePlanet2025 CTF_DESCRIPTION="A hardcore hacking competition" CTF_FLAG_PREFIX=CTF CTF_DYNAMIC_SCORING=true CTF_DECAY_RATE=5 CTF_SECRET_KEY= CTF_DB_PATH=ctf.db CTF_PORT=5000 CTF_MAX_ATTEMPTS=10 CTF_RATE_WINDOW=60 CTF_REGISTRATION=true ``` ## 🧪 测试 ``` pytest tests/ -v pytest tests/ -v --cov=ctf_core --cov-report=html ``` ## 📄 许可证 MIT — 可在您的 CTF 赛事中自由使用。
标签:CTF平台, Docker, Flag验证, Flask, OPA, Python, REST API, SQLite, Web安全, 二进制安全, 云资产清单, 动态积分, 夺旗赛, 安全规则引擎, 安全防御评估, 实时记分板, 密码学, 开源, 手动系统调用, 无后门, 竞赛系统, 网络安全, 脚手架, 蓝队分析, 请求拦截, 逆向工具, 逆向工程, 隐私保护, 靶场