网络敏感信息识别模块
作者:Sec-Labs | 发布时间:
项目地址
https://github.com/Marshal-EASM/webssi
TruffleHog项目简介
TruffleHog是一个用于查找泄露的凭据的工具。
相关技术点
- Git
- Docker
- S3
- SSH
项目用途
- 在Git repo中查找泄露的凭据
- 在GitHub Org中查找泄露的凭据
- 在S3 bucket中查找泄露的凭据
- 查找SSH认证方式的GitHub Repo中的泄露凭据或敏感信息
- 扫描单个文件或目录中的泄露凭据或敏感信息
该工具可以帮助用户及时发现泄露的凭据或敏感信息,防范信息泄露和安全风险。可以在Docker中运行,也可以进行二进制安装。

TruffleHog
查找泄露的凭据。
:mag_right: 正在扫描
...及更多
:loudspeaker: 加入我们的社区
有问题?反馈?加入slack和我们一起聊天
https://join.slack.com/t/trufflehog-community/shared_invite/zt-pw2qbi43-Aa86hkiimstfdKH9UCpPzQ
:tv: 演示
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=trufflesecurity
:floppy_disk: 安装
有几个选项可供您选择:
# MacOS用户
brew install trufflesecurity/trufflehog/trufflehog
# Docker
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
# Docker for M1 and M2 Mac
docker run --platform linux/arm64 --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys
# 二进制版本
从https://github.com/trufflesecurity/trufflehog/releases下载并解压缩
# 从源代码编译
git clone https://github.com/trufflesecurity/trufflehog.git
cd trufflehog; go install
:rocket: 快速入门
1:仅扫描已验证的凭据
命令:
trufflehog git https://github.com/trufflesecurity/test_keys --only-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 <counter@counters-MacBook-Air.local>
Repository: https://github.com/trufflesecurity/test_keys
Timestamp: 2022-06-16 10:17:40 -0700 PDT
...
2:仅扫描已验证的GitHub Org
trufflehog github --org=trufflesecurity --only-verified
3:仅扫描仅验证的GitHub Repo并获取JSON输出
命令:
trufflehog git https://github.com/trufflesecurity/test_keys --only-verified --json
预期输出:
{"SourceMetadata":{"Data":{"Git":{"commit":"fbc14303ffbf8fb1c2c1914e8dda7d0121633aca","file":"keys","email":"counter \u003ccounter@counters-MacBook-Air.local\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}
...
4:仅扫描已验证的密钥的S3存储桶
trufflehog s3 --bucket=<bucket name> --only-verified
5:使用docker中的SSH身份验证扫描Github Repo
docker run --rm -v "$HOME/.ssh:/root/.ssh:ro" trufflesecurity/trufflehog:latest git ssh://github.com/trufflesecurity/test_keys
6:扫描单个文件或目录
trufflehog filesystem path/to/file1.txt path/to/file2.txt path/to/dir
```## 7:扫描GCS存储桶以查找已验证的机密信息。
```bash
trufflehog gcs --project-id=<project-ID> --cloud-environment --only-verified
:question: 常见问题解答
- 我只看到了
🐷🔑🐷 TruffleHog. Unearth your secrets. 🐷🔑🐷,然后程序退出,怎么回事?- 这意味着未检测到任何机密信息。
- 当我扫描GitHub组织时,为什么扫描需要很长时间?
- 未经身份验证的GitHub扫描具有速率限制。为了改善速率限制,请使用个人访问令牌的
--token标志。
- 未经身份验证的GitHub扫描具有速率限制。为了改善速率限制,请使用个人访问令牌的
- 它说已验证了私钥,这是什么意思?
- 查看我们的Driftwood博客文章以了解如何做到这一点,简而言之,我们确认了该密钥可以用于SSH或SSL 博客文章
:newspaper: v3中有什么新内容?
TruffleHog v3是一个完全重写的Go语言版本,具有许多新的强大功能。
- 我们已经添加了超过700个凭据检测器,支持对其各自的API进行活动验证。
- 我们还添加了本地支持扫描GitHub、GitLab、文件系统、S3、GCS和Circle CI。
- 使用我们的Driftwood技术,即可在数百万GitHub用户和数十亿TLS证书中快速验证私钥。
- 扫描二进制文件和其他文件格式
- 作为GitHub Action和pre-commit钩子可用
什么是凭据验证?
对于每个可能检测到的凭据,我们都精心实现了针对我们认为它属于的API的程序验证。验证消除了假阳性。例如,AWS凭据检测器执行了针对AWS API的GetCallerIdentity API调用,以验证AWS凭据是否活动。
:memo: 用法
TruffleHog为您可能要扫描的每个数据源都有一个子命令:
- git
- github
- gitlab
- S3
- filesystem(文件和目录)
- syslog
- circleci
- GCS(Google Cloud Storage)
- stdin(即将推出)
每个子命令都可以具有选项,您可以使用提供给子命令的--help标志查看选项:
$ trufflehog git --help
usage: TruffleHog git [<flags>] <uri>
Find credentials in git repositories.
Flags:
--help Show context-sensitive help (also try --help-long and --help-man).
--debug Run in debug mode.
--trace Run in trace mode.
--profile Enables profiling and sets a pprof and fgprof server on :18066.
-j, --json Output in JSON format.
--json-legacy Use the pre-v3.0 JSON format. Only works with git, gitlab, and github sources.
--concurrency=10 Number of concurrent workers.
--no-verification Don't verify the results.
--only-verified Only output verified results.
--filter-unverified Only output first unverified result per chunk per detector if there are more than one results.
--config=CONFIG Path to configuration file.
--print-avg-detector-time Print the average time spent on each detector.
--no-update Don't check for updates.
--fail Exit with code 183 if results are found.
--version Show application version.
Args:
<uri> Git repository URL. https://, file://, or ssh:// schema expected.
例如,要扫描git存储库,请从以下位置开始
$ trufflehog git https://github.com/trufflesecurity/trufflehog.git
退出代码:
- 0:没有错误,也没有找到结果。
- 1:遇到错误。源可能没有完成扫描。
- 183:未遇到错误,但找到了结果。仅在使用
--fail标志时返回。
:octocat: TruffleHog Github Action
- name: TruffleHog
uses: trufflesecurity/trufflehog@main
with:
# Repository path
path:
# Start scanning from here (usually main branch).
base:
# Scan commits until here (usually dev branch).
head: # optional
# Extra args to be passed to the trufflehog cli.
extra_args: --debug --only-verified
TruffleHog OSS Github Action可用于扫描泄漏的凭据的一系列提交。如果发现任何结果,该操作将失败。
例如,要扫描拉取请求的内容,可以使用以下工作流程:
name: TruffleHog Secrets Scan
on: [pull_request]
jobs:
TruffleHog:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: TruffleHog OSS
uses: trufflesecurity/trufflehog@main
with:
path: ./
base: ${{ github.event.repository.default_branch }}
head: HEAD
extra_args: --debug --only-verified
Precommit钩子
Trufflehog可以在precommit钩子中使用,以防止凭据在离开计算机之前泄漏。提供了一个示例.pre-commit-config.yaml(有关安装,请参见pre-commit.com)。
repos:- 仓库:本地
钩子:
- id: trufflehog
name: TruffleHog
description: 检测您数据中的机密信息
entry: bash -c 'trufflehog git file://. --since-commit HEAD --only-verified --fail'
#要在docker中运行trufflehog,请改用以下条目:
# entry: bash -c 'docker run --rm -v "$(pwd):/workdir" -i --rm trufflesecurity/trufflehog:latest git file:///workdir --since-commit HEAD --only-verified --fail'
language: system
stages: ["commit", "push"]
#正则表达式检测器(alpha)
Trufflehog支持自定义正则表达式的检测和验证。
为了进行检测,至少需要一个正则表达式和一个关键字。
**关键字**是一个固定的文本字符串标识符,出现在要检测的正则表达式中或周围。为了允许最大的验证灵活性,使用包含正则表达式匹配项的Webhook。
Trufflehog将发送一个JSON POST请求,其中包含正则表达式匹配项到已配置的Webhook端点。如果端点响应“200 OK”响应状态代码,则将认为机密信息已验证。
**注意:**此功能为alpha版本,可能会更改。
##正则表达式检测器示例
```yaml
# config.yaml
detectors:
- name: hog detector
keywords:
- hog
regex:
adjective: hogs are (\S+)
verify:
- endpoint: http://localhost:8000/
# 如果端点是HTTP,则必须设置unsafe
unsafe: true
headers:
- 'Authorization: super secret authorization header'
$ trufflehog filesystem /tmp --config config.yaml --only-verified
🐷🔑🐷 TruffleHog. Unearth your secrets. 🐷🔑🐷
Found verified result 🐷🔑
Detector Type: CustomRegex
Decoder Type: PLAIN
Raw result: hogs are cool
File: /tmp/hog-facts.txt
##验证服务器示例(Python)
除非运行验证服务器,否则自定义正则表达式检测器发现的机密信息将无法验证。这是上面的config.yaml文件的验证服务器示例Python实现。
import json
from http.server import BaseHTTPRequestHandler, HTTPServer
AUTH_HEADER = 'super secret authorization header'
class Verifier(BaseHTTPRequestHandler):
def do_GET(self):
self.send_response(405)
self.end_headers()
def do_POST(self):
try:
if self.headers['Authorization'] != AUTH_HEADER:
self.send_response(401)
self.end_headers()
return
# read the body
length = int(self.headers['Content-Length'])
request = json.loads(self.rfile.read(length))
self.log_message("%s", request)
# check the match
if request['hog detector']['adjective'][-1] == 'cool':
self.send_response(200)
self.end_headers()
else:
# any other response besides 200
self.send_response(406)
self.end_headers()
except Exception:
self.send_response(400)
self.end_headers()
with HTTPServer(('', 8000), Verifier) as server:
try:
server.serve_forever()
except KeyboardInterrupt:
pass
:heart: 贡献者
感谢所有为此项目做出贡献的人。[贡献]。
:computer: 贡献
非常欢迎贡献!请首先查看我们的贡献指南。
我们不再接受TruffleHog v2的贡献,但是该代码在v2分支中可用。
添加新的机密信息检测器
我们已经发布了一些文档和工具,以开始添加新的机密信息检测器。让我们一起改进检测!
作为库使用
目前,trufflehog正在进行大量开发,目前无法保证公共API的稳定性。
许可证更改
自v3.0以来,TruffleHog在AGPL 3许可下发布,包含在[LICENSE](LICENSE)中。 TruffleHog v3.0未使用以前的任何代码库,但是注意在命令行界面上保留向后兼容性。此版本之前的工作仍可在此存储库的历史记录以及先前的软件包发布和标记中获得,采用GPL 2.0。需要完成CLA以接受今后的贡献。
:money_with_wings: 企业产品
您是否有兴趣持续监控Git、Jira、Slack、Confluence等以查找凭据?我们有一个企业产品可以帮助。在这里联系我们以了解更多信息 https://trufflesecurity.com/contact/
我们将来自企业产品的收入用于资助更多的令人敬畏的开源项目,整个社区都可以从中受益。