-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcard_handlers.go
228 lines (196 loc) · 7.99 KB
/
card_handlers.go
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package main
import (
"fmt"
)
func handleCardType(cardType string, facilityCode, cardNumber, bitLength int, write, verify bool, uid, hexData string, simulate bool) {
switch cardType {
case "iclass":
handleICLASS(facilityCode, cardNumber, bitLength, simulate, write, verify)
case "prox":
handleProx(facilityCode, cardNumber, bitLength, simulate, write, verify)
case "awid":
handleAWID(facilityCode, cardNumber, bitLength, simulate, write, verify)
case "indala":
handleIndala(facilityCode, cardNumber, bitLength, simulate, write, verify)
case "em":
handleEM(hexData, simulate, write, verify)
case "piv":
handlePIV(uid, simulate, write, verify)
case "mifare":
handleMIFARE(uid, simulate, write, verify)
default:
fmt.Println(Red, "Unsupported card type. Supported types are: iclass, prox, awid, indala, em, piv, mifare.", Reset)
}
}
func handleICLASS(facilityCode, cardNumber, bitLength int, simulate, write, verify bool) {
var preamble uint64
var cardData uint64
if bitLength != 26 && bitLength != 35 {
fmt.Println(Red, "Invalid bit length for iCLASS. Supported bit lengths are 26 and 35.", Reset)
return
}
if bitLength == 26 {
preamble = 0x2004000000
cardData = generate26bitHex(facilityCode, cardNumber, preamble, write, simulate)
} else if bitLength == 35 {
preamble = 0x2800000000
cardData = generate35bitHex(facilityCode, cardNumber, preamble, write, simulate)
}
if simulate {
simulateCardData("iclass", cardData, bitLength, facilityCode, cardNumber, "", "")
} else if write {
writeCardData("iclass", cardData, bitLength, facilityCode, cardNumber, "", verify, "")
}
if verify {
verifyCardData("iclass", facilityCode, cardNumber, "", "")
}
}
func handleProx(facilityCode, cardNumber, bitLength int, simulate, write, verify bool) {
if simulate {
simulateCardData("prox", 0, bitLength, facilityCode, cardNumber, "", "")
} else {
fmt.Println(Green, "\nHandling Prox card...", Reset)
if write {
fmt.Println(Green, "\nThe following will be written to a T5577 card:", Reset)
} else {
fmt.Println(Green, "\nWrite the following values to a T5577 card:", Reset)
}
fmt.Println(Green, "", Reset)
switch bitLength {
case 26:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w H10301 --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 30:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w ATSW30 --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 31:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w ADT31 --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 33:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w D10202 --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 34:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w H10306 --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 35:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w C1k35s --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 36:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w S12906 --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 37:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w H10304 --fc %d --cn %d", facilityCode, cardNumber), Reset)
case 48:
fmt.Println(Yellow, fmt.Sprintf("lf hid clone -w C1k48s --fc %d --cn %d", facilityCode, cardNumber), Reset)
default:
fmt.Println(Red, "Unsupported bit length for Prox card.", Reset)
return
}
if write {
writeCardData("prox", 0, bitLength, facilityCode, cardNumber, "", verify, "")
}
if verify {
verifyCardData("prox", facilityCode, cardNumber, "", "")
}
}
}
func handleAWID(facilityCode, cardNumber, bitLength int, simulate, write, verify bool) {
if simulate {
simulateCardData("awid", 0, bitLength, facilityCode, cardNumber, "", "")
} else {
fmt.Println(Green, "\nHandling AWID card...", Reset)
if write {
fmt.Println(Green, "\nThe following will be written to a T5577 card:", Reset)
} else {
fmt.Println(Green, "\nWrite the following values to a T5577 card:", Reset)
}
fmt.Println(Green, "", Reset)
bitLength := 26
if bitLength == 26 {
fmt.Println(Yellow, fmt.Sprintf("\nlf awid clone --fmt 26 --fc %d --cn %d", facilityCode, cardNumber), Reset)
}
if write {
writeCardData("awid", 0, bitLength, facilityCode, cardNumber, "", verify, "")
}
if verify {
verifyCardData("awid", facilityCode, cardNumber, "", "")
}
}
}
func handleIndala(facilityCode, cardNumber, bitLength int, simulate, write, verify bool) {
if simulate {
simulateCardData("indala", 0, bitLength, facilityCode, cardNumber, "", "")
} else {
fmt.Println(Green, "\nHandling Indala card...", Reset)
fmt.Println(Yellow, "\nNote that the only supported bit length for writing an Indala card is 26-bit. Indala 27-bit and 29-bit will be written as a 26-bit card. \nThis may cause an issue given facility code and card number ranges. If so, grab the BIN data from doppelganger and encode the data\nfor writing or you can simulate the card with the Proxmark3: `lf hid sim -w ind27/ind29 --fc {FC} --cn {CN}'", Reset)
if write {
fmt.Println(Green, "\nThe following will be written to a T5577 card:", Reset)
} else {
fmt.Println(Green, "\nWrite the following values to a T5577 card:", Reset)
}
fmt.Println(Green, "", Reset)
bitLength := 26
fmt.Println(Yellow, fmt.Sprintf("lf indala clone --fc %d --cn %d", facilityCode, cardNumber), Reset)
if write {
writeCardData("indala", 0, bitLength, facilityCode, cardNumber, "", verify, "")
}
if verify {
verifyCardData("indala", facilityCode, cardNumber, "", "")
}
}
}
func handleEM(hexData string, simulate, write, verify bool) {
if simulate {
simulateCardData("em", 0, 0, 0, 0, hexData, "")
} else {
fmt.Println(Green, "\nHandling EM card...", Reset)
if write {
fmt.Println(Green, "\nThe following will be written to a T5577 card:", Reset)
} else {
fmt.Println(Green, "\nWrite the following values to a T5577 card:", Reset)
}
fmt.Println(Green, "", Reset)
fmt.Println(Yellow, fmt.Sprintf("lf em 410x clone --id %s", hexData), Reset)
if write {
writeCardData("em", 0, 0, 0, 0, hexData, verify, "")
}
if verify {
verifyCardData("em", 0, 0, hexData, "")
}
}
}
func handlePIV(uid string, simulate bool, write, verify bool) {
if simulate {
simulateCardData("piv", 0, 0, 0, 0, "", uid)
} else {
fmt.Println(Green, "\nHandling PIV card...", Reset)
if write {
fmt.Println(Green, "\nThe following will be written to a UID rewritable MIFARE card:", Reset)
} else {
fmt.Println(Green, "\nWrite the following values to a UID rewritable MIFARE card:", Reset)
}
fmt.Println(Green, "", Reset)
fmt.Println(Yellow, fmt.Sprintf("hf mf csetuid -u %s", uid), Reset)
fmt.Println(Green, "\nNote, this will only emulate the Wiegand signal of the captured card. This will not fully replicate the captured PIV card. This considered experimental as the badging system that your client employs may interpret the data differently than the reader that provided the Wiegand output to doppelganger.", Reset)
if write {
writeCardData("piv", 0, 0, 0, 0, "", verify, uid)
}
if verify {
verifyCardData("piv", 0, 0, "", uid)
}
}
}
func handleMIFARE(uid string, simulate bool, write, verify bool) {
if simulate {
simulateCardData("mifare", 0, 0, 0, 0, "", uid)
} else {
fmt.Println(Green, "\nHandling MIFARE card...", Reset)
if write {
fmt.Println(Green, "\nThe following will be written to a UID rewritable MIFARE card:", Reset)
} else {
fmt.Println(Green, "\nWrite the following values to a UID rewritable MIFARE card:", Reset)
}
fmt.Println(Green, "", Reset)
fmt.Println(Yellow, fmt.Sprintf("hf mf csetuid -u %s", uid), Reset)
fmt.Println(Green, "\nNote, this will only emulate the Wiegand signal of the captured card. This will not fully replicate the captured MIFARE card. This considered experimental as the badging system that your client employs may interpret the data differently than the reader that provided the Wiegand output to doppelganger.", Reset)
if write {
writeCardData("mifare", 0, 0, 0, 0, "", verify, uid)
}
if verify {
verifyCardData("mifare", 0, 0, "", uid)
}
}
}