-
Notifications
You must be signed in to change notification settings - Fork 16
/
brute.py
61 lines (47 loc) · 1.44 KB
/
brute.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
import math
import time
import string
import itertools
import multiprocessing
def permutate(packet, thread, threads, offset, count, check, timestamp):
amount = 0
for guess in packet:
guess = "".join(guess)
if thread == threads - 1:
total = offset + (amount * threads)
percent = round((total/count)*100, 6)
now = time.time()
speed = round((amount / (now - timestamp)) * threads)
print(" - {} - permutations: {} / {} ({}%) - threads: {} - speed: {} p/s".format(guess, total, count, percent, threads, speed), end=" \r")
if check(guess) == 1:
return guess
amount += 1
return None
def process(result):
global found
if result:
found = result
def force(start, charset, minimum, maximum, chunk, check, cache):
global found
found = None
threads = multiprocessing.cpu_count()
offset = start[1]
for length in range(minimum, maximum):
if length < start[0]:
continue
permutations = itertools.product(charset, repeat=length)
count = len(charset) ** length
offset = start[1]
while offset < count:
pool = multiprocessing.Pool()
for thread in range(0, threads):
leap = thread * chunk
pool.apply_async(permutate, args=(itertools.islice(permutations, offset + leap, offset + leap + chunk), thread, threads, offset, count, check, time.time()), callback=process)
pool.close()
pool.join()
if found:
return found
offset += threads * chunk
cache(length, offset)
offset = 0
return False