查找、验证和分析泄露的凭证
发现泄露的凭证。
您是否有兴趣持续监控 Git、Jira、Slack、Confluence、Microsoft Teams、Sharepoint(以及更多) 中的凭证?我们有一个企业产品可以提供帮助!了解更多信息请访问 https://trufflesecurity.com/trufflehog-enterprise。
我们将企业产品的收入用于资助更多优秀的开源项目,让整个社区都能受益。
TruffleHog 是最强大的秘密发现、分类、验证和分析工具。在这里,秘密指机器用于向另一台机器验证自身身份的凭证。这包括 API 密钥、数据库密码、私密加密密钥等等。
TruffleHog 可以在许多地方查找秘密,包括 Git、聊天、维基、日志、API 测试平台、对象存储、文件系统等。
TruffleHog 对 800 多种秘密类型进行分类,将它们映射回其所属的特定身份。它是 AWS 秘密?Stripe 秘密?Cloudflare 秘密?Postgres 密码?SSL 私钥?有时仅凭查看很难判断,所以 TruffleHog 会对找到的所有内容进行分类。
对于 TruffleHog 能分类的每个秘密,它还可以登录以确认该秘密是否有效。这一步对于判断是否存在当前的活跃危险至关重要。
对于最常见的 20 多种泄露凭证类型,TruffleHog 不是发送一个请求来检查秘密能否登录,而是可以发送多个请求,以了解关于该秘密的一切信息。谁创建了它?它可以访问哪些资源?它在这些资源上拥有哪些权限?
有问题?有反馈?欢迎加入 Slack 或 Discord 与我们交流。
加入我们的 Slack 社区
加入 秘密扫描 Discord
```bash
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=trufflesecurity
# :floppy_disk: 安装
为您提供了几种安装方式:
### MacOS 用户```bash
brew install trufflehog
确保在执行以下命令之前 Docker 引擎正在运行:
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
#### Windows 命令提示符```bash
docker run --rm -it -v "%cd:/=\%:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
docker run --rm -it -v "${PWD}:/pwd" trufflesecurity/trufflehog github --repo https://github.com/trufflesecurity/test_keys
#### M1 和 M2 Mac```bash
docker run --platform linux/arm64 --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
Download and unpack from https://github.com/trufflesecurity/trufflehog/releases
### 从源代码编译```bash
git clone https://github.com/trufflesecurity/trufflehog.git
cd trufflehog; go install
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin
### 使用安装脚本,验证校验和签名(需要已安装 cosign)```bash
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -v -b /usr/local/bin
curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin
# :closed_lock_with_key: 验证构建产物
所有构建产物都应用了校验和,生成的校验和文件使用 cosign 进行签名。
你需要以下工具来验证签名:
- [Cosign](https://docs.sigstore.dev/cosign/system_config/installation/)
验证步骤如下:
1. 从 [releases](https://github.com/trufflesecurity/trufflehog/releases) 页面下载你需要的构建产物文件以及以下文件。
- trufflehog\_{version}\_checksums.txt
- trufflehog\_{version}\_checksums.txt.pem
- trufflehog\_{version}\_checksums.txt.sig
2. 验证签名: ```shell
cosign verify-blob <path to trufflehog_{version}_checksums.txt> \
--certificate <path to trufflehog_{version}_checksums.txt.pem> \
--signature <path to trufflehog_{version}_checksums.txt.sig> \
--certificate-identity-regexp 'https://github\.com/trufflesecurity/trufflehog/\.github/workflows/.+' \
--certificate-oidc-issuer "https://token.actions.githubusercontent.com"
将 {version} 替换为下载的文件版本
或者,如果您使用安装脚本,请传递 -v 选项以执行签名验证。这要求在运行安装脚本之前安装 Cosign 二进制文件。
命令:```bash trufflehog git https://github.com/trufflesecurity/test_keys --results=verified
预期输出:```
🐷🔑🐷 TruffleHog. Unearth your secrets. 🐷🔑🐷
Found verified result 🐷🔑
Detector Type: AWS
Decoder Type: PLAIN
Raw result: AKIAYVP4CIPPERUVIFXG
Line: 4
Commit: fbc14303ffbf8fb1c2c1914e8dda7d0121633aca
File: keys
Email: counter <[email protected]>
Repository: https://github.com/trufflesecurity/test_keys
Timestamp: 2022-06-16 10:17:40 -0700 PDT
...
trufflehog github --org=trufflesecurity --results=verified
## 3:扫描一个 GitHub 组织,排除已归档的仓库```bash
trufflehog github --org=trufflesecurity --exclude-archived
命令:```bash trufflehog git https://github.com/trufflesecurity/test_keys --results=verified --json
输入:
预期输出:```
{"SourceMetadata":{"Data":{"Git":{"commit":"fbc14303ffbf8fb1c2c1914e8dda7d0121633aca","file":"keys","email":"counter \[email protected]\u003e","repository":"https://github.com/trufflesecurity/test_keys","timestamp":"2022-06-16 10:17:40 -0700 PDT","line":4}}},"SourceID":0,"SourceType":16,"SourceName":"trufflehog - git","DetectorType":2,"DetectorName":"AWS","DecoderName":"PLAIN","Verified":true,"Raw":"AKIAYVP4CIPPERUVIFXG","Redacted":"AKIAYVP4CIPPERUVIFXG","ExtraData":{"account":"595918472158","arn":"arn:aws:iam::595918472158:user/canarytokens.com@@mirux23ppyky6hx3l6vclmhnj","user_id":"AIDAYVP4CIPPJ5M54LRCY"},"StructuredData":null}
...
trufflehog github --repo=https://github.com/trufflesecurity/test_keys --issue-comments --pr-comments
## 6: 扫描S3存储桶以获取高置信度结果 (已验证 + 未知)```bash
trufflehog s3 --bucket=<bucket name> --results=verified,unknown
trufflehog s3 --role-arn=
## 8: 在Docker中使用SSH认证扫描Github仓库```bash
docker run --rm -v "$HOME/.ssh:/root/.ssh:ro" trufflesecurity/trufflehog:latest git ssh://github.com/trufflesecurity/test_keys
trufflehog filesystem path/to/file1.txt path/to/file2.txt path/to/dir
## 10: 扫描本地 git 仓库
克隆 git 仓库。例如 [test keys](https://github.com/trufflesecurity/trufflehog/blob/main/git%40github.com%3Atrufflesecurity/test_keys.git) 仓库。```bash
git clone [email protected]:trufflesecurity/test_keys.git
从父目录(git仓库外部)运行 trufflehog。```bash trufflehog git file://test_keys --results=verified,unknown
为防止本地扫描中的恶意 git 配置(参见 CVE-2025-41390),TruffleHog 会在扫描前将本地 git 仓库克隆到临时目录中。这遵循了 [Git 的安全最佳实践](https://git-scm.com/docs/git#_security)。如果你想指定一个自定义路径来克隆仓库(而非 tmp),可以使用 `--clone-path` 标志。如果希望跳过本地克隆过程并直接扫描仓库(仅适用于受信任的仓库),可以使用 `--trust-local-git-config` 标志。
## 11: 仅扫描 GCS 存储桶中的已验证秘密```bash
trufflehog gcs --project-id=<project-ID> --cloud-environment --results=verified
多次使用 --image 标志来扫描多个镜像。```bash
trufflehog docker --image trufflesecurity/secrets --results=verified
trufflehog docker --image docker://new_image:tag --results=verified