-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgather.py
executable file
·111 lines (73 loc) · 2.93 KB
/
gather.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#!/usr/bin/python3
import glob
import imp
import os
import threading
import gather_plain as txt
import proxy
from arguments import args
from logger import log
# address list type is list of 2 element tuples
def gather_all():
plugins = load_plugins()
threads = []
lock = threading.Lock()
address_list = []
for i,plugin_path in enumerate(plugins):
x = threading.Thread(target=worker, args=(plugin_path, address_list, lock))
threads.append(x)
log.debug(f"Created thread {i} for plugin {plugin_path}")
for i,x in enumerate(threads):
x.start()
for i,x in enumerate(threads):
x.join()
log.debug("Plugin threads terminated")
gather_plain_sources(address_list)
log.debug("Filtering addresses and creating proxy objects")
used_addresses = []
filtered_address_list = []
for proxy_tuple in address_list:
if proxy_tuple[0] not in used_addresses:
filtered_address_list.append(proxy_tuple)
used_addresses.append(proxy_tuple[0])
proxy_list = [proxy.Proxy(*t) for t in filtered_address_list if proxy.validate_address(t[0])]
log.info(f"Successfully gathered {len(proxy_list)} proxies!")
return proxy_list
def load_plugins(plugin_dir="plugins"):
plugins = glob.glob(plugin_dir+os.sep+'*.py')
plugins.remove('plugins/template.py')
plugins.remove('plugins/spys_one.py') # currently broken USE SELENIUM INSTEAD OF RETARDED DEOBSF
if args.disable_plugins:
for plugin in args.disable_plugins.split(','):
if plugin in plugins:
plugins.remove(plugin)
log.debug(f"Disabled plugin {plugin}")
else:
log.warning(f"Plugin specified for disable '{plugin}' not found. Continuing...")
if args.no_selenium:
plugins.remove('cyberhub_pw.py') #TODO dynamically do this
log.debug("Disabled selenium-based plugins")
return plugins
def gather_plain_sources(address_list):
txt_gathered = txt.grab_all()
address_list += txt_gathered
log.debug("Completed gathering from plain text sources")
def worker(plugin_path, address_list, lock):
try:
m = imp.load_source('module', plugin_path)
g = m.Grabber()
except Exception:
log.exception(f"Failed to load module at {plugin_path}")
return
try:
raw_thread_address_list = g.grab_all()
log.debug(f"Successfully gathered from plugin '{plugin_path}'")
except Exception:
log.exception(f"Failed to gather proxies for source '{plugin_path}'. Printing trace: ")
log.warning(f"Continuing after error, results for plugin '{plugin_path}' not scraped")
log.warning(f"Consider disabling plugin with arguments '--disable-plugins {plugin_path}'")
return
thread_address_list = [(address, g.name) for address in raw_thread_address_list]
lock.acquire()
address_list += thread_address_list
lock.release()