Sergey Nivens - Fotolia
Software developers want to hide high-entropy secret keys in their GitHub repositories -- but they shouldn't, and may no longer be able to now that there's a tool for digging those secret keys out of old code repos.
Truffle Hog, a simple utility in just 113 lines of Python code, roots through Git repositories for strings of text that are long enough -- and random enough -- to be cryptographic secrets likely to be used for encryption, decryption or authentication.
Truffle Hog "[s]earches through Git repositories for high entropy strings, digging deep into commit history and branches," the developer, Dylan Ayrey wrote in the project's GitHub page. "This is effective at finding secrets accidentally committed that contain high entropy."
While not necessarily as bad as shipping internet of things hardware with hard-coded admin passwords, software developers often take shortcuts in early stages of projects. Embedding security tokens or other strings with high entropy into their source code early in a project, especially when the source code is stored on a publicly accessible site like GitHub, opens a particularly nasty path for attackers. While the secrets may be removed from production code, developers aren't always able to remove them from earlier or branched versions of their code in Git repositories.
"This module will go through the entire commit history of each branch, and check each diff from each commit," Ayrey wrote. The Truffle Hog program also evaluates "the Shannon entropy for both the base64 char set and hexadecimal char set for every blob of text greater than 20 characters comprised of those character sets in each diff. If at any point a high entropy string [greater than] 20 characters is detected, it will print to the screen."
One user on Twitter was especially impressed with Truffle Hog.
Participants on Reddit reported that Amazon has already fielded a tool similar to Truffle Hog capable of finding AWS secret keys in public software repositories.
"I have accidentally committed my AWS secret keys before to a public repo," Reddit user KingOtar reported. "Amazon actually found them and shut down my account until I created new ones. Kinda neat [A]mazon."
New to Git and distributed version control? Here are some Git examples and Jenkins-Git integration tutorials designed to help you master the popular source code versioning tool:
- The five basic Git commands beginners need to master
- Undo a commit and manipulate commit history with this git reset --hard example
- Learn to git revert a commit with the bash shell
- Use the git cherry-pick command across Git branches
- Change the Git editor to Notepad++
- Where the Windows Git configuration files are stored
- Make continuous integration part of your DevOps journey with this Jenkins CI tutorial