]>
Commit | Line | Data |
---|---|---|
db25599d | 1 | //----------------------------------------------------------------------------- |
2 | // Authored by Craig Young <cyoung@tripwire.com> based on cmdlfhid.c structure | |
3 | // | |
4 | // cmdlfhid.c is Copyright (C) 2010 iZsh <izsh at fail0verflow.com> | |
5 | // | |
6 | // This code is licensed to you under the terms of the GNU GPL, version 2 or, | |
7 | // at your option, any later version. See the LICENSE.txt file for the text of | |
8 | // the license. | |
9 | //----------------------------------------------------------------------------- | |
10 | // Low frequency AWID26 commands | |
11 | //----------------------------------------------------------------------------- | |
12 | ||
13 | #include <stdio.h> // sscanf | |
14 | #include "proxmark3.h" // Definitions, USB controls, etc | |
15 | #include "ui.h" // PrintAndLog | |
16 | #include "cmdparser.h" // CmdsParse, CmdsHelp | |
17 | #include "cmdlfawid.h" // AWID function declarations | |
18 | #include "lfdemod.h" // parityTest | |
a126332a | 19 | #include "util.h" // weigandparity |
20 | #include "protocols.h" // for T55xx config register definitions | |
7838f4be | 21 | #include "cmdmain.h" |
978920b9 | 22 | #include "sleep.h" |
508b37ba | 23 | |
db25599d | 24 | static int CmdHelp(const char *Cmd); |
25 | ||
db25599d | 26 | int usage_lf_awid_fskdemod(void) { |
8fd9bfb0 | 27 | PrintAndLog("Enables AWID compatible reader mode printing details of scanned AWID26 or AWID50 tags."); |
a126332a | 28 | PrintAndLog("By default, values are printed and logged until the button is pressed or another USB command is issued."); |
8fd9bfb0 | 29 | PrintAndLog("If the [1] option is provided, reader mode is exited after reading a single AWID card."); |
a126332a | 30 | PrintAndLog(""); |
8fd9bfb0 | 31 | PrintAndLog("Usage: lf awid fskdemod [1]"); |
a126332a | 32 | PrintAndLog("Options :"); |
8fd9bfb0 | 33 | PrintAndLog(" 1 : (optional) stop after reading a single card"); |
a126332a | 34 | PrintAndLog(""); |
8fd9bfb0 | 35 | PrintAndLog("Samples"); |
36 | PrintAndLog(" lf awid fskdemod"); | |
37 | PrintAndLog(" lf awid fskdemod 1"); | |
a126332a | 38 | return 0; |
db25599d | 39 | } |
40 | ||
41 | int usage_lf_awid_sim(void) { | |
8fd9bfb0 | 42 | PrintAndLog("Enables simulation of AWID card with specified facility-code and card number."); |
a126332a | 43 | PrintAndLog("Simulation runs until the button is pressed or another USB command is issued."); |
a126332a | 44 | PrintAndLog(""); |
8fd9bfb0 | 45 | PrintAndLog("Usage: lf awid sim <format> <facility-code> <card-number>"); |
a126332a | 46 | PrintAndLog("Options :"); |
8fd9bfb0 | 47 | PrintAndLog(" <format> : format length 26|50"); |
48 | PrintAndLog(" <facility-code> : 8|16bit value facility code"); | |
49 | PrintAndLog(" <card number> : 16|32-bit value card number"); | |
a126332a | 50 | PrintAndLog(""); |
8fd9bfb0 | 51 | PrintAndLog("Samples"); |
52 | PrintAndLog(" lf awid sim 26 224 1337"); | |
53 | PrintAndLog(" lf awid sim 50 2001 13371337"); | |
a126332a | 54 | return 0; |
db25599d | 55 | } |
56 | ||
57 | int usage_lf_awid_clone(void) { | |
8fd9bfb0 | 58 | PrintAndLog("Enables cloning of AWID card with specified facility-code and card number onto T55x7."); |
a126332a | 59 | PrintAndLog("The T55x7 must be on the antenna when issuing this command. T55x7 blocks are calculated and printed in the process."); |
a126332a | 60 | PrintAndLog(""); |
8fd9bfb0 | 61 | PrintAndLog("Usage: lf awid clone <format> <facility-code> <card-number>"); |
a126332a | 62 | PrintAndLog("Options :"); |
8fd9bfb0 | 63 | PrintAndLog(" <format> : format length 26|50"); |
64 | PrintAndLog(" <facility-code> : 8|16bit value facility code"); | |
65 | PrintAndLog(" <card number> : 16|32-bit value card number"); | |
66 | PrintAndLog(" Q5 : optional - clone to Q5 (T5555) instead of T55x7 chip"); | |
a126332a | 67 | PrintAndLog(""); |
8fd9bfb0 | 68 | PrintAndLog("Samples"); |
69 | PrintAndLog(" lf awid clone 26 224 1337"); | |
70 | PrintAndLog(" lf awid clone 50 2001 13371337"); | |
a126332a | 71 | return 0; |
db25599d | 72 | } |
73 | ||
508b37ba | 74 | int usage_lf_awid_brute(void){ |
8fd9bfb0 | 75 | PrintAndLog("Enables bruteforce of AWID reader with specified facility-code."); |
978920b9 | 76 | PrintAndLog("This is a incremental attack against reader."); |
508b37ba | 77 | PrintAndLog(""); |
8fd9bfb0 | 78 | PrintAndLog("Usage: lf awid brute <format> <facility-code>"); |
508b37ba | 79 | PrintAndLog("Options :"); |
8fd9bfb0 | 80 | PrintAndLog(" <format> : format length 26|50"); |
81 | PrintAndLog(" <facility-code> : 8|16bit value facility code"); | |
508b37ba | 82 | PrintAndLog(""); |
8fd9bfb0 | 83 | PrintAndLog("Samples"); |
84 | PrintAndLog(" lf awid brute 26 224"); | |
85 | PrintAndLog(" lf awid brute 50 2001"); | |
508b37ba | 86 | return 0; |
87 | } | |
88 | ||
52f2df61 | 89 | int CmdAWIDDemodFSK(const char *Cmd) { |
a126332a | 90 | int findone = 0; |
91 | if (Cmd[0] == 'h' || Cmd[0] == 'H') return usage_lf_awid_fskdemod(); | |
92 | if (Cmd[0] == '1') findone = 1; | |
93 | ||
94 | UsbCommand c = {CMD_AWID_DEMOD_FSK, {findone, 0, 0}}; | |
95 | clearCommandBuffer(); | |
96 | SendCommand(&c); | |
97 | return 0; | |
db25599d | 98 | } |
99 | ||
a126332a | 100 | //refactored by marshmellow |
8fd9bfb0 | 101 | int getAWIDBits(uint8_t fmtlen, uint32_t fc, uint32_t cn, uint8_t *bits) { |
102 | ||
103 | // the return bits, preamble 0000 0001 | |
104 | bits[7] = 1; | |
105 | ||
a126332a | 106 | uint8_t pre[66]; |
107 | memset(pre, 0, sizeof(pre)); | |
52f2df61 | 108 | |
8fd9bfb0 | 109 | // add formatlength |
110 | num_to_bytebits(fmtlen, 8, pre); | |
111 | ||
112 | // add facilitycode, cardnumber and wiegand parity bits | |
113 | if ( fmtlen == 26 ) { | |
114 | uint8_t wiegand[24]; | |
115 | num_to_bytebits(fc, 8, wiegand); | |
116 | num_to_bytebits(cn, 16, wiegand+8); | |
117 | wiegand_add_parity(pre+8, wiegand, sizeof(wiegand)); | |
118 | } else { | |
119 | uint8_t wiegand[48]; | |
120 | num_to_bytebits(fc, 16, wiegand); | |
121 | num_to_bytebits(cn, 32, wiegand+16); | |
122 | wiegand_add_parity(pre+8, wiegand, sizeof(wiegand)); | |
123 | } | |
124 | ||
125 | // add AWID 4bit parity | |
126 | size_t bitLen = addParity(pre, bits+8, 66, 4, 1); | |
fcb1cdba | 127 | |
a126332a | 128 | if (bitLen != 88) return 0; |
52f2df61 | 129 | return 1; |
db25599d | 130 | } |
131 | ||
a126332a | 132 | int CmdAWIDSim(const char *Cmd) { |
8fd9bfb0 | 133 | uint32_t fc = 0, cn = 0; |
134 | uint8_t fmtlen = 0; | |
a126332a | 135 | uint8_t bits[96]; |
136 | uint8_t *bs = bits; | |
137 | size_t size = sizeof(bits); | |
fcb1cdba | 138 | memset(bs, 0x00, size); |
52f2df61 | 139 | |
fcb1cdba | 140 | uint64_t arg1 = ( 10 << 8 ) + 8; // fcHigh = 10, fcLow = 8 |
52f2df61 | 141 | uint64_t arg2 = 50; // clk RF/50 invert=0 |
142 | ||
8fd9bfb0 | 143 | char cmdp = param_getchar(Cmd, 0); |
144 | if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_awid_sim(); | |
52f2df61 | 145 | |
8fd9bfb0 | 146 | fmtlen = param_get8(Cmd, 0); |
147 | fc = param_get32ex(Cmd, 1, 0, 10); | |
148 | cn = param_get32ex(Cmd, 2, 0, 10); | |
149 | if ( !fc || !cn) return usage_lf_awid_sim(); | |
52f2df61 | 150 | |
8fd9bfb0 | 151 | switch(fmtlen) { |
152 | case 26: | |
153 | if ((fc & 0xFF) != fc) { | |
154 | fc &= 0xFF; | |
155 | PrintAndLog("Facility-Code Truncated to 8-bits (AWID26): %u", fc); | |
156 | } | |
157 | ||
158 | if ((cn & 0xFFFF) != cn) { | |
159 | cn &= 0xFFFF; | |
160 | PrintAndLog("Card Number Truncated to 16-bits (AWID26): %u", cn); | |
161 | } | |
162 | break; | |
163 | case 50: | |
164 | if ((fc & 0xFFFF) != fc) { | |
165 | fc &= 0xFFFF; | |
166 | PrintAndLog("Facility-Code Truncated to 16-bits (AWID50): %u", fc); | |
167 | } | |
168 | break; | |
169 | default: break; | |
170 | } | |
171 | ||
172 | PrintAndLog("Emulating AWID %u -- FC: %u; CN: %u\n", fmtlen, fc, cn); | |
52f2df61 | 173 | PrintAndLog("Press pm3-button to abort simulation or run another command"); |
174 | ||
8fd9bfb0 | 175 | if (!getAWIDBits(fmtlen, fc, cn, bs)) { |
52f2df61 | 176 | PrintAndLog("Error with tag bitstream generation."); |
177 | return 1; | |
178 | } | |
179 | // AWID uses: fcHigh: 10, fcLow: 8, clk: 50, invert: 0 | |
52f2df61 | 180 | // arg1 --- fcHigh<<8 + fcLow |
181 | // arg2 --- Inversion and clk setting | |
182 | // 96 --- Bitstream length: 96-bits == 12 bytes | |
a126332a | 183 | UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}}; |
184 | memcpy(c.d.asBytes, bs, size); | |
52f2df61 | 185 | clearCommandBuffer(); |
186 | SendCommand(&c); | |
187 | return 0; | |
db25599d | 188 | } |
189 | ||
a126332a | 190 | int CmdAWIDClone(const char *Cmd) { |
191 | uint32_t blocks[4] = {T55x7_MODULATION_FSK2a | T55x7_BITRATE_RF_50 | 3<<T55x7_MAXBLOCK_SHIFT, 0, 0, 0}; | |
8fd9bfb0 | 192 | uint32_t fc = 0, cn = 0; |
193 | uint8_t fmtlen = 0; | |
a126332a | 194 | uint8_t bits[96]; |
52f2df61 | 195 | uint8_t *bs=bits; |
a126332a | 196 | memset(bs,0,sizeof(bits)); |
52f2df61 | 197 | |
8fd9bfb0 | 198 | char cmdp = param_getchar(Cmd, 0); |
199 | if (strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_awid_clone(); | |
f3cfe428 | 200 | |
8fd9bfb0 | 201 | fmtlen = param_get8(Cmd, 0); |
202 | fc = param_get32ex(Cmd, 1, 0, 10); | |
203 | cn = param_get32ex(Cmd, 2, 0, 10); | |
a126332a | 204 | |
8fd9bfb0 | 205 | if ( !fc || !cn) return usage_lf_awid_clone(); |
206 | ||
207 | switch(fmtlen) { | |
208 | case 50: | |
209 | if ((fc & 0xFFFF) != fc) { | |
210 | fc &= 0xFFFF; | |
211 | PrintAndLog("Facility-Code Truncated to 16-bits (AWID50): %u", fc); | |
212 | } | |
213 | break; | |
214 | default: | |
215 | fmtlen = 26; | |
216 | if ((fc & 0xFF) != fc) { | |
217 | fc &= 0xFF; | |
218 | PrintAndLog("Facility-Code Truncated to 8-bits (AWID26): %u", fc); | |
219 | } | |
f3cfe428 | 220 | |
8fd9bfb0 | 221 | if ((cn & 0xFFFF) != cn) { |
222 | cn &= 0xFFFF; | |
223 | PrintAndLog("Card Number Truncated to 16-bits (AWID26): %u", cn); | |
224 | } | |
225 | break; | |
f3cfe428 | 226 | } |
52f2df61 | 227 | |
8fd9bfb0 | 228 | if (param_getchar(Cmd, 4) == 'Q' || param_getchar(Cmd, 4) == 'q') |
229 | blocks[0] = T5555_MODULATION_FSK2 | T5555_INVERT_OUTPUT | 50<<T5555_BITRATE_SHIFT | 3<<T5555_MAXBLOCK_SHIFT; | |
230 | ||
231 | if ( !getAWIDBits(fmtlen, fc, cn, bs)) { | |
52f2df61 | 232 | PrintAndLog("Error with tag bitstream generation."); |
233 | return 1; | |
234 | } | |
235 | ||
a126332a | 236 | blocks[1] = bytebits_to_byte(bs,32); |
237 | blocks[2] = bytebits_to_byte(bs+32,32); | |
238 | blocks[3] = bytebits_to_byte(bs+64,32); | |
52f2df61 | 239 | |
8fd9bfb0 | 240 | PrintAndLog("Preparing to clone AWID %u to T55x7 with FC: %u, CN: %u", fmtlen, fc, cn); |
52f2df61 | 241 | PrintAndLog("Blk | Data "); |
242 | PrintAndLog("----+------------"); | |
243 | PrintAndLog(" 00 | 0x%08x", blocks[0]); | |
244 | PrintAndLog(" 01 | 0x%08x", blocks[1]); | |
245 | PrintAndLog(" 02 | 0x%08x", blocks[2]); | |
246 | PrintAndLog(" 03 | 0x%08x", blocks[3]); | |
247 | ||
248 | UsbCommand resp; | |
249 | UsbCommand c = {CMD_T55XX_WRITE_BLOCK, {0,0,0}}; | |
f3cfe428 | 250 | |
a126332a | 251 | for (uint8_t i=0; i<4; i++) { |
52f2df61 | 252 | c.arg[0] = blocks[i]; |
253 | c.arg[1] = i; | |
254 | clearCommandBuffer(); | |
255 | SendCommand(&c); | |
256 | if (!WaitForResponseTimeout(CMD_ACK, &resp, 1000)){ | |
257 | PrintAndLog("Error occurred, device did not respond during write operation."); | |
258 | return -1; | |
f3cfe428 | 259 | } |
260 | } | |
261 | return 0; | |
db25599d | 262 | } |
263 | ||
508b37ba | 264 | int CmdAWIDBrute(const char *Cmd){ |
265 | ||
8fd9bfb0 | 266 | uint32_t fc = 0x00; |
267 | uint8_t fmtlen = 0; | |
508b37ba | 268 | uint8_t bits[96]; |
269 | uint8_t *bs = bits; | |
270 | size_t size = sizeof(bits); | |
271 | memset(bs, 0x00, size); | |
272 | ||
273 | char cmdp = param_getchar(Cmd, 0); | |
8fd9bfb0 | 274 | if (strlen(Cmd) > 4 || strlen(Cmd) == 0 || cmdp == 'h' || cmdp == 'H') return usage_lf_awid_brute(); |
508b37ba | 275 | |
8fd9bfb0 | 276 | fmtlen = param_get8(Cmd, 0); |
277 | fc = param_get32ex(Cmd, 1, 0, 10); | |
278 | if ( !fc ) return usage_lf_awid_brute(); | |
279 | ||
280 | switch(fmtlen) { | |
281 | case 50: | |
282 | if ((fc & 0xFFFF) != fc) { | |
283 | fc &= 0xFFFF; | |
284 | PrintAndLog("Facility-Code Truncated to 16-bits (AWID50): %u", fc); | |
285 | } | |
286 | break; | |
287 | default: | |
288 | if ((fc & 0xFF) != fc) { | |
289 | fc &= 0xFF; | |
290 | PrintAndLog("Facility-Code Truncated to 8-bits (AWID26): %u", fc); | |
291 | } | |
292 | break; | |
293 | } | |
508b37ba | 294 | |
8fd9bfb0 | 295 | PrintAndLog("Bruteforceing AWID %d Reader", fmtlen); |
508b37ba | 296 | PrintAndLog("Press pm3-button to abort simulation or run another command"); |
297 | ||
298 | uint64_t arg1 = (10<<8) + 8; // fcHigh = 10, fcLow = 8 | |
299 | uint64_t arg2 = 50; // clk RF/50 invert=0 | |
300 | UsbCommand c = {CMD_FSK_SIM_TAG, {arg1, arg2, size}}; | |
301 | ||
302 | for ( uint16_t cn = 1; cn < 0xFFFF; ++cn){ | |
303 | if (ukbhit()) { | |
304 | PrintAndLog("aborted via keyboard!"); | |
305 | c.cmd = CMD_PING; | |
306 | c.arg[0] = 0x00; | |
307 | c.arg[1] = 0x00; | |
308 | c.arg[2] = 0x00; | |
309 | clearCommandBuffer(); | |
310 | SendCommand(&c); | |
311 | return 1; | |
312 | } | |
313 | ||
8fd9bfb0 | 314 | (void)getAWIDBits(fmtlen, fc, cn, bs); |
508b37ba | 315 | memcpy(c.d.asBytes, bs, size); |
316 | clearCommandBuffer(); | |
317 | SendCommand(&c); | |
318 | ||
319 | PrintAndLog("Trying FC: %u; CN: %u", fc, cn); | |
320 | // pause | |
321 | sleep(1); | |
322 | } | |
323 | return 0; | |
324 | } | |
325 | ||
a126332a | 326 | static command_t CommandTable[] = { |
f3cfe428 | 327 | {"help", CmdHelp, 1, "This help"}, |
328 | {"fskdemod", CmdAWIDDemodFSK, 0, "['1'] Realtime AWID FSK demodulator (option '1' for one tag only)"}, | |
329 | {"sim", CmdAWIDSim, 0, "<Facility-Code> <Card Number> -- AWID tag simulator"}, | |
a126332a | 330 | {"clone", CmdAWIDClone, 0, "<Facility-Code> <Card Number> <Q5> -- Clone AWID to T55x7"}, |
508b37ba | 331 | {"brute", CmdAWIDBrute, 0, "<Facility-Code> -- bruteforce card number"}, |
f3cfe428 | 332 | {NULL, NULL, 0, NULL} |
db25599d | 333 | }; |
334 | ||
a126332a | 335 | int CmdLFAWID(const char *Cmd) { |
4c36581b | 336 | clearCommandBuffer(); |
f3cfe428 | 337 | CmdsParse(CommandTable, Cmd); |
338 | return 0; | |
db25599d | 339 | } |
340 | ||
a126332a | 341 | int CmdHelp(const char *Cmd) { |
f3cfe428 | 342 | CmdsHelp(CommandTable); |
343 | return 0; | |
db25599d | 344 | } |