maogouste/api-security-dojo
GitHub: maogouste/api-security-dojo
一个多语言实现的故意包含漏洞的 API 安全学习靶场,覆盖 OWASP API Top 10 及 GraphQL 常见安全问题,通过 CTF 式挑战帮助用户实践 API 攻防技能。
Stars: 0 | Forks: 0
# API 安全道场
用于学习 API 安全的包含故意漏洞的 API。提供 6 种语言版本。
## 警告
本软件包含**故意的**安全漏洞,仅供教育目的使用。
**切勿用于生产环境。**
## 快速开始
```
# 克隆
git clone https://github.com/maogouste/api-security-dojo.git
cd api-security-dojo
# 安装 hatch (一次性)
pip install hatch
# 运行 Python backend (自动创建 venv)
cd implementations/python-fastapi
hatch run serve # http://localhost:8000
# 或其他 backends:
cd implementations/node-express && npm install && npm start # :3005
cd implementations/go-gin && go run main.go # :3002
cd implementations/php-laravel && php -S localhost:3003 index.php
cd implementations/java-spring && mvn spring-boot:run # :3004
cd implementations/rust-actix && cargo run # :3006
```
## 实现版本
| 后端 | 语言 | 端口 | 框架 |
|---------|----------|------|-----------|
| python-fastapi | Python | 8000 | FastAPI |
| go-gin | Go | 3002 | Gin |
| php-laravel | PHP | 3003 | Vanilla PHP |
| java-spring | Java | 3004 | Spring Boot |
| node-express | Node.js | 3005 | Express.js |
| rust-actix | Rust | 3006 | Actix-web |
所有实现版本共享:
- 相同的漏洞 (V01-V10, G01-G05)
- 相同的数据库 schema
- 相同的 API endpoint
- 相同的 CTF 式挑战 flag
## 漏洞
### REST API (V01-V10)
| ID | 名称 | OWASP |
|----|------|-------|
| V01 | 对象级别授权失效 | API1:2023 |
| V02 | 身份验证失效 | API2:2023 |
| V03 | 数据过度暴露 | API3:2023 |
| V04 | 缺乏速率限制 | API4:2023 |
| V05 | 批量赋值 | API6:2023 |
| V06 | SQL 注入 | API8:2023 |
| V07 | 命令注入 | API8:2023 |
| V08 | 安全配置错误 | API7:2023 |
| V09 | 资产管理不当 | API9:2023 |
| V10 | 日志记录不足 | API10:2023 |
### GraphQL (G01-G05)
| ID | 名称 |
|----|------|
| G01 | Introspection 暴露 |
| G02 | 嵌套查询 (DoS) |
| G03 | 批量攻击 |
| G04 | 字段建议 |
| G05 | 授权绕过 |
## Endpoint
| Endpoint | 描述 |
|----------|-------------|
| `/` | API 信息 |
| `/health` | 健康检查 |
| `/docs` | Swagger UI (仅限 FastAPI) |
| `/api/login` | 身份验证 |
| `/api/users` | 用户管理 |
| `/api/products` | 产品目录 |
| `/api/tools/ping` | 网络工具 |
| `/api/v1/*` | 旧版 API (V09) |
| `/graphql` | GraphQL endpoint |
## 使用 Hatch 进行开发
[Hatch](https://hatch.pypa.io/) 会自动管理 Python 环境。
### Python 后端
```
cd implementations/python-fastapi
hatch run serve # Start server on :8000
hatch run dev # Start with auto-reload
hatch run test # Run unit tests
hatch run test-cov # Run tests with coverage
hatch shell # Activate the venv
```
### 跨实现测试
```
# 从项目根目录
hatch run test # All tests
hatch run rest # REST V01-V10 tests
hatch run graphql # GraphQL G01-G05 tests
hatch run health # Health endpoint tests
# 测试特定 backend
hatch run python # Python only
hatch run go # Go only
hatch run rust # Rust only
# 测试特定漏洞
hatch run v01 # BOLA tests
hatch run v06 # SQL Injection tests
hatch run g01 # GraphQL Introspection
```
## 模式
```
# 挑战模式 (默认) - 自己寻找漏洞
DOJO_MODE=challenge hatch run serve
# 文档模式 - 完整的漏洞利用详情
DOJO_MODE=documentation hatch run serve
```
## 前端
包含一个 React 前端用于交互式探索:
```
cd frontend
npm install && npm run dev
```
通过 http://localhost:3000 访问 - 包含适用于所有 6 个实现版本的后端选择器。
## Docker
```
# 运行所有 backends
docker-compose up --build
# 服务将可以在端口 8000, 3002, 3003, 3004, 3005 上访问
```
## 使用 API Security Checker 进行测试
使用 [api-security-checker](https://github.com/maogouste/api-security-checker) 来验证漏洞:
```
# 安装 scanner
pip install hatch
cd /path/to/api-security-checker
hatch run apisec scan http://localhost:8000 -u john -p password123
```
## 默认凭据
| 用户名 | 密码 | 角色 |
|----------|----------|------|
| admin | admin123 | admin |
| john | password123 | user |
| jane | password456 | user |
## 许可证
MIT - 仅供教育使用。
标签:API安全, CISA项目, GraphQL, JSON输出, JS文件枚举, MITM代理, 可视化界面, 多语言演示, 安全教育, 安全靶场, 日志审计, 请求拦截, 逆向工具