Skip to content

Commit d078d62

Browse files
committed
update: update from python2.7 to python3.6
1 parent 4e6f923 commit d078d62

File tree

4 files changed

+36
-39
lines changed

4 files changed

+36
-39
lines changed

GitPrey.py

+28-30
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
11
#!/usr/bin/env python
2-
# -*- coding: utf-8 -*-
32

43
try:
54
import requests
65
from requests.auth import HTTPBasicAuth
76
except ImportError:
8-
print "[!_!]ERROR INFO: You have to install requests module."
7+
print("[!]Error: You have to install requests module.")
98
exit()
109

1110
try:
1211
from bs4 import BeautifulSoup
1312
except ImportError:
14-
print "[!_!]ERROR INFO: You have to install BeautifulSoup module."
13+
print("[!]Error: You have to install BeautifulSoup module.")
1514
exit()
1615

1716
import re
17+
import math
1818
import sys
1919
import time
20-
import imp
20+
import importlib.util
2121
import argparse
2222

2323
try:
2424
from config.Config import *
2525
except ImportError:
26-
print "[!_!]ERROR INFO: Can't find Config file for searching."
26+
print("[!]Error: Can't find Config file for searching.")
2727
exit()
2828

2929
try:
3030
from include.ColorPrint import *
3131
except ImportError:
32-
print "[!_!]ERROR INFO: Can't find ColorPrint file for printing."
32+
print("[!]Error: Can't find ColorPrint file for printing.")
3333
exit()
3434

3535
HOST_NAME = "https://github.com/"
@@ -51,11 +51,11 @@ class GitPrey(object):
5151
\$$$$$$ |$$$$$$\ $$ | $$ | $$ | $$ |$$$$$$$$\ $$ |
5252
\______/ \______| \__| \__| \__| \__|\________| \__|
5353
54-
Author: Cooper Pei
55-
Version: 2.5
54+
Author: repoog
55+
Version: 2.6
5656
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
5959
"""
6060

6161
def __init__(self, keyword):
@@ -72,12 +72,12 @@ def search_project(self):
7272
"""
7373
unique_project_list = []
7474
self.__auto_login(USER_NAME, PASSWORD)
75-
info_print('[@_@] Searching projects hard...')
75+
info_print('[*] Searching projects hard...')
7676

7777
# Get unique project list of first page searched results
7878
total_progress = SCAN_DEEP[SEARCH_LEVEL - 1]
7979
query_string = self.keyword + " in:file,path"
80-
for i in xrange(total_progress):
80+
for i in range(total_progress):
8181
# Print process of searching project
8282
progress_point = int((i + 1) * (100 / total_progress))
8383
sys.stdout.write(str(progress_point) + '%|' + '#' * progress_point + '|\r')
@@ -123,7 +123,7 @@ def sensitive_info_query(self, project_string, mode):
123123
file_pattern = " filename:" + " filename:".join(file_sig_list)
124124
code_dic = {}
125125
# 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):
127127
project_pattern = info_sig_list[i*5:i*5+5]
128128
repo_code_dic = self.__file_content_inspect(project_string, file_pattern, project_pattern)
129129
code_dic.update(repo_code_dic)
@@ -219,11 +219,11 @@ def __output_project_info(project):
219219
:returns: None
220220
"""
221221
user_name, project_name = project.split(r"/")
222-
user_info = "[+_+] User Nickname: {nickname}"
222+
user_info = "[+] User Nickname: {nickname}"
223223
project_print(user_info.format(nickname=user_name))
224-
project_info = "[+_+] Project Name: {name}"
224+
project_info = "[+] Project Name: {name}"
225225
project_print(project_info.format(name=project_name))
226-
project_info = "[+_+] Project Link: {link}"
226+
project_info = "[+] Project Link: {link}"
227227
project_print(project_info.format(link=HOST_NAME + project))
228228

229229
def __auto_login(self, username, password):
@@ -242,7 +242,7 @@ def __auto_login(self, username, password):
242242
login_request.post("https://github.com/session", data=post_data, headers=self.headers)
243243
self.cookies = login_request.cookies
244244
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.')
246246
exit()
247247

248248
def __get_page_html(self, url):
@@ -257,8 +257,8 @@ def __get_page_html(self, url):
257257
time.sleep(SCAN_DEEP[SEARCH_LEVEL - 1])
258258
self.__get_page_html(url)
259259
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))
262262
exit()
263263
except requests.ReadTimeout:
264264
return ''
@@ -282,10 +282,8 @@ def init():
282282
Initialize GitPrey with module inspection and input inspection
283283
:return: None
284284
"""
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.')
289287
exit()
290288

291289
# Get command parameters for searching level and key words
@@ -303,10 +301,10 @@ def init():
303301
info_print(GitPrey.__doc__)
304302

305303
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.")
307305
exit()
308306
else:
309-
keyword_output = "[^_^] START INFO: The key word for searching is: {keyword}"
307+
keyword_output = "[*] The key word for searching is: {keyword}"
310308
info_print(keyword_output.format(keyword=key_words))
311309

312310
return key_words
@@ -322,21 +320,21 @@ def project_miner(key_words):
322320
_gitprey = GitPrey(key_words)
323321
total_project_list = _gitprey.search_project()
324322

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"
326324
info_print(project_info_output.format(num=len(total_project_list)))
327325

328326
# Join all projects to together to search
329327
repo_string = " repo:" + " repo:".join(total_project_list)
330328

331329
# Scan all projects with pattern filename
332-
info_print("[^_^] START INFO: Begin searching sensitive file.")
330+
info_print("[*] Begin searching sensitive file.")
333331
_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")
335333

336334
# Scan all projects with pattern content
337-
info_print("[^_^] START INFO: Begin searching sensitive content.")
335+
info_print("[*] Begin searching sensitive content.")
338336
_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")
340338

341339

342340
if __name__ == "__main__":

include/ColorPrint.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
#!/usr/bin/env python
2-
# coding = utf-8
32

43
try:
54
from colorama import init, Fore
65
except ImportError:
7-
print "[!_!]ERROR INFO: You have to install colorama module."
6+
print("[!]Error: You have to install colorama module.")
87
exit()
98

109
import logging
@@ -22,31 +21,31 @@
2221

2322
def error_print(string):
2423
# Print error information with red color
25-
print Fore.RED + string
24+
print(Fore.RED + string)
2625
logger.error(string)
2726

2827

2928
def info_print(string):
3029
# Print information with green color
31-
print Fore.GREEN + string
30+
print(Fore.GREEN + string)
3231
logger.info(string)
3332

3433

3534
def project_print(string):
3635
# Print project information with deep green color
37-
print Fore.CYAN + string
36+
print(Fore.CYAN + string)
3837
logger.info(string)
3938

4039

4140
def file_print(string):
4241
# Print file url with yellow color
43-
print Fore.YELLOW + string
42+
print(Fore.YELLOW + string)
4443
logger.info(string)
4544

4645

4746
def code_print(string):
4847
# Print code line with white color
49-
print Fore.WHITE + string
48+
print(Fore.WHITE + string)
5049
logger.info(string)
5150

5251

pattern/file.db

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ password
77
secret
88
setting
99
log
10-
sql
10+
sql

pattern/info.db

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@ jdbc
1212
password
1313
passwd
1414
pass
15-
pwd
15+
pwd

0 commit comments

Comments
 (0)