GO KALI FREE

Gitleaks

Vulnerability Analysis

Intermediatelow risk

Gitleaks is an open-source SAST tool for detecting and preventing hardcoded secrets such as passwords, API keys and tokens in Git repositories, historical commits, files and standard input. It supports local reviews, pre-commit checks and CI pipelines so teams can find past or present credential exposure before it reaches production.

Installation

sudo apt install gitleaks

Basic Syntax

gitleaks git -v

Quick Facts

Full Name
Gitleaks
License
MIT
Language
Go
Category
Secret Scanning
Type
SAST Secret Detection
First Released
2018
Latest Release
v8.30.1
Status
Feature complete - security fixes only

Tool Overview

Gitleaks is an MIT-licensed SAST secret scanner written in Go. It detects hardcoded passwords, API keys, tokens and related secrets in Git repositories, ordinary files, directories and standard input. The `git` command examines repository history through `git log -p`, while `dir` evaluates current filesystem content without requiring Git metadata. Reports can be exported as JSON, CSV, JUnit, SARIF or a custom Go text/template.

The tool is designed for prevention as well as investigation. Developers can install the documented pre-commit hook, teams can run the Gitleaks Action in GitHub workflows, and security reviewers can create baseline reports that suppress known historical findings while preserving visibility into new ones. Project-specific `.gitleaks.toml` files can extend the default configuration, define custom rules, add allowlists and select individual rule IDs.

Gitleaks does not verify whether a candidate secret is accepted by its service. Every result therefore needs contextual triage, but raw findings must still be treated as sensitive because they can contain live credentials. Rotate or revoke an exposed credential before focusing on source cleanup, and never paste it into chat or an unrestricted report. Scan only repositories and files you own or are authorized to assess.

The maintainer has stated: "Gitleaks is feature complete. I'm not merging new features into Gitleaks. Future releases will be security patches only. I'm shifting my focus to Betterleaks." The latest verified release is v8.30.1, published 2026-03-21. Pin a reviewed release or container version so local and CI results remain reproducible while still applying future security patches.

Quick Reference Commands

Verified quick-reference commands for Gitleaks
CommandPurpose
gitleaks git -vScan the current Git repository and print verbose finding details.
gitleaks git -v --log-opts="--all" path_to_repoScan all refs available in an authorized local repository.Ensure the clone contains the branches and commits you intend to review.
gitleaks dir path_to_directoryScan an authorized directory without requiring Git history.
cat some_file | gitleaks -v stdinStream authorized data into Gitleaks through standard input.
gitleaks git --report-path gitleaks-report.json && gitleaks git --baseline-path gitleaks-report.json --report-path findings.jsonCreate a baseline and report only findings that are new relative to it.
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest dir /pathScan an authorized mounted folder with the Docker Hub image.
Gitleaks READMEGitleaks on Kali Linux

Common Commands

