Open Source Intelligence (OSINT): Finding Leaked Secrets with TruffleHog
Welcome back, cyberwarriors!Β
Youβve probably seen people committing their env files to GitHub without noticing it. When youβre looking for a job as a coder, that mistake alone is significant enough to get you rejected if it happens during the technical portion. And if it ever happened to you, itβs happened to plenty of others too.
Today weβll look at TruffleHog. Itβs a tool that scans Git repositories and their full history for secrets that got committed by accident. It uses high entropy checks with custom regular expressions to catch strings that look like API keys, tokens, passwords and other sensitive data. You can point it at one repository or use a GitHub or GitLab API to hit a lot of projects in one go.
A developer can delete a key from the latest commit, but it will still live in Gitβs past. With those credentials, you access services without making much noise.
Installation
First install git-dumper and TruffleHog. The Python package and the GitHub release are not the same, so pay attention to which one youβre on.
kali > pip3 install git-dumper
kali > pip3 install trufflehog
Weβll use git-dumper when we find an exposed .git directory and then run TruffleHog against that dump. Leaked .git folders are still common.
Dump a Repository
Some servers leave the entire .git directory open. Below you can see a website where it was fully accessible.

Dump it by giving git-dumper the URL and a local folder for the files.
kali > git-dumper http://example.com/.git dump

Other websites block the directory listing but still serve some of the files.

Git-dumper can pull every object, commit and reference it can reach.
kali > git-dumper http://example.com/.git/ dump

Everything will be stored in the dump folder.
Analyzing the Repositories
Once the dump is on disk, run TruffleHog against it. By default it runs entropy-based matching. That can help, but it shouldnβt be the only mode you know. In our case, regex with entropy off gave us more results.Β
kali > trufflehog --regex --entropy NO dump


In one of the files we found database credentials.
You can also install TruffleHog from the GitHub release and scan the filesystem directly:
kali > curl -sSfL https://raw.githubusercontent.com/trufflesecurity/trufflehog/main/scripts/install.sh | sh -s -- -b /usr/local/bin
kali > trufflehog filesystem /home/kali/Documents/dump

This build is fine for tuning your scans, but it often makes more noise and false positives, so just be aware of it.
Other Ways to Analyze Repositories
Depending on which build youβre using, try these flags to change what you get in the output.
Scan a repo for verified secrets:
kali > trufflehog git https://github.com/trufflesecurity/test_keys --results=verified,unknown

Verified means TruffleHog checked these finding live against the service API (AWS, GitHub and so on). Unknown is both high entropy and regex hits that it couldnβt confirm.
Same scan with JSON output:
kali > trufflehog git https://github.com/trufflesecurity/test_keys --results=verified,unknown --json

Scan a GitHub repo including issues and pull requests:
kali > trufflehog github --repo=https://github.com/trufflesecurity/test_keys --issue-comments --pr-comments


That digs into issues, comments, PR bodies and comments. You can find leaks in discussions too.
Scan a local Git repo:
kali > trufflehog git file://test_keys --results=verified,unknown
Useful when youβve compromised a dev Linux machine with multiple projects on it. Thereβs a better chance of finding something locally than pushed to GitHub, although both can happen, as you now know.
Summary
We had an external pentest where several services were accessible but no credentials could be found. Surprisingly, some developers had kept projects they were doing for the company publicly accessible on GitHub. Eventually we found a working pair and got into a database.
TruffleHog can be really helpful here. Sensitive files sometimes get exposed without the publisher even knowing it. Weβre humans and we make mistakes. Offensive or defensive, the point is the same.
The post Open Source Intelligence (OSINT): Finding Leaked Secrets with TruffleHog first appeared on Hackers Arise.








