Back to Articles

GitHacker: Weaponizing Exposed .git Folders to Recover Complete Repository History

[ View on GitHub ]

GitHacker: Weaponizing Exposed .git Folders to Recover Complete Repository History

Hook

A single misconfigured Apache directive can leak your entire codebase, commit history, and even developer stashes. Worse yet, the attacker doesn’t need directory listing enabled to pull it off.

Context

Web developers occasionally deploy their applications without properly sanitizing the .git folder from production servers. This seemingly minor oversight creates a significant security vulnerability: anyone can access Git’s internal structure and potentially reconstruct the entire repository. Early exploitation tools like GitTools and dvcs-ripper could recover basic source code when web servers had directory listing enabled, but they fell short in two critical areas. First, they couldn’t extract the full richness of Git metadata—stashes containing unfinished work, branch histories revealing development strategies, or tags marking release cycles. Second, they became nearly useless when administrators disabled directory indexing, a common hardening measure.

GitHacker emerged from this gap, designed specifically for penetration testers who need comprehensive repository recovery during security assessments. Created by Wang Yihang, the tool distinguishes itself by treating Git repositories as intelligence sources rather than mere source code containers. The tool’s architecture recognizes that repository metadata can be valuable during security assessments.

Technical Insight

Enabled

Disabled

Discover branches

Web Server with .git/

Directory Listing?

Direct File Enumeration

Brute-force Git Paths

Multi-threaded Download Pool

.git/index & Metadata Files

Extract Object References

Parse .git/logs/HEAD

Download Git Objects

Git Repository Reconstruction

Recovered Repository

System architecture — auto-generated

GitHacker operates through a multi-threaded download strategy that exploits how Git stores repository data. The tool begins by attempting to fetch key Git files to reconstruct the repository structure.

The architecture branches into two distinct operational modes. When directory listing is enabled (Apache’s DirectoryIndex feature), GitHacker enumerates available files directly and downloads them systematically. The more sophisticated mode activates when directory listing is disabled. Here, GitHacker brute-forces known Git file paths and common branch/tag names:

# Running in brute-force mode when directory listing is disabled
docker run -v $(pwd)/results:/tmp/githacker/results wangyihang/githacker \
  --brute \
  --output-folder /tmp/githacker/results \
  --url http://target.example.com/.git/

The brute-force strategy targets predictable Git internal structures and common branch names. Once GitHacker retrieves .git/logs/HEAD, it extracts additional branch names from the reflog entries, creating a recursive discovery process.

What separates GitHacker from competitors like git-dumper is its handling of stashes and its branch/tag brute-forcing capability when directory listing is disabled. The comparison matrix in the README reveals a stark reality: when directory listing is disabled, dvcs-ripper completely fails, git-dumper cannot discover branches or tags, while GitHacker maintains comprehensive coverage through brute-forcing common naming patterns.

The tool’s multi-threaded architecture allows concurrent downloads of different Git objects, which appears to accelerate the recovery process when exploiting repositories with many objects.

Security researchers should note the tool’s evolution following vulnerability disclosures. Earlier versions (≤1.1.0) were susceptible to attacks from malicious repositories. The current architecture strongly recommends Docker-based execution:

# Docker provides jailed execution environment
docker run -v $(pwd)/results:/tmp/githacker/results wangyihang/githacker \
  --output-folder /tmp/githacker/results \
  --url-file websites.txt

This containerization approach ensures that even if a malicious repository contains dangerous elements, the blast radius remains contained within the disposable container. The volume mount (-v) safely extracts recovered repositories to the host filesystem while maintaining isolation during the exploitation phase.

Gotcha

GitHacker’s power comes with significant operational constraints that penetration testers must understand before deployment. The tool’s own documentation warns that versions 1.1.0 and earlier contained exploitable vulnerabilities. The README specifically mentions: arbitrary file write via recursive file downloader, and remote code execution via malicious .git/config and .git/hooks/* files. An attacker operating a honeypot could deliberately expose a weaponized .git folder that exploits GitHacker itself. The recommended Docker deployment addresses this, but it’s not optional security theater—it’s essential defense against targeted counterattacks.

The brute-forcing capability for branches and tags, while valuable, operates on common naming conventions rather than exhaustive discovery. If developers use unconventional branch names, GitHacker won’t discover them unless directory listing is enabled. The tool can only find what it can guess, and creative naming defeats pattern-based discovery. Additionally, the README notes that GitHacker cannot solve the fundamental Git pack file naming problem—pack files use SHA-1 hashes that aren’t predictable from external information, so the tool relies on finding references to these pack files rather than brute-forcing their names.

Verdict

Use GitHacker if you’re conducting authorized penetration tests or security assessments where comprehensive Git repository recovery provides security value. The tool’s superior metadata recovery (stashes, branches, tags, reflogs, commits, remotes) and ability to operate when directory listing is disabled make it the strongest choice among comparable tools according to the comparison matrix in the README. Always run it in Docker containers on isolated testing infrastructure as the README explicitly recommends. Skip it if you only need basic source code recovery (simpler tools may suffice for quick assessments), if you cannot provide adequate isolation (the security risks are documented and genuine), or if you’re working in any context that isn’t explicitly authorized security testing. This is a specialized offensive tool built for security professionals who understand both its capabilities and its risks.

// ADD TO YOUR README
[![Featured on Starlog](https://starlog.is/api/badge/cybersecurity/wangyihang-githacker.svg)](https://starlog.is/api/badge-click/cybersecurity/wangyihang-githacker)