Any time I recommend software to a friend, there is always an inevitable question: How much does it cost? The quality isn't necessarily the discerning factorβno one wants to pay for something if it isn't necessary. That makes free, open-source tools very easy to recommend to most people without a moment's hesitation.
As longer, more complex passwords have become a necessity, remembering all those strings of numbers, letters, and special characters has become nearly impossible. Password managers can solve that problem, but what happens when you want to move to a different login organizer? Sure, you could manually type all your logins into a new app, but now Android can do that for you without the tedium.
Google designed the new login transfer process to happen entirely on your phone, so you need the corresponding apps installed with your credentials synced. To start the move, you'll have to find the import option in the app you want to use. The location of that feature will vary, but in Google Password Manager (built into Android), it's near the top under the settings tab.
The import option in Google Password Manager will plug in to the new migration system, while export still just creates an unencrypted CSV with your passwords that can be dumped into any app. It will be similar in other apps, so make sure to start the process in the app you want to use. Currently, this works in Google's app, 1Password, Bitwarden, and Dashlane.
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.
When you just land on a new machine, you often have to sit down and go through every running service just to figure out whatβs actually installed and which of those apps might be worth a closer look for credentials in a config somewhere. You canβt skip this part, as it usually gives you something youβll need later in the engagement, but it eats time. A lot of it.
There are older tools that try to do something similar, but the two weβre covering today are more current. LOLCreds and CredsHound come from the same developer and they cover a huge amount of software.
So letβs see how they work.
LOLCreds
LOLCreds is a website that has 678 different credentials. Some software generates a password when you install it or prompts you to enter it. There are also static credentials that are baked into the product. The D-Link backdoor credentials are a good example of the second kind.Β
LOLCreds also tracks AI API keys and shows you exactly where to find them on a system. Hereβs what it has on Cursor.
MySQL is a more basic example. Its password is often hidden in a config file or sitting as a variable in the env file.
CredsHound
All of that is great when you already know what software youβre hunting through and youβre picking it one at a time. But machines might have dozens of applications running. Software can be removed, but configs stay and password reuse is common. You can use CredsHound for this hunt.Β
CredsHound is a scanner written in Go. Under the hood it pulls templates from LOLCreds so it can run product aware checks. It has been fully optimized for modern environments, so it will scan everything from DBeaver encrypted databases to OpenCode, GitHub Copilot CLI, Hugging Face, OpenAI and more.Β
Setting Up
Before you start using the scanner, you need to have Go installed.
There are different ways you can run it, but you always start with updating the template library. The scanner can be used with different privileges, but weβll use root.Β
Our system is fresh, so thereβs not much on it yet. A box thatβs been sitting in prod for a while will have more interesting results, like the one below.
CredsHound can also work with BloodHound to show you the relationships between credentials as a graph. Hereβs how to set it up:
Then you import the JSON file into BloodHound and see what comes up.
When youβve collected many of these JSON files from different machines, youβll start seeing the architecture of what youβre testing.
A few more commands youβll find useful:
# Scan the current directory
bash$ > credshound .
# Scan multiple roots
bash$ > credshound ~/project /etc
# Scan only env variables
bash$ > credshound -sources env
# Scan current and process environment variables on Linux
bash$ > credshound -sources env,proc
Summary
Credential hunting is a tedious thing when you do it manually, but you canβt really skip this part. Itβs essential to move further. The tools covered can make the whole process easier and the output rich. LOLCreds has a reference library for different products and CredsHound can scan your hosts for secrets with results that you may import into BloodHound.
If you like red teaming, we have our Red Team Operator training, where we cover more tools and techniques to help you emulate real APT work, so you can give a company a realistic stress test and help make it secure.