sudo apt install gitleaksInstall the official Kali Linux Gitleaks package.
brew install gitleaksInstall Gitleaks through Homebrew on macOS or Linux.
docker pull zricethezav/gitleaks:latest && docker pull ghcr.io/gitleaks/gitleaks:latestPull the documented Gitleaks images from Docker Hub and GitHub Container Registry.
docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest dir /pathScan an authorized host folder with the Docker Hub Gitleaks image.
docker run -v ${path_to_host_folder_to_scan}:/path ghcr.io/gitleaks/gitleaks:latest dir /pathScan an authorized host folder with the GitHub Container Registry Gitleaks image.
git clone https://github.com/gitleaks/gitleaks.git && cd gitleaks && make buildClone the official repository and build Gitleaks from source.
gitleaks --versionPrint the installed Gitleaks version for setup and audit records.
gitleaks --helpDisplay current Gitleaks commands and global options.
gitleaks git -vScan the current Git repository and print verbose finding details.
gitleaks git path_to_repoScan the history of a named local Git repository.
gitleaks git -v --log-opts="--all commitA..commitB" path_to_repoScan the selected Git revision range across all refs in an authorized repository.
gitleaks dir path_to_directoryScan an authorized directory without requiring Git history.
gitleaks dir path_to_fileScan one authorized file for secret candidates.
cat some_file | gitleaks -v stdinStream an authorized file into Gitleaks through standard input.
gitleaks git --report-format json --report-path gitleaks-report.jsonScan the current Git repository and save findings as JSON.
gitleaks dir path_to_directory --report-format csv --report-path gitleaks-report.csvScan a directory and write findings in CSV format.
gitleaks git --report-format sarif --report-path gitleaks-report.sarifCreate a SARIF report for ingestion by compatible code-scanning systems.
gitleaks git --report-format junit --report-path gitleaks-report.xmlWrite Git findings as a JUnit report for compatible CI systems.
gitleaks dir ~/leaky-repo/ --report-path "report.json" --report-format template --report-template testdata/report/jsonextra.tmplRender a directory scan with a Go text/template report file.
gitleaks git --exit-code 2Return exit code 2 instead of the default leaks-found code when findings are detected.
gitleaks git --config path_to_config.tomlScan the current Git repository with an explicit Gitleaks configuration file.
GITLEAKS_CONFIG=path_to_config.toml gitleaks git -vSelect a configuration through the GITLEAKS_CONFIG environment variable.
gitleaks git --enable-rule generic-api-keyRun the Git scan with only the named generic-api-key rule enabled.
gitleaks git --report-path gitleaks-report.json && gitleaks git --baseline-path gitleaks-report.json --report-path findings.jsonCreate a baseline report and then report only findings that are new relative to it.
gitleaks git --gitleaks-ignore-path path_to_projectUse the .gitleaksignore file found in the specified file or folder location.
gitleaks dir path_to_directory --ignore-gitleaks-allowReport candidates even when their lines contain gitleaks:allow comments.
gitleaks git --redact=100Redact all detected secret text from logs and standard output.
gitleaks dir path_to_directory --max-decode-depth 2 --max-archive-depth 2Decode supported encoded text and traverse nested archives to the selected depths.
gitleaks dir path_to_directory --log-level debug --timeout 60 --max-target-megabytes 10Run a debug-level directory scan with a 60-second timeout and a per-file size limit.
pre-commit autoupdate && pre-commit installUpdate the configured Gitleaks pre-commit hook revision and install the hook in the current repository.

Step-by-Step Guide

  1. 1Confirm that the repository, directory or input belongs to you or is explicitly authorized for secret scanning, because findings may expose live credentials.
  2. 2Install Gitleaks with `sudo apt install gitleaks` on Kali Linux or use another documented route such as Homebrew, Docker or a source build.
  3. 3Run `gitleaks --version` and record the installed release; Gitleaks is feature complete and future releases are expected to contain security patches only, so pin an approved release version.
  4. 4Enter an authorized repository and run `gitleaks git -v` to scan its Git history through the underlying `git log -p` workflow.
  5. 5Read the Finding, Secret, RuleID, Entropy, File, Line, Commit, Author, Email, Date and Fingerprint fields to locate and classify each exposure.
  6. 6Revoke or rotate the exposed credential first, remove it from active files and history where appropriate, and rescan without copying the secret into tickets, reports or chat.
  7. 7Create a baseline with `gitleaks git --report-path gitleaks-report.json`, then use `--baseline-path gitleaks-report.json` so subsequent reviews focus on new issues.
  8. 8Install the documented pre-commit hook and add the Gitleaks Action or an equivalent authorized CI command so new leaks are detected before merge.

Use Cases

Git History Secret Scanning

Inspect current and historical revisions in an authorized Git repository for hardcoded passwords, API keys and tokens, with commit metadata identifying where a candidate entered history.

Directory and File Review

Scan directories or individual files that are not stored in Git, including deployment bundles, source exports and configuration backups covered by the assessment scope.

Pre-commit Prevention

Install the documented pre-commit hook so secret candidates can be reviewed before they become part of repository history.

