使用170多条规则在源代码、Web URL和CI/CD中查找凭据和密钥,对照供应商API进行验证,并生成SARIF、JSONL、HTML、PDF或Excel报告。
DAST + SAST 密钥扫描器,具备实时验证、source-map 解析和 CI 原生报告功能,外加一个 SAST 漏洞与错误配置引擎。
在源代码树、运行中的 Web 应用和 CI 日志中查找泄露的凭据。针对供应商 API 进行实时验证。扫描相同的源代码树以查找代码漏洞和错误配置。输出 SARIF 用于代码扫描仪表板,JSONL 用于 SOAR 流水线,或 Excel/PDF/HTML 用于客户报告。
拥挤的领域(gitleaks、trufflehog、detect-secrets)在 git 树上的 SAST 方面表现出色,但仅止步于此——而且它们只扫描密钥。scan4secrets 填补了它们未覆盖的空白,在密钥检测之上增加了实时 Web DAST、实时供应商验证以及代码漏洞/错误配置引擎:
| 能力 | gitleaks | trufflehog | detect-secrets | scan4secrets |
|---|---|---|---|---|
| SAST 密钥检测 | Y | Y | Y | Y |
| DAST 实时 Web 爬取 | - | - | - | Y |
| JS source-map 解析 | - | - | - | Y |
| JS 端点提取 | - | - | - | Y |
| HTTP 头密钥扫描 | - | - | - | Y |
| 实时令牌验证 | - | Y | - | Y |
| SARIF 输出 | Y | - | - | Y |
| Excel / PDF / HTML 报告 | - | - | - | Y |
| 熵门控 + 允许列表 | Y | Y | Y | Y |
| YAML 规则模式 | - (TOML) | - | - | Y |
| 认证 DAST(cookie/header/proxy) | n/a | n/a | n/a | Y |
| SAST 漏洞 / 错误配置检测 | - | - | - | Y |
它是 gitleaks 的补充,而非替代品。两者结合使用:在 pre-commit + CI 中使用 gitleaks 进行 git 历史 SAST,使用 scan4secrets 对 staging/production 进行实时 DAST。
# from source
git clone https://github.com/m14r41/scan4secrets
cd scan4secrets
pip install -e .
# OR via pipx
pipx install git+https://github.com/m14r41/scan4secrets
# OR Docker
docker run --rm -v $(pwd):/scan ghcr.io/m14r41/scan4secrets:latest --path /scan
安装后,scan4secrets 命令即可在 PATH 中使用。
# SAST: scan a local directory
scan4secrets --path /code
# DAST: crawl a live target
scan4secrets --url https://staging.example.com --threads 32
# DAST runs ALL bundled wordlists by default (1279 paths: /.env, /wp-config.php, /backup.zip, ...)
scan4secrets --url https://target.com
# Use YOUR OWN wordlist file (replaces the bundled set)
scan4secrets --url https://target.com --wordlist /path/to/my-paths.txt
# Combine multiple custom wordlist files
scan4secrets --url https://target.com --wordlist seclists/Common.txt internal-paths.txt
# Restrict to specific bundled wordlists by stem
scan4secrets --url https://wp.example.com --wordlist-only wordpress common env
# Turn wordlist seeding off entirely (only follow live links)
scan4secrets --url https://target.com --no-wordlist
# Full audit with verification + HTML report
scan4secrets --path . --url https://app.example.com \
--verify --report html sarif json \
--output reports/audit-$(date +%F)
# Authenticated DAST with proxy (works with Burp / ZAP)
scan4secrets --url https://app.example.com \
--cookie "session=abc123" \
--header "X-Tenant: acme" \
--proxy http://127.0.0.1:8080
# CI gate (exit 1 if anything >= high)
scan4secrets --path . --report sarif --fail-on high \
--output reports/scan
# SAST: secrets + code vulnerabilities / misconfigurations
scan4secrets --path ./src --misconfig
# SAST: vulnerabilities / misconfigurations only (skip secret detection)
scan4secrets --path ./src --misconfig-only
--misconfig)除了密钥之外,scan4secrets 还附带一个用于代码漏洞和错误配置的 SAST 引擎。添加 --misconfig 可同时扫描密钥和漏洞,或使用 --misconfig-only 仅扫描漏洞:
scan4secrets --path ./src --misconfig # secrets + vulnerabilities
scan4secrets --path ./src --misconfig-only # vulnerabilities only
scan4secrets --path . --misconfig --report html --output report
它通过污点/上下文门控来保持低误报率,可检测——SQL 注入、NoSQL 注入、操作系统命令注入、代码注入(eval)、SSTI、XXE、不安全反序列化、LFI / 路径遍历、LDAP 与 XPath 注入、SSRF、开放重定向、CORS 错误配置、CSRF 禁用、原型污染、XSS(跨 11 种模板引擎的反射型/存储型/DOM 型:EJS、Handlebars、Pug、Jinja、Thymeleaf、Razor、Blade、ERB、Vue、Angular、React)、弱加密(DES/RC4/ECB/静态 IV/弱 RSA)、不安全随机性、JWT 缺陷(alg:none、算法混淆、硬编码签名密钥、验证禁用)、TLS 绕过、时序不安全的密钥比较、SAML 签名非必需、硬编码凭据、敏感数据日志记录,以及 IaC/配置错误配置(Terraform、Kubernetes、Dockerfile、GitHub Actions、ASP.NET web.config、WCF/SOAP)。
涵盖的语言:python、node、javascript、typescript、react、php、ruby、go、java、kotlin、csharp/.NET、sql,以及 XML/WSDL、JSP、Terraform/HCL、Kubernetes YAML 和 Dockerfile。
每个漏洞发现都带有丰富的记录:漏洞名称、严重性、描述、证据(文件:行号)、易受攻击的代码、安全代码、修复建议、技术影响、业务影响,以及 CWE + OWASP Top-10 映射。
除了逐行引擎之外,整文件扫描还能捕获行扫描器遗漏的密钥:嵌套 XML 标签(<SMS_API_KEY><value>…</value></SMS_API_KEY>)、拆分的 <key>/<value> 对、JSON 键/值对象、多行 YAML/properties,以及 Base64 编码的密钥。它还弥补了熵门控的一个盲点——以凭据命名的赋值(例如 AM_CLIENT_SECRET=…)会基于名称信号被标记,且没有熵下限,因此真实的低熵密钥不再被静默丢弃。
共 416 条规则——193 条密钥规则 + 223 条漏洞/错误配置规则。
密钥规则涵盖:
完整参考以及如何添加自定义规则,请参见 docs/rules-engine.md。
使用 --verify 时,scan4secrets 会针对每个检测到的令牌向供应商 API 发起一次 HTTP 请求,以确认该凭据是否仍然有效:
| 规则 | 探测 | 成功 |
|---|---|---|
github-pat-classic / github-pat-fine-grained | GET https://api.github.com/user | HTTP 200 |
stripe-secret-live | GET https://api.stripe.com/v1/charges?limit=1 | HTTP 200 |
slack-bot-token | POST https://slack.com/api/auth.test | HTTP 200 |
openai-key | GET https://api.openai.com/v1/models | HTTP 200 |
每个发现都会在每种输出格式中获得 verified=true|false|null。已验证的令牌是事件级证据;未验证的则是一种假设。
完整的供应商列表以及如何添加探测,请参见 docs/verification.md。
scan4secrets --path . --report sarif json jsonl csv html excel pdf --output reports/run
| 格式 | 最适合 |
|---|---|
sarif | GitHub Code Scanning、GitLab Security Dashboard、Sonar、Defect Dojo |
json | 工具集成、后处理 |
jsonl | SIEM/SOAR 流水线(Splunk、Datadog、Sentinel) |
csv | 电子表格分类 |
html | 用于客户审查的可折叠、可展开发现卡片 |
excel | 数据透视表和执行摘要 |
pdf | 合规证据包 |