rodrigoramosrs/gitleaksplus

GitHub: rodrigoramosrs/gitleaksplus

基于gitleaks v7.6.1分支的密钥泄露检测工具,专注于恢复直接扫描远程GitHub仓库的便捷功能。

Stars: 0 | Forks: 0

``` ○ │╲ │ ○ ○ ░ ░ gitleaks plus ``` Gitleaks plus 的创建是为了恢复 gitleaks v**7.6.1** 版本的功能,该版本允许即时扫描 GitHub 仓库。 感谢原作者 @zricethezav 创建了这个很棒的工具!要查找原始项目,请点击 这里
# 原始文档

Github Test Follow @zricethezav

### 安装 Gitleaks 可以使用 Homebrew、Docker 或 Go 安装。在 [releases 页面](https://github.com/zricethezav/gitleaks/releases) 上,Gitleaks 也为许多流行的平台和操作系统类型提供了二进制形式。此外,Gitleaks 可以作为 pre-commit hook 直接在您的仓库中实现。 ##### MacOS ``` brew install gitleaks ``` ##### Docker ``` # 仅拉取镜像 docker pull zricethezav/gitleaks:latest # 从克隆的 repo 运行它 cd to/your/repo/ docker run -v ${PWD}:/my-repo zricethezav/gitleaks:latest --path="/my-repo" [OPTIONS] ``` ##### Go ``` GO111MODULE=on go get github.com/zricethezav/gitleaks/v7 ``` ##### 作为 pre-commit hook 有关说明,请参阅 [pre-commit](https://github.com/pre-commit/pre-commit)。 示例 `.pre-commit-config.yaml` ``` # 修订版本不会手动更新 # 查看此 https://github.com/zricethezav/gitleaks/releases # 以查看是否有更新版本 - repo: https://github.com/zricethezav/gitleaks rev: v7.6.0 hooks: - id: gitleaks ``` ### 使用与选项 ``` Usage: gitleaks [OPTIONS] Application Options: -v, --verbose Show verbose output from scan -q, --quiet Sets log level to error and only output leaks, one json object per line -r, --repo-url= Repository URL -p, --path= Path to directory (repo if contains .git) or file -c, --config-path= Path to config --repo-config-path= Path to gitleaks config relative to repo root --clone-path= Path to clone repo to disk --version Version number --username= Username for git repo --password= Password for git repo --access-token= Access token for git repo --threads= Maximum number of threads gitleaks spawns --ssh-key= Path to ssh key used for auth --unstaged Run gitleaks on unstaged code --branch= Branch to scan --redact Redact secrets from log messages and leaks --debug Log debug messages --no-git Treat git repos as plain directories and scan those files --leaks-exit-code= Exit code when leaks have been encountered (default: 1) --append-repo-config Append the provided or default config with the repo config. --additional-config= Path to an additional gitleaks config to append with an existing config. Can be used with --append-repo-config to append up to three configurations -o, --report= Report output path -f, --format= json, csv, sarif (default: json) --files-at-commit= Sha of commit to scan all files at commit --commit= Sha of commit to scan or "latest" to scan the last commit of the repository --commits= Comma separated list of a commits to scan --commits-file= Path to file of line separated list of commits to scan --commit-since= Scan commits more recent than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format. --commit-until= Scan commits older than a specific date. Ex: '2006-01-02' or '2006-01-02T15:04:05-0700' format. --depth= Number of commits to scan Help Options: -h, --help Show this help message ``` ### [扫描](https://www.youtube.com/watch?v=WUzpRL8mKCk) #### 基本的 repo-url 扫描: 这将扫描 tests/secrets 的整个历史记录,并在遇到泄露时(设置了 `-v`/`--verbose`)记录日志。 ``` gitleaks --repo-url=https://github.com/my-insecure/repo -v ``` #### 基本的 repo-url 扫描并输出到报告: 如果您想要 sarif 或 csv 格式的报告,可以设置 `-f/--format` 选项 ``` gitleaks --repo-url=https://github.com/my-insecure/repo -v --report=my-report.json ``` #### 扫描特定 commit: ``` gitleaks --repo-url=https://github.com/my-insecure/repo --commit=commit-sha -v ``` #### 扫描本地 repo: ``` gitleaks --path=path/to/local/repo -v ``` #### 扫描包含在父目录中的仓库: 如果您在 `path/to/local` 下有 `repo1`、`repo2`、`repo3`,gitleaks 将发现并扫描这些仓库。 ``` gitleaks --path=path/to/local/ -v ``` #### 扫描本地目录: 如果您想扫描仓库的当前内容,完全忽略 git。您可以使用 `--no-git` 选项来执行此操作。 ``` gitleaks --path=path/to/local/repo -v --no-git ``` #### 扫描文件: 或者,如果您想使用 gitleaks 规则扫描单个文件。您可以通过在 `--path` 中指定文件并包含 `--no-git` 选项来执行此操作。 ``` gitleaks --path=path/to/local/repo/main.go -v --no-git ``` #### 扫描未暂存的更改: 如果您有未暂存的更改并且当前位于仓库的根目录,则可以在不指定 `--path` 或 `--repo-url` 的情况下运行 `gitleaks`,这将对您未提交的更改运行扫描。或者,如果您想指定一个 路径,您可以运行: ``` gitleaks --path=path/to/local/repo -v --unstaged ``` ### 配置 使用 `--config-path` 或 `--repo-config-path` 提供您自己的 gitleaks 配置。`--config-path` 加载本地 gitleaks 配置,而 `--repo-config-path` 将加载仅存在于您要扫描的仓库中的配置。例如,`gitleaks --repo-config-path=".github/gitleaks.config"`。 Gitleaks 使用的默认配置位于[此处](https://github.com/zricethezav/gitleaks/blob/master/config/gitleaks.toml)。更多配置示例可以在[此处](https://github.com/zricethezav/gitleaks/tree/master/examples)查看。配置文件将包含几个不同的 TOML 表。下面提供了进一步的说明。 ### 规则摘要 规则以 [TOML](https://github.com/toml-lang/toml) 格式编写,如 [TomlLoader struct](https://github.com/zricethezav/gitleaks/blob/master/config/config.go#L57-L87) 中所定义,可以总结为: ``` [[rules]] description = "a string describing one of many rule in this config" regex = '''one-go-style-regex-for-this-rule''' file = '''a-file-name-regex''' path = '''a-file-path-regex''' tags = ["tag","another tag"] [[rules.entropies]] # note these are strings, not floats Min = "3.5" Max = "4.5" Group = "1" [rules.allowlist] description = "a string" files = ['''one-file-name-regex'''] commits = [ "commit-A", "commit-B"] paths = ['''one-file-path-regex'''] regexes = ['''one-regex-within-the-already-matched-regex'''] [allowlist] description = "a description string for a global allowlist config" commits = [ "commit-A", "commit-B"] files = [ '''file-regex-a''', '''file-regex-b'''] paths = [ '''path-regex-a''', '''path-regex-b'''] repos = [ '''repo-regex-a''', '''repo-regex-b'''] regexes = ['''one-regex-within-the-already-matched-regex'''] ``` 正则表达式 _不是_ 完整的 Perl 集,因此没有 look-ahead 或 look-behind。 ### 示例 #### 示例 1 第一个也是最常编辑的表数组是 `[[rules]]`。您可以在此处定义自己的自定义规则,供 Gitleaks 在扫描仓库时使用。`[[rules]]` 表中的示例键/值: ``` [[rules]] description = "generic secret regex" regex = '''secret(.{0,20})([0-9a-zA-Z-._{}$\/\+=]{20,120})''' tags = ["secret", "example"] ``` #### 示例 2 我们还可以 **组合** 正则表达式 AND 熵: ``` [[rules]] description = "entropy and regex example" regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]''' [[rules.Entropies]] Min = "4.5" Max = "4.7" ``` 将此规则翻译成英文,该规则指出:“如果我们遇到一行与 *regex* 匹配的代码,并且该行落在 [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) 为 4.5 到 4.7 的范围内,则该行必须是泄露” #### 示例 3 让我们比较两行代码: ``` aws_secret='ABCDEF+c2L7yXeGvUyrPgYsDnWRRC1AYEXAMPLE' ``` 和 ``` aws_secret=os.getenv('AWS_SECRET_ACCESS_KEY') ``` 第一行代码是分配给变量 `aws_secret` 的硬编码密钥的示例。第二行代码是通过环境变量将密钥分配给 `aws_secret` 的示例。两者都会被 *示例 2* 中定义的规则捕获,但只有第一行实际上是泄露。让我们定义一个新规则,它只捕获第一行代码。我们可以通过组合正则表达式 **groups** 和熵来做到这一点。 ``` [[rules]] description = "entropy and regex example" regex = '''secret(.{0,20})['|"]([0-9a-zA-Z-._{}$\/\+=]{20,120})['|"]''' [[rules.Entropies]] Min = "4.5" Max = "4.7" Group = "2" ``` 请注意我们是如何为此规则添加 `Group = "2"` 的。我们可以将此规则翻译成英文:“如果我们遇到一行与 regex 匹配的代码,并且 *第二个 regex group* 的熵落在 [Shannon entropy](https://en.wikipedia.org/wiki/Entropy_(information_theory)) 为 4.5 到 4.7 的范围内,则该行必须是泄露” ### 示例 4:使用 allowlist regex AWS secret keys 的正确 Perl 正则表达式是 `(?Jason Long 创建的 Git Logo,该图标基于 知识共享署名 3.0 未移植许可协议 授权。
标签:DevSecOps, Docker, EVTX分析, GitHub安全, Gitleaks, Go语言, meg, Pre-commit, Python安全, Redis利用, SolidJS, 上游代理, 云安全监控, 信息安全, 安全助手, 安全防御评估, 开源安全工具, 日志审计, 源码安全, 秘钥扫描, 程序破解, 网络安全研究, 请求拦截, 逆向工程平台, 静态分析