|
| 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() |
0 commit comments