CI/CD Secret Gate

Run Gitleaks in an authorized CI workflow, save a machine-readable report and use the configured leaks-found exit code to block unsafe changes.

Legacy Repository Baseline

Generate a baseline for accepted historical findings and report only candidates that appear after the baseline was created.

Encoded and Archived Content Review

Enable decoding and archive traversal when an approved review must inspect encoded content or files nested inside zip and tar archives.

Key Features

Best Practices

Common Errors

Current path is not a Git repository
Change into the authorized repository or pass its local path to `gitleaks git`.
Exit code 126 for an unknown flag
Run `gitleaks --help`, remove the unknown option and verify that the documented command matches the pinned release.
Exit code 1
Review the protected report and logs to distinguish a secret finding from an execution error; use `--exit-code` if CI needs a distinct leaks-found code.
Expected rule does not run
Review configuration precedence and record whether --config, GITLEAKS_CONFIG, GITLEAKS_CONFIG_TOML, .gitleaks.toml or the default config was used.
Git history scan misses an expected revision
Obtain the required authorized refs and confirm the Git log range before rerunning Gitleaks.
Encoded or archived content is not scanned
Set reviewed `--max-decode-depth` or `--max-archive-depth` values and account for the added processing and output sensitivity.
Large target is skipped
Confirm that the limit is appropriate for the authorized data set and adjust it deliberately if the larger file must be inspected.
Known candidate is suppressed
Review the suppression, audit inline comments with `--ignore-gitleaks-allow` and remove any entry that conceals a real credential.

People Also Ask

Does Gitleaks scan Git history?

Yes. The `git` command uses `git log -p` under the hood, allowing Gitleaks to inspect historical patches as well as content associated with the selected repository range.

How do I make Gitleaks scan only the current commit?

Use `--log-opts` with an appropriate Git log selection such as `-1` for the latest commit, or use `gitleaks dir .` when only current working-tree files should be scanned without historical metadata.

How do I install Gitleaks on Kali Linux?

Run `sudo apt install gitleaks`, then verify the installed executable with `gitleaks --version` and pin the approved release used by your workflow.

What is Gitleaks used for?

Gitleaks detects likely passwords, API keys, tokens and related secrets in Git repositories, files, directories and standard input.

Can Gitleaks run in Docker?

Mount an authorized host folder into either the Docker Hub or GHCR image and scan its container path with the `git` or `dir` command.

Is Gitleaks better than TruffleHog?

Gitleaks is lighter and well suited to Git-focused pre-commit checks, while TruffleHog adds broader source coverage and live verification for supported secrets.

Related Tools

TruffleHog

Vulnerability Analysis

TruffleHog is an open-source secrets discovery, classification, verification and analysis tool by Truffle Security. It scans Git history, GitHub, filesystems, Docker images, cloud storage and other supported sources for API keys, passwords, private keys and related machine credentials.

Nuclei

Vulnerability Analysis

Nuclei is used to send requests across targets based on templates, allowing zero false positives and providing rapid scanning over large infrastructure footprints.

Hashcat

Password Attacks

Learn how to use Hashcat in Kali Linux as a beginner, from checking the install and selecting the right modes to running a wordlist crack and reading results.

OpenVAS

Vulnerability Analysis

OpenVAS (Open Vulnerability Assessment System) is a full-featured vulnerability scanner providing a comprehensive architectural network engine that checks endpoints against thousands of active vulnerability feeds.

Lynis

Vulnerability Analysis

Lynis is a battle-tested security auditing tool for systems running Linux, macOS, or Unix-based operating systems. It performs an in-depth local scan to discover security weaknesses, configuration flaws, and system hardening opportunities.

SSLScan

Vulnerability Analysis

SSLScan queries SSL/TLS services (such as HTTPS) to determine supported ciphers, key exchanges, and security flaws like Heartbleed or broken protocol configurations.

Related Cybersecurity Guides

Active Directory · Advanced

BloodHound Guide: Mapping Active Directory Relationships

