|
6 | 6 | import os |
7 | 7 | import argparse |
8 | 8 | import time |
| 9 | +import feedparser |
9 | 10 | from copy import copy |
10 | 11 | from sys import stderr |
11 | 12 |
|
@@ -39,12 +40,45 @@ def search_wrapper(gen): |
39 | 40 | except Exception as e: |
40 | 41 | raise e |
41 | 42 |
|
42 | | -def search(repo_to_search=None, user_to_search=None, gh_dorks_file=None): |
| 43 | +def metasearch(repo_to_search=None, user_to_search=None, gh_dorks_file=None, active_monit=None, refresh_time=60): |
| 44 | + if active_monit is None: |
| 45 | + search( |
| 46 | + repo_to_search, |
| 47 | + user_to_search, |
| 48 | + gh_dorks_file, |
| 49 | + active_monit |
| 50 | + ) |
| 51 | + else: |
| 52 | + monit( |
| 53 | + gh_dorks_file, |
| 54 | + active_monit, |
| 55 | + refresh_time |
| 56 | + ) |
| 57 | + |
| 58 | +def monit(gh_dorks_file=None,active_monit=None,refresh_time=60): |
| 59 | + if gh_user is None: |
| 60 | + raise Exception('Error, env Github user variable needed') |
| 61 | + else: |
| 62 | + print("Monitoring user private feed searching new code to be 'dorked'. Every new merged pull request trigger user scan.") |
| 63 | + print("-----") |
| 64 | + items_history = list() |
| 65 | + gh_private_feed = "https://github.com/"+gh_user+".private.atom?token="+active_monit |
| 66 | + while True: |
| 67 | + feed = feedparser.parse( gh_private_feed ) |
| 68 | + for i in feed['items']: |
| 69 | + if "merged pull" in i["title"]: |
| 70 | + if i["title"] not in items_history: |
| 71 | + search(user_to_search=i["author_detail"]["name"],gh_dorks_file=gh_dorks_file) |
| 72 | + items_history.append(i["title"]) |
| 73 | + print("Waiting for new items...") |
| 74 | + time.sleep(refresh_time) |
| 75 | + |
| 76 | +def search(repo_to_search=None, user_to_search=None, gh_dorks_file=None, active_monit=None): |
43 | 77 | if gh_dorks_file is None: |
44 | 78 | gh_dorks_file = 'github-dorks.txt' |
45 | 79 | if not os.path.isfile(gh_dorks_file): |
46 | 80 | raise Exception('Error, the dorks file path is not valid') |
47 | | - |
| 81 | + print("Scannig user: ", user_to_search) |
48 | 82 | found = False |
49 | 83 | with open(gh_dorks_file, 'r') as dork_file: |
50 | 84 | for dork in dork_file: |
@@ -100,7 +134,7 @@ def main(): |
100 | 134 | '-v', |
101 | 135 | '--version', |
102 | 136 | action='version', |
103 | | - version='%(prog)s 0.1.0' |
| 137 | + version='%(prog)s 0.1.1' |
104 | 138 | ) |
105 | 139 |
|
106 | 140 | group = parser.add_mutually_exclusive_group(required=True) |
@@ -128,12 +162,22 @@ def main(): |
128 | 162 | help='Github dorks file. Eg: github-dorks.txt' |
129 | 163 | ) |
130 | 164 |
|
| 165 | + group.add_argument( |
| 166 | + '-m', |
| 167 | + '--monit', |
| 168 | + dest='active_monit', |
| 169 | + action='store', |
| 170 | + help='Monitors Github user private feed. Need to provide token from feed. Find this token on feed icon at Github.com (when logged)' |
| 171 | + ) |
| 172 | + |
131 | 173 | args = parser.parse_args() |
132 | | - search( |
| 174 | + metasearch( |
133 | 175 | repo_to_search=args.repo_to_search, |
134 | 176 | user_to_search=args.user_to_search, |
135 | | - gh_dorks_file=args.gh_dorks_file |
| 177 | + gh_dorks_file=args.gh_dorks_file, |
| 178 | + active_monit=args.active_monit |
136 | 179 | ) |
137 | 180 |
|
138 | 181 | if __name__ == '__main__': |
139 | 182 | main() |
| 183 | + |
0 commit comments