-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCTFALC.py
More file actions
89 lines (55 loc) · 1.91 KB
/
Copy pathCTFALC.py
File metadata and controls
89 lines (55 loc) · 1.91 KB
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
from argparse import ArgumentParser
from binascii import unhexlify
from hashlib import sha1
from itertools import permutations
from time import time
def print_info(message):
print("\n\033[1;33m[i]\033[0m", message, "\n")
def print_alert(message):
print("\n\n\033[1;32m[!]\033[0m", message, "\n")
def print_line(num):
print("-" * 13)
print(f"| {num[0]} | {num[1]} | { num[2] } |")
def print_gesture_path(positions):
print("\n\nFollow these steps to unlock the phone:")
for x in range(3):
line = []
for y in range(3):
if str(x*3+y + 1) not in positions:
line.append(" ")
else:
line.append(positions[str(x*3+y + 1)])
print_line(line)
print("-" * 13, "\n")
def crack_gesture(key):
cells = list(range(9))
start = time()
for length in range(3,10):
print(f"trying length {length} patterns...", end="")
for possible_pattern in permutations(cells, r=length):
pattern = "".join(str(c) for c in possible_pattern)
hash = sha1(unhexlify("".join("0" + str(pos) for pos in pattern))).hexdigest()
if hash == key:
print_alert(f"GESTURE FOUND!!! \033[4m{pattern}\033[24m")
pattern = ''.join(str(int(i)+1) for i in pattern)
positions = {}
for a, b in enumerate(pattern):
positions[b] = a + 1
print_gesture_path(positions)
print_info(f"Time: {time() - start}s")
exit(0)
print(" nothing")
print_info("Nothing found!")
def main():
parser = ArgumentParser(description="Cracks a lock pattern on Android phones")
parser.add_argument("gesture_file", help="The path to the gesture.key file", type=str, default="./gesture.key")
args = parser.parse_args()
with open(args.gesture_file, "rb") as fi:
key = bytes(fi.read(sha1().digest_size)).hex()
print_info(f"Looking for key {key}...")
if len(key) / 2 != sha1().digest_size:
print_info("Gesture.key file is invalid")
exit(1)
crack_gesture(key)
if __name__ == "__main__":
main()