1
1
#!/usr/bin/env python
2
- # -*- coding: utf-8 -*-
3
2
4
3
try :
5
4
import requests
6
5
from requests .auth import HTTPBasicAuth
7
6
except ImportError :
8
- print "[!_!]ERROR INFO : You have to install requests module."
7
+ print ( "[!]Error : You have to install requests module." )
9
8
exit ()
10
9
11
10
try :
12
11
from bs4 import BeautifulSoup
13
12
except ImportError :
14
- print "[!_!]ERROR INFO : You have to install BeautifulSoup module."
13
+ print ( "[!]Error : You have to install BeautifulSoup module." )
15
14
exit ()
16
15
17
16
import re
17
+ import math
18
18
import sys
19
19
import time
20
- import imp
20
+ import importlib . util
21
21
import argparse
22
22
23
23
try :
24
24
from config .Config import *
25
25
except ImportError :
26
- print "[!_!]ERROR INFO : Can't find Config file for searching."
26
+ print ( "[!]Error : Can't find Config file for searching." )
27
27
exit ()
28
28
29
29
try :
30
30
from include .ColorPrint import *
31
31
except ImportError :
32
- print "[!_!]ERROR INFO : Can't find ColorPrint file for printing."
32
+ print ( "[!]Error : Can't find ColorPrint file for printing." )
33
33
exit ()
34
34
35
35
HOST_NAME = "https://github.com/"
@@ -51,11 +51,11 @@ class GitPrey(object):
51
51
\$$$$$$ |$$$$$$\ $$ | $$ | $$ | $$ |$$$$$$$$\ $$ |
52
52
\______/ \______| \__| \__| \__| \__|\________| \__|
53
53
54
- Author: Cooper Pei
55
- Version: 2.5
54
+ Author: repoog
55
+ Version: 2.6
56
56
Create Date: 2016-03-15
57
- Update Date: 2017-07-05
58
- Python Version: v2.7.10
57
+ Update Date: 2019-05-20
58
+ Python Version: v3.6.4
59
59
"""
60
60
61
61
def __init__ (self , keyword ):
@@ -72,12 +72,12 @@ def search_project(self):
72
72
"""
73
73
unique_project_list = []
74
74
self .__auto_login (USER_NAME , PASSWORD )
75
- info_print ('[@_@ ] Searching projects hard...' )
75
+ info_print ('[* ] Searching projects hard...' )
76
76
77
77
# Get unique project list of first page searched results
78
78
total_progress = SCAN_DEEP [SEARCH_LEVEL - 1 ]
79
79
query_string = self .keyword + " in:file,path"
80
- for i in xrange (total_progress ):
80
+ for i in range (total_progress ):
81
81
# Print process of searching project
82
82
progress_point = int ((i + 1 ) * (100 / total_progress ))
83
83
sys .stdout .write (str (progress_point ) + '%|' + '#' * progress_point + '|\r ' )
@@ -123,7 +123,7 @@ def sensitive_info_query(self, project_string, mode):
123
123
file_pattern = " filename:" + " filename:" .join (file_sig_list )
124
124
code_dic = {}
125
125
# Most five AND/OR operators in search function.
126
- for i in xrange ( len (info_sig_list )/ 5 + 1 ):
126
+ for i in range ( math . floor ( len (info_sig_list )/ 5 ) + 1 ):
127
127
project_pattern = info_sig_list [i * 5 :i * 5 + 5 ]
128
128
repo_code_dic = self .__file_content_inspect (project_string , file_pattern , project_pattern )
129
129
code_dic .update (repo_code_dic )
@@ -219,11 +219,11 @@ def __output_project_info(project):
219
219
:returns: None
220
220
"""
221
221
user_name , project_name = project .split (r"/" )
222
- user_info = "[+_+ ] User Nickname: {nickname}"
222
+ user_info = "[+] User Nickname: {nickname}"
223
223
project_print (user_info .format (nickname = user_name ))
224
- project_info = "[+_+ ] Project Name: {name}"
224
+ project_info = "[+] Project Name: {name}"
225
225
project_print (project_info .format (name = project_name ))
226
- project_info = "[+_+ ] Project Link: {link}"
226
+ project_info = "[+] Project Link: {link}"
227
227
project_print (project_info .format (link = HOST_NAME + project ))
228
228
229
229
def __auto_login (self , username , password ):
@@ -242,7 +242,7 @@ def __auto_login(self, username, password):
242
242
login_request .post ("https://github.com/session" , data = post_data , headers = self .headers )
243
243
self .cookies = login_request .cookies
244
244
if self .cookies ['logged_in' ] == 'no' :
245
- error_print ('[!_!] ERROR INFO : Login Github failed, please check account in config file.' )
245
+ error_print ('[!] Error : Login Github failed, please check account in config file.' )
246
246
exit ()
247
247
248
248
def __get_page_html (self , url ):
@@ -257,8 +257,8 @@ def __get_page_html(self, url):
257
257
time .sleep (SCAN_DEEP [SEARCH_LEVEL - 1 ])
258
258
self .__get_page_html (url )
259
259
return page_html .text
260
- except requests .ConnectionError , e :
261
- error_print ("[!_!] ERROR INFO : There is '%s' problem in requesting html page." % str (e ))
260
+ except requests .ConnectionError as e :
261
+ error_print ("[!] Error : There is '%s' problem in requesting html page." % str (e ))
262
262
exit ()
263
263
except requests .ReadTimeout :
264
264
return ''
@@ -282,10 +282,8 @@ def init():
282
282
Initialize GitPrey with module inspection and input inspection
283
283
:return: None
284
284
"""
285
- try :
286
- imp .find_module ('lxml' )
287
- except ImportError :
288
- error_print ('[!_!]ERROR INFO: You have to install lxml module.' )
285
+ if not importlib .util .find_spec ('lxml' ):
286
+ error_print ('[!]Error: You have to install lxml module.' )
289
287
exit ()
290
288
291
289
# Get command parameters for searching level and key words
@@ -303,10 +301,10 @@ def init():
303
301
info_print (GitPrey .__doc__ )
304
302
305
303
if not is_keyword_valid (key_words ):
306
- error_print ("[!_!] ERROR INFO : The key word you input is invalid. Please try again." )
304
+ error_print ("[!] Error : The key word you input is invalid. Please try again." )
307
305
exit ()
308
306
else :
309
- keyword_output = "[^_^] START INFO: The key word for searching is: {keyword}"
307
+ keyword_output = "[*] The key word for searching is: {keyword}"
310
308
info_print (keyword_output .format (keyword = key_words ))
311
309
312
310
return key_words
@@ -322,21 +320,21 @@ def project_miner(key_words):
322
320
_gitprey = GitPrey (key_words )
323
321
total_project_list = _gitprey .search_project ()
324
322
325
- project_info_output = "\n [*_*] PROJECT INFO: Found {num} public projects related to the key words.\n "
323
+ project_info_output = "\n [*] Found {num} public projects related to the key words.\n "
326
324
info_print (project_info_output .format (num = len (total_project_list )))
327
325
328
326
# Join all projects to together to search
329
327
repo_string = " repo:" + " repo:" .join (total_project_list )
330
328
331
329
# Scan all projects with pattern filename
332
- info_print ("[^_^] START INFO: Begin searching sensitive file." )
330
+ info_print ("[*] Begin searching sensitive file." )
333
331
_gitprey .sensitive_info_query (repo_string , "filename" )
334
- info_print ("[^_^] END INFO: Sensitive file searching is done.\n " )
332
+ info_print ("[*] Sensitive file searching is done.\n " )
335
333
336
334
# Scan all projects with pattern content
337
- info_print ("[^_^] START INFO: Begin searching sensitive content." )
335
+ info_print ("[*] Begin searching sensitive content." )
338
336
_gitprey .sensitive_info_query (repo_string , "content" )
339
- info_print ("[^_^] END INFO: Sensitive content searching is done.\n " )
337
+ info_print ("[*] Sensitive content searching is done.\n " )
340
338
341
339
342
340
if __name__ == "__main__" :
0 commit comments