UPinar/contrastscan

GitHub: UPinar/contrastscan

一款用 C 语言编写的高速网站安全评级扫描器,覆盖十一项安全检测并以百分制给出直观的 A-F 评级。

Stars: 0 | Forks: 0

# ContrastScan [![Tests](https://static.pigsec.cn/wp-content/uploads/repos/2026/03/3cbcd7eceb155624.svg)](https://github.com/UPinar/contrastscan/actions/workflows/tests.yml) [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE) [![Python 3.12](https://img.shields.io/badge/Python-3.12-blue.svg)](https://python.org) [![C](https://img.shields.io/badge/Scanner-C-00599C.svg)](scanner/src/contrastscan.c) **免费的安全扫描器,可为任何网站评出 A-F 的安全等级。** 11 项检测,100 分制评分,单一 JSON 输出。无需注册,无需 API 密钥。 **在线演示:** [contrastcyber.com](https://contrastcyber.com) | **API 平台:** [api.contrastcyber.com](https://api.contrastcyber.com) | **博客文章:** [Dev.to](https://dev.to/upinar/i-built-a-security-scanner-in-c-that-grades-any-website-a-f-heres-how-dbj) ![安全评级](https://contrastcyber.com/badge/contrastcyber.com.svg) ## 为什么选择 ContrastScan? - **一个评级,而非长篇大论** — 扫描任何域名,在 3 秒内获得单一的 A-F 评分 - **使用 C 语言编写** — 原生 TLS 握手,直接 DNS 查询,无运行时开销 - **支持自托管** — `git clone && bash setup.sh` 即可完成 - **永久免费** — 无需注册,无需 API 密钥,每小时 100 次请求 ## 快速开始 ### 命令行界面 (CLI) ``` make ./contrastscan example.com ``` ``` { "domain": "example.com", "total_score": 85, "max_score": 100, "grade": "B", "headers": { "score": 21, "max": 25 }, "ssl": { "score": 20, "max": 20 }, "dns": { "score": 15, "max": 15 }, "redirect": { "score": 8, "max": 8 }, "disclosure": { "score": 5, "max": 5 }, "cookies": { "score": 5, "max": 5 }, "dnssec": { "score": 0, "max": 5 }, "methods": { "score": 5, "max": 5 }, "cors": { "score": 5, "max": 5 }, "html": { "score": 5, "max": 5 }, "csp_analysis": { "score": 1, "max": 2 } } ``` ### Web 应用 ``` git clone https://github.com/UPinar/contrastscan.git cd contrastscan bash setup.sh source venv/bin/activate && cd app && uvicorn main:app --host 0.0.0.0 --port 8000 ``` 在浏览器中打开 `http://localhost:8000`。 ## API 免费,无需密钥 — 每个 IP 每小时 100 次请求。 ``` # JSON 扫描 curl "https://contrastcyber.com/api/scan?domain=example.com" # 纯文本报告 curl "https://contrastcyber.com/api/report?domain=example.com" -o report.txt # 批量扫描 curl -X POST "https://contrastcyber.com/api/bulk" \ -H "Content-Type: application/json" \ -d '{"domains": ["example.com", "google.com"]}' # Grade badge (用于你的 README) # ![Security](https://contrastcyber.com/badge/yourdomain.com.svg) ``` | 端点 | 描述 | |----------|-------------| | `GET /api/scan?domain=X` | 包含检测结果的 JSON 扫描结果 | | `GET /api/report?domain=X` | 可下载的文本报告 | | `POST /api/bulk` | 批量扫描(JSON 或 CSV 上传) | | `GET /api/recon/{scan_id}` | 被动侦察结果 | | `GET /badge/{domain}.svg` | 动态 SVG 评级徽章 | ### 频率限制 | 限制 | 值 | |-------|-------| | 每 IP | 100/小时 | | 每域名 | 10/小时 | ## 扫描器(11 个模块,100 分) | 模块 | 最高分 | 检测内容 | |--------|-----|----------------| | 安全响应头 | 25 | CSP, HSTS, X-Content-Type-Options, X-Frame-Options, Referrer-Policy, Permissions-Policy | | SSL/TLS | 20 | TLS 版本、密码强度、证书有效性及链验证 | | DNS 安全 | 15 | SPF, DKIM(基于 MX 的提供商检测 + 日期探测), DMARC | | HTTP 重定向 | 8 | HTTP 到 HTTPS 的强制执行 | | 信息泄露 | 5 | Server / X-Powered-By 响应头暴露 | | Cookie 安全 | 5 | Secure, HttpOnly, SameSite 标志 | | DNSSEC | 5 | DNSKEY 记录是否存在 | | HTTP 方法 | 5 | TRACE, PUT, DELETE 检测 | | CORS | 5 | 通配符来源、凭证泄露 | | HTML 分析 | 5 | 混合内容、内联脚本、SRI | | CSP 深度分析 | 2 | unsafe-inline, unsafe-eval, 通配符 | ### 评级标准 | 评级 | 分数 | |-------|-------| | A | 90-100 | | B | 75-89 | | C | 60-74 | | D | 40-59 | | F | 0-39 | ## Web 应用功能 - 包含严重级别和修复建议的漏洞检测结果 - 企业级检测(Google, Facebook 等) - 批量扫描(CSV/TXT 上传) - 可下载的 .txt 报告 - 动态 SVG 评级徽章 - 包含评级分布的统计仪表板 - 被动侦察(WHOIS、技术栈、WAF、子域名、CT 日志) - 子域名接管检测(30 个服务:GitHub Pages, Heroku, AWS S3, Azure, Shopify, Netlify 等) ## 安全特性 - **SSRF 防护** — 通过 CURLOPT_RESOLVE 防止 DNS 重绑定 - **基于数据库的速率限制** — IP 每小时限制存储在 SQLite 中 - **输入验证** — 空字节、unicode、格式化字符串、注入防护 - **CSRF** — Origin + Referer 请求头验证 - **私有 IP 屏蔽** — 屏蔽所有非全局 IP(RFC 1918、链路本地、共享地址空间) ## 测试 ``` bash run_tests.sh # 1046+ tests (no network) bash run_tests.sh --all # + live integration + smoke + load ``` | 套件 | 测试数 | 测试内容 | |-------|-------|------| | C 单元测试 | 194 | 评分、解析、CDN 检测 | | 后端测试 | 163 | 验证、CSRF、速率限制、结果 | | E2E 测试 | 84 | HTTP 路由、模板、扫描流程 | | 认证测试 | 15 | 速率限制、使用情况跟踪 | | 竞态测试 | 12 | 并发速率限制、数据库写入 | | 模糊测试 | 23 | 注入、SSRF 绕过、抗崩溃能力 | | 集成测试 | 53 | 模块通信、配置一致性 | | 侦察测试 | 156 | WHOIS, DNS, 技术栈、子域名、接管检测 | | 新功能测试 | 34 | 批量扫描、OpenAPI、徽章 | ## 架构 ``` contrastscan/ ├── scanner/src/contrastscan.c # C scanner engine (2,287 LOC) ├── app/ # Python FastAPI backend │ ├── main.py # Routes │ ├── config.py # Constants │ ├── db.py # SQLite (WAL mode, thread-local pool) │ ├── scanner.py # C binary execution + SSRF protection │ ├── validation.py # Domain/IP validation, CSRF │ ├── ratelimit.py # Domain rate limiting │ ├── auth.py # Rate limiting helpers │ ├── findings.py # Vulnerability analysis, enterprise detection │ ├── report.py # Plain-text report generation │ ├── recon.py # Passive recon (WHOIS, tech stack, WAF, subdomains) │ ├── templates/ # Jinja2 HTML (7 pages) │ ├── static/ # CSS, images │ └── tests/ # Python tests (921 tests) ├── tests/ # C tests (194 unit) ├── setup.sh # One-command setup ├── run_tests.sh # Run all tests ├── Makefile # C build system └── requirements.txt # Python dependencies ``` ## 技术栈 | C | Python | |---|--------| | libcurl | FastAPI | | OpenSSL | Jinja2 | | libresolv | uvicorn | | cJSON | httpx | | | dnspython | ## 许可证 MIT
标签:C++17, Cookie安全, CSP检测, DNSSEC验证, DNS安全, HTML分析, HTTP头分析, HTTP方法, HTTP重定向, Python, SSL/TLS检测, Web安全, 信息泄露检测, 内容安全策略, 单文件二进制, 安全测试工具, 安全评分系统, 实时处理, 密码管理, 开源安全工具, 插件系统, 无后门, 无服务器架构, 网站安全评估, 网络安全扫描器, 自我托管, 蓝队分析, 规则仓库, 资产安全, 跨域资源共享(CORS), 逆向工具, 逆向工程平台