Learn how to use BloodHound and SharpHound for Active Directory reconnaissance, attack path analysis, privilege escalation detection, and security assessment.

Security · Intermediate

Credential Stuffing: Automated Account Takeover Attacks

Learn about credential stuffing attacks that use leaked credentials from data breaches to automate account takeover across different services.

Tools · Beginner

How to Use WPScan: WordPress Vulnerability Scanning in Kali Linux

How to use WPScan in Kali Linux: install it, save your free API token, run your first WordPress vulnerability scan — cheat sheet, 15 FAQs.

Maltego · Intermediate

Maltego Transforms Explained: How the Transform Engine Works

Deep dive into Maltego's transform engine. Understand transform architecture, categories, chaining, the Transform Hub, TREST API, and how to create custom transforms.

Frequently Asked Questions

What is Gitleaks?

Gitleaks is an open-source static application security testing tool for detecting hardcoded secrets in Git repositories, historical commits, files and standard input. It looks for passwords, API keys, tokens and similar credential material using configurable rules, regular expressions, keywords and entropy conditions. It is written in Go and distributed under the MIT licence.

What is Gitleaks used for?

Gitleaks is used to detect and prevent hardcoded secrets before or after they enter source control. Teams run it during repository reviews, as a pre-commit hook and in CI pipelines. It can also scan ordinary directories, individual files, standard input, decoded text and supported archives. A finding should lead to credential rotation, source cleanup and a controlled rescan.

How do I install Gitleaks on Kali Linux?

Kali Linux provides an official package. Run `sudo apt install gitleaks`, which installs a package with an installed size of 9.88 MB, and then confirm the executable with `gitleaks --version`. Record and pin the approved release because the maintainer states that Gitleaks is feature complete and future releases will be security patches only.

How do I install Gitleaks on Windows, Ubuntu or macOS?

On macOS, use the documented `brew install gitleaks` route. Ubuntu and other Linux users can use Homebrew, Docker or the documented source build with `git clone https://github.com/gitleaks/gitleaks.git`, `cd gitleaks` and `make build`. On Windows, use a compatible Docker environment or build from the official source in an environment that provides the required Go and make tooling. Do not rely on an undocumented install script.

Gitleaks vs TruffleHog — which secret scanner should I use?

Gitleaks is lighter, Git-focused and configuration-driven, with a strong pre-commit and baseline workflow. TruffleHog, the on-site alternative, covers Git plus Docker, cloud and other sources and can verify supported secrets live against their services. Choose Gitleaks for fast local, pre-commit and Git-history checks; choose TruffleHog when live verification or broader source coverage matters. Some teams use Gitleaks early and TruffleHog later for authorized verification.

Gitleaks vs TruffleHog for pre-commit — which is better?

Gitleaks is usually the simpler pre-commit choice because its documented hook runs directly against repository changes and its configuration can live with the project. TruffleHog is valuable when verification is required, but live service checks may be undesirable during every local commit. Use Gitleaks for a fast local gate, then consider an authorized TruffleHog workflow for deeper verification.

How do I use the Gitleaks pre-commit hook?

Add a `.pre-commit-config.yaml` entry using repository `https://github.com/gitleaks/gitleaks`, the README example revision `v8.24.2`, and hook id `gitleaks` or `gitleaks-docker` for Docker execution. Run `pre-commit autoupdate` to move to an approved current revision, then `pre-commit install`. The documented emergency skip is `SKIP=gitleaks git commit -m "..."`, but it should be exceptional, reviewed and never used to conceal a real secret.

How do I run Gitleaks with Docker?

Pull `zricethezav/gitleaks:latest` from Docker Hub or `ghcr.io/gitleaks/gitleaks:latest` from GHCR. Mount the authorized host folder and scan the container path, for example `docker run -v ${path_to_host_folder_to_scan}:/path zricethezav/gitleaks:latest dir /path`. Pin an approved image version in production instead of depending indefinitely on the moving `latest` tag.

How does Gitleaks configuration and .gitleaks.toml work?

