CyberReema/ShieldAPI
GitHub: CyberReema/ShieldAPI
一个结合存在漏洞的 FastAPI 实验室与自定义 Python 扫描器的 API 安全教学项目,用于演示、检测和验证常见的 API 安全漏洞及其修复方案。
Stars: 0 | Forks: 0
# ShieldAPI
ShieldAPI 是一个网络安全项目,旨在演示如何使用自定义的 Python 安全扫描器来检测存在漏洞的 API endpoint。
该项目包含:
- 一个存在漏洞的 FastAPI 后端
- 故意设置的 API 安全漏洞
- 一个基于 Python 的安全扫描器
- Markdown 扫描报告生成
- 漏洞文档
## 项目目标
该项目旨在通过构建一个存在漏洞的 API,并随后创建一个能够自动检测这些问题的扫描器,来帮助理解常见的 API 安全问题。
本项目侧重于防御性安全和安全编码意识。
## 功能
### 存在漏洞的 API 实验室
后端包含故意设置存在漏洞的 endpoint:
| 漏洞 | Endpoint | 严重程度 |
|---|---|---|
| 访问控制失效 | `/admin/users` | 高 |
| IDOR / BOLA | `/orders/{order_id}` | 高 |
| 敏感数据暴露 | `/debug/config` | 严重 |
### 安全扫描器
扫描器会检查存在漏洞的 API 并检测:
- 未经身份验证即暴露的管理员数据
- 通过更改对象 ID 访问的订单数据
- 在 API 响应中暴露的敏感配置数据
扫描器会在以下位置生成 Markdown 报告:
```
reports/scan-report.md
```
## 项目架构
ShieldAPI 分为四个主要部分:
```
ShieldAPI/
│
├── backend/
│ └── main.py
│ FastAPI vulnerable API lab with intentionally insecure endpoints
│ and secure fixed endpoint versions.
│
├── scanner/
│ └── scanner.py
│ Python security scanner that detects vulnerabilities,
│ maps them to OWASP API Security Top 10, and validates fixes.
│
├── reports/
│ └── scan-report.md
│ Generated Markdown security report with findings, evidence,
│ severity levels, remediation advice, and secure validation results.
│
├── docs/
│ └── vulnerabilities.md
│ Educational documentation explaining each vulnerability,
│ impact, OWASP mapping, and remediation.
│
└── screenshots/
├── api-docs.png
└── scanner-report.png
Screenshots used in the README to demonstrate the project.
```
## 项目工作流
```
Run vulnerable API
→ Scan endpoints
→ Detect vulnerabilities
→ Map findings to OWASP API Security Top 10
→ Generate security report
→ Validate secure fixes
```
## 技术栈
- Python
- FastAPI
- Uvicorn
- Requests
- Git
- Markdown
## 截图
### API 文档

### 扫描器报告

### 存在漏洞的 IDOR / BOLA Endpoint
此截图显示更改订单 ID 会暴露其他用户的订单数据。

### 阻止未经授权访问的安全 Admin Endpoint
此截图显示安全的 admin endpoint 会阻止没有有效 Authorization header 的请求。

## 如何运行项目
### 1. 创建并激活虚拟环境
```
py -m venv .venv
.\.venv\Scripts\Activate.ps1
```
### 2. 安装依赖
```
pip install -r requirements.txt
```
### 3. 启动 API 服务器
```
uvicorn backend.main:app --reload
```
API 将运行在:
```
http://127.0.0.1:8000
```
API 文档:
```
http://127.0.0.1:8000/docs
```
### 4. 运行扫描器
打开第二个终端并运行:
```
python scanner\scanner.py
```
扫描报告将保存至:
```
reports/scan-report.md
```
## 演示的漏洞
### OWASP API 安全 Top 10 映射
| 项目发现 | Endpoint | OWASP API 安全 Top 10 2023 映射 |
|---|---|---|
| IDOR / BOLA | `/orders/{order_id}` | API1:2023 Broken Object Level Authorization |
| 访问控制失效 | `/admin/users` | API5:2023 Broken Function Level Authorization |
| 敏感数据暴露 | `/debug/config` | API8:2023 Security Misconfiguration |
### 1. 访问控制失效
`/admin/users` endpoint 在未检查用户是否经过身份验证或授权的情况下,就暴露了管理员数据。
### 2. IDOR / BOLA
`/orders/{order_id}` endpoint 允许在未验证所有权的情况下,通过更改订单 ID 来访问不同的订单。
### 3. 敏感数据暴露
`/debug/config` endpoint 暴露了敏感的配置值,例如数据库 URL、API 密钥和 JWT 密钥。
## 修复验证
ShieldAPI 不仅演示了存在漏洞的 API 行为。它还包含了安全的 endpoint 版本,展示了如何修复和验证每个问题。
扫描器测试两类内容:
1. **存在漏洞的 endpoint**
这些 endpoint 故意暴露安全问题,以便扫描器能够检测到它们。
2. **安全的 endpoint**
这些 endpoint 应用了身份验证、基于角色的授权、对象所有权检查以及更安全的配置处理。
| 漏洞 | 存在漏洞的 Endpoint | 安全 Endpoint | 安全控制 |
| ----------------------- | -------------------- | --------------------------- | ----------------------------------------------------- |
| 访问控制失效 | `/admin/users` | `/secure/admin/users` | 需要身份验证和 admin 角色 |
| IDOR / BOLA | `/orders/{order_id}` | `/secure/orders/{order_id}` | 在返回数据前验证对象所有权 |
| 敏感数据暴露 | `/debug/config` | `/secure/debug/config` | 防止在 API 响应中返回密钥 |
扫描器会验证是否检测到了存在漏洞的 endpoint,以及安全的 endpoint 是否正确地阻止了未经授权的访问。
安全验证结果示例:
```
[PASS] Secure admin endpoint blocks unauthenticated access
[PASS] Secure admin endpoint blocks normal users
[PASS] Secure admin endpoint allows admin users
[PASS] Secure order endpoint allows object owner
[PASS] Secure order endpoint blocks IDOR/BOLA
[PASS] Secure config endpoint does not expose secrets
```
这演示了完整的安全工作流:
```
Identify vulnerability → Map to OWASP API Top 10 → Recommend remediation → Validate secure implementation
```
## 免责声明
本项目仅用于教育和防御性网络安全学习。
所有漏洞均是在本地实验室环境中故意创建的。
## 展示的技能
本项目展示了以下方面的实用技能:
- API 安全测试
- 漏洞检测
- 访问控制失效分析
- IDOR / BOLA 测试
- 敏感数据暴露检测
- Python 脚本编写
- FastAPI 后端开发
- Git 和 GitHub 项目管理
- 安全文档编写
- Markdown 报告生成
标签:API安全, AV绕过, CISA项目, FastAPI, JSON输出, OWASP API Top 10, Python, StruQ, 加密, 字符串匹配, 安全靶场, 无后门, 漏洞扫描器, 逆向工具