Skip to main content
Git stores its entire history, every commit, every branch, every stash, inside the .git directory at a repo’s root, and that directory frequently ends up exposed on a live web server, deployed alongside the application instead of excluded from it. Anyone who can reach .git over HTTP can rebuild the full source tree offline, including anything ever committed and later “removed,” config files, old credentials, commented-out debug endpoints, all of it.

Dumping

Rebuilding a usable working copy of the repo from just the exposed .git directory, no web shell or further access needed.

Credential & Secret Hunting

Once dumped (or once you already have filesystem access to a repo during post-exploitation), mining its full history for anything a developer ever committed and later thought was gone.

Detecting an Exposed .git Directory

Worth folding into a directory fuzzing pass (see Directory & Subdomain Fuzzing) rather than checking one path at a time across many hosts:
/.git/config and /.git/index are worth checking directly too even when HEAD 404s, some server configs block one path but not the others.

Dumping the Repository

GitTools is purpose-built for exactly this, gitdumper.sh pulls down every object it can reach without needing directory listing enabled.

Reconstructing & Reviewing

GitTools’ dumper leaves raw objects behind, not a checked-out working copy, extractor.sh (also part of GitTools) rebuilds every commit it can find into browsable snapshots:
If git-dumper was used instead, the dump is already a usable .git directory, standard git commands work directly against it:

Credential & Secret Extraction

Stored Remote Credentials

Searching the Full History

A secret removed in a later commit is not gone, it’s still sitting in an earlier one, searching the entire history (not just the current files) is the whole point of doing this rather than just browsing the live site.
git blame <file> identifies exactly who introduced a given line and when, useful once a secret is found, for figuring out whether it’s still valid or how long it’s been exposed.

Automated Secret Scanning

Manual grep-ing the log works but misses encoded/high-entropy secrets that don’t match an obvious keyword. These tools scan the full commit history for anything that looks like a credential, regardless of what it’s named. Truffelhog
Gitleaks
git-secrets (AWS Labs) is the defensive counterpart, a pre-commit hook that blocks a secret from ever being committed in the first place, worth knowing about since its absence is exactly why the techniques above find anything at all.

Malicious Git Hooks (Write Access)

.git/hooks/ scripts (post-commit, pre-push, etc.) are never transmitted by clone, pull, or push, they’re purely local. If write access to a shared repo’s working directory is already in hand (a writable deployment path, a CI checkout, an NFS-mounted repo), planting a hook there executes code the next time anyone on that same checkout commits, pushes, or merges, a quiet, easy-to-overlook persistence mechanism.

Searching Public Repos (grep.app)

grep.app regex searches the full text of every public repo on GitHub at once, useful for finding a target’s secrets leaked in someone else’s repo (a contractor’s fork, a personal dotfiles repo, e.g) that enumeration would never surface directly.

Quick Reference Tools

GitTools

Dump + extract an exposed .git directory into browsable commits.

git-dumper

Single-script alternative, dumps straight into a usable .git directory.

TruffleHog

Automated secret scanning across full commit history, not just current files.

Gitleaks

Similar automated secret scanner, worth running alongside TruffleHog, each catches patterns the other misses.

HackTricks: Git

Additional tools (Git-Money, DVCS-Pillage, gitrob) and GitHub-wide secret hunting.