HodeTech/Leakwatch

GitHub: HodeTech/Leakwatch

一款开源的高性能机密扫描器,能在代码、Git 历史、容器镜像和云存储中检测并验证泄露的 API 密钥与凭证。

Stars: 1 | Forks: 0

Leakwatch — 检测、验证并报告泄露的机密 **检测、验证并报告代码、Git 历史记录、容器和云中泄露的机密。** 开源 (MIT) · 单一二进制文件 · 为 CI 打造。 [![CI](https://static.pigsec.cn/wp-content/uploads/repos/cas/ad/ad5834178f7599af9fdda11629d49cae07f2997beec49821b2920eff5bfd50e7.svg)](https://github.com/HodeTech/Leakwatch/actions/workflows/ci.yml) [![Release](https://img.shields.io/github/v/release/HodeTech/Leakwatch?sort=semver&color=e6394d)](https://github.com/HodeTech/Leakwatch/releases/latest) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/HodeTech/leakwatch)](https://goreportcard.com/report/github.com/HodeTech/leakwatch) [![GitHub Marketplace](https://img.shields.io/badge/Marketplace-Leakwatch-2ea44f?logo=github)](https://github.com/marketplace/actions/leakwatch-secret-scanner) [快速开始](#quick-start) · [GitHub Action](#github-action) · [验证](#is-it-still-live) · [检测器](#detectors) · [文档](https://hodetech.github.io/Leakwatch/)
## 什么是 Leakwatch? 泄露的 API key、token 和密码是导致数据泄露的最常见原因之一。**Leakwatch** 可以在您的**代码库、完整 Git 历史、容器镜像和云存储**中找到它们,然后*验证每个机密是否仍然有效*,从而让您将时间花在真正的安全事件上,而不是在处理无用的干扰信息。 ``` $ leakwatch scan fs . SEVERITY DETECTOR FILE REDACTED STATUS REMEDIATION -------- -------- ---- -------- ------ ----------- CRITICAL github-token config.env ****cdEF unverified - CRITICAL database-connection-string config.env postgres://admin:****@db.prod.internal:5432/app unverified - CRITICAL aws-access-key-id config.env ****MPLE unverified - Found 3 secrets (3 critical). ``` ## 功能 - **6 种扫描源** — 文件系统、Git 历史(每一次提交)、容器镜像、AWS S3、Google Cloud Storage、Slack - **63 个内置检测器** + **YAML 自定义规则**(无需 Go 代码) - **54 个实时验证器 (85.7%)** — 确认机密是否*仍然活跃*,而不仅仅是存在 - **5 种输出格式** — JSON、SARIF、CSV、终端表格和 **GitHub 内联注解** - **即插即用的分发方式** — GitHub Action (Marketplace)、Docker 镜像、Homebrew、`go install`、单一静态二进制文件 - **机密安全** — 默认输出脱敏;机密永远不会被记录或存储 - **快速且适配 CI** — Aho-Corasick 关键字预过滤 + Shannon 熵、并发 worker pool、支持退出代码、SARIF → Code Scanning ## 快速开始 ``` # Homebrew (macOS/Linux) brew install HodeTech/tap/leakwatch # Go go install github.com/HodeTech/leakwatch@latest # Docker docker run --rm -v "$(pwd):/scan" ghcr.io/hodetech/leakwatch:latest scan fs /scan ``` …或者从 [发布页面](https://github.com/HodeTech/Leakwatch/releases) 获取预编译的二进制文件。然后: ``` leakwatch scan fs . # scan the current directory leakwatch scan git . # scan full Git history leakwatch scan image nginx:latest # scan a container image leakwatch scan fs . --format sarif -o results.sarif # SARIF for Code Scanning leakwatch scan git . --only-verified # only secrets confirmed live (CLI verifies by default) leakwatch init # generate a .leakwatch.yaml ```
更多示例 — 云端、Slack、多仓库、修复 ``` leakwatch scan s3 my-bucket --prefix config/ leakwatch scan gcs my-bucket --prefix secrets/ leakwatch scan slack --token xoxb-... --channels general,engineering leakwatch scan repos https://github.com/org/a.git https://github.com/org/b.git --parallel 5 leakwatch scan git . --since-commit HEAD~1 # only new commits (great for CI) leakwatch scan fs . --remediation # include rotation steps & doc links ```
## GitHub Action 只需一行代码即可将机密扫描添加到任何工作流中 — 已在 [GitHub Marketplace](https://github.com/marketplace/actions/leakwatch-secret-scanner) 上发布: ``` - uses: actions/checkout@v4 - uses: HodeTech/Leakwatch@v1 with: scan-type: fs # fs | git | image ``` - **`format: github`** → 扫描结果将作为**内联注解**显示在 Pull Request 上。 - **`format: sarif` + `sarif-upload: true`** → 扫描结果将显示为 **Code Scanning 警报**(需要 `permissions: security-events: write`)。 - **`scan-diff: auto`**(Git 扫描)→ 仅扫描 PR/push 引入的提交。 退出代码(用于 CI 门控):**`0`** 无发现 · **`1`** 报告了发现 · **`2`** 错误。 完整的输入和方案:**[CI/CD 集成指南](docs/guides/ci-cd-integration.md)**。 ## 它还有效吗? 检测只是工作的一半 — 已经轮换的 key 并不算安全事件。对于大多数机密类型,Leakwatch 会向提供商发起**受控的、只读的 API 调用**以确认状态: | 级别 | 含义 | 覆盖范围 | |------|---------------|----------| | **实时验证** | 只读 API 调用确认 key 处于活跃/非活跃状态 | 约 49 个检测器 | | **格式检查** | 在没有安全实时检查的情况下进行结构化验证 | 5 个检测器 | | **无法验证** | 无公开 API(如 JWT、私钥)— 已检测并需手动分类处理 | 9 个检测器 | 这相当于 **63 个检测器中有 54 个 (85.7%)** 支持验证。CLI 默认开启验证,而 Action 中默认关闭(以保持 CI 的快速和离线状态)— 可以使用 `no-verify` 切换。 ## 为什么选择 Leakwatch? | | **Leakwatch** | TruffleHog | Gitleaks | |---|---|---|---| | License | **MIT** | AGPL-3.0 | MIT [^gl] | | 实时机密验证 | **是(54 个验证器)** | 是 | 否 | | 容器镜像扫描 | **是** | 是 | 否 | | 云端来源 (S3 / GCS / Slack) | **是** | 否 | 否 | | SARIF 输出 | **是** | 否 [^th] | 是 | | 自定义规则 | **YAML** | YAML | TOML | | 单一静态二进制文件 | **是** | 是 | 是 | **简而言之:** Leakwatch 是这三者中**唯一**既拥有宽松的 MIT 许可证**又**支持实时验证的工具 — 此外还在一个零依赖的二进制文件中提供了容器和云扫描以及原生 SARIF 支持。 [^gl]: Gitleaks CLI 是 MIT 许可证;官方的 `gitleaks-action` 在商业 EULA 下运行,并且**组织**账户需要(免费)许可密钥。 [^th]: TruffleHog 输出 JSON / plain / GitHub-Actions 格式,没有原生的 SARIF 格式化程序。这三个工具都使用 Aho-Corasick 预过滤、Shannon 熵过滤,并支持自定义规则。 ## 检测器 涵盖这些类别的 **63 个内置检测器**,以及您自己的 [YAML 自定义规则](docs/guides/custom-rules.md): | 类别 | 示例 | |----------|----------| | **Cloud** | AWS, GCP, Azure, Cloudflare, DigitalOcean, Heroku, Vercel | | **AI / ML** | OpenAI, Anthropic, Hugging Face, DeepSeek | | **Dev & CI/CD** | GitHub, GitLab, npm, PyPI, RubyGems, Docker Hub, CircleCI, Terraform Cloud | | **通讯与电子邮件** | Slack, Discord, Telegram, MS Teams, SendGrid, Mailgun, Postmark | | **支付** | Stripe, Coinbase | | **数据库与基础设施** | Postgres/MySQL/Mongo, Redis, Snowflake, RabbitMQ, Supabase, FTP, LDAP, Databricks | | **身份与机密** | JWT, 私钥 (RSA/SSH/PGP), Okta, Auth0, HashiCorp Vault, Doppler | | **监控与安全** | Datadog, Grafana, PagerDuty, New Relic, Sentry, Snyk, Twilio | | **SaaS** | Shopify, Notion, Linear, Figma, Airtable | | **通用与自定义** | 高熵通用 key · LaunchDarkly · SonarCloud · 您的 YAML 规则 |
完整的检测器目录 (63),包含 ID、严重性和验证信息 | 类别 | 检测器 | ID | 严重性 | |----------|----------|----|----------| | Cloud — AWS | Access Key ID | `aws-access-key-id` | 严重 | | Cloud — GCP | Service Account Key | `gcp-service-account` | 严重 | | Cloud — Azure | Storage Connection String | `azure-storage-key` | 严重 | | Cloud — Azure | Entra ID Client Secret | `azure-entra-secret` | 严重 | | Cloud — Cloudflare | API Token | `cloudflare-api-token` | 严重 | | Cloud — DigitalOcean | Personal Access Token | `digitalocean-token` | 严重 | | Cloud — Heroku | API Key | `heroku-api-key` | 严重 | | Cloud — Vercel | API Token | `vercel-token` | 高 | | AI/ML | OpenAI API Key | `openai-api-key` | 严重 | | AI/ML | Anthropic API Key | `anthropic-api-key` | 严重 | | AI/ML | Hugging Face Token | `huggingface-token` | 严重 | | AI/ML | DeepSeek API Key | `deepseek-api-key` | 严重 | | DevTools | GitHub PAT | `github-token` | 严重 | | DevTools | GitHub OAuth Token | `github-oauth-token` | 严重 | | DevTools | GitLab PAT | `gitlab-pat` | 严重 | | DevTools | Bitbucket App Password | `bitbucket-app-password` | 严重 | | DevTools | NPM Token | `npm-token` | 高 | | DevTools | PyPI Token | `pypi-api-token` | 高 | | DevTools | RubyGems Key | `rubygems-api-key` | 高 | | DevTools | Docker Hub PAT | `dockerhub-pat` | 严重 | | CI/CD | CircleCI Token | `circleci-token` | 高 | | CI/CD | Terraform Cloud Token | `terraform-cloud-token` | 严重 | | 通讯 | Slack Bot Token | `slack-token` | 严重 | | 通讯 | Slack Webhook | `slack-webhook` | 高 | | 通讯 | Discord Bot Token | `discord-bot-token` | 严重 | | 通讯 | Telegram Bot Token | `telegram-bot-token` | 高 | | 通讯 | MS Teams Webhook | `teams-webhook` | 高 | | 电子邮件 | SendGrid API Key | `sendgrid-api-key` | 严重 | | 电子邮件 | Mailgun API Key | `mailgun-api-key` | 严重 | | 电子邮件 | Postmark Server Token | `postmark-server-token` | 高 | | 支付 | Stripe Live Key | `stripe-api-key-live` | 严重 | | 支付 | Stripe Test Key | `stripe-api-key-test` | 高 | | 支付 | Coinbase API Key | `coinbase-api-key` | 严重 | | 区块链 | Infura API Key | `infura-api-key` | 高 | | 数据库 | Connection String (PG/MySQL/MongoDB) | `database-connection-string` | 严重 | | 数据库 | Redis Connection | `redis-connection-string` | 严重 | | 数据库 | Snowflake Credentials | `snowflake-credentials` | 严重 | | 数据库 | RabbitMQ Connection | `rabbitmq-connection-string` | 严重 | | 数据库 | Supabase Service Key | `supabase-service-key` | 严重 | | 基础设施 | FTP/SFTP Credentials | `ftp-credentials` | 严重 | | 基础设施 | LDAP Credentials | `ldap-credentials` | 严重 | | 基础设施 | Databricks PAT | `databricks-token` | 严重 | | 身份 | JWT | `jwt` | 高 | | 身份 | Private Key (RSA/SSH/PGP) | `private-key` | 严重 | | 身份 | Okta API Token | `okta-api-token` | 严重 | | 身份 | Auth0 Management Token | `auth0-management-token` | 严重 | | 身份 | HashiCorp Vault Token | `hashicorp-vault-token` | 严重 | | 监控 | Datadog API Key | `datadog-api-key` | 严重 | | 监控 | Grafana API Key | `grafana-api-key` | 高 | | 监控 | PagerDuty API Key | `pagerduty-api-key` | 高 | | 监控 | New Relic API Key | `newrelic-api-key` | 高 | | 监控 | Sentry Auth Token | `sentry-token` | 高 | | 安全 | Snyk API Key | `snyk-api-key` | 高 | | 安全 | Twilio API Key | `twilio-api-key` | 严重 | | Secrets Mgmt | Doppler Service Token | `doppler-token` | 严重 | | 特性开关 | LaunchDarkly SDK Key | `launchdarkly-sdk-key` | 高 | | 代码质量 | SonarCloud Token | `sonarcloud-token` | 高 | | SaaS | Shopify Access Token | `shopify-access-token` | 严重 | | SaaS | Notion Token | `notion-token` | 高 | | SaaS | Linear API Key | `linear-api-key` | 高 | | SaaS | Figma PAT | `figma-pat` | 高 | | SaaS | Airtable PAT | `airtable-pat` | 高 | | 通用 | Generic API Key | `generic-api-key` | 中等 |
## 输出格式 `--format` 选择输出格式;`output`/`-o` 将内容写入文件而不是 stdout。 | 格式 | 用途 | |--------|-----------| | `json` | 机器可读的扫描结果(默认) | | `sarif` | GitHub Code Scanning / 安全工具 (v2.1.0) | | `csv` | 电子表格(已进行公式注入清理) | | `table` | 人类可读的终端输出(按严重性着色) | | `github` | GitHub Actions 中的内联 Pull Request 注解 | ## 配置 使用 `leakwatch init` 生成配置模板文件,或者编写 `.leakwatch.yaml`: ``` scan: concurrency: 8 max-file-size: 10485760 # 10 MB detection: entropy: { enabled: true, threshold: 4.0 } verification: enabled: true timeout: 10s filter: exclude-paths: ["vendor/**", "node_modules/**", "**/*.lock"] output: format: json show-raw: false ``` 使用 `.leakwatchignore` 和 `# leakwatch:ignore` 标记来抑制已知的误报。详情:**[配置指南](docs/guides/configuration.md)**。 ## 安全性 - 默认情况下,机密值会被**脱敏**(例如 `AKIA****MPLE`),并且**永远不会写入磁盘或日志**。只有当您明确传递 `--show-raw` 参数时,才会输出原始值。 - 验证使用对提供商的**受控的、只读** API 调用;它不会发起任何改变状态的请求。 - 发现了漏洞?请通过 [GitHub 安全公告](https://github.com/HodeTech/Leakwatch/security/advisories/new) 私下报告。 ## 架构 ``` flowchart LR subgraph Sources["Sources (6)"] S1["Git"] S2["Filesystem"] S3["Container"] S4["AWS S3"] S5["GCS"] S6["Slack"] end subgraph Engine["Detection Engine"] E1["Aho-Corasick prefilter"] E2["Regex"] E3["Shannon entropy"] end subgraph Verify["Verification (54 verifiers)"] V1["Live API"] V2["Format validation"] end Sources -->|chunks| Engine Engine -->|findings| Verify Verify --> Output["JSON · SARIF · CSV · Table · GitHub"] ``` 深入了解:[架构](docs/architecture/03-ARCHITECTURE.md) · [ADR](docs/decisions/README.md) ## 文档 完整的双语 (EN/TR) 手册位于 **[hodetech.github.io/Leakwatch](https://hodetech.github.io/Leakwatch/)**。快速链接: [入门指南](docs/guides/getting-started.md) · [配置](docs/guides/configuration.md) · [CI/CD](docs/guides/ci-cd-integration.md) · [自定义规则](docs/guides/custom-rules.md) · [容器扫描](docs/guides/container-scanning.md) · [云端扫描](docs/guides/cloud-scanning.md) · [Git 扫描](docs/guides/git-scanning.md) · [Slack 扫描](docs/guides/slack-scanning.md) · [验证](docs/guides/secret-verification.md) · [Docker](docs/guides/docker-usage.md) · [VS Code 插件](docs/guides/vscode-extension.md) · [路线图](docs/05-ROADMAP.md) ## 贡献 欢迎您的贡献 — 请参阅 [CONTRIBUTING.md](CONTRIBUTING.md)。 ``` git clone https://github.com/HodeTech/Leakwatch.git cd Leakwatch && go mod download && go test ./... ``` ## 许可证 [MIT](LICENSE) © HodeTech — Leakwatch 由 [HodeTech](https://github.com/HodeTech) 维护。
标签:AI应用开发, CCS 2025, DevSecOps, EVTX分析, Go, LNA, Ruby工具, StruQ, 上游代理, 敏感信息扫描, 日志审计, 请求拦截