solosurge/security-scanner
GitHub: solosurge/security-scanner
一款命令行 Web 应用安全评估工具,通过审计 HTTP 安全头、验证 SSL/TLS 证书、检测服务器信息泄露并结合实时威胁情报,帮助用户快速发现 Web 应用的安全配置缺陷与潜在风险。
Stars: 0 | Forks: 0
# 自动化安全扫描器 v1.0


一款命令行 Web 应用安全评估工具,可审计 HTTP 安全头、验证 SSL/TLS 证书、检测服务器信息泄露,并通过来自 VirusTotal 和 AbuseIPDB 的实时威胁情报来丰富结果。它基于模块化的检查器架构构建,添加新的安全检查只需放入单个文件即可完成。
## 功能特性
- 安全头(Security Headers) — 审计 HTTP 响应头的存在性与配置(HSTS、CSP、X-Frame-Options、X-Content-Type-Options、Referrer-Policy、Permissions-Policy)
- SSL/TLS 证书 — 验证证书有效性、过期警告、信任链、自签名检测及协议版本
- 服务器信息泄露 — 检测暴露服务器软件或版本详细信息的头和响应
- 威胁情报 — 查询 VirusTotal 和 AbuseIPDB 以揭示已知的恶意域名和高风险 IP 地址
- 多种输出格式:彩色终端表格、详细发现视图以及 JSON
- 将报告保存到磁盘以供日后查看
- 可一次运行所有检查器,也可针对特定项运行
## 安装说明
```
git clone https://github.com/solosurge/security-scanner.git
cd security-scanner
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
cp .env.example .env
# 打开 .env 并添加你的 API keys
```
### API 密钥
两个免费级别的 API 密钥可解锁威胁情报检查器:
| 服务 | 免费额度 | 注册 |
|---------|-----------|---------|
| VirusTotal | 500 次请求/天 | https://www.virustotal.com |
| AbuseIPDB | 1,000 次请求/天 | https://www.abuseipdb.com |
将它们添加到您的 `.env` 文件中(有关模板请参见 `.env.example`):
```
VIRUSTOTAL_API_KEY=your_virustotal_api_key_here
ABUSEIPDB_API_KEY=your_abuseipdb_api_key_here
```
该扫描器在没有 API 密钥的情况下也能运行——威胁情报检查器将返回带有清晰提示的 `ERROR`,并且所有其他检查器会继续正常运行。
## 使用说明
```
# 扫描所有 checkers 并显示详细输出
python main.py https://example.com --detailed
# 仅运行 threat intelligence 检查
python main.py https://example.com --checkers threat-intel --detailed
# 运行特定的 checkers
python main.py https://example.com --checkers headers ssl --detailed
# 将报告保存为 JSON
python main.py https://example.com --output json --save reports/scan.json
# 运行单元测试
python -m pytest tests/ -v
```
**可用的检查器:** `headers`、`ssl`、`server-info`、`threat-intel`、`all`(默认)
**完整选项:**
```
positional arguments:
target Target URL to scan (e.g., https://example.com)
optional arguments:
--timeout SECONDS Request timeout in seconds (default: 10)
--output FORMAT Output format: table, json, or detailed (default: table)
--checkers [...] Specific checkers to run (default: all)
--detailed Show detailed findings for each check
--save FILEPATH Save report to file
--verbose Enable verbose output
--no-color Disable colored output
```
## 输出示例
```
╔═══════════════════════════════════════════════════════════════╗
║ AUTOMATED SECURITY SCANNER v1.0 ║
║ Web Application Security Assessment Tool ║
╚═══════════════════════════════════════════════════════════════╝
Starting security scan...
================================================================================
Security Headers
Status: FAIL | Severity: HIGH | Duration: 565ms
================================================================================
Finding #1:
Issue: Missing Strict-Transport-Security header
Severity: HIGH
Description: Prevents protocol downgrade attacks and cookie hijacking
Recommendation: Add header: Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Finding #2:
Issue: Missing Content-Security-Policy header
Severity: HIGH
Description: Prevents XSS, clickjacking, and other code injection attacks
================================================================================
Threat Intelligence
Status: PASS | Severity: INFO | Duration: 1419ms
================================================================================
Finding #1:
Issue: Domain reputation clean
Severity: INFO
Description: VirusTotal reports no malicious or suspicious activity for 'example.com'.
Finding #2:
Issue: IP address reputation clean
Severity: INFO
Description: AbuseIPDB reports no significant abuse activity. IP: 172.66.147.243 | Country: US | ISP: Cloudflare, Inc. | Usage: Content Delivery Network | Total Reports: 0
============================================================
SCAN SUMMARY
============================================================
Total Checks: 4 | Passed: 2 | Failed: 1 | Warnings: 1
Total Findings: 11 | High: 2 | Medium: 2 | Low: 4 | Info: 3
[WARNING] Critical or high severity findings detected!
```
## 项目结构
```
Security_Scanner/
├── main.py # CLI entry point (argparse, colorama)
├── requirements.txt
├── .env.example # API key template — safe to commit
├── scanner/
│ ├── __init__.py # Package exports
│ ├── base_checker.py # BaseChecker ABC, CheckResult, SeverityLevel
│ ├── core.py # SecurityScanner orchestrator
│ ├── headers.py # HTTP security headers checker
│ ├── ssl_checker.py # SSL/TLS certificate checker
│ ├── server_info.py # Server information disclosure checker
│ ├── threat_intel.py # VirusTotal + AbuseIPDB threat intelligence checker
│ └── reporter.py # Output formatting (table, JSON, summary)
└── tests/
├── __init__.py
└── test_threat_intel.py # Unit tests with mocked API calls
```
## 运行测试
```
python -m pytest tests/ -v
```
测试模拟了所有的外部 API 调用和 DNS 解析,因此它们可以在离线且无需任何 API 密钥的情况下运行。
## 架构说明
每个检查器都继承自 `BaseChecker`,这是一个抽象基类,强制要求实现统一的 `check() -> CheckResult` 接口,并为计时、发现结果创建以及错误处理提供共享工具。`SecurityScanner` 充当协调器——它注册检查器类,使用目标 URL 和超时时间实例化它们,按顺序运行它们,并聚合结果。添加新检查意味着只需创建一个文件,其中包含实现了 `check()` 和 `name` 的类,然后在 `core.py` 和 `main.py` 中注册它。`CheckResult` 数据类负责规范化所有检查器的输出,这让报告生成器无论运行了哪些检查,都能生成一致的表格、JSON 和摘要。
## 技术栈
- Python 3.12
- [requests](https://docs.python-requests.org/) — HTTP 客户端
- [colorama](https://github.com/tartley/colorama) — 彩色终端输出
- [tabulate](https://github.com/astanin/python-tabulate) — 格式化表格
- [python-dotenv](https://github.com/theskumar/python-dotenv) — 环境变量管理
- [cryptography](https://cryptography.io/) — SSL 证书解析
- unittest / pytest — 带有模拟 API 调用的测试
## 免责声明
本工具仅供授权的安全测试使用。在扫描您不拥有或未获得明确测试权限的系统之前,请务必获取适当的授权。
标签:AbuseIPDB, API集成, Ask搜索, CSP, GitHub, HSTS, HTTP安全头审计, meg, Python, SSL/TLS证书验证, VirusTotal, 信息安全, 可观测性, 威胁情报, 安全合规, 安全报告, 安全标准, 安全规则引擎, 实时处理, 密码管理, 开发者工具, 开源安全工具, 无后门, 无线安全, 服务器信息泄露检测, 网络代理, 网络安全扫描器, 聊天机器人, 自动化安全评估, 逆向工具, 逆向工程平台