Mr20x20/pyshield-web-scanner

GitHub: Mr20x20/pyshield-web-scanner

一款 Python 编写的 Web 错误配置扫描器,检测目标 URL 的敏感文件暴露、安全标头缺失、TLS 证书问题及目录列表等常见安全弱点并输出风险评分报告。

Stars: 0 | Forks: 0

# 🌐 PyShield Web 安全扫描器 一款 Web 错误配置扫描器,用于检查目标 URL 是否存在常见的安全弱点——包括暴露的敏感文件、缺失的安全标头、TLS 证书问题以及目录列表。它是 **PyShield** 安全生态系统的一部分。 ## 📸 示例输出 ``` ============================================================ PyShield Web Security Scanner — Results ============================================================ Target : https://example.com Risk Score : 50 Risk Level : HIGH ------------------------------------------------------------ Findings : 7 total | CRITICAL:0 HIGH:2 MEDIUM:2 LOW:3 ------------------------------------------------------------ Server : cloudflare Page Title : Example Domain ------------------------------------------------------------ FINDINGS: [HIGH ] Missing: HSTS — forces HTTPS connections [HIGH ] Missing: CSP — prevents XSS and injection attacks [MEDIUM ] Missing: Prevents clickjacking attacks [LOW ] Information disclosure: Reveals web server software ============================================================ ``` ## 🏗️ 架构 ``` Target URL │ ▼ ┌─────────────────┐ │ http_client.py │ Centralized HTTP session, response wrapper └────────┬────────┘ │ ▼ ┌─────────────────┐ │ discovery.py │ robots.txt, sitemap.xml, tech detection └────────┬────────┘ │ ▼ ┌─────────────────────────────────────────────┐ │ checks/ │ │ ┌─────────────────┐ ┌──────────────────┐ │ │ │ exposed_files.py│ │ headers.py │ │ │ │ .env, .git, │ │ CSP, HSTS, │ │ │ │ phpinfo, admin │ │ X-Frame-Options │ │ │ └─────────────────┘ └──────────────────┘ │ │ ┌─────────────────┐ ┌──────────────────┐ │ │ │ tls.py │ │ directory.py │ │ │ │ cert expiry, │ │ listing enabled │ │ │ │ self-signed │ │ on directories │ │ │ └─────────────────┘ └──────────────────┘ │ └────────────────────┬────────────────────────┘ │ ▼ ┌─────────────────────┐ │ risk_engine.py │ Weighted scoring → risk level └──────────┬──────────┘ │ ▼ ┌─────────────────────┐ │ reporter.py │ JSON report + terminal summary └──────────┬──────────┘ │ ▼ web_scan_report.json ←── PyShield SIEM Dashboard ``` ## 🔍 检查项目 ### 暴露的敏感文件(40 个路径) 绝对不应公开访问的文件: | 路径 | 风险 | 危险原因 | |---|---|---| | `/.env` | 严重 | 包含数据库密码、API 密钥 | | `/.git/config` | 严重 | 暴露源代码仓库 | | `/phpinfo.php` | 高 | 泄露 PHP 配置、服务器路径 | | `/wp-admin/` | 高 | WordPress 管理面板 | | `/phpmyadmin/` | 高 | 数据库管理界面 | | `/backup.sql` | 中 | 数据库转储文件 | | `/robots.txt` | 低 | 暴露隐藏路径 | ### 安全标头 保护用户免受常见攻击的标头: | 标头 | 缺失 = 风险 | |---|---| | `Strict-Transport-Security` | 允许 HTTP 降级攻击 | | `Content-Security-Policy` | XSS 攻击没有浏览器防御 | | `X-Frame-Options` | 可能发生 Clickjacking 攻击 | | `X-Content-Type-Options` | MIME 嗅探攻击 | 不应存在的标头: | 标头 | 风险 | |---|---| | `Server: nginx/1.18.0` | 告知攻击者可搜索的确切 CVE | | `X-Powered-By: PHP/8.1` | 暴露后端技术 | ### TLS 证书 - 证书过期(30 天时警告,7 天时严重) - 主机名不匹配 - 自签名证书检测 ### 目录列表 检查 12 个常见目录是否启用了列表——如果 `/uploads/` 显示了其内容,攻击者就可以枚举所有上传的文件。 ## 🚀 快速开始 ### 1. 克隆仓库 ``` git clone https://github.com/Mr20x20/pyshield-web-scanner.git cd pyshield-web-scanner ``` ### 2. 创建虚拟环境 ``` python -m venv venv # Windows venv\Scripts\activate # Linux / macOS source venv/bin/activate ``` ### 3. 安装依赖 ``` pip install -r requirements.txt ``` ### 4. 运行扫描 ``` # 扫描任何目标 URL python run.py https://example.com # HTTP 目标 python run.py http://192.168.1.1 # 本地开发服务器 python run.py http://127.0.0.1:8080 ``` ## 📁 项目结构 ``` pyshield-web-scanner/ ├── run.py # Entry point — orchestrates full pipeline ├── http_client.py # Centralized HTTP client + response wrapper ├── discovery.py # Endpoint discovery and tech detection ├── risk_engine.py # Scoring engine + risk level assessment ├── reporter.py # Terminal summary + JSON report writer ├── config.py # All settings, paths, and rules in one place ├── checks/ │ ├── exposed_files.py # Sensitive file/directory checks (threaded) │ ├── headers.py # Security header analysis │ ├── tls.py # TLS/SSL certificate validation │ └── directory.py # Directory listing detection (threaded) ├── requirements.txt └── reports/ # Auto-created — scan output └── web_scan_report.json ``` ## ⚙️ 配置 `config.py` 中的所有设置: | 设置 | 默认值 | 描述 | |---|---|---| | `REQUEST_TIMEOUT` | 3秒 | 单次请求超时 | | `USER_AGENT` | PyShield-Scanner/1.0 | 扫描器标识 | | `TLS_EXPIRY_WARNING` | 30 天 | 证书过期前警告 | | `TLS_EXPIRY_CRITICAL` | 7 天 | 严重证书过期阈值 | ## 📊 风险评分 | 严重性 | 分数 | 示例 | |---|---|---| | 严重 | +25 | `.env` 文件暴露 | | 高 | +15 | 缺失 HSTS 标头 | | 中 | +7 | 缺失 X-Frame-Options | | 低 | +2 | 存在 Server 标头 | | 总分 | 风险等级 | |---|---| | 0 | 安全 | | 1–10 | 低 | | 11–30 | 中 | | 31–60 | 高 | | 60+ | 严重 | ## 🔗 SIEM 集成 输出的 `web_scan_report.json` 兼容 [PyShield Dashboard](https://github.com/Mr20x20/PyShield_Dashboard) 流水线,可用作传感器源。 ## 🛠️ 技术栈 - **语言:** Python 3.11+ - **HTTP:** `requests` - **TLS:** Python `ssl`(标准库) - **并发:** `concurrent.futures.ThreadPoolExecutor` ## 🔐 法律与道德声明 仅扫描您拥有或获得**明确书面授权**进行测试的系统。 未经授权的扫描在您所在的司法管辖区可能是非法的。 ## 📜 许可证 MIT 许可证 — 详情请参阅 [LICENSE](LICENSE)。 ## 👤 作者 **Mr20x20** — 网络与安全爱好者 GitHub: [github.com/Mr20x20](https://github.com/Mr20x20) ## 🔗 相关项目 - [PyShield Dashboard](https://github.com/Mr20x20/PyShield_Dashboard) — 实时 SIEM 仪表板 - [PyShield Honeypot](https://github.com/Mr20x20/pyshield-honeypot) — 攻击者分析器 - [PyShield Threat Intel](https://github.com/Mr20x20/pyshield-threat-intel) — CVE 漏洞扫描器
标签:GraphQL安全矩阵, Python, Web安全, 主机安全, 安全扫描器, 无后门, 构建工具, 蓝队分析, 逆向工具