LevaAverGit/appsec-review-lab-v2
GitHub: LevaAverGit/appsec-review-lab-v2
基于 FastAPI 的应用安全教学实验室,通过漏洞与修复对比演示 OWASP Top 10 常见漏洞及 SAST/DAST 审查流程。
Stars: 0 | Forks: 0
# AppSec 审查实验室
[](https://github.com/LevaAverGit/appsec-review-lab-v2/actions/workflows/ci.yml)
一个受控实验室,展示了 8 个常见的 Web 漏洞及其安全对应的修复方案、SAST/DAST 检查和结构化报告 —— 同时映射到 [OWASP Top 10](docs/OWASP_MAPPING.md) 和 [OWASP API 安全 Top 10](docs/API_SECURITY.md)(BOLA、BFLA、Mass Assignment、SSRF)。
旨在展示初级/初级+水平的 AppSec 意识、安全编码和 Python 后端技能。它不是一个生产级安全工具。
**快速预览:** `python scripts/demo.py` 会将每个漏洞/安全对并排运行 —— 请在 [docs/DEMO.md](docs/DEMO.md) 中查看捕获的输出结果。
## 本项目展示的内容
- **7 个漏洞对** —— 每个漏洞都有一个故意设计有缺陷的 endpoint 和带有明确修复的安全对应项
- **OWASP Top 10 (2021)** —— 涵盖了 10 个类别中的 7 个:A01、A03(两次)、A05(两次)、A07、A10
- **SAST 检查** —— 能在 Python 源代码中查找危险编码模式的 regex 模式扫描器
- **DAST 检查** —— 探测正在运行的 endpoint 并发送攻击 payload 的进程内 payload 测试
- **结构化报告** —— 带有 findings 模型(Finding、AppSecReport)的 Markdown 和 JSON AppSec 报告
- **FastAPI 后端** —— Pydantic v2 模型、JWT 认证、多部分文件上传、参数化查询
- **159 个测试,0 个失败** —— TestClient、tmp_path 数据库隔离,无 mock
- **15 份文档** —— PRD、威胁模型、安全代码审查、修复指南、面试笔记等
## 涵盖的漏洞
| # | 漏洞 | OWASP | CWE | 漏洞版本 | 安全版本 |
|---|---|---|---|---|---|
| 1 | SQL 注入 | A03:2021 | CWE-89 | `GET /vulnerable/search` | `GET /secure/search` |
| 2 | IDOR | A01:2021 | CWE-639 | `GET /vulnerable/notes/{id}` | `GET /secure/notes/{id}` |
| 3 | 弱 JWT | A07:2021 | CWE-287/347 | `POST /vulnerable/login` | `POST /secure/login` |
| 4 | SSRF | A10:2021 | CWE-918 | `GET /vulnerable/fetch` | `GET /secure/fetch` |
| 5 | 存储型 XSS | A03:2021 | CWE-79 | `POST /vulnerable/comments` | `POST /secure/comments` |
| 6 | 不安全的上传 | A05:2021 | CWE-434/22 | `POST /vulnerable/upload` | `POST /secure/upload` |
| 7 | 安全配置错误 | A05:2021 | CWE-200 | `GET /vulnerable/debug` | `GET /secure/debug` |
## 快速开始
```
# 需要 Python 3.11+
python3.11 -m venv .venv && .venv/bin/pip install -r requirements-dev.txt
# 或者使用 make
make install
# 运行所有测试
make test
# 启动 API
make run-api
# http://127.0.0.1:8001/docs
```
## 演示:SQL 注入
```
# Tautology — 返回所有行
curl "http://localhost:8001/vulnerable/search?q=' OR '1'='1"
# UNION injection — 导出用户凭证
curl "http://localhost:8001/vulnerable/search?q=' UNION SELECT id,username,password_hash FROM users --"
# 在安全端点上使用相同 payload — 返回空列表(参数化查询)
curl "http://localhost:8001/secure/search?q=' OR '1'='1"
```
## 架构
```
app/
├── api/
│ ├── routes_vulnerable.py ← 7 intentionally flawed endpoints
│ ├── routes_secure.py ← 7 mitigated counterparts
│ └── routes_reports.py ← /reports/findings.json and .md
├── services/
│ ├── sast_checks.py ← regex pattern scanner
│ ├── dast_checks.py ← in-process payload checks
│ └── report_service.py ← Finding + AppSecReport generation
├── db/ ← SQLite schema + seed data
└── models/schemas.py ← Finding, AppSecReport, User, Note
```
详情请参阅 `docs/ARCHITECTURE.md`。
## 报告
```
# JSON 报告
curl http://localhost:8001/reports/findings.json
# Markdown 报告
curl http://localhost:8001/reports/findings.md
```
报告示例:`reports/sample_findings.json`, `reports/sample_appsec_report.md`
## 测试
```
make test # 159 tests
```
| 模块 | 覆盖范围 |
|---|---|
| `test_sql_injection.py` | Tautology、UNION、破坏性 payload;参数化查询安全 |
| `test_idor.py` | 漏洞版本上的跨用户访问;安全版本上的所有权强制执行 |
| `test_jwt.py` | 接受/拒绝伪造的 token、过期的 token;强制执行 exp claim |
| `test_ssrf.py` | 阻止 Loopback、RFC1918、file://、ftp://;`_is_safe_url` 单元测试 |
| `test_xss.py` | Script 标签原始存储与转义存储的对比;存在 CSP header |
| `test_file_upload.py` | 扩展名白名单;路径遍历预防;大小限制 |
| `test_security_misc.py` | 调试暴露机密信息与返回 404 的对比 |
| `test_sast_checks.py` | 模式检测;finding 字段;真实路由文件比较 |
| `test_dast_checks.py` | 所有 7 个检查函数;run_all_checks 结果集 |
| `test_report_service.py` | Finding 字段;Markdown 部分;API endpoint |
## 项目结构
```
appsec-review-lab/
├── app/
│ ├── main.py
│ ├── api/
│ │ ├── routes_vulnerable.py
│ │ ├── routes_secure.py
│ │ └── routes_reports.py
│ ├── core/config.py
│ ├── db/
│ │ ├── database.py
│ │ └── schema.sql
│ ├── models/schemas.py
│ └── services/
│ ├── sast_checks.py
│ ├── dast_checks.py
│ └── report_service.py
├── tests/ 159 tests
├── docs/ 16 documentation files
├── reports/
│ ├── sample_appsec_report.md
│ └── sample_findings.json
├── .github/workflows/ci.yml
├── Makefile
├── pyproject.toml
└── requirements.txt
```
## 文档
| 文件 | 内容 |
|---|---|
| `docs/PRD.md` | 项目需求 —— 范围、目标、约束条件 |
| `docs/THREAT_MODEL.md` | 实验室应用的 STRIDE 威胁模型 |
| `docs/ARCHITECTURE.md` | 系统结构、请求流、存储模型 |
| `docs/VULNERABILITIES.md` | 各漏洞参考:根本原因、修复、CWE |
| `docs/OWASP_MAPPING.md` | OWASP Top 10 (2021) 类别映射 |
| `docs/FINDINGS_MODEL.md` | Finding 和 AppSecReport 数据模型 |
| `docs/SECURE_CODE_REVIEW.md` | 每种漏洞类型的代码审查清单 |
| `docs/REMEDIATION_GUIDE.md` | 带有代码示例的逐步修复指南 |
| `docs/REPORT_FORMAT.md` | JSON 和 Markdown 报告结构 |
| `docs/API_OVERVIEW.md` | 带有示例的 endpoint 参考表 |
| `docs/TESTING_APPROACH.md` | 测试结构、隔离、各模块覆盖范围 |
| `docs/SETUP.md` | 安装和运行说明 |
| `docs/SKILLS_MAPPING.md` | 各展示技能的能力对照表 |
| `docs/LIMITATIONS.md` | 范围限制和项目未涵盖的内容 |
| `docs/INTERVIEW_NOTES.md` | 谈话要点、预期问题、定位 |
| `docs/appsec-interview-pitch.md` | RU/EN 推介、SAST/DAST 解释、Q&A、生产环境笔记 |
## 本项目不涉及的内容
- 不是生产级应用程序
- 不是真正的漏洞扫描器(SAST/DAST 检查仅作为启发式演示)
- 不能替代 Semgrep、Bandit、OWASP ZAP 或 Burp Suite
- 所有利用型测试仅针对本地进程内实验室应用 —— 不联系任何外部主机
## 限制
请参阅 `docs/LIMITATIONS.md`。关键点:
- 所有数据均为合成数据 —— 不涉及真实系统
- SAST 模式基于 regex,会漏掉经过混淆的代码
- 未涵盖 CSRF、XXE、反序列化、时序攻击
- 上传目录不会自动清理
## 展示的技能
完整的能力映射请参阅 `docs/SKILLS_MAPPING.md`。
展示了初级/初级+工程师应对 AppSec 工程和安全 Python 后端任务的准备情况:
- Python 3.11、FastAPI、Pydantic v2、SQLite、pytest
- OWASP Top 10 (2021) 实践知识
- 带有明确缓解措施的有漏洞代码与安全代码对
- JWT 实现(弱版本和安全版本)
- SSRF 防护实现
- 启发式 SAST 和 DAST 工具
- 结构化的 AppSec 报告
## 许可证
MIT
标签:AV绕过, DAST, FastAPI, OWASP Top 10, Python, SAST, 安全规则引擎, 安全靶场, 恶意软件分析, 无后门, 盲注攻击, 逆向工具