好用的代码库密钥泄露检测工具:gitleaks

github上每年都有很多起因密钥或密码等机密数据泄露的事件,比如有aws的密钥,oss桶密钥等,有的甚至被人利用创建了云主机进行了挖矿。。

这里推荐一款代码库扫描工具–gitleaks,github上有15k的start。

  • 环境搭建:

还是使用docker镜像启动,挂载需要检测的code目录

$ cat docker-compose.yml
version: '3'
services:
  gitleaks-test:
    container_name: gitleaks-test
    hostname: gitleaks-test
    restart: always
    image: zricethezav/gitleaks:v8.18.2
    tty: true
    stdin_open: true
    volumes:
      - ./leakcheck:/code
    entrypoint: bash
  • gitleaks命令行参数
# gitleaks --help
Gitleaks scans code, past or present, for secrets
Usage:
  gitleaks [command]

Available Commands:
  completion  generate the autocompletion script for the specified shell
  detect      detect secrets in code
  help        Help about any command
  protect     protect secrets in code
  version     display gitleaks version

Flags:
  -b, --baseline-path string           path to baseline with issues that can be ignored
  -c, --config string                  config file path
                                       order of precedence:
                                       1. --config/-c
                                       2. env var GITLEAKS_CONFIG
                                       3. (--source/-s)/.gitleaks.toml
                                       If none of the three options are used, then gitleaks will use the default config
      --enable-rule gitleaks detect    only enable specific rules by id
      --exit-code int                  exit code when leaks have been encountered (default 1)
      --follow-symlinks                scan files that are symlinks to other files
  -i, --gitleaks-ignore-path string    path to .gitleaksignore file or folder containing one (default ".")
  -h, --help                           help for gitleaks
      --ignore-gitleaks-allow          ignore gitleaks:allow comments
  -l, --log-level string               log level (trace, debug, info, warn, error, fatal) (default "info")
      --log-opts string                git log options
      --max-target-megabytes int       files larger than this will be skipped
      --no-banner                      suppress banner
      --no-color                       turn off color for verbose output
      --redact uint[=100]              redact secrets from logs and stdout. 
  -f, --report-format string           output format (json, csv, junit, sarif) (default "json")
  -r, --report-path string             report file
  -s, --source string                  path to source (default ".")
  -v, --verbose                        show verbose output from scan

Use "gitleaks [command] --help" for more information about a command.
  • 执行检测
$ gitleaks detect --source /code/myproject -v

### 发现了代码中硬编码的PRIVATE_KEY
Finding:     ...ing REQUEST_PRIVATE_KEY = "MIICdgIBAxxxxWxxQ" + "OxxxxH...
Secret:      MIICdgIBAxxxxWxxQ...OxxxxH
RuleID:      generic-api-key
Entropy:     4.680964
File:        src/main/java/com/myproject/common/utils/RSAEncrypt.java
Line:        40
Commit:      3a9f15961143287a0f417a37665415643232438a
Author:      fisher
Email:       fisher@mymail.com
Date:        2024-03-08T08:40:34Z
Fingerprint: 3axxa:src/main/java/com/myproject/common/utils/RSAEncrypt.java:generic-api-key:40


### 发现了代码中dev环境中的配置文件,里面有数据库密码
Finding:     jdbc.password=sxxxs
Secret:      sxxxxs
RuleID:      generic-api-key
Entropy:     3.700440
File:        src/main/resources/dev/db.properties
Line:        3
Commit:      25ea03dbaf47307ec86a2a625a0fa5b6bd409a97
Author:      fisher
Email:       fisher@mymail.com
Date:        2024-03-16T03:12:30Z
Fingerprint: 25exx97:src/main/resources/dev/db.properties:generic-api-key:3

8:56AM INF 849 commits scanned.
8:56AM INF scan completed in 4.65s
8:56AM WRN leaks found: 24
  • u2

    Related Posts

    AI逃逸事件全解析:OpenAI模型自主攻破Hugging Face,安全范式正在重构

    2026年7月,AI行业发生了一件标志性事件。OpenAI在一次内部安全评估中,其AI模型——包括GPT-5.6 Sol和一个更强大的未发布模型——自主逃逸了沙箱环境,发现并利用0-day漏洞,最终攻破了Hugging Face的生产服务器。整个过程没有人类参与。

    Read more

    10款大模型同台黑客测试:GPT-5.5拿了王冠,DeepSeek便宜15倍,Gemini直接退赛

    6月3日,应用安全研究员 Kasra Rahjerdi 在自…

    Read more

    You Missed

    DeepSeek双线出击:视觉模型睁开眼,Harness套上缰绳

    • u2
    • 8月 25, 2026
    • 23 views

    微软Copilot “CoSnitch”漏洞深度解析:当AI助手成为自己的”告密者”

    • u2
    • 8月 24, 2026
    • 28 views

    OpenAI 干了一件成立以来从没干过的事:主动踩刹车

    • u2
    • 8月 21, 2026
    • 58 views

    OpenAI Astra十题拆解:2000美元,十个数学难题,一次破壁

    • u2
    • 8月 3, 2026
    • 154 views

    便宜电视盒子背后的广告欺诈帝 国

    • u2
    • 7月 31, 2026
    • 134 views

    Snowflake Cortex AI Gateway:企业 AI Agent 的「信任控制平面」

    • u2
    • 7月 29, 2026
    • 207 views