Vicsar71/web-vuln-scanner

GitHub: Vicsar71/web-vuln-scanner

一款异步 Web 漏洞扫描器,通过自动爬取目标应用检测 SQL 注入、反射型 XSS、LFI/路径遍历和开放重定向等常见漏洞,并附带一个故意存在漏洞的 Flask 演示应用。

Stars: 0 | Forks: 1

# Web 漏洞扫描器 一款异步 Web 漏洞扫描器,可自动爬取目标应用,并测试发现的每个表单和 URL 参数是否存在常见的注入漏洞。 内置 **VulnShop** —— 一个故意存在漏洞的 Flask 应用,让你无需任何设置即可立即看到它的运行效果。 ## 检测内容 | 模块 | 技术 | 严重程度 | |--------|-----------|----------| | SQL 注入 | 基于报错 (MySQL, PostgreSQL, SQLite) | 严重 | | 反射型 XSS | 使用唯一标记的 Payload 回显检测 | 高危 | | LFI / 路径遍历 | Unix (`/etc/passwd`) 和 Windows (`win.ini`) | 严重 | | 开放重定向 | 注入外部 URL,检查 3xx 响应的 `Location` 标头 | 中危 | ## 快速开始 ``` git clone https://github.com/Vicsar71/web-vuln-scanner cd web-vuln-scanner python -m venv .venv && .venv\Scripts\activate # Windows pip install -r requirements.txt ``` **终端 1 — 启动包含漏洞的演示应用:** ``` python vuln_app/app.py # VulnShop 运行在 http://localhost:5000 ``` **终端 2 — 运行扫描器:** ``` python -m scanner scan http://localhost:5000 ``` ![HTML 报告截图](https://static.pigsec.cn/wp-content/uploads/repos/cas/33/33143ab17f855949c63c9242168226e1230b10518240dfe9ee2866fbe681411e.png) 示例输出: ``` Web Vulnerability Scanner Target : http://localhost:5000 Depth : 1 Timeout: 10.0s Hallazgos — 7 total ┌───────────┬────────────────────┬──────────────────────────┬───────────┐ │ Severidad │ Tipo │ URL │ Parámetro │ ├───────────┼────────────────────┼──────────────────────────┼───────────┤ │ CRITICAL │ sql_injection │ http://localhost:5000/s… │ q │ │ CRITICAL │ sql_injection │ http://localhost:5000/l… │ username │ │ CRITICAL │ sql_injection │ http://localhost:5000/l… │ password │ │ CRITICAL │ lfi_path_traversal │ http://localhost:5000/v… │ file │ │ HIGH │ xss_reflected │ http://localhost:5000/s… │ q │ │ HIGH │ xss_reflected │ http://localhost:5000/v… │ file │ │ MEDIUM │ open_redirect │ http://localhost:5000/g… │ url │ └───────────┴────────────────────┴──────────────────────────┴───────────┘ URLs rastreadas: 5 | Requests: 125 | Duración: 41.9s Saved: reports/localhost_5000_20260702.json Saved: reports/localhost_5000_20260702.md Saved: reports/localhost_5000_20260702.html ``` ## CLI 参考 ``` # 基本扫描(深度 1,MD + JSON 报告) python -m scanner scan http://localhost:5000 # 深度爬取 python -m scanner scan http://localhost:5000 --depth 2 # 保存 HTML 报告(深色主题,在浏览器中打开) python -m scanner scan http://localhost:5000 --format html # 保存所有格式(MD + HTML + JSON) python -m scanner scan http://localhost:5000 --format both # 自定义输出目录和超时 python -m scanner scan http://localhost:5000 --output results/ --timeout 15 # 版本信息 python -m scanner version ``` | 标志 | 默认值 | 描述 | |------|---------|-------------| | `--depth` | `1` | 爬取深度 (0 = 仅起始 URL) | | `--timeout` | `10.0` | 单次请求超时时间(秒) | | `--format` | `md` | 报告格式:`md` \| `html` \| `both` (始终会写入 JSON) | | `--output` | `reports/` | 输出目录 | ## 工作原理 ``` Target URL │ ▼ Crawler ──── visits pages up to --depth levels │ extracts: forms (GET/POST) + links with query params │ ▼ For each endpoint × parameter: ├── SQLi module → injects 7 error-based payloads, looks for DB error strings ├── XSS module → injects 4 script/onerror payloads with a unique marker, │ checks if the raw payload is reflected unescaped └── LFI module → tries 17 traversal depths for /etc/passwd and win.ini, confirms by matching known file content signatures │ ▼ Reporter → JSON (always) + Markdown / HTML (optional) ``` **为什么要分离检测逻辑?** 每个模块都暴露了一个纯 `check_response(text) -> str | None` 函数,该函数仅接收一个字符串并返回证据或 `None`。这使得检测规则无需任何 HTTP 模拟即可进行单元测试。 ## 项目结构 ``` web-vuln-scanner/ ├── scanner/ │ ├── models.py # Pydantic: VulnFinding, ScanReport, Severity, VulnType │ ├── crawler.py # async crawler — discovers forms and parameterised links │ ├── modules/ │ │ ├── sqli.py # SQL injection: payloads + error signature matching │ │ ├── xss.py # Reflected XSS: unique marker + verbatim reflection check │ │ └── lfi.py # LFI/traversal: Unix + Windows payloads + content signatures │ ├── runner.py # orchestrates crawl → modules → ScanReport │ ├── reporter.py # Markdown + JSON output │ └── cli.py # Typer CLI with Rich output ├── vuln_app/ │ └── app.py # Deliberately vulnerable Flask app (SQLi, XSS, LFI, redirect) └── tests/ # 47 unit tests — no network required ``` ## VulnShop — 演示目标 `vuln_app/app.py` 是一个最小化的 Flask 应用,在四个 endpoint 中故意包含了漏洞: | Endpoint | 漏洞 | 详情 | |----------|---------------|--------| | `GET /search?q=` | SQLi + XSS | 将原始字符串插值到 SQLite 查询中;`q` 未转义直接回显在 HTML 中 | | `POST /login` | SQLi | `username` 和 `password` 直接注入到 `WHERE` 子句中 | | `GET /view?file=` | LFI | 无路径过滤 —— `../` 遍历可读取任意文件 | | `GET /go?url=` | 开放重定向 | `url` 直接传递给 `redirect()` | ## 运行测试 ``` pytest # all 47 tests pytest tests/test_sqli.py # SQL injection detection pytest tests/test_xss.py # XSS detection pytest tests/test_lfi.py # LFI detection pytest tests/test_crawler.py # endpoint extraction pytest tests/test_reporter.py # report generation ``` 所有测试均为纯单元测试 —— 无需网络,也无需 Flask 服务器。 ## 道德使用 本工具仅供**授权的安全测试和学习使用**。请仅扫描你拥有的或已获得明确书面测试许可的应用程序。所有的开发和测试均是针对 VulnShop(一个本地、故意存在漏洞的应用)进行的。 ## 路线图 - [x] 里程碑 1 — SQLi、反射型 XSS、LFI、异步爬虫、MD/JSON 报告、47 项测试 - [x] 里程碑 2 — HTML 报告生成器(暗黑主题、防范 XSS)、开放重定向模块、70 项测试
标签:CISA项目, DOE合作, Python, SQL注入检测, Web安全, XSS检测, 加密, 无后门, 漏洞扫描器, 蓝队分析, 计算机取证, 路径遍历检测, 逆向工具