-
Notifications
You must be signed in to change notification settings - Fork 26
/
csaw_tester0.py
133 lines (115 loc) · 6.02 KB
/
csaw_tester0.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
import tempfile
import subprocess
import sys
import os
from clint.textui.colored import red, blue, green
os.system('clear')
p = [bytes([108+i+j for j in range(32)]) for i in range(32)]
k = [bytes([68+i for j in range(3)]) for i in range(16)]
print(red("STARTING HAL-FUZZ FOR CHALLENGE 0..."))
print(blue("Brute-forcing key..."))
for z in range(0x7000, 2**16):
bs = z.to_bytes(2, byteorder='big')
# 0 1 2 3 4 5 6 7 8 9 a b c d e f
p = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 0
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 1
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 2
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 3
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, bs[0], bs[1], 0, 0], # 4
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 5
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 6
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 7
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],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0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 48
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 49
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 50
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 51
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 52
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 53
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 54
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 55
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 56
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 57
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 58
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 59
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 60
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 61
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 62
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 63
]
a = 0x0
b = 0x0
challnum = 0
entry = []
for q in p:
entry += q
entry = bytearray(entry)
sep = b"<LF>"
chunksize = 30 # from reversing teh thing
chunknum = 1
cmd = 1
stuff = b""
# chunk the RFID data
for i in range(0, len(entry), chunksize):
stuff += int.to_bytes(cmd, 1, 'little') + int.to_bytes(chunknum, 1, 'little') + entry[i:i+chunksize] + sep
chunknum += 1
# TODO: WTF is chunk 0x24
# TODO: Keys are chunk 0x25
# Now send a, b, and challenge num
stuff += int.to_bytes(cmd, 1, 'little') + int.to_bytes(0x26, 1, 'little') + int.to_bytes((a << 4)+b, 1, 'little') + int.to_bytes(challnum, 1, 'little') + sep
# Now ask for the answer
stuff += int.to_bytes(cmd, 1, 'little') + int.to_bytes(0x1, 1, 'little') + b'\x00' + sep
infile = tempfile.mkstemp()[1]
with open(infile, 'wb') as f:
f.write(stuff)
out = b""
try:
out = subprocess.check_output("./test_csaw_esc_csa.sh %s" % infile, shell=True, stderr=None)
except subprocess.CalledProcessError:
pass
if b'solved' in out:
print(green("SOLUTION FOUND!!"))
print(hex(z))
break
else:
sys.stdout.write("#")
sys.stdout.flush()