-
Notifications
You must be signed in to change notification settings - Fork 1
/
bruteforce.py
76 lines (64 loc) · 2.41 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
######################################################
# This script will only bruteforce 4 or 6 digit PINs #
# Can be modified to include longer PINs #
######################################################
import argparse
import logging
import hashlib
from Crypto.Cipher import AES
from Crypto.Util import Counter
import binascii
logging.basicConfig(
level=logging.DEBUG,
format='[%(levelname)s] %(asctime)s %(message)s',
datefmt='%d-%m-%Y %H:%M:%S',
)
def four_digit_pin(input):
logging.info("Beginning 4 digit PIN bruteforce")
four_digit = [f"{i:04}" for i in range(10000)]
for pin in four_digit:
key = hashlib.sha1(pin.encode()).digest()[:16]
iv = key
counter = Counter.new(128, initial_value=int.from_bytes(iv, "big"))
cipher = AES.new(key, AES.MODE_CTR, counter=counter)
with open(input, "rb") as enc_data:
dec_data = cipher.decrypt(enc_data.read(16))
header = binascii.hexlify(dec_data).decode("utf8")
if header.startswith("ffd8ff"):
logging.info(f"PIN found: {pin}")
return pin
else:
continue
def six_digit_pin(input):
logging.info("Beginning 6 digit PIN bruteforce")
four_digit = [f"{i:06}" for i in range(1000000)]
for pin in four_digit:
key = hashlib.sha1(pin.encode()).digest()[:16]
iv = key
counter = Counter.new(128, initial_value=int.from_bytes(iv, "big"))
cipher = AES.new(key, AES.MODE_CTR, counter=counter)
with open(input, "rb") as enc_data:
dec_data = cipher.decrypt(enc_data.read(16))
header = binascii.hexlify(dec_data).decode("utf8")
if header.startswith("ffd8ff"):
logging.info(f"PIN found: {pin}")
return pin
else:
continue
def bruteforce(input):
if not input.endswith(".6zu"):
logging.warning("Script requires a .6zu file")
raise SystemExit(1)
if four_digit_pin(input):
raise SystemExit(1)
if six_digit_pin(input):
raise SystemExit(1)
logging.info("Could not find PIN, could possibly not be a 4 or 6 digits")
def main():
parser = argparse.ArgumentParser("LockMyPix Bruteforce")
parser.add_argument("input",
help="Path to .6zu file")
args = parser.parse_args()
bruteforce(args.input)
if __name__ == "__main__":
main()