Skip to content

Commit 75bf80d

Browse files
committed
add a github dork checker tool
1 parent c8c6827 commit 75bf80d

5 files changed

Lines changed: 179 additions & 0 deletions

File tree

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,45 @@
11
# Github Dorks
22
[Github search](https://github.com/search) is quite powerful and useful feature and can be used to search sensitive data on the repositories. Collection of github dorks that can reveal sensitive personal and/or organizational information such as private keys, credentials, authentication tokens, etc. This list is supposed to be useful for assessing security and performing pen-testing of systems.
33

4+
### GitHub Dork Search Tool
5+
[github-dork.py](github-dork.py) is a simple python tool that can search through your repository or your organization/user repositories. Its not a perfect tool at the moment but provides a basic functionality to automate the search on your repositories against the dorks specified in text file.
6+
7+
#### Installation
8+
This tool uses [pygithub3.py](https://github.com/sigmavirus24/github3.py) to talk with GitHub Search API.
9+
10+
Clone this repository and run:
11+
```shell
12+
pip install -r requirements.txt
13+
```
14+
15+
#### Usage
16+
17+
```
18+
GH_USER - Environment variable to specify github user
19+
GH_PWD - Environment variable to specify password
20+
GH_TOKEN - Environment variable to specify github token
21+
```
22+
23+
Some example usages are listed below:
24+
25+
```shell
26+
python github-dork.py -r techgaun/github-dorks # search single repo
27+
28+
python github-dork.py -u techgaun # search all repos of user
29+
30+
python github-dork.py -u dev-nepal # search all repos of an organization
31+
32+
GH_USER=techgaun GH_PWD=<mypass> python github-dork.py -u dev-nepal # search as authenticated user
33+
34+
GH_TOKEN=<github_token> python github-dork.py -u dev-nepal # search using auth token
35+
```
36+
37+
#### Limitations
38+
39+
- Authenticated requests get a higher rate limit. But, you can still hit limit with user/org with too many repos or even with large repos or large number of dorks. This is a major limitation, imo, at the moment for this tool.
40+
- Output formatting is not great. PR welcome
41+
- Handle rate limit and retry. PR welcome
42+
443
### Contribution
544
Please consider contributing the dorks that can reveal potentially senstive information in github.
645

github-dork.py

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#!/usr/bin/env python
2+
# -*- encoding: utf-8 -*-
3+
4+
5+
import github3 as github
6+
import os
7+
import argparse
8+
from time import sleep
9+
10+
11+
gh_user = os.getenv('GH_USER', None)
12+
gh_pass = os.getenv('GH_PWD', None)
13+
gh_token = os.getenv('GH_TOKEN', None)
14+
gh_dorks_file = "github-dorks.txt"
15+
16+
gh = github.GitHub(username=gh_user, password=gh_pass, token=gh_token)
17+
18+
19+
def search(repo_to_search=None, user_to_search=None):
20+
found = False
21+
with open(gh_dorks_file, 'r') as dork_file:
22+
for dork in dork_file:
23+
dork = dork.strip()
24+
addendum = ''
25+
if repo_to_search is not None:
26+
addendum = ' repo:' + repo_to_search
27+
elif user_to_search is not None:
28+
addendum = ' user:' + user_to_search
29+
30+
dork = dork + addendum
31+
search_results = gh.search_code(dork)
32+
try:
33+
for search_result in search_results:
34+
found = True
35+
fmt_args = {
36+
'dork': dork,
37+
'text_matches': search_result.text_matches,
38+
'path': search_result.path,
39+
'score': search_result.score,
40+
'url': search_result.html_url
41+
}
42+
print(
43+
'''Found result for {dork}
44+
Text matches: {text_matches}
45+
File path: {path}
46+
Score/Relevance: {score}
47+
URL of File: {url}
48+
'''.format(**fmt_args)
49+
)
50+
except github.exceptions.ForbiddenError as e:
51+
print(e)
52+
# need to retry in case of API rate limit reached
53+
# note done yet
54+
except github.exceptions.GitHubError as e:
55+
print('GitHubError encountered on search of dork: ' + dork)
56+
print(e)
57+
except Exception as e:
58+
print('Error encountered on search of dork: ' + dork)
59+
60+
if not found:
61+
print('No results for your dork search' + addendum + '. Hurray!')
62+
63+
64+
def main():
65+
parser = argparse.ArgumentParser(
66+
description='Search github for github dorks',
67+
epilog='Use responsibly, Enjoy pentesting'
68+
)
69+
parser.add_argument(
70+
'-v',
71+
'--version',
72+
action='version',
73+
version='%(prog)s 0.1.0'
74+
)
75+
group = parser.add_mutually_exclusive_group(required=True)
76+
group.add_argument(
77+
'-u',
78+
'--user',
79+
dest='user_to_search',
80+
action='store',
81+
help='Github user/org to search within. Eg: techgaun'
82+
)
83+
group.add_argument(
84+
'-r',
85+
'--repo',
86+
dest='repo_to_search',
87+
action='store',
88+
help='Github repo to search within. Eg: techgaun/github-dorks'
89+
)
90+
91+
args = parser.parse_args()
92+
search(
93+
repo_to_search=args.repo_to_search,
94+
user_to_search=args.user_to_search
95+
)
96+
97+
if __name__ == '__main__':
98+
main()

github-dorks-test.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
filename:.npmrc _auth
2+
filename:.dockercfg auth
3+
extension:md

github-dorks.txt

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
filename:.npmrc _auth
2+
filename:.dockercfg auth
3+
extension:pem private
4+
extension:ppk private
5+
filename:id_rsa or filename:id_dsa
6+
extension:sql mysql dump
7+
extension:sql mysql dump password
8+
filename:credentials aws_access_key_id
9+
filename:.s3cfg
10+
filename:wp-config.php
11+
filename:.htpasswd
12+
filename:.env DB_USERNAME NOT homestead
13+
filename:.env MAIL_HOST=smtp.gmail.com
14+
filename:.git-credentials
15+
PT_TOKEN language:bash
16+
filename:.bashrc password
17+
filename:.bashrc mailchimp
18+
filename:.bash_profile aws
19+
rds.amazonaws.com password
20+
extension:json api.forecast.io
21+
extension:json mongolab.com
22+
extension:yaml mongolab.com
23+
jsforce extension:js conn.login
24+
SF_USERNAME "salesforce"
25+
filename:.tugboat NOT "_tugboat"
26+
HEROKU_API_KEY language:shell
27+
HEROKU_API_KEY language:json
28+
filename:.netrc password
29+
filename:_netrc password
30+
filename:hub oauth_token
31+
filename:robomongo.json
32+
filename:filezilla.xml Pass
33+
filename:recentservers.xml Pass
34+
filename:config.json auths
35+
filename:idea14.key
36+
filename:config irc_pass
37+
filename:connections.xml
38+
filename:express.conf path:.openshift

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github3.py==1.0.0a2

0 commit comments

Comments
 (0)