bruno0564/vulnscan

GitHub: bruno0564/vulnscan

一个轻量级的纯 Python Web 漏洞扫描器,通过可插拔的检查项机制检测常见的 Web 安全配置错误和漏洞。

Stars: 0 | Forks: 0

# vulnscan 使用 Python 从头构建的 Web 漏洞扫描器。检查常见的配置错误和安全问题,不依赖第三方扫描框架。 ## 检查项 | 检查项 | 严重程度 | 描述 | |---|---|---| | 安全 headers | Medium | HSTS、CSP、X-Content-Type-Options、Referrer-Policy 等 | | 信息泄露 headers | Low | Server、X-Powered-By、X-AspNet-Version | | Cookie flags | Medium | Secure、HttpOnly、SameSite(不区分大小写,RFC 6265) | | CORS 配置错误 | Medium / High | 通配符 origin,带 credentials 的 origin 反射 | | Clickjacking | Medium | 可被嵌套的页面 —— 没有 X-Frame-Options 且没有 CSP frame-ancestors | | 危险的 HTTP 方法 | Medium | 通过 OPTIONS 暴露的 PUT、DELETE、TRACE/TRACK、CONNECT、PATCH | | Open redirect | Medium | 重定向参数(next、url…)跳转至外部主机 | | 暴露的路径 | Low / Medium | .git、.env、管理面板、debug endpoints、备份文件 | | 反射型 XSS | Medium | 查询参数未经转义直接回显到页面中 | | SQL injection | High | 通过在参数中注入引号触发数据库错误特征 | | TLS / 证书 | Medium / High | 过期/即将过期的证书、验证失败、过时的协议 | | security.txt | Low | 缺少 /.well-known/security.txt (RFC 9116) | | 子域名 | Low | 可通过 DNS 解析的常见子域名(api、dev、staging…) | ## 安装 ``` python -m venv .venv && source .venv/bin/activate pip install -e . # installs the `vulnscan` command ``` 对于开发(linting、types、tests),请改为安装 dev extras: ``` pip install -e ".[dev]" pre-commit install ``` ## 用法 ``` # 基础扫描 vulnscan https://example.com # JSON 输出 vulnscan https://example.com --json # 默认并发执行 checks(8 个 workers);可调整或序列化执行 vulnscan https://example.com --workers 16 vulnscan https://example.com --workers 1 # fully sequential # 保持礼貌:请求之间等待 0.5s,每个请求上限为 5s # (--delay 强制顺序执行,从而确保切实遵守节奏) vulnscan https://example.com --delay 0.5 --timeout 5 # 认证后的扫描 vulnscan https://example.com --bearer "$TOKEN" vulnscan https://example.com --basic admin:s3cret vulnscan https://example.com --header "Cookie: session=abc123" # 编写独立的 HTML 报告 vulnscan https://example.com --html report.html # 为 GitHub Code Scanning 编写 SARIF 报告 vulnscan https://example.com --sarif results.sarif ``` ## GitHub 代码扫描 vulnscan 可以输出 [SARIF](https://sarifweb.azurewebsites.net/),这是 GitHub 用于代码扫描 (Code Scanning) 的格式。检查结果随后将作为警报显示在仓库的 **Security** 标签页中,其严重程度映射到 SARIF 级别(high → error,medium → warning,low → note)。 仓库中的 [`action.yml`](action.yml) 提供了一个开箱即用的 composite action。最小化的 workflow(参见 [`.github/workflows/security-scan.yml`](.github/workflows/security-scan.yml)): ``` permissions: security-events: write jobs: scan: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 - uses: bruno0564/vulnscan@v1 with: url: https://example.com output: vulnscan.sarif - uses: github/codeql-action/upload-sarif@v3 with: sarif_file: vulnscan.sarif ``` ## 输出示例 ``` Target: https://example.com [200] Findings: 0 high 3 medium 2 low [MEDIUM] Strict-Transport-Security Missing HSTS — forces HTTPS [MEDIUM] Content-Security-Policy Missing — XSS protection weakened [LOW] Server Exposes server software and version: Apache/2.4.41 ``` ## 架构 检查项是**可插拔的** (pluggable)。每一项都是使用 `@register` 注册的小型函数,扫描器通过注册表发现它们 —— 因此添加 检查项完全不需要修改 `scanner.py`。 ``` vulnscan/ ├── vulnscan/ │ ├── cli.py — argument parsing and report output │ ├── scanner.py — fetches the page, runs every registered check │ ├── auth.py — builds the HTTP session (Bearer / Basic / headers) │ ├── report.py — self-contained HTML report rendering │ ├── types.py — Severity, Finding, ScanResult │ └── checks/ │ ├── base.py — ScanContext (+ throttled request) + @register registry │ ├── headers.py — security and info disclosure headers │ ├── cookies.py — cookie flag analysis │ ├── cors.py — CORS misconfiguration │ ├── clickjacking.py — X-Frame-Options / CSP frame-ancestors │ ├── methods.py — dangerous HTTP methods (OPTIONS/Allow) │ ├── redirects.py — open redirect probing │ ├── directories.py — common exposed paths │ ├── xss.py — reflected XSS probing │ ├── sqli.py — error-based SQL injection probing │ ├── tls.py — certificate validity / protocol version │ ├── security_txt.py — RFC 9116 security.txt presence │ └── subdomains.py — DNS subdomain enumeration ├── tests/ — pytest suite (HTTP mocked, no real network) └── pyproject.toml — packaging + ruff/mypy/pytest config ``` ## 开发 ``` ruff check vulnscan/ tests/ # lint mypy vulnscan/ tests/ # static types (strict) pytest # tests + coverage ``` ## 路线图 - [x] XSS 反射检测 - [x] SQL injection 基础探测 - [x] 子域名枚举 - [x] HTML 报告输出 - [x] 速率限制 / 请求间延迟 - [x] 认证支持(Bearer token、Basic auth) - [x] Clickjacking、危险的 HTTP 方法、open redirect、TLS 和 security.txt 检查 - [x] 并发扫描(thread pool) - [x] SARIF 输出 + 用于 Code Scanning 的 GitHub Action - [ ] 经过认证的爬取以发现更多 endpoints - [ ] 可配置的检查项选择(`--only` / `--skip`)
标签:图数据库, 安全规则引擎, 逆向工具