Ashishdev13/web-vulnerability-scanner
GitHub: Ashishdev13/web-vulnerability-scanner
一款基于 Python 的自动化 Web 漏洞扫描器,通过智能爬取和 Payload 注入检测常见 Web 安全漏洞,专为安全教育和授权测试设计。
Stars: 0 | Forks: 0
# Web 漏洞扫描器 (迷你 Burp Suite)
**一款自动化 Web 应用安全扫描器,通过智能爬取、Payload 注入和配置分析来识别 Web 应用程序中的常见漏洞。**
[](https://python.org)
[](#)
[](LICENSE)
[](#%EF%B8%8F-disclaimer)
## 关于本项目
本项目是一个**基于 Python 的自动化 Web 漏洞扫描器**,其灵感来源于 Burp Suite 和 OWASP ZAP 等专业工具。它对经过授权的 Web 目标执行多阶段安全评估——包括爬取应用程序、注入测试 Payload、分析服务器配置,并生成包含严重等级评估发现的专业报告。
该扫描器通过**8个阶段的 Pipeline** 运行:首先爬取目标以发现所有页面、表单和输入字段,然后系统地测试 SQL Injection、Cross-Site Scripting (XSS)、开放重定向、缺失的安全头、暴露的目录、不安全的 Cookie 以及 SSL/TLS 弱点。结果被编译成机器可读的 JSON 和带有严重性仪表板的样式化 HTML 报告。
该工具基于**“同意优先”**的理念构建——如果没有显式的 `--consent` 标志,扫描器将拒绝运行,并内置了速率限制以避免目标服务器过载。
### 核心能力
| 模块 | 功能描述 | 严重性 |
|--------|-------------|----------|
| **SQL Injection** | 向表单和 URL 参数注入 15+ SQL Payload,检测数据库错误消息 | Critical (严重) |
| **XSS (Cross-Site Scripting)** | 注入 12 个脚本 Payload,检测响应中未转义的反射 | High (高) |
| **SSL/TLS Checker** | 验证证书,检查过期时间,检测弱协议和弱加密套件 | High-Critical (高-严重) |
| **Open Redirect** | 使用外部 URL 测试 20+ 个参数名中的重定向类参数 | Medium (中) |
| **Security Headers** | 验证 CSP, HSTS, X-Frame-Options, X-Content-Type-Options 等 | Medium-Low (中-低) |
| **Directory Brute Force** | 测试 130+ 个常见路径(`/admin`, `/.env`, `/.git`, `/backup` 等) | Medium-High (中-高) |
| **Cookie Security** | 检查缺失的 HttpOnly, Secure, 和 SameSite 标志 | Medium (中) |
| **Web Crawler** | 深度为 3 的 BFS 爬取,提取所有链接、表单和输入字段 | - |
## 演示
### 终端输出
```
╦ ╦╔═╗╔╗ ╦ ╦╦ ╦╦ ╔╗╔ ╔═╗╔═╗╔═╗╔╗╔╔╗╔╔═╗╦═╗
║║║║╣ ╠╩╗ ╚╗╔╝║ ║║ ║║║ ╚═╗║ ╠═╣║║║║║║║╣ ╠╦╝
╚╩╝╚═╝╚═╝ ╚╝ ╚═╝╩═╝╝╚╝ ╚═╝╚═╝╩ ╩╝╚╝╝╚╝╚═╝╩╚═
Mini Burp Suite v1.0.0
Automated Web Vulnerability Scanner
[+] Authorization confirmed via --consent flag
[*] Starting scan against: https://example.com
[*] Rate limit: 5 req/s
============================================================
PHASE 1: Crawling Target
============================================================
Crawl complete: 12 URLs, 3 forms found
============================================================
PHASE 2: SSL/TLS Analysis
============================================================
Found 1 SSL/TLS findings
============================================================
PHASE 3: Security Headers Check
============================================================
Found 6 header findings
...phases 4-8...
============================================================
SCAN COMPLETE
============================================================
Duration: 45.3 seconds
SCAN RESULTS SUMMARY
────────────────────────────────────────
Critical : 0
High : 2
Medium : 3
Low : 4
Info : 2
────────────────────────────────────────
Total : 11
============================================================
GENERATING REPORTS
============================================================
JSON Report: reports/scan_20260228_040324.json
HTML Report: reports/scan_20260228_040324.html
```
### HTML 报告预览
扫描器生成专业的深色主题 HTML 报告,包含:
- 严重性摘要仪表板(Critical / High / Medium / Low / Info 计数)
- 按模块分组的发现,带有颜色编码的严重性徽章
- 每个发现的详细证据和受影响的 URL
## 演示的安全概念
本项目演示了以下**进攻性和防御性安全概念**:
### 漏洞检测
- **SQL Injection (SQLi)** - 理解数据库查询中未过滤的用户输入如何导致数据泄露;使用基于错误和基于布尔的 Payload 进行测试
- **Cross-Site Scripting (XSS)** - 未经输出编码的反射用户输入如何在浏览器中实现脚本注入
- **Open Redirect** - 未经验证的重定向参数如何被滥用于钓鱼攻击
### Web 安全配置
- **Security Headers** - CSP, HSTS, X-Frame-Options, 和 X-Content-Type-Options 在纵深防御中的作用
- **Cookie Security Flags** - HttpOnly 如何防止 XSS Cookie 窃取,Secure 如何强制仅 HTTPS 传输,SameSite 如何缓解 CSRF
- **SSL/TLS Hardening** - 证书生命周期管理,弃用 TLSv1/1.1,以及弱加密套件风险
### 侦察技术
- **Web Crawling** - 基于 BFS 的链接和表单发现,用于攻击面映射
- **Directory Enumeration** - 发现暴露的管理面板、配置文件、备份和版本控制工件
- **Information Disclosure** - 通过 Server 和 X-Powered-By 头检测服务器版本泄露
### 安全工具设计
- **Consent-First Architecture** - 在任何扫描开始前必须有授权标志
- **Rate Limiting** - Token-Bucket 限流,防止对目标造成拒绝服务
- **Structured Reporting** - CVSS 风格的严重性评级,用于漏洞优先级排序
## 技术栈
| 技术 | 用途 |
|-----------|---------|
| **Python 3.8+** | 核心语言 |
| **Requests** | 用于所有 Web 交互的 HTTP 客户端 |
| **BeautifulSoup4** | 用于爬虫的 HTML 解析(链接/表单提取) |
| **Jinja2** | 用于 HTML 报告生成的模板引擎 |
| **Colorama** | 跨平台的彩色终端输出 |
| **ssl** (stdlib) | TLS 证书和加密套件分析 |
| **socket** (stdlib) | 用于协议检查的低层连接测试 |
| **argparse** (stdlib) | 带有同意强制执行的 CLI 参数解析 |
## 安装说明
### 前置条件
- Python 3.8 或更高版本
- pip 包管理器
### 设置
```
# Clone repository
git clone https://github.com/Ashishdev13/web-vulnerability-scanner.git
cd web-vulnerability-scanner
# Install dependencies
pip install -r requirements.txt
```
### 快速验证
```
# Show help
python -m scanner --help
# Test consent rejection (should refuse without --consent)
python -m scanner --url https://example.com
```
## 运行 Naabu
```
# Basic scan (--consent is REQUIRED)
python -m scanner --url https://example.com --consent
# Custom rate limit (10 requests/second)
python -m scanner --url https://example.com --consent --rate-limit 10
# Save reports to custom directory
python -m scanner --url https://example.com --consent --output-dir ./my-reports
# Use a custom wordlist for directory brute-forcing
python -m scanner --url https://example.com --consent --wordlist ./custom-paths.txt
```
### CLI 选项
| 标志 | 短选项 | 描述 | 默认值 |
|------|-------|-------------|---------|
| `--url` | `-u` | 要扫描的目标 URL | **必需** |
| `--consent` | `-c` | 确认你拥有扫描授权 | **必需** |
| `--rate-limit` | `-r` | 每秒最大请求数 | `5` |
| `--output-dir` | `-o` | 报告输出目录 | `reports/` |
| `--wordlist` | `-w` | 自定义字典文件路径 | 内置 (130 条路径) |
### 报告
扫描结果保存在 `reports/` 目录中,有两种格式:
| 格式 | 文件 | 用例 |
|--------|------|----------|
| **JSON** | `scan_YYYYMMDD_HHMMSS.json` | 机器可读,CI/CD 集成,进一步分析 |
| **HTML** | `scan_YYYYMMDD_HHMMSS.html` | 人工可读报告,带有样式化的严重性仪表板 |
### 严重性级别
| 级别 | 描述 |
|-------|-------------|
| **Critical** | 即时利用风险 - SQL injection,过期证书 |
| **High** | 重大安全风险 - XSS,弱 SSL,缺少 HTTPS |
| **Medium** | 中等风险 - 缺少 CSP,开放重定向,暴露的敏感文件 |
| **Low** | 轻微问题 - 信息泄露,缺少可选头 |
| **Info** | 信息性 - 服务器版本详情,使用的协议 |
## 测试
本项目包含一个全面的 **pytest** 测试套件,覆盖所有模块,重点关注安全关键代码路径和代码审查期间发现的每个 Bug 的回归测试。
### 快速开始
```
# Install test dependencies
pip install -r requirements-dev.txt
# Run all tests
pytest
# Run with coverage report
pytest --cov=scanner --cov-report=term-missing
```
### 覆盖率摘要
| 模块 | 覆盖率 | 关键测试 |
|--------|----------|-----------|
| `config.py` | 100% | Severity 枚举值,Payload 列表,常量类型 |
| `utils.py` | 100% | URL 规范化,安全请求错误处理,Finding 工厂 |
| `reporter.py` | 100% | JSON 结构,严重性排序,**内联 HTML 中的 XSS 转义** |
| `headers.py` | 100% | 缺失的头,弱 CSP,弱 X-Frame-Options,信息泄露 |
| `cookies.py` | 98% | 标志解析,**多个 Set-Cookie 头捕获** |
| `rate_limiter.py` | 98% | 速率延迟,超时默认值,HTTP 方法委托 |
| `crawler.py` | 96% | BFS 深度限制,表单提取,链接规范化 |
| `dirbrute.py` | 96% | 字典加载,状态分类,**敏感路径精确匹配** |
| `open_redirect.py` | 96% | 重定向检测,URL 参数测试,常见路径 |
| `sqli.py` | 95% | 字面量匹配,**正则签名匹配**,表单 POST/GET |
| `xss.py` | 94% | 反射 Payload 检测,表单和 URL 参数测试 |
| `ssl_checker.py` | 78% | 过期/即将过期证书,自签名,弱协议 |
| `main.py` | 49% | URL 验证,同意关卡,CLI 参数 |
| **总体** | **87%** | **149 个测试,全部通过** |
### 安全关键测试
这些测试验证了代码审查期间发现的漏洞修复:
- **SQLi 正则签名回归** - 诸如 `sql syntax.*mysql` 的模式使用 `re.search()` 匹配,而不是错误的字面量 `in` 操作符
- **内联报告中的 XSS 转义** - 诸如 `` 的恶意目标 URL 在后备报告中被 HTML 转义
- **多个 Set-Cookie 头** - 通过原始头捕获所有 Cookie,而不仅仅是 `resp.headers.get()` 中的第一个
- **敏感路径精确匹配** - `config` 不再对 `/reconfiguration` 产生误报,`db` 不再匹配 `/debug`
## 项目结构
```
web-vulnerability-scanner/
├── scanner/
│ ├── __init__.py # Package init
│ ├── __main__.py # Package entry point (python -m scanner)
│ ├── main.py # CLI, consent check, 8-phase scan orchestration
│ ├── config.py # Payloads, signatures, severity enum, constants
│ ├── crawler.py # BFS web crawler (depth 3, link + form extraction)
│ ├── rate_limiter.py # Token-bucket rate limiter wrapping requests.Session
│ ├── reporter.py # JSON + HTML report generation
│ ├── utils.py # URL helpers, safe request wrapper, finding factory
│ └── modules/
│ ├── sqli.py # SQL Injection testing (15 payloads, 19 error sigs)
│ ├── xss.py # Reflected XSS testing (12 payloads)
│ ├── open_redirect.py # Open redirect detection (20 param names)
│ ├── headers.py # Security header analysis (7 headers)
│ ├── dirbrute.py # Directory brute-forcing (130 paths)
│ ├── cookies.py # Cookie flag checker (HttpOnly/Secure/SameSite)
│ └── ssl_checker.py # SSL/TLS cert + protocol + cipher analysis
├── tests/
│ ├── conftest.py # Shared fixtures (mock_session, mock_response, etc.)
│ ├── test_config.py # Severity enum, payload lists, constant types
│ ├── test_utils.py # URL normalization, safe request, finding factory
│ ├── test_crawler.py # BFS depth limit, form/link extraction
│ ├── test_rate_limiter.py # Rate limiting, HTTP method delegation
│ ├── test_sqli.py # SQL injection detection + regex regression
│ ├── test_xss.py # Reflected XSS detection
│ ├── test_cookies.py # Cookie flags + multi-header regression
│ ├── test_headers.py # Missing headers, weak CSP, info disclosure
│ ├── test_dirbrute.py # Wordlist loading + sensitive path regression
│ ├── test_open_redirect.py # Redirect detection, URL param testing
│ ├── test_ssl_checker.py # Cert validation, weak protocols
│ ├── test_reporter.py # JSON/HTML output + XSS escape regression
│ └── test_main.py # URL validation, consent gate, CLI args
├── wordlists/
│ └── common_paths.txt # Directory brute-force wordlist
├── templates/
│ └── report_template.html # Jinja2 dark-themed HTML report template
├── reports/ # Generated reports (gitignored)
├── requirements.txt
├── requirements-dev.txt # Test dependencies (pytest, pytest-cov)
├── pytest.ini # Pytest configuration
├── .gitignore
└── README.md
```
## 免责声明
- 本扫描器旨在帮助安全学生、渗透测试人员和开发人员了解常见的 Web 漏洞及其检测方式。
- 在扫描任何系统之前,你**必须获得**系统所有者的明确书面许可。`--consent` 标志的存在是为了强化这一要求。
- **未经授权的扫描是非法的**,依据包括《计算机欺诈与滥用法》(CFAA)、《计算机滥用法》以及全球类似的立法。
- 作者对因使用本工具而产生的任何误用、损害或法律后果**不承担任何责任**。
- 本工具**不能替代**专业的安全评估。请使用 Burp Suite、OWASP ZAP 或 Nessus 等成熟工具进行生产环境安全测试。
- 切勿对你不拥有或未获得测试授权的系统使用本工具。
**使用本工具即表示你同意自行承担你的行为责任。**
## 许可证
本项目根据 MIT 许可证授权。有关详细信息,请参阅 [LICENSE](LICENSE)。
为了通过动手工具开发来学习进攻性安全概念而构建。
标签:CISA项目, Cookie安全检测, DOE合作, MIT协议, OWASP Top 10, Python安全工具, SQL注入检测, SSL/TLS弱点检测, Web安全扫描器, XSS跨站脚本攻击, 代码生成, 字符串匹配, 安全头部分析, 开放重定向检测, 渗透测试工具, 爬虫与注入, 目录枚举, 移动安全, 网络安全, 迷你Burp Suite, 逆向工具, 隐私保护