mahesh-tools/websec

GitHub: mahesh-tools/websec

WebSec 是一款模块化 CLI 工具,通过被动和半被动方式审计 Web 目标的安全态势,快速生成易读的多格式安全报告。

Stars: 0 | Forks: 0

🔒 WebSec

Web 漏洞与安全态势扫描器

一款快速、模块化的 CLI 工具,用于审计 Web 目标的安全态势。

## 概述 WebSec 是一款命令行安全扫描器,可对 Web 目标执行被动和半被动分析。它专为安全专业人员、学生和 CTF 参与者设计,帮助他们在不部署主动利用 payload 的情况下,快速生成站点安全态势的易读报告。 WebSec 专为**授权的渗透测试项目**、**CEH 实践实验室**、**CTF 挑战**和**漏洞赏金侦察**而打造。 ## 功能 | 模块 | 检查内容 | |---|---| | `headers` | HTTP 安全头(CSP、HSTS、X-Frame-Options 等)的存在性与强度 | | `ssl` | 证书有效性、过期时间、协议版本、加密强度、自签名检测 | | `ports` | 常见开放端口(21、22、23、80、443、3306、6379、9200、27017 等) | | `cookies` | 对所有设置的 cookie 进行 Secure、HttpOnly、SameSite 标志分析 | | `cors` | CORS 来源反射、通配符策略、null 来源、凭据泄漏 | | `dns` | A/MX/NS/TXT 记录、SPF/DMARC 存在性、区域传送(AXFR)尝试 | | `redirect` | HTTP→HTTPS 重定向链、重定向代码正确性、开放重定向参数 | ## 安装说明 ### 前置条件 - Python 3.10+ - `dig` 和 `whois` 系统工具(可选 — 可增强 DNS 模块) ``` # 1. Clone 仓库 git clone https://github.com/YOUR_USERNAME/websec.git cd websec # 2. 安装 Python 依赖 pip install -r requirements.txt # 3. (可选)安装系统工具 # Ubuntu/Debian: sudo apt install dnsutils whois -y # macOS: brew install bind whois ``` ## 运行说明 ``` python3 websec.py -t [options] ``` ### 基础示例 ``` # 按域名扫描 python3 websec.py -t google.com # 按完整 URL 扫描 python3 websec.py -t https://example.com # 详细输出(显示每个 finding 的 evidence) python3 websec.py -t example.com -v # 仅运行特定模块 python3 websec.py -t example.com -m headers,ssl,cookies # 完整扫描 — 所有模块 python3 websec.py -t example.com --full-scan # 保存 HTML 报告 python3 websec.py -t example.com -o report.html --format html # 保存 JSON 报告(用于集成/自动化) python3 websec.py -t example.com -o report.json --format json # 无颜色(用于将输出 pipe 到文件) python3 websec.py -t example.com --no-color > scan.txt # 自定义 timeout 和 thread 数 python3 websec.py -t example.com --timeout 15 --threads 10 ``` ### 所有选项 ``` Options: -t, --target Target domain or URL (required) -m, --modules Comma-separated modules: headers,ssl,ports,cookies,cors,dns,redirect -o, --output Output file path for report --format Report format: txt | html | json (default: txt) --full-scan Run all modules --timeout Request timeout in seconds (default: 10) --threads Threads for port scan (default: 5) -v, --verbose Show evidence per finding --no-color Disable ANSI color --version Show version -h, --help Show help ``` ## 输出示例 ``` ██╗ ██╗███████╗██████╗ ███████╗███████╗ ██████╗ ██║ ██║██╔════╝██╔══██╗██╔════╝██╔════╝██╔════╝ ██║ █╗ ██║█████╗ ██████╔╝███████╗█████╗ ██║ ██║███╗██║██╔══╝ ██╔══██╗╚════██║██╔══╝ ██║ ╚███╔███╔╝███████╗██████╔╝███████║███████╗╚██████╗ ╚══╝╚══╝ ╚══════╝╚═════╝ ╚══════╝╚══════╝ ╚═════╝ Web Vulnerability & Security Scanner Version 1.0.0 Target : https://example.com Modules : all Started : 2025-06-15 14:22:01 ──────────────────────────────────────────────────────────── [~] Running module: HEADERS → 6 findings (1.3s) [2 high/critical] [~] Running module: SSL → 4 findings (0.8s) [~] Running module: PORTS → 3 findings (4.1s) [1 high/critical] [~] Running module: COOKIES → 3 findings (0.6s) [2 high/critical] [~] Running module: CORS → 1 findings (0.9s) [~] Running module: DNS → 7 findings (2.2s) [1 high/critical] [~] Running module: REDIRECT → 1 findings (0.5s) ──────────────────────────────────────────────────────────── FINDINGS [HIGH] [HTTP Headers] Missing Header: Content-Security-Policy CSP missing — increases risk of XSS and data injection attacks. → Define a strict Content-Security-Policy header. [HIGH] [HTTP Headers] Missing Header: Strict-Transport-Security HSTS not set — vulnerable to protocol downgrade and MITM. → Add: Strict-Transport-Security: max-age=31536000; includeSubDomains [MEDIUM] [HTTP Headers] Missing Header: X-Frame-Options Site may be vulnerable to clickjacking. → Add: X-Frame-Options: DENY ... ══════════════════════════════════════════════════════════════ Scan completed in 10.4s Total findings : 25 Critical=0 High=6 Medium=8 Low=4 Info=7 ══════════════════════════════════════════════════════════════ ``` ## 报告格式 WebSec 支持三种输出格式: - **TXT** — 纯文本,适用于日志记录和管道传输 - **HTML** — 带有严重性颜色编码的深色主题可视化报告 - **JSON** — 机器可读格式,适用于 CI/CD pipeline 和集成 ## 模块详情 ### `headers` — HTTP 安全头 检查 8 个安全头,包括 CSP、HSTS、X-Frame-Options、X-Content-Type-Options、Referrer-Policy、Permissions-Policy、X-XSS-Protection、Cache-Control。同时检测弱 CSP 指令(`unsafe-inline`、通配符)和信息泄漏头(`Server`、`X-Powered-By`)。 ### `ssl` — SSL/TLS 分析 验证证书链,检查过期时间(<30 天时发出警告,如已过期则标记为严重),检测已废弃的协议(TLS 1.0/1.1、SSLv3)、弱密码(<128 位)以及自签名证书。 ### `ports` — 端口扫描器 使用并发 TCP socket 扫描 27 个常见端口。标记危险服务:Telnet (23)、SMB (445)、RDP (3389)、Redis (6379)、MongoDB (27017)、Elasticsearch (9200)、Jupyter (8888)。 ### `cookies` — Cookie 安全 检查每个 `Set-Cookie` 头是否缺少 `Secure`、`HttpOnly` 和 `SameSite` 标志。检测不含 `Secure` 的 `SameSite=None`。 ### `cors` — CORS 策略 使用攻击者控制的来源(`evil.com`、`null`、`attacker.example.com`)进行探测,以检测来源反射、通配符策略以及通过 `Access-Control-Allow-Credentials` 造成的凭据泄漏。 ### `dns` — DNS 侦察 解析 A/AAAA、MX、NS、TXT 记录。检查 SPF 和 DMARC 记录。在发现的名称服务器上尝试进行 AXFR 区域传送。 ### `redirect` — 重定向分析 检查 HTTP→HTTPS 重定向的正确性(301 与 302),并被动检测 URL 中的开放重定向参数(`url=`、`redirect=`、`next=`、`goto=`、`dest=`)。 ## 架构 ``` websec/ ├── websec.py ← Entry point / CLI ├── core/ │ ├── banner.py ← ASCII banner │ └── scanner.py ← Module orchestrator ├── modules/ │ ├── headers.py ← HTTP headers audit │ ├── ssl_check.py ← SSL/TLS analysis │ ├── ports.py ← Port scanner │ ├── cookies.py ← Cookie flags │ ├── cors.py ← CORS detection │ ├── dns_recon.py ← DNS recon │ └── redirect_check.py ← Redirect analysis ├── reports/ │ └── reporter.py ← TXT / HTML / JSON output ├── utils/ │ ├── colors.py ← ANSI color helpers │ ├── validator.py ← URL/target validation │ └── logger.py ← Logging setup ├── requirements.txt ├── setup.py └── README.md ``` ## 道德与法律声明 ## 许可证 MIT © WebSec
标签:Python, Web安全, 实时处理, 插件系统, 无后门, 聊天机器人, 蓝队分析