未认证 API 报告
发布: (2025年12月28日 GMT+8 22:58)
4 min read
原文: Dev.to
Source: Dev.to
Overview
一个安全自动化工具,用于扫描 API 端点,识别未认证访问漏洞。它会测试各种 HTTP 方法和认证方案,以检测可能在未进行适当认证的情况下暴露数据的 API。
Features
- Multi-Method Testing: 测试 GET、POST、PUT、DELETE 方法
- Authentication Bypass Detection: 识别在未进行适当认证的情况下可访问的 API
- Token Validation: 使用多种认证方案(Bearer、Basic)进行测试
- Automated Reporting: 生成详细的安全报告
- Email Notifications: 发送安全发现的警报
- Concurrent Processing: 多线程扫描以提升效率
Prerequisites
- Python 3.13+
- 必要的 Python 包(见
requirements.txt) - 对目标 API 的网络访问权限
- 用于通知的邮件配置
Installation
# Navigate to the solution directory
cd unauthenticated-apis-report
# Install dependencies
pip install -r requirements.txt
Configuration
API List Configuration
创建 unauthenticated-api.json 并填入你的 API 端点:
{
"data": [
"https://api.example.com/v1/users",
"https://api.example.com/v1/orders",
"https://api.example.com/v1/admin"
]
}
Notification Setup
在 Notification 模块中配置邮件通知,以便接收安全警报。
Usage
Basic Scan
python unauthenticated-api.py
Key Functions
get_api_list(): 从配置中加载 API 端点check_authentication(api_url): 对特定端点进行认证测试get_api_authentication(): 执行单独的认证测试generate_password(): 生成用于测试的随机令牌
Security Testing Methods
- No Authentication Headers – 测试 API 在没有任何认证的情况下是否能成功响应。
- Invalid Token Testing – 使用随机生成的令牌进行测试,以识别验证薄弱的情况。
- Authentication Scheme Testing
- Bearer 令牌验证
- Basic 认证测试
- 自定义授权头部
- HTTP Method Testing – 对每个端点测试所有常见的 HTTP 方法。
Report Output
该工具会生成详细报告,内容包括:
- 请求/响应细节
- 认证状态
- 漏洞发现
- 修复建议
Security Considerations
- Ethical Use: 仅扫描你拥有或已获授权测试的 API。
- Rate Limiting: 实施延迟,以免对目标系统造成过大负载。
- Credential Security: 测试时切勿使用真实凭证。
- Network Security: 仅在安全、授权的网络环境中运行。
Integration
CI/CD Pipeline
将其集成到安全扫描工作流中:
# Add to pipeline
python unauthenticated-api.py --output-format json
Monitoring
设置定期扫描,以监控新出现的漏洞。
Troubleshooting
Common Issues
- Connection Timeouts: 对响应慢的 API 增加超时时间。
- Rate Limiting: 在请求之间添加延迟。
- SSL Errors: 配置正确的证书验证。
Debug Mode
启用详细日志以进行深入排查。
Contributing
- 添加新的认证方案进行测试
- 增强报告功能
- 改进错误处理
- 支持更多 HTTP 方法
GitHub Link
https://github.com/prashantgupta123/devops-automation/tree/main/unauthenticated-apis-report
Security Notice
此工具仅用于授权的安全测试。请确保在扫描任何 API 前已获得适当的权限。未经授权的测试可能违反服务条款或适用法律。