-
Notifications
You must be signed in to change notification settings - Fork 27
/
csaw_tester4.py
119 lines (102 loc) · 5.24 KB
/
csaw_tester4.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
import tempfile
import subprocess
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)]
# 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
[0x4a, 0x5c, 0x4c, 0x3e, 0x36, 0x22, 0x7d, 0x60, 0x6c, 0x64, 0x7c, 0x2e, 0, 0, 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, 0x11, 0x10, 0x33, 0x01, 0x04, 0x44, 0x04, 0x44, 0x02, 0x20, 0x55, 0x03], # 8
[0x02, 0x20, 0x00, 0x00, 0x00, 0x00, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], # 9
[0, 0, 0, 0, 0, 0, 0, 0, 0,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], # 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 = 4
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)
print(infile)
out = ""
try:
out = subprocess.check_output("./test_csaw_esc_csb.sh %s" % infile, shell=True, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
pass
print(out.decode('latin1'))