visit
After hunting for security bugs I’ve realized clients I’m working with are not familiar enough (or at all) with basic “hacking” techniques. API keys, passwords, SSH encrypted keys, and certificates are all great mechanisms of protection, as long they are kept secret. Once they’re out in the wild, it doesn’t matter how complex the password is or what hash algorithm was used to encrypt it somewhere else. In this post, I’m going to share concepts, methods, and tools used by researchers both for finding secrets and exploiting them. I’ll also list mitigation action items that are simple to implement.
It’s important to mention that the attack & defend “game” is not an even one; an attacker only needs one successful attempt to get in, whereas the defender has to succeed 100% of the time. The hard part is knowing where to look. Once you can list your virtual “gates” through which hackers can find their way in, you can protect them with rather simple mechanisms. I believe their simplicity sometimes shadows their importance and makes a reason to be overlooked by many teams.So here’s a quick and simple, yet not one to overlook TL;DR:
<code style="box-sizing: border-box; font-family: Monaco, Consolas, "Lucida Console", monospace;"><span class="c1" style="box-sizing: border-box; transition: all 0.2s ease-in-out 0s; color: rgb(178, 204, 214);">// DEBUG ONLY</span>
<span class="c1" style="box-sizing: border-box; transition: all 0.2s ease-in-out 0s; color: rgb(178, 204, 214);">// TODO: remove --></span>
<span class="nx" style="box-sizing: border-box; transition: all 0.2s ease-in-out 0s; color: rgb(130, 170, 255);">API_KEY</span><span class="o" style="box-sizing: border-box; transition: all 0.2s ease-in-out 0s; color: rgb(137, 221, 255);">=</span><span class="nx" style="box-sizing: border-box; transition: all 0.2s ease-in-out 0s; color: rgb(130, 170, 255);">t0psecr3tkey00237948</span>
</code>
JS files are not only used to find secrets by hackers. This is your application code open to any prying eyes. An intelligent hacker might read the code thoroughly to understand naming conventions, API paths, and find informational comments. These are later on extrapolated to a list of words and paths and loaded into automated scanners. This is what’s referred to as an intelligent automated scan; one where the attacker combines automated processes and gathered organization-specific information.
A real comment left on a target’s front page, revealing a set of unprotected API endpoints leaking data.<code style="box-sizing: border-box; font-family: Monaco, Consolas, "Lucida Console", monospace;"><span class="cm" style="box-sizing: border-box; transition: all 0.2s ease-in-out 0s; color: rgb(178, 204, 214);">/* Debug ->
domain.com/api/v3 not yet in production
and therefore not using auth guards yet
use only for debugging purposes until approved */</span>
</code>
What should you do then?
They take a look back at the Wayback machine
The , also known as the “Wayback Machine” holds periodic scans of websites all over the internet for years and years back. This is a mining field for hackers with a target. With tools like (based on ) one can scan any target of old files. This means that even if you’ve found and removed a key but did not rotate it, a hacker might still find it in an old version of your website and use it against you.Found a key laying around where it’s not supposed to?The way WaybackMachine is not only good for finding keys
Old code reveals all kind of interesting information for exploiters:GitHub is a goldmine for hackers. With a simple search, knowing where to look can yield interesting results. If your account is not enforcing MFA, each and every user in the organization is a walking security hole. It’s not far-fetched to assume that one of the collaborators in the organization is not using a unique password and that his password was once leaked through another system. A hacker that targets the organization can easily automate such a scan or even go manually through it. The list of employees can be generated with like searching for employees on Linkedin, or in the GitHub public users list.
For example, here’s a good starting point if you’re trying to probe Tesla:<code style="box-sizing: border-box; font-family: Monaco, Consolas, "Lucida Console", monospace;">//api.github.com/orgs/teslamotors/members
</code>
Why does it happen?
Dorks 101
“Dorks” are search lines that utilize the search engine's different features, with targeted search strings to pinpoint results. from the exploit DB.Before giving the gist of it, if you want to go deep here, and I personally recommend that you do, . He discusses how to scan, how to use dorks, what to look for and where when going through a manual process.GitHub dorks are less complex than Google simply because it lacks the complexity of features Google offers. Still, searching for the right strings in the right places can do wonders. Just go ahead and search one string of the next list on GitHub, you’re in for a treat:<code style="box-sizing: border-box; font-family: Monaco, Consolas, "Lucida Console", monospace;">password
dbpassword
dbuser
access_key
secret_access_key
bucket_password
redis_password
root_password
</code>
If you try targeting the search to interesting files like f
ilename:.npmrc _auth or filename:.htpasswd
you can filter the type of leak you’re looking for. .<code style="box-sizing: border-box; font-family: Monaco, Consolas, "Lucida Console", monospace;">"MySQL_ROOT_PASSWORD:" "docker-compose" ext:yml
</code>
This is targeting a specific file format (yml) and a vulnerable file (docker-compose) where developers tend to store their not-so-unique passwords. Go ahead and run this search line, you’d be surprised to see what comes up.
Other interesting lines may include RSA keys or AWS credentials, here’s another example:<code style="box-sizing: border-box; font-family: Monaco, Consolas, "Lucida Console", monospace;">"-----BEGIN RSA PRIVATE KEY-----" ext:key
</code>
That’s where Github dorks which we’ve discussed earlier come in; knowing a system’s endpoints naming convention, e.g. api.mydomain.com/v1/payments/... can be very helpful. Searching the company’s Github repos (and their employees) for the basic API string can many times find those random endpoints names.However, random strings still have a place when building systems; they are always a better option than incremental resource IDs, like users, or orders.. It’s being used by almost everyone in the industry. Often with a personal twist and touch in the context of the target, it’s a massive source. Another powerful tool to leverage string lists is , an ultra-fast fuzz tool written in Go.Remember, security through obscurity is not a good practice (although don’t ignore it completely)
“Move fast and break things”, is not the best mantra in the context of information protectionKnowing how hackers work, is usually a very good first step in understanding security and applying it to systems as a protector. Consider the approaches above and the fact that this is a very limited list of paths hackers take when penetrating systems. A good thing to do is to keep in mind the security aspects of anything being deployed to a system, regardless of its customer-facing/internal nature.Managing security can sometimes be a pain in the ass, but rest assured, the mayhem you’re avoiding by just taking care of the very basic elements, will keep you safe and sane.
Thank you for reading this far! I hope that I’ve helped to open some minds to risks that are out there and we all miss or overlook.
Feel free to with any feedback or questions. Any form or shape or discussion is most welcome!