Gitleaks checks configuration in this order: `--config` or `-c`, `GITLEAKS_CONFIG`, `GITLEAKS_CONFIG_TOML`, the target's `.gitleaks.toml`, and finally the built-in default configuration. Custom `[[rules]]` can define an id, description, regex, secretGroup, entropy, keywords and tags. `[extend] useDefault = true` retains default rules while adding project-specific behavior.

How do I scan a directory with Gitleaks?

Run `gitleaks dir path_to_directory` to scan current files without Git history. The aliases `files` and `directory` are also available. If no target is supplied, `gitleaks dir` scans the current working directory. A single file can be selected with `gitleaks dir path_to_file`, while streamed data can be checked with `cat some_file | gitleaks -v stdin`.

How do I scan all branches or a commit range with Gitleaks?

The `git` command uses `git log -p` under the hood. Pass Git log options through `--log-opts`; for example, `gitleaks git -v --log-opts="--all commitA..commitB" path_to_repo` examines the selected revision range across refs included by `--all`. Ensure the local clone contains the required branches and commits before interpreting a clean result.

What are the Gitleaks exit codes?

Exit code 0 means no leaks are present. Exit code 1 means leaks or an execution error were encountered, so CI should retain the report and logs needed to distinguish those conditions. Exit code 126 means an unknown flag was supplied. The `--exit-code` option replaces the leaks-found code, allowing a pipeline to reserve a chosen nonzero value for detected secrets.

How do I ignore a false positive in Gitleaks?

For a reviewed fake fixture, place `gitleaks:allow` on the same line so the normal scan ignores it. Use `.gitleaksignore` to suppress a finding by Fingerprint when that experimental mechanism is appropriate, or configure rule and global allowlists with commits, paths, stopwords or regexes. Document every suppression, and use `--ignore-gitleaks-allow` when auditing inline comments.

Is Gitleaks free and open source?

Yes. Gitleaks is open-source software released under the MIT licence. The repository was created on 2018-01-27 and had 31,004 GitHub stars and 2,371 forks when checked on 2026-11-14. The maintainer states: "Gitleaks is feature complete. I'm not merging new features into Gitleaks. Future releases will be security patches only. I'm shifting my focus to Betterleaks." Pin an approved release version for repeatable scans.

Tags

#secret-scanning#git-security#devsecops#ci-cd#api-keys#leaked-credentials#vulnerability-analysis

Output Explanation

Gitleaks reports structured fields for each detected secret candidate. In the official README sample, Finding is `export BUNDLE_ENTERPRISE__CONTRIBSYS__COM=cafebabe:deadbeef`, Secret is `cafebabe:deadbeef`, RuleID is `sidekiq-secret`, Entropy is `2.609850`, File is `cmd/generate/config/rules/sidekiq.go`, Line is `23`, Commit is `cd5226711335c68be1e720b318b7bc3135a30eb2`, Author is `John`, Email is `john@users.noreply.github.com`, Date is `2022-08-03T12:31:40Z`, and Fingerprint is `cd5226711335c68be1e720b318b7bc3135a30eb2:cmd/generate/config/rules/sidekiq.go:sidekiq-secret:23`. Finding shows the matching source context, Secret is the sensitive substring, RuleID identifies the rule, Entropy records the calculated randomness score, File and Line locate the text, and the Git-specific fields identify the introducing revision and author metadata. Fingerprint provides a stable identifier used by `.gitleaksignore`. Exit code 0 means no leaks were present, exit code 1 means leaks or an error were encountered, and exit code 126 means an unknown flag was supplied; `--exit-code` changes the leaks-found code. `--redact` hides a selected percentage of secret text from logs and standard output, with 100 percent as the default. A scan with no finding records and exit code 0 means Gitleaks found no matches under the active configuration and selected scope, not that the repository is guaranteed to contain no secret.

Ethical Usage Notice

This tool is designed for authorized security testing, educational purposes, and legitimate network administration only. Unauthorized access to computer systems is illegal.