Azmine-Zim/Scan-Affordi-Vulnerability-Scanner-and-Reporter

GitHub: Azmine-Zim/Scan-Affordi-Vulnerability-Scanner-and-Reporter

一款自托管的网络漏洞扫描与报告工具,整合 Nmap 扫描能力与 NVD CVE 数据库查询,提供 Web/CLI 双界面及自动 PDF 报告生成。

Stars: 0 | Forks: 0

# Scan Affordi — 网络扫描器与漏洞报告工具 ![Python](https://img.shields.io/badge/Python-3.10%2B-blue?logo=python&logoColor=white) ![Flask](https://img.shields.io/badge/Flask-3.0-black?logo=flask&logoColor=white) ![Nmap](https://img.shields.io/badge/Nmap-7%2B-green) ![NVD API](https://img.shields.io/badge/NVD_CVE_API-2.0-orange) ![License](https://img.shields.io/badge/License-MIT-yellow) ![Ethical Use](https://img.shields.io/badge/Ethical_Use-Authorized_Only-red) ## 问题陈述 安全团队和渗透测试人员通常需要: 1. 发现网络上**暴露了哪些主机和服务** 2. 识别这些服务是否存在**已知的 CVE 漏洞** 3. 生成结构化、可共享的**漏洞报告**供利益相关者查阅 大多数企业级工具(如 Nessus、Qualys)每年的费用高达数千美元。本项目自动化了相同的核心工作流 —— **主机发现 → 服务指纹识别 → CVE 丰富化 → 报告生成** —— 作为一个自托管的 Python 工具,仅需在单机上运行,无需订阅。 ## 架构 ``` ┌─────────────────────────────────────────────────────────────────┐ │ USER INTERFACE │ │ Flask Web UI (port 5000) ── or ── CLI (cli.py) │ └──────────────────────────┬──────────────────────────────────────┘ │ target + profile ▼ ┌─────────────────────────────────────────────────────────────────┐ │ scanner/network_scanner.py │ │ │ │ python-nmap ──► nmap binary ──► raw XML parse │ │ │ │ Returns: hosts[] ─ ip, hostname, status │ │ ports[] ─ port, protocol, state, service, version │ │ os_match, open_count, banner │ └──────────────────────────┬──────────────────────────────────────┘ │ service keyword per open port ▼ ┌─────────────────────────────────────────────────────────────────┐ │ scanner/cve_lookup.py │ │ │ │ NVD CVE API 2.0 ◄──── requests ◄──── TTL in-process cache │ │ │ │ Returns per port: cve_id, description, cvss_score, severity │ │ Bubbles up worst severity to host level │ └──────────────────────────┬──────────────────────────────────────┘ │ enriched scan_result dict ┌──────┴──────┐ ▼ ▼ ┌──────────────┐ ┌─────────────────────────────┐ │ Web UI │ │ scanner/report_generator.py│ │ results.html│ │ │ │ (live table)│ │ ReportLab → PDF │ └──────────────┘ │ Cover ▸ Summary ▸ Hosts │ └──────────────┬──────────────┘ │ reports/*.pdf ``` ## 功能特性 | 功能 | 描述 | |---|---| | **主机发现** | 通过 Nmap 检测存活主机、开放端口、服务 Banner、操作系统指纹 | | **CVE 丰富化** | 通过 NVD API 自动查询每个服务的已知 CVE(基于 CVSS v3.1 评分) | | **风险等级** | 每个主机/端口均被评级为 CRITICAL / HIGH / MEDIUM / LOW / INFO | | **PDF 报告** | 专业的彩色 PDF —— 包含执行摘要和逐主机的 CVE 详细分析 | | **暗色 Web UI** | 响应式网络安全主题仪表板(适配桌面端 + 移动端) | | **CLI 界面** | 完整的终端工作流,支持彩色输出和 JSON 导出 | | **5 种扫描配置** | Quick, Standard, Full, Stealth SYN, UDP | | **TTL 缓存** | CVE 结果在会话期间缓存 —— 避免频繁请求 NVD API | | **REST API** | `/api/scan` JSON 端点,便于与其他工具集成 | ## 项目结构 ``` NetworkScannerVulnReporter/ │ ├── app.py # Flask web application + all routes ├── cli.py # Command-line interface (argparse) ├── config.py # Central configuration (loads from .env) ├── requirements.txt # Python dependencies ├── .env.example # Environment variable template (safe to commit) ├── .gitignore # Excludes .env, PDFs, venv, secrets │ ├── scanner/ │ ├── __init__.py # Package exports │ ├── network_scanner.py # Nmap wrapper + XML result parser │ ├── cve_lookup.py # NVD API v2.0 client + TTL cache │ └── report_generator.py # ReportLab PDF builder │ ├── templates/ │ ├── base.html # Navbar + flash messages + footer │ ├── index.html # Two-column scan form + sidebar │ ├── results.html # Scan results with expandable CVE rows │ └── reports.html # Report management (download / delete) │ ├── static/ │ └── style.css # Full dark theme — 800+ lines, fully responsive │ └── reports/ └── .gitkeep # Keeps folder in git; actual PDFs are gitignored ``` ## 前置条件 | 需求 | 说明 | |---|---| | Python 3.10+ | [python.org](https://www.python.org/downloads/) | | **Nmap 7+** | [nmap.org/download](https://nmap.org/download.html) — 必须位于系统 PATH 中 | | NVD API Key | 免费 — [nvd.nist.gov/developers/request-an-api-key](https://nvd.nist.gov/developers/request-an-api-key) | | 管理员 / root 权限 | SYN 隐蔽扫描 (`-sS`) 和操作系统检测 (`-O`) 需要此权限 | ## 安装 ``` # 1. Clone the repository git clone https://github.com/Azmine-Zim/scan-affordi.git cd scan-affordi # 2. 创建并激活 virtual environment python -m venv .venv # Windows .venv\Scripts\activate # Linux / macOS source .venv/bin/activate # 3. 安装依赖 pip install -r requirements.txt # 4. 配置环境变量 copy .env.example .env # Windows # cp .env.example .env # Linux/macOS # 5. 编辑 .env — 添加你的 NVD API key 和强 SECRET_KEY # NVD_API_KEY=your-key-here # SECRET_KEY=generate-a-long-random-string ``` ## 使用方法 ### Web UI ``` python app.py # 打开 http://127.0.0.1:5000 ``` 1. 输入目标(IP、主机名、CIDR 范围或连字符范围) 2. 选择扫描配置 3. 点击 **EXECUTE SCAN** 4. 查看带有颜色编码严重性的结果 —— 下载自动生成的 PDF ### CLI ``` # Standard scan with CVE lookup + PDF python cli.py scan 192.168.1.1 # Full scan on a subnet python cli.py scan 10.0.0.0/24 --profile full # Quick scan, skip CVE lookup, export JSON python cli.py scan scanme.nmap.org --profile quick --no-cve --json # Stealth SYN scan, no PDF python cli.py scan 192.168.1.100 --profile stealth --no-pdf # List all scan profiles python cli.py profiles # List saved reports python cli.py reports ``` ### REST API ``` # Trigger a scan and get a JSON response curl -X POST http://127.0.0.1:5000/api/scan \ -H "Content-Type: application/json" \ -d '{"target": "192.168.1.1", "profile": "standard"}' ``` ## 扫描配置 | 配置 | Nmap 标志 | 速度 | 使用场景 | |---|---|---|---| | `quick` | `-T4 -F` | ~10s | 快速检查前 100 个端口 | | `standard` | `-T4 -sV --version-intensity 5` | ~30s | 服务 + 版本检测 | | `full` | `-T4 -sV -sC -O` | ~2–5 min | OS + 脚本 + 完整版本 | | `stealth` | `-T2 -sS -sV` | ~5–10 min | 慢速 SYN 扫描 —— 可规避基础 IDS | | `udp` | `-T4 -sU --top-ports 200` | ~3 min | UDP 服务发现 | ## CVE 严重性等级 (CVSS v3.x) | 分数 | 严重性 | 建议措施 | |---|---|---| | 9.0 – 10.0 | 🔴 **CRITICAL** | 立即修复 / 隔离系统 | | 7.0 – 8.9 | 🟠 **HIGH** | 7 天内打补丁 | | 4.0 – 6.9 | 🟡 **MEDIUM** | 30 天内打补丁 | | 0.1 – 3.9 | 🟢 **LOW** | 90 天内在维护期间打补丁 | | N/A | ⚪ **INFO** | 监控 —— 未分配 CVSS 分数 | ## 环境变量 根据模板(见 `.env.example`)创建 `.env` 文件。**切勿提交实际的 `.env` 文件 —— 它已被 gitignore 忽略。** | 变量 | 默认值 | 描述 | |---|---|---| | `NVD_API_KEY` | *(空)* | 来自 NVD 的免费密钥 —— 将速率限制提升至 50 请求/30秒 | | `SECRET_KEY` | `changeme-in-production` | Flask 会话签名密钥 —— **请在生产环境中更改** | | `NMAP_PATH` | `nmap` | 如果不在系统 PATH 中,需指定 nmap 二进制文件的完整路径 | ## 安全设计 本项目的设计确保了开源的安全性: - ✅ **代码中无密钥** —— 所有敏感值均通过 `os.getenv()` 从 `.env` 加载 - ✅ **`.env` 已被 gitignore** —— API 密钥和密钥永远不会上传到 GitHub - ✅ **生成的 PDF 已被 gitignore** —— 扫描数据保留在您的本地机器上 - ✅ **不存储输入** —— 扫描目标仅在内存中处理 - ✅ **无数据库** —— 零持久化用户数据,无数据泄露风险 - ✅ **TTL 缓存** —— CVE 缓存存在于进程内,重启后清除 ## 部署 ### 本地开发 ``` python app.py # http://127.0.0.1:5000 ``` ### 快速公开演示 (ngrok) ``` pip install pyngrok # In one terminal: python app.py # In another terminal: ngrok http 5000 # Get a temporary public URL — ideal for portfolio demos and interviews ``` ### VPS / 生产环境 (Ubuntu) ``` sudo apt update && sudo apt install nmap python3-pip -y git clone https://github.com/Azmine-Zim/scan-affordi.git cd scan-affordi pip install -r requirements.txt cp .env.example .env nano .env # add your NVD_API_KEY and a strong SECRET_KEY gunicorn -w 2 -b 0.0.0.0:5000 app:app ``` ## 截图 ### 扫描器 — 主页 ![Scanner UI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/b0d8642265035241.png) ### 报告 — 存档页面 ![Reports UI](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/9ce324617f035242.png) ## 使用的技术 | 库 | 版本 | 用途 | |---|---|---| | [python-nmap](https://pypi.org/project/python-nmap/) | 0.7.1 | Nmap Python 封装 | | [Flask](https://flask.palletsprojects.com/) | 3.0.3 | Web 框架 | | [ReportLab](https://www.reportlab.com/) | 4.2.2 | PDF 生成 | | [Requests](https://docs.python-requests.org/) | 2.31.0 | NVD API HTTP 客户端 | | [python-dotenv](https://pypi.org/project/python-dotenv/) | 1.0.1 | `.env` 文件加载器 | | [Colorama](https://pypi.org/project/colorama/) | 0.4.6 | 终端彩色输出 | | [Tabulate](https://pypi.org/project/tabulate/) | 0.9.0 | CLI 表格格式化 | ## ⚠️ 道德使用声明 负责任的披露和道德行为是网络安全的**核心能力** —— 而非事后补救。此工具旨在培养这些技能。 ## 提交规范 提交遵循 [Conventional Commits](https://www.conventionalcommits.org/) 规范: ``` feat: add new feature fix: bug fix docs: README or comment updates refactor: code restructure without feature change style: CSS / formatting changes test: add or update tests chore: dependency or config updates ``` ## 许可证 MIT License — 详情见 [LICENSE](LICENSE)。 ## 作者 GitHub: [github.com/Azmine-Zim](https://github.com/Azmine-Zim) Stack: Python · Flask · Nmap · Metasploit · Burp Suite · Hydra · C/C++ · Java
标签:Claude, CTI, CVE检测, Facebook API, Flask, Nmap, NVD API, Python, Web安全, 企业安全, 安全合规, 密码管理, 对称加密, 开源安全工具, 插件系统, 数据统计, 无后门, 服务指纹, 漏洞报告生成, 端口扫描, 网络代理, 网络安全, 网络安全审计, 网络扫描器, 网络测绘, 网络资产管理, 自动化审计, 蓝队分析, 虚拟驱动器, 逆向工具, 逆向工程平台, 隐私保护