-
Notifications
You must be signed in to change notification settings - Fork 0
/
bruteforce.py
83 lines (64 loc) · 2.07 KB
/
bruteforce.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
import sys, getopt
import subprocess
import time
import threading
# lockcode = "00000000000000000000000000000000"
# maxlockcode="340282366920938463463374607431768211455"
def func(args):
return args
def crack_lock(low, high):
print(f"Cracking with {low} and {high}!")
for i in range(low, high + 1):
completed = 0
while completed == 0:
# HEX-ifies the string
lockcode = str(hex(i))
# Removes the leading 0x
lockcode = lockcode[2:].zfill(32)
print(lockcode)
bashCommand = (
f"ykman config set-lock-code --clear --force --lock-code {lockcode}"
)
process = subprocess.run(
bashCommand.split(), capture_output=True, text=True
)
if "WARNING" not in process.stderr:
completed = 1
if "ERROR" not in process.stderr:
print(f"Complete with {lockcode}!")
f = open(f"{lockcode}.txt", "a")
f.write(lockcode + "\n" + str(process))
f.close()
else:
print(f"TOO FAST, retrying {lockcode}")
def main(argv):
start = 0
end = 0
threads = 0
opts, args = getopt.getopt(argv, "t:s:e:")
for opt, arg in opts:
if opt == "-t":
threads = int(arg)
elif opt == "-s":
start = int(arg)
elif opt == "-e":
end = int(arg)
if start > end:
print("The start must be less than the end target")
sys.exit()
difference = end - start
if difference % threads != 0:
print("The difference must be divisable by threads! Exiting!")
sys.exit()
slices = difference // threads - 1
for i in range(threads):
if i == threads - 1:
end = start + slices + 1
else:
end = start + slices
t = threading.Thread(target=crack_lock, args=(start, end))
t.start()
start = end + 1
print("Done!")
if __name__ == "__main__":
main(sys.argv[1:])