]> cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhfmf.c
REM: removed a debug function call, PrintToSendBuffer
[proxmark3-svn] / client / cmdhfmf.c
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2011,2012 Merlok
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // High frequency MIFARE commands
9 //-----------------------------------------------------------------------------
10
11 #include "cmdhfmf.h"
12 #include "cmdhfmfhard.h"
13 #include "nonce2key/nonce2key.h"
14
15 static int CmdHelp(const char *Cmd);
16 int usage_hf14_mifare(void){
17 PrintAndLog("Usage: hf mf mifare [h] <block number>");
18 PrintAndLog("options:");
19 PrintAndLog(" h this help");
20 PrintAndLog(" <block number> (Optional) target other key A than block 0.");
21 PrintAndLog("samples:");
22 PrintAndLog(" hf mf mifare");
23 PrintAndLog(" hf mf mifare 16");
24 return 0;
25 }
26 int usage_hf14_mf1ksim(void){
27 PrintAndLog("Usage: hf mf sim [h] u <uid (8,14,20 hex symbols)> n <numreads> i x");
28 PrintAndLog("options:");
29 PrintAndLog(" h this help");
30 PrintAndLog(" u (Optional) UID 4,7 or 10bytes. If not specified, the UID 4b from emulator memory will be used");
31 PrintAndLog(" n (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");
32 PrintAndLog(" i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");
33 PrintAndLog(" x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");
34 PrintAndLog("samples:");
35 PrintAndLog(" hf mf sim u 0a0a0a0a");
36 PrintAndLog(" hf mf sim u 11223344556677");
37 PrintAndLog(" hf mf sim u 112233445566778899AA");
38 return 0;
39 }
40 int usage_hf14_dbg(void){
41 PrintAndLog("Usage: hf mf dbg [h] <debug level>");
42 PrintAndLog("options:");
43 PrintAndLog(" h this help");
44 PrintAndLog(" <debug level> (Optional) see list for valid levels");
45 PrintAndLog(" 0 - no debug messages");
46 PrintAndLog(" 1 - error messages");
47 PrintAndLog(" 2 - plus information messages");
48 PrintAndLog(" 3 - plus debug messages");
49 PrintAndLog(" 4 - print even debug messages in timing critical functions");
50 PrintAndLog(" Note: this option therefore may cause malfunction itself");
51 PrintAndLog("samples:");
52 PrintAndLog(" hf mf dbg 3");
53 return 0;
54 }
55 int usage_hf14_sniff(void){
56 PrintAndLog("It continuously gets data from the field and saves it to: log, emulator, emulator file.");
57 PrintAndLog("Usage: hf mf sniff [h] [l] [d] [f]");
58 PrintAndLog("options:");
59 PrintAndLog(" h this help");
60 PrintAndLog(" l save encrypted sequence to logfile `uid.log`");
61 PrintAndLog(" d decrypt sequence and put it to log file `uid.log`");
62 // PrintAndLog(" n/a e decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory");
63 PrintAndLog(" f decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`");
64 PrintAndLog("sample:");
65 PrintAndLog(" hf mf sniff l d f");
66 return 0;
67 }
68 int usage_hf14_nested(void){
69 PrintAndLog("Usage:");
70 PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]");
71 PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");
72 PrintAndLog(" <target block number> <target key A/B> [t]");
73 PrintAndLog("options:");
74 PrintAndLog(" h this help");
75 PrintAndLog(" card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
76 PrintAndLog(" t transfer keys into emulator memory");
77 PrintAndLog(" d write keys to binary file");
78 PrintAndLog(" ");
79 PrintAndLog("samples:");
80 PrintAndLog(" hf mf nested 1 0 A FFFFFFFFFFFF ");
81 PrintAndLog(" hf mf nested 1 0 A FFFFFFFFFFFF t ");
82 PrintAndLog(" hf mf nested 1 0 A FFFFFFFFFFFF d ");
83 PrintAndLog(" hf mf nested o 0 A FFFFFFFFFFFF 4 A");
84 return 0;
85 }
86 int usage_hf14_hardnested(void){
87 PrintAndLog("Usage:");
88 PrintAndLog(" hf mf hardnested <block number> <key A|B> <key (12 hex symbols)>");
89 PrintAndLog(" <target block number> <target key A|B> [known target key (12 hex symbols)] [w] [s]");
90 PrintAndLog(" or hf mf hardnested r [known target key]");
91 PrintAndLog(" ");
92 PrintAndLog("options:");
93 PrintAndLog(" h this help");
94 PrintAndLog(" w acquire nonces and write them to binary file nonces.bin");
95 PrintAndLog(" s slower acquisition (required by some non standard cards)");
96 PrintAndLog(" r read nonces.bin and start attack");
97 PrintAndLog(" t tests?");
98 PrintAndLog(" ");
99 PrintAndLog("samples:");
100 PrintAndLog(" hf mf hardnested 0 A FFFFFFFFFFFF 4 A");
101 PrintAndLog(" hf mf hardnested 0 A FFFFFFFFFFFF 4 A w");
102 PrintAndLog(" hf mf hardnested 0 A FFFFFFFFFFFF 4 A w s");
103 PrintAndLog(" hf mf hardnested r");
104 PrintAndLog(" hf mf hardnested r a0a1a2a3a4a5");
105 PrintAndLog(" ");
106 PrintAndLog("Add the known target key to check if it is present in the remaining key space:");
107 PrintAndLog(" sample5: hf mf hardnested 0 A A0A1A2A3A4A5 4 A FFFFFFFFFFFF");
108 return 0;
109 }
110 int usage_hf14_chk(void){
111 PrintAndLog("Usage: hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t|d] [<key (12 hex symbols)>] [<dic (*.dic)>]");
112 PrintAndLog("options:");
113 PrintAndLog(" h this help");
114 PrintAndLog(" * all sectors");
115 PrintAndLog(" card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
116 PrintAndLog(" d write keys to binary file");
117 PrintAndLog(" t write keys to emulator memory\n");
118 PrintAndLog(" ");
119 PrintAndLog("samples:");
120 PrintAndLog(" hf mf chk 0 A 1234567890ab keys.dic");
121 PrintAndLog(" hf mf chk *1 ? t");
122 PrintAndLog(" hf mf chk *1 ? d");
123 return 0;
124 }
125
126 int CmdHF14AMifare(const char *Cmd) {
127 uint32_t uid = 0;
128 uint32_t nt = 0, nr = 0;
129 uint64_t par_list = 0, ks_list = 0, r_key = 0;
130 int16_t isOK = 0;
131 int tmpchar;
132 uint8_t blockNo = 0;
133
134 char cmdp = param_getchar(Cmd, 0);
135 if ( cmdp == 'H' || cmdp == 'h') return usage_hf14_mifare();
136
137 blockNo = param_get8(Cmd, 0);
138 UsbCommand c = {CMD_READER_MIFARE, {true, blockNo, 0}};
139
140 // message
141 printf("-------------------------------------------------------------------------\n");
142 printf("Executing darkside attack. Expected execution time: 25sec on average :-)\n");
143 printf("Press button on the proxmark3 device to abort both proxmark3 and client.\n");
144 printf("-------------------------------------------------------------------------\n");
145 clock_t t1 = clock();
146 time_t start, end;
147 time(&start);
148
149 start:
150 clearCommandBuffer();
151 SendCommand(&c);
152
153 //flush queue
154 while (ukbhit()) {
155 tmpchar = getchar();
156 (void)tmpchar;
157 }
158
159 // wait cycle
160 while (true) {
161 printf(".");
162 fflush(stdout);
163 if (ukbhit()) {
164 tmpchar = getchar();
165 (void)tmpchar;
166 printf("\naborted via keyboard!\n");
167 break;
168 }
169
170 UsbCommand resp;
171 if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {
172 isOK = resp.arg[0];
173 printf("\n");
174 uid = (uint32_t)bytes_to_num(resp.d.asBytes + 0, 4);
175 nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4);
176 par_list = bytes_to_num(resp.d.asBytes + 8, 8);
177 ks_list = bytes_to_num(resp.d.asBytes + 16, 8);
178 nr = bytes_to_num(resp.d.asBytes + 24, 4);
179
180 switch (isOK) {
181 case -1 : PrintAndLog("Button pressed. Aborted.\n"); break;
182 case -2 : PrintAndLog("Card isn't vulnerable to Darkside attack (doesn't send NACK on authentication requests).\n"); break;
183 case -3 : PrintAndLog("Card isn't vulnerable to Darkside attack (its random number generator is not predictable).\n"); break;
184 case -4 : PrintAndLog("Card isn't vulnerable to Darkside attack (its random number generator seems to be based on the wellknown");
185 PrintAndLog("generating polynomial with 16 effective bits only, but shows unexpected behaviour.\n"); break;
186 default: ;
187 }
188 break;
189 }
190 }
191 printf("\n");
192
193 // par == 0
194 if (isOK == -1 && par_list == 0) {
195 if (!nonce2key_ex(uid, nt, nr, ks_list, &r_key) ){
196 PrintAndLog("Found valid key: %012"llx" \n", r_key);
197 goto END;
198 }
199 }
200
201 // error
202 if (isOK != 1) return 1;
203
204 // execute original function from util nonce2key
205 if (nonce2key(uid, nt, nr, par_list, ks_list, &r_key)) {
206 isOK = 2;
207 PrintAndLog("Key not found (lfsr_common_prefix list is null). Nt=%08x", nt);
208 PrintAndLog("Failing is expected to happen in 25%% of all cases. Trying again with a different reader nonce...");
209 c.arg[0] = false;
210 goto start;
211 } else {
212 PrintAndLog("Found valid key: %012"llx" \n", r_key);
213 }
214 END:
215 t1 = clock() - t1;
216 time(&end);
217 unsigned long elapsed_time = difftime(end, start);
218 if ( t1 > 0 )
219 PrintAndLog("Time in darkside: %.0f ticks %u seconds\n", (float)t1, elapsed_time);
220 return 0;
221 }
222
223 int CmdHF14AMfWrBl(const char *Cmd) {
224 uint8_t blockNo = 0;
225 uint8_t keyType = 0;
226 uint8_t key[6] = {0, 0, 0, 0, 0, 0};
227 uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
228
229 char cmdp = 0x00;
230
231 if (strlen(Cmd)<3) {
232 PrintAndLog("Usage: hf mf wrbl <block number> <key A/B> <key (12 hex symbols)> <block data (32 hex symbols)>");
233 PrintAndLog(" sample: hf mf wrbl 0 A FFFFFFFFFFFF 000102030405060708090A0B0C0D0E0F");
234 return 0;
235 }
236
237 blockNo = param_get8(Cmd, 0);
238 cmdp = param_getchar(Cmd, 1);
239 if (cmdp == 0x00) {
240 PrintAndLog("Key type must be A or B");
241 return 1;
242 }
243 if (cmdp != 'A' && cmdp != 'a') keyType = 1;
244 if (param_gethex(Cmd, 2, key, 12)) {
245 PrintAndLog("Key must include 12 HEX symbols");
246 return 1;
247 }
248 if (param_gethex(Cmd, 3, bldata, 32)) {
249 PrintAndLog("Block data must include 32 HEX symbols");
250 return 1;
251 }
252 PrintAndLog("--block no:%d, key type:%c, key:%s", blockNo, keyType?'B':'A', sprint_hex(key, 6));
253 PrintAndLog("--data: %s", sprint_hex(bldata, 16));
254
255 UsbCommand c = {CMD_MIFARE_WRITEBL, {blockNo, keyType, 0}};
256 memcpy(c.d.asBytes, key, 6);
257 memcpy(c.d.asBytes + 10, bldata, 16);
258 clearCommandBuffer();
259 SendCommand(&c);
260
261 UsbCommand resp;
262 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
263 uint8_t isOK = resp.arg[0] & 0xff;
264 PrintAndLog("isOk:%02x", isOK);
265 } else {
266 PrintAndLog("Command execute timeout");
267 }
268
269 return 0;
270 }
271
272 int CmdHF14AMfRdBl(const char *Cmd) {
273 uint8_t blockNo = 0;
274 uint8_t keyType = 0;
275 uint8_t key[6] = {0, 0, 0, 0, 0, 0};
276
277 char cmdp = 0x00;
278
279
280 if (strlen(Cmd)<3) {
281 PrintAndLog("Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>");
282 PrintAndLog(" sample: hf mf rdbl 0 A FFFFFFFFFFFF ");
283 return 0;
284 }
285
286 blockNo = param_get8(Cmd, 0);
287 cmdp = param_getchar(Cmd, 1);
288 if (cmdp == 0x00) {
289 PrintAndLog("Key type must be A or B");
290 return 1;
291 }
292 if (cmdp != 'A' && cmdp != 'a') keyType = 1;
293 if (param_gethex(Cmd, 2, key, 12)) {
294 PrintAndLog("Key must include 12 HEX symbols");
295 return 1;
296 }
297 PrintAndLog("--block no:%d, key type:%c, key:%s ", blockNo, keyType?'B':'A', sprint_hex(key, 6));
298
299 UsbCommand c = {CMD_MIFARE_READBL, {blockNo, keyType, 0}};
300 memcpy(c.d.asBytes, key, 6);
301 clearCommandBuffer();
302 SendCommand(&c);
303
304 UsbCommand resp;
305 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
306 uint8_t isOK = resp.arg[0] & 0xff;
307 uint8_t *data = resp.d.asBytes;
308
309 if (isOK)
310 PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 16));
311 else
312 PrintAndLog("isOk:%02x", isOK);
313 } else {
314 PrintAndLog("Command execute timeout");
315 }
316
317 return 0;
318 }
319
320 int CmdHF14AMfRdSc(const char *Cmd) {
321 int i;
322 uint8_t sectorNo = 0;
323 uint8_t keyType = 0;
324 uint8_t key[6] = {0, 0, 0, 0, 0, 0};
325 uint8_t isOK = 0;
326 uint8_t *data = NULL;
327 char cmdp = 0x00;
328
329 if (strlen(Cmd)<3) {
330 PrintAndLog("Usage: hf mf rdsc <sector number> <key A/B> <key (12 hex symbols)>");
331 PrintAndLog(" sample: hf mf rdsc 0 A FFFFFFFFFFFF ");
332 return 0;
333 }
334
335 sectorNo = param_get8(Cmd, 0);
336 if (sectorNo > 39) {
337 PrintAndLog("Sector number must be less than 40");
338 return 1;
339 }
340 cmdp = param_getchar(Cmd, 1);
341 if (cmdp != 'a' && cmdp != 'A' && cmdp != 'b' && cmdp != 'B') {
342 PrintAndLog("Key type must be A or B");
343 return 1;
344 }
345 if (cmdp != 'A' && cmdp != 'a') keyType = 1;
346 if (param_gethex(Cmd, 2, key, 12)) {
347 PrintAndLog("Key must include 12 HEX symbols");
348 return 1;
349 }
350 PrintAndLog("--sector no:%d key type:%c key:%s ", sectorNo, keyType?'B':'A', sprint_hex(key, 6));
351
352 UsbCommand c = {CMD_MIFARE_READSC, {sectorNo, keyType, 0}};
353 memcpy(c.d.asBytes, key, 6);
354 clearCommandBuffer();
355 SendCommand(&c);
356 PrintAndLog(" ");
357
358 UsbCommand resp;
359 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
360 isOK = resp.arg[0] & 0xff;
361 data = resp.d.asBytes;
362
363 PrintAndLog("isOk:%02x", isOK);
364 if (isOK) {
365 for (i = 0; i < (sectorNo<32?3:15); i++) {
366 PrintAndLog("data : %s", sprint_hex(data + i * 16, 16));
367 }
368 PrintAndLog("trailer: %s", sprint_hex(data + (sectorNo<32?3:15) * 16, 16));
369 }
370 } else {
371 PrintAndLog("Command execute timeout");
372 }
373
374 return 0;
375 }
376
377 uint8_t FirstBlockOfSector(uint8_t sectorNo) {
378 if (sectorNo < 32) {
379 return sectorNo * 4;
380 } else {
381 return 32 * 4 + (sectorNo - 32) * 16;
382 }
383 }
384
385 uint8_t NumBlocksPerSector(uint8_t sectorNo) {
386 if (sectorNo < 32) {
387 return 4;
388 } else {
389 return 16;
390 }
391 }
392
393 int CmdHF14AMfDump(const char *Cmd) {
394 uint8_t sectorNo, blockNo;
395
396 uint8_t keyA[40][6];
397 uint8_t keyB[40][6];
398 uint8_t rights[40][4];
399 uint8_t carddata[256][16];
400 uint8_t numSectors = 16;
401
402 FILE *fin;
403 FILE *fout;
404
405 UsbCommand resp;
406
407 char cmdp = param_getchar(Cmd, 0);
408 switch (cmdp) {
409 case '0' : numSectors = 5; break;
410 case '1' :
411 case '\0': numSectors = 16; break;
412 case '2' : numSectors = 32; break;
413 case '4' : numSectors = 40; break;
414 default: numSectors = 16;
415 }
416
417 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') {
418 PrintAndLog("Usage: hf mf dump [card memory]");
419 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
420 PrintAndLog("");
421 PrintAndLog("Samples: hf mf dump");
422 PrintAndLog(" hf mf dump 4");
423 return 0;
424 }
425
426 if ((fin = fopen("dumpkeys.bin","rb")) == NULL) {
427 PrintAndLog("Could not find file dumpkeys.bin");
428 return 1;
429 }
430
431 // Read keys A from file
432 size_t bytes_read;
433 for (sectorNo=0; sectorNo<numSectors; sectorNo++) {
434 bytes_read = fread( keyA[sectorNo], 1, 6, fin );
435 if ( bytes_read == 0) {
436 PrintAndLog("File reading error.");
437 fclose(fin);
438 return 2;
439 }
440 }
441
442 // Read keys B from file
443 for (sectorNo=0; sectorNo<numSectors; sectorNo++) {
444 bytes_read = fread( keyB[sectorNo], 1, 6, fin );
445 if ( bytes_read == 0) {
446 PrintAndLog("File reading error.");
447 fclose(fin);
448 return 2;
449 }
450 }
451
452 fclose(fin);
453
454 PrintAndLog("|-----------------------------------------|");
455 PrintAndLog("|------ Reading sector access bits...-----|");
456 PrintAndLog("|-----------------------------------------|");
457
458 for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {
459 UsbCommand c = {CMD_MIFARE_READBL, {FirstBlockOfSector(sectorNo) + NumBlocksPerSector(sectorNo) - 1, 0, 0}};
460 memcpy(c.d.asBytes, keyA[sectorNo], 6);
461 clearCommandBuffer();
462 SendCommand(&c);
463
464 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
465 uint8_t isOK = resp.arg[0] & 0xff;
466 uint8_t *data = resp.d.asBytes;
467 if (isOK){
468 rights[sectorNo][0] = ((data[7] & 0x10)>>2) | ((data[8] & 0x1)<<1) | ((data[8] & 0x10)>>4); // C1C2C3 for data area 0
469 rights[sectorNo][1] = ((data[7] & 0x20)>>3) | ((data[8] & 0x2)<<0) | ((data[8] & 0x20)>>5); // C1C2C3 for data area 1
470 rights[sectorNo][2] = ((data[7] & 0x40)>>4) | ((data[8] & 0x4)>>1) | ((data[8] & 0x40)>>6); // C1C2C3 for data area 2
471 rights[sectorNo][3] = ((data[7] & 0x80)>>5) | ((data[8] & 0x8)>>2) | ((data[8] & 0x80)>>7); // C1C2C3 for sector trailer
472 } else {
473 PrintAndLog("Could not get access rights for sector %2d. Trying with defaults...", sectorNo);
474 rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = 0x00;
475 rights[sectorNo][3] = 0x01;
476 }
477 } else {
478 PrintAndLog("Command execute timeout when trying to read access rights for sector %2d. Trying with defaults...", sectorNo);
479 rights[sectorNo][0] = rights[sectorNo][1] = rights[sectorNo][2] = 0x00;
480 rights[sectorNo][3] = 0x01;
481 }
482 }
483
484 PrintAndLog("|-----------------------------------------|");
485 PrintAndLog("|----- Dumping all blocks to file... -----|");
486 PrintAndLog("|-----------------------------------------|");
487
488 bool isOK = true;
489 for (sectorNo = 0; isOK && sectorNo < numSectors; sectorNo++) {
490 for (blockNo = 0; isOK && blockNo < NumBlocksPerSector(sectorNo); blockNo++) {
491 bool received = false;
492
493 if (blockNo == NumBlocksPerSector(sectorNo) - 1) { // sector trailer. At least the Access Conditions can always be read with key A.
494 UsbCommand c = {CMD_MIFARE_READBL, {FirstBlockOfSector(sectorNo) + blockNo, 0, 0}};
495 memcpy(c.d.asBytes, keyA[sectorNo], 6);
496 clearCommandBuffer();
497 SendCommand(&c);
498 received = WaitForResponseTimeout(CMD_ACK,&resp,1500);
499 } else { // data block. Check if it can be read with key A or key B
500 uint8_t data_area = sectorNo<32?blockNo:blockNo/5;
501 if ((rights[sectorNo][data_area] == 0x03) || (rights[sectorNo][data_area] == 0x05)) { // only key B would work
502 UsbCommand c = {CMD_MIFARE_READBL, {FirstBlockOfSector(sectorNo) + blockNo, 1, 0}};
503 memcpy(c.d.asBytes, keyB[sectorNo], 6);
504 SendCommand(&c);
505 received = WaitForResponseTimeout(CMD_ACK,&resp,1500);
506 } else if (rights[sectorNo][data_area] == 0x07) { // no key would work
507 isOK = false;
508 PrintAndLog("Access rights do not allow reading of sector %2d block %3d", sectorNo, blockNo);
509 } else { // key A would work
510 UsbCommand c = {CMD_MIFARE_READBL, {FirstBlockOfSector(sectorNo) + blockNo, 0, 0}};
511 memcpy(c.d.asBytes, keyA[sectorNo], 6);
512 clearCommandBuffer();
513 SendCommand(&c);
514 received = WaitForResponseTimeout(CMD_ACK,&resp,1500);
515 }
516 }
517
518 if (received) {
519 isOK = resp.arg[0] & 0xff;
520 uint8_t *data = resp.d.asBytes;
521 if (blockNo == NumBlocksPerSector(sectorNo) - 1) { // sector trailer. Fill in the keys.
522 data[0] = (keyA[sectorNo][0]);
523 data[1] = (keyA[sectorNo][1]);
524 data[2] = (keyA[sectorNo][2]);
525 data[3] = (keyA[sectorNo][3]);
526 data[4] = (keyA[sectorNo][4]);
527 data[5] = (keyA[sectorNo][5]);
528 data[10] = (keyB[sectorNo][0]);
529 data[11] = (keyB[sectorNo][1]);
530 data[12] = (keyB[sectorNo][2]);
531 data[13] = (keyB[sectorNo][3]);
532 data[14] = (keyB[sectorNo][4]);
533 data[15] = (keyB[sectorNo][5]);
534 }
535 if (isOK) {
536 memcpy(carddata[FirstBlockOfSector(sectorNo) + blockNo], data, 16);
537 PrintAndLog("Successfully read block %2d of sector %2d.", blockNo, sectorNo);
538 } else {
539 PrintAndLog("Could not read block %2d of sector %2d", blockNo, sectorNo);
540 break;
541 }
542 }
543 else {
544 isOK = false;
545 PrintAndLog("Command execute timeout when trying to read block %2d of sector %2d.", blockNo, sectorNo);
546 break;
547 }
548 }
549 }
550
551 if (isOK) {
552 if ((fout = fopen("dumpdata.bin","wb")) == NULL) {
553 PrintAndLog("Could not create file name dumpdata.bin");
554 return 1;
555 }
556 uint16_t numblocks = FirstBlockOfSector(numSectors - 1) + NumBlocksPerSector(numSectors - 1);
557 fwrite(carddata, 1, 16*numblocks, fout);
558 fclose(fout);
559 PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks, 16*numblocks);
560 }
561
562 return 0;
563 }
564
565 int CmdHF14AMfRestore(const char *Cmd) {
566 uint8_t sectorNo,blockNo;
567 uint8_t keyType = 0;
568 uint8_t key[6] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
569 uint8_t bldata[16] = {0x00};
570 uint8_t keyA[40][6];
571 uint8_t keyB[40][6];
572 uint8_t numSectors;
573
574 FILE *fdump;
575 FILE *fkeys;
576
577 char cmdp = param_getchar(Cmd, 0);
578 switch (cmdp) {
579 case '0' : numSectors = 5; break;
580 case '1' :
581 case '\0': numSectors = 16; break;
582 case '2' : numSectors = 32; break;
583 case '4' : numSectors = 40; break;
584 default: numSectors = 16;
585 }
586
587 if (strlen(Cmd) > 1 || cmdp == 'h' || cmdp == 'H') {
588 PrintAndLog("Usage: hf mf restore [card memory]");
589 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
590 PrintAndLog("");
591 PrintAndLog("Samples: hf mf restore");
592 PrintAndLog(" hf mf restore 4");
593 return 0;
594 }
595
596 if ((fkeys = fopen("dumpkeys.bin","rb")) == NULL) {
597 PrintAndLog("Could not find file dumpkeys.bin");
598 return 1;
599 }
600
601 size_t bytes_read;
602 for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {
603 bytes_read = fread( keyA[sectorNo], 1, 6, fkeys );
604 if ( bytes_read == 0) {
605 PrintAndLog("File reading error (dumpkeys.bin).");
606 fclose(fkeys);
607 return 2;
608 }
609 }
610
611 for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {
612 bytes_read = fread( keyB[sectorNo], 1, 6, fkeys );
613 if ( bytes_read == 0) {
614 PrintAndLog("File reading error (dumpkeys.bin).");
615 fclose(fkeys);
616 return 2;
617 }
618 }
619
620 fclose(fkeys);
621
622 if ((fdump = fopen("dumpdata.bin","rb")) == NULL) {
623 PrintAndLog("Could not find file dumpdata.bin");
624 return 1;
625 }
626 PrintAndLog("Restoring dumpdata.bin to card");
627
628 for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {
629 for(blockNo = 0; blockNo < NumBlocksPerSector(sectorNo); blockNo++) {
630 UsbCommand c = {CMD_MIFARE_WRITEBL, {FirstBlockOfSector(sectorNo) + blockNo, keyType, 0}};
631 memcpy(c.d.asBytes, key, 6);
632 bytes_read = fread(bldata, 1, 16, fdump);
633 if ( bytes_read == 0) {
634 PrintAndLog("File reading error (dumpdata.bin).");
635 fclose(fdump);
636 return 2;
637 }
638
639 if (blockNo == NumBlocksPerSector(sectorNo) - 1) { // sector trailer
640 bldata[0] = (keyA[sectorNo][0]);
641 bldata[1] = (keyA[sectorNo][1]);
642 bldata[2] = (keyA[sectorNo][2]);
643 bldata[3] = (keyA[sectorNo][3]);
644 bldata[4] = (keyA[sectorNo][4]);
645 bldata[5] = (keyA[sectorNo][5]);
646 bldata[10] = (keyB[sectorNo][0]);
647 bldata[11] = (keyB[sectorNo][1]);
648 bldata[12] = (keyB[sectorNo][2]);
649 bldata[13] = (keyB[sectorNo][3]);
650 bldata[14] = (keyB[sectorNo][4]);
651 bldata[15] = (keyB[sectorNo][5]);
652 }
653
654 PrintAndLog("Writing to block %3d: %s", FirstBlockOfSector(sectorNo) + blockNo, sprint_hex(bldata, 16));
655
656 memcpy(c.d.asBytes + 10, bldata, 16);
657 clearCommandBuffer();
658 SendCommand(&c);
659
660 UsbCommand resp;
661 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
662 uint8_t isOK = resp.arg[0] & 0xff;
663 PrintAndLog("isOk:%02x", isOK);
664 } else {
665 PrintAndLog("Command execute timeout");
666 }
667 }
668 }
669
670 fclose(fdump);
671 return 0;
672 }
673
674 int CmdHF14AMfNested(const char *Cmd) {
675 int i, j, res, iterations;
676 sector *e_sector = NULL;
677 uint8_t blockNo = 0;
678 uint8_t keyType = 0;
679 uint8_t trgBlockNo = 0;
680 uint8_t trgKeyType = 0;
681 uint8_t SectorsCnt = 0;
682 uint8_t key[6] = {0, 0, 0, 0, 0, 0};
683 uint8_t keyBlock[6*6];
684 uint64_t key64 = 0;
685 bool transferToEml = false;
686
687 bool createDumpFile = false;
688 FILE *fkeys;
689 uint8_t standart[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
690 uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
691
692 if (strlen(Cmd)<3) return usage_hf14_nested();
693
694 char cmdp, ctmp;
695 cmdp = param_getchar(Cmd, 0);
696 blockNo = param_get8(Cmd, 1);
697 ctmp = param_getchar(Cmd, 2);
698
699 if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {
700 PrintAndLog("Key type must be A or B");
701 return 1;
702 }
703
704 if (ctmp != 'A' && ctmp != 'a')
705 keyType = 1;
706
707 if (param_gethex(Cmd, 3, key, 12)) {
708 PrintAndLog("Key must include 12 HEX symbols");
709 return 1;
710 }
711
712 if (cmdp == 'o' || cmdp == 'O') {
713 cmdp = 'o';
714 trgBlockNo = param_get8(Cmd, 4);
715 ctmp = param_getchar(Cmd, 5);
716 if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {
717 PrintAndLog("Target key type must be A or B");
718 return 1;
719 }
720 if (ctmp != 'A' && ctmp != 'a')
721 trgKeyType = 1;
722 } else {
723
724 switch (cmdp) {
725 case '0': SectorsCnt = 05; break;
726 case '1': SectorsCnt = 16; break;
727 case '2': SectorsCnt = 32; break;
728 case '4': SectorsCnt = 40; break;
729 default: SectorsCnt = 16;
730 }
731 }
732
733 ctmp = param_getchar(Cmd, 4);
734 if (ctmp == 't' || ctmp == 'T') transferToEml = true;
735 else if (ctmp == 'd' || ctmp == 'D') createDumpFile = true;
736
737 ctmp = param_getchar(Cmd, 6);
738 transferToEml |= (ctmp == 't' || ctmp == 'T');
739 transferToEml |= (ctmp == 'd' || ctmp == 'D');
740
741 if (cmdp == 'o') {
742 int16_t isOK = mfnested(blockNo, keyType, key, trgBlockNo, trgKeyType, keyBlock, true);
743 switch (isOK) {
744 case -1 : PrintAndLog("Error: No response from Proxmark.\n"); break;
745 case -2 : PrintAndLog("Button pressed. Aborted.\n"); break;
746 case -3 : PrintAndLog("Tag isn't vulnerable to Nested Attack (its random number generator is not predictable).\n"); break;
747 case -4 : PrintAndLog("No valid key found"); break;
748 case -5 :
749 key64 = bytes_to_num(keyBlock, 6);
750
751 // transfer key to the emulator
752 if (transferToEml) {
753 uint8_t sectortrailer;
754 if (trgBlockNo < 32*4) { // 4 block sector
755 sectortrailer = (trgBlockNo & 0x03) + 3;
756 } else { // 16 block sector
757 sectortrailer = (trgBlockNo & 0x0f) + 15;
758 }
759 mfEmlGetMem(keyBlock, sectortrailer, 1);
760
761 if (!trgKeyType)
762 num_to_bytes(key64, 6, keyBlock);
763 else
764 num_to_bytes(key64, 6, &keyBlock[10]);
765 mfEmlSetMem(keyBlock, sectortrailer, 1);
766 }
767 return 0;
768 default : PrintAndLog("Unknown Error.\n");
769 }
770 return 2;
771 }
772 else { // ------------------------------------ multiple sectors working
773 clock_t t1 = clock();
774 unsigned long elapsed_time;
775 time_t start, end;
776 time(&start);
777
778 e_sector = calloc(SectorsCnt, sizeof(sector));
779 if (e_sector == NULL) return 1;
780
781 //test current key and additional standard keys first
782 memcpy(keyBlock, key, 6);
783 num_to_bytes(0xffffffffffff, 6, (uint8_t*)(keyBlock + 1 * 6));
784 num_to_bytes(0x000000000000, 6, (uint8_t*)(keyBlock + 2 * 6));
785 num_to_bytes(0xa0a1a2a3a4a5, 6, (uint8_t*)(keyBlock + 3 * 6));
786 num_to_bytes(0xb0b1b2b3b4b5, 6, (uint8_t*)(keyBlock + 4 * 6));
787 num_to_bytes(0xaabbccddeeff, 6, (uint8_t*)(keyBlock + 5 * 6));
788
789 PrintAndLog("Testing known keys. Sector count=%d", SectorsCnt);
790 for (i = 0; i < SectorsCnt; i++) {
791 for (j = 0; j < 2; j++) {
792 if (e_sector[i].foundKey[j]) continue;
793
794 res = mfCheckKeys(FirstBlockOfSector(i), j, true, 6, keyBlock, &key64);
795
796 if (!res) {
797 e_sector[i].Key[j] = key64;
798 e_sector[i].foundKey[j] = TRUE;
799 }
800 }
801 }
802 clock_t t2 = clock() - t1;
803 time(&end);
804 elapsed_time = difftime(end, start);
805 if ( t2 > 0 )
806 PrintAndLog("Time to check 6 known keys: %.0f ticks %u seconds\n", (float)t2 , elapsed_time);
807
808 PrintAndLog("enter nested...");
809
810 // nested sectors
811 iterations = 0;
812 bool calibrate = true;
813
814 for (i = 0; i < NESTED_SECTOR_RETRY; i++) {
815 for (uint8_t sectorNo = 0; sectorNo < SectorsCnt; ++sectorNo) {
816 for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) {
817
818 if (e_sector[sectorNo].foundKey[trgKeyType]) continue;
819
820 int16_t isOK = mfnested(blockNo, keyType, key, FirstBlockOfSector(sectorNo), trgKeyType, keyBlock, calibrate);
821 switch (isOK) {
822 case -1 : PrintAndLog("Error: No response from Proxmark.\n"); break;
823 case -2 : PrintAndLog("Button pressed. Aborted.\n"); break;
824 case -3 : PrintAndLog("Tag isn't vulnerable to Nested Attack (its random number generator is not predictable).\n"); break;
825 case -4 : //key not found
826 calibrate = false;
827 iterations++;
828 continue;
829 case -5 :
830 calibrate = false;
831 iterations++;
832 e_sector[sectorNo].foundKey[trgKeyType] = 1;
833 e_sector[sectorNo].Key[trgKeyType] = bytes_to_num(keyBlock, 6);
834 continue;
835
836 default : PrintAndLog("Unknown Error.\n");
837 }
838 free(e_sector);
839 return 2;
840 }
841 }
842 }
843
844 t1 = clock() - t1;
845 time(&end);
846 elapsed_time = difftime(end, start);
847 if ( t1 > 0 )
848 PrintAndLog("Time in nested: %.0f ticks %u seconds\n", (float)t1, elapsed_time);
849
850
851 // 20160116 If Sector A is found, but not Sector B, try just reading it of the tag?
852 PrintAndLog("trying to read key B...");
853 for (i = 0; i < SectorsCnt; i++) {
854 // KEY A but not KEY B
855 if ( e_sector[i].foundKey[0] && !e_sector[i].foundKey[1] ) {
856
857 uint8_t sectrail = (FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1);
858
859 PrintAndLog("Reading block %d", sectrail);
860
861 UsbCommand c = {CMD_MIFARE_READBL, {sectrail, 0, 0}};
862 num_to_bytes(e_sector[i].Key[0], 6, c.d.asBytes); // KEY A
863 clearCommandBuffer();
864 SendCommand(&c);
865
866 UsbCommand resp;
867 if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500)) continue;
868
869 uint8_t isOK = resp.arg[0] & 0xff;
870 if (!isOK) continue;
871
872 uint8_t *data = resp.d.asBytes;
873 key64 = bytes_to_num(data+10, 6);
874 if (key64) {
875 PrintAndLog("Data:%s", sprint_hex(data+10, 6));
876 e_sector[i].foundKey[1] = TRUE;
877 e_sector[i].Key[1] = key64;
878 }
879 }
880 }
881
882
883 //print them
884 printKeyTable( SectorsCnt, e_sector );
885
886 // transfer them to the emulator
887 if (transferToEml) {
888 for (i = 0; i < SectorsCnt; i++) {
889 mfEmlGetMem(keyBlock, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1);
890 if (e_sector[i].foundKey[0])
891 num_to_bytes(e_sector[i].Key[0], 6, keyBlock);
892 if (e_sector[i].foundKey[1])
893 num_to_bytes(e_sector[i].Key[1], 6, &keyBlock[10]);
894 mfEmlSetMem(keyBlock, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1);
895 }
896 }
897
898 // Create dump file
899 if (createDumpFile) {
900 if ((fkeys = fopen("dumpkeys.bin","wb")) == NULL) {
901 PrintAndLog("Could not create file dumpkeys.bin");
902 free(e_sector);
903 return 1;
904 }
905 PrintAndLog("Printing keys to binary file dumpkeys.bin...");
906 for(i=0; i<SectorsCnt; i++) {
907 if (e_sector[i].foundKey[0]){
908 num_to_bytes(e_sector[i].Key[0], 6, tempkey);
909 fwrite ( tempkey, 1, 6, fkeys );
910 }
911 else{
912 fwrite ( &standart, 1, 6, fkeys );
913 }
914 }
915 for(i=0; i<SectorsCnt; i++) {
916 if (e_sector[i].foundKey[1]){
917 num_to_bytes(e_sector[i].Key[1], 6, tempkey);
918 fwrite ( tempkey, 1, 6, fkeys );
919 }
920 else{
921 fwrite ( &standart, 1, 6, fkeys );
922 }
923 }
924 fclose(fkeys);
925 }
926
927 free(e_sector);
928 }
929 return 0;
930 }
931
932 int CmdHF14AMfNestedHard(const char *Cmd) {
933 uint8_t blockNo = 0;
934 uint8_t keyType = 0;
935 uint8_t trgBlockNo = 0;
936 uint8_t trgKeyType = 0;
937 uint8_t key[6] = {0, 0, 0, 0, 0, 0};
938 uint8_t trgkey[6] = {0, 0, 0, 0, 0, 0};
939
940 char ctmp;
941 ctmp = param_getchar(Cmd, 0);
942 if (ctmp == 'H' || ctmp == 'h' ) return usage_hf14_hardnested();
943 if (ctmp != 'R' && ctmp != 'r' && ctmp != 'T' && ctmp != 't' && strlen(Cmd) < 20) return usage_hf14_hardnested();
944
945 bool know_target_key = false;
946 bool nonce_file_read = false;
947 bool nonce_file_write = false;
948 bool slow = false;
949 int tests = 0;
950
951 if (ctmp == 'R' || ctmp == 'r') {
952 nonce_file_read = true;
953 if (!param_gethex(Cmd, 1, trgkey, 12)) {
954 know_target_key = true;
955 }
956 } else if (ctmp == 'T' || ctmp == 't') {
957 tests = param_get32ex(Cmd, 1, 100, 10);
958 } else {
959 blockNo = param_get8(Cmd, 0);
960 ctmp = param_getchar(Cmd, 1);
961 if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {
962 PrintAndLog("Key type must be A or B");
963 return 1;
964 }
965 if (ctmp != 'A' && ctmp != 'a') {
966 keyType = 1;
967 }
968
969 if (param_gethex(Cmd, 2, key, 12)) {
970 PrintAndLog("Key must include 12 HEX symbols");
971 return 1;
972 }
973
974 trgBlockNo = param_get8(Cmd, 3);
975 ctmp = param_getchar(Cmd, 4);
976 if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {
977 PrintAndLog("Target key type must be A or B");
978 return 1;
979 }
980 if (ctmp != 'A' && ctmp != 'a') {
981 trgKeyType = 1;
982 }
983
984 uint16_t i = 5;
985
986 if (!param_gethex(Cmd, 5, trgkey, 12)) {
987 know_target_key = true;
988 i++;
989 }
990
991 while ((ctmp = param_getchar(Cmd, i))) {
992 if (ctmp == 's' || ctmp == 'S') {
993 slow = true;
994 } else if (ctmp == 'w' || ctmp == 'W') {
995 nonce_file_write = true;
996 } else {
997 PrintAndLog("Possible options are w and/or s");
998 return 1;
999 }
1000 i++;
1001 }
1002 }
1003
1004 PrintAndLog("--target block no:%3d, target key type:%c, known target key: 0x%02x%02x%02x%02x%02x%02x%s, file action: %s, Slow: %s, Tests: %d ",
1005 trgBlockNo,
1006 trgKeyType?'B':'A',
1007 trgkey[0], trgkey[1], trgkey[2], trgkey[3], trgkey[4], trgkey[5],
1008 know_target_key ? "" : " (not set)",
1009 nonce_file_write ? "write": nonce_file_read ? "read" : "none",
1010 slow ? "Yes" : "No",
1011 tests);
1012
1013 int16_t isOK = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, know_target_key?trgkey:NULL, nonce_file_read, nonce_file_write, slow, tests);
1014
1015 if (isOK) {
1016 switch (isOK) {
1017 case 1 : PrintAndLog("Error: No response from Proxmark.\n"); break;
1018 case 2 : PrintAndLog("Button pressed. Aborted.\n"); break;
1019 default : break;
1020 }
1021 return 2;
1022 }
1023
1024 return 0;
1025 }
1026
1027 int CmdHF14AMfChk(const char *Cmd) {
1028
1029 if (strlen(Cmd)<3) return usage_hf14_chk();
1030
1031 FILE * f;
1032 char filename[FILE_PATH_SIZE]={0};
1033 char buf[13];
1034 uint8_t *keyBlock = NULL, *p;
1035 uint8_t stKeyBlock = 20;
1036
1037 sector *e_sector = NULL;
1038
1039 int i, res;
1040 int keycnt = 0;
1041 char ctmp = 0x00;
1042 uint8_t blockNo = 0;
1043 uint8_t SectorsCnt = 1;
1044 uint8_t keyType = 0;
1045 uint64_t key64 = 0;
1046
1047 uint8_t tempkey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
1048
1049 int transferToEml = 0;
1050 int createDumpFile = 0;
1051
1052 keyBlock = calloc(stKeyBlock, 6);
1053 if (keyBlock == NULL) return 1;
1054
1055 uint64_t defaultKeys[] = {
1056 0xffffffffffff, // Default key (first key used by program if no user defined key)
1057 0x000000000000, // Blank key
1058 0xa0a1a2a3a4a5, // NFCForum MAD key
1059 0xb0b1b2b3b4b5,
1060 0xaabbccddeeff,
1061 0x4d3a99c351dd,
1062 0x1a982c7e459a,
1063 0xd3f7d3f7d3f7,
1064 0x714c5c886e97,
1065 0x587ee5f9350f,
1066 0xa0478cc39091,
1067 0x533cb6c723f6,
1068 0x8fd0a4f256e9
1069 };
1070 int defaultKeysSize = sizeof(defaultKeys) / sizeof(uint64_t);
1071
1072 for (int defaultKeyCounter = 0; defaultKeyCounter < defaultKeysSize; defaultKeyCounter++)
1073 num_to_bytes(defaultKeys[defaultKeyCounter], 6, (uint8_t*)(keyBlock + defaultKeyCounter * 6));
1074
1075
1076 if (param_getchar(Cmd, 0)=='*') {
1077 blockNo = 3;
1078 switch(param_getchar(Cmd+1, 0)) {
1079 case '0': SectorsCnt = 5; break;
1080 case '1': SectorsCnt = 16; break;
1081 case '2': SectorsCnt = 32; break;
1082 case '4': SectorsCnt = 40; break;
1083 default: SectorsCnt = 16;
1084 }
1085 } else {
1086 blockNo = param_get8(Cmd, 0);
1087 }
1088
1089 ctmp = param_getchar(Cmd, 1);
1090 switch (ctmp) {
1091 case 'a': case 'A':
1092 keyType = !0;
1093 break;
1094 case 'b': case 'B':
1095 keyType = !1;
1096 break;
1097 case '?':
1098 keyType = 2;
1099 break;
1100 default:
1101 PrintAndLog("Key type must be A , B or ?");
1102 free(keyBlock);
1103 return 1;
1104 };
1105
1106 ctmp = param_getchar(Cmd, 2);
1107 if (ctmp == 't' || ctmp == 'T') transferToEml = 1;
1108 else if (ctmp == 'd' || ctmp == 'D') createDumpFile = 1;
1109
1110 for (i = transferToEml || createDumpFile; param_getchar(Cmd, 2 + i); i++) {
1111 if (!param_gethex(Cmd, 2 + i, keyBlock + 6 * keycnt, 12)) {
1112 if ( stKeyBlock - keycnt < 2) {
1113 p = realloc(keyBlock, 6*(stKeyBlock+=10));
1114 if (!p) {
1115 PrintAndLog("Cannot allocate memory for Keys");
1116 free(keyBlock);
1117 return 2;
1118 }
1119 keyBlock = p;
1120 }
1121 PrintAndLog("key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,
1122 (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],
1123 (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6);
1124 keycnt++;
1125 } else {
1126 // May be a dic file
1127 if ( param_getstr(Cmd, 2 + i,filename) >= FILE_PATH_SIZE ) {
1128 PrintAndLog("File name too long");
1129 free(keyBlock);
1130 return 2;
1131 }
1132
1133 if ( (f = fopen( filename , "r")) ) {
1134 while( fgets(buf, sizeof(buf), f) ){
1135 if (strlen(buf) < 12 || buf[11] == '\n')
1136 continue;
1137
1138 while (fgetc(f) != '\n' && !feof(f)) ; //goto next line
1139
1140 if( buf[0]=='#' ) continue; //The line start with # is comment, skip
1141
1142 if (!isxdigit(buf[0])){
1143 PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf);
1144 continue;
1145 }
1146
1147 buf[12] = 0;
1148
1149 if ( stKeyBlock - keycnt < 2) {
1150 p = realloc(keyBlock, 6*(stKeyBlock+=10));
1151 if (!p) {
1152 PrintAndLog("Cannot allocate memory for defKeys");
1153 free(keyBlock);
1154 fclose(f);
1155 return 2;
1156 }
1157 keyBlock = p;
1158 }
1159 memset(keyBlock + 6 * keycnt, 0, 6);
1160 num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt);
1161 PrintAndLog("check key[%2d] %012"llx, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6));
1162 keycnt++;
1163 memset(buf, 0, sizeof(buf));
1164 }
1165 fclose(f);
1166 } else {
1167 PrintAndLog("File: %s: not found or locked.", filename);
1168 free(keyBlock);
1169 return 1;
1170
1171 }
1172 }
1173 }
1174
1175 if (keycnt == 0) {
1176 PrintAndLog("No key specified, trying default keys");
1177 for (;keycnt < defaultKeysSize; keycnt++)
1178 PrintAndLog("key[%2d] %02x%02x%02x%02x%02x%02x", keycnt,
1179 (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2],
1180 (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6);
1181 }
1182
1183 // initialize storage for found keys
1184 e_sector = calloc(SectorsCnt, sizeof(sector));
1185 if (e_sector == NULL) {
1186 free(keyBlock);
1187 return 1;
1188 }
1189
1190 // empty e_sector
1191 for(int i = 0; i < SectorsCnt; ++i){
1192 e_sector[i].Key[0] = 0xffffffffffff;
1193 e_sector[i].Key[1] = 0xffffffffffff;
1194 e_sector[i].foundKey[0] = FALSE;
1195 e_sector[i].foundKey[1] = FALSE;
1196 }
1197
1198
1199 uint8_t trgKeyType = 0;
1200 uint32_t max_keys = keycnt > (USB_CMD_DATA_SIZE/6) ? (USB_CMD_DATA_SIZE/6) : keycnt;
1201
1202 // time
1203 clock_t t1 = clock();
1204 time_t start, end;
1205 time(&start);
1206
1207 // check keys.
1208 for (trgKeyType = !keyType; trgKeyType < 2; (keyType==2) ? (++trgKeyType) : (trgKeyType=2) ) {
1209
1210 int b = blockNo;
1211 for (int i = 0; i < SectorsCnt; ++i) {
1212
1213 // skip already found keys.
1214 if (e_sector[i].foundKey[trgKeyType]) continue;
1215
1216 for (uint32_t c = 0; c < keycnt; c += max_keys) {
1217
1218 uint32_t size = keycnt-c > max_keys ? max_keys : keycnt-c;
1219
1220 res = mfCheckKeys(b, trgKeyType, true, size, &keyBlock[6*c], &key64);
1221 if (!res) {
1222 e_sector[i].Key[trgKeyType] = key64;
1223 e_sector[i].foundKey[trgKeyType] = TRUE;
1224 break;
1225 }
1226 printf(".");
1227 fflush(stdout);
1228 }
1229 b < 127 ? ( b +=4 ) : ( b += 16 );
1230 }
1231 }
1232 t1 = clock() - t1;
1233 time(&end);
1234 unsigned long elapsed_time = difftime(end, start);
1235 if ( t1 > 0 )
1236 PrintAndLog("\nTime in checkkeys: %.0f ticks %u seconds\n", (float)t1, elapsed_time);
1237
1238
1239 // 20160116 If Sector A is found, but not Sector B, try just reading it of the tag?
1240 if ( keyType != 1 ) {
1241 PrintAndLog("testing to read key B...");
1242 for (i = 0; i < SectorsCnt; i++) {
1243 // KEY A but not KEY B
1244 if ( e_sector[i].foundKey[0] && !e_sector[i].foundKey[1] ) {
1245
1246 uint8_t sectrail = (FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1);
1247
1248 PrintAndLog("Reading block %d", sectrail);
1249
1250 UsbCommand c = {CMD_MIFARE_READBL, {sectrail, 0, 0}};
1251 num_to_bytes(e_sector[i].Key[0], 6, c.d.asBytes); // KEY A
1252 clearCommandBuffer();
1253 SendCommand(&c);
1254
1255 UsbCommand resp;
1256 if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500)) continue;
1257
1258 uint8_t isOK = resp.arg[0] & 0xff;
1259 if (!isOK) continue;
1260
1261 uint8_t *data = resp.d.asBytes;
1262 key64 = bytes_to_num(data+10, 6);
1263 if (key64) {
1264 PrintAndLog("Data:%s", sprint_hex(data+10, 6));
1265 e_sector[i].foundKey[1] = 1;
1266 e_sector[i].Key[1] = key64;
1267 }
1268 }
1269 }
1270 }
1271
1272
1273 //print them
1274 printKeyTable( SectorsCnt, e_sector );
1275
1276 if (transferToEml) {
1277 uint8_t block[16] = {0x00};
1278 for (uint8_t i = 0; i < SectorsCnt; ++i ) {
1279 mfEmlGetMem(block, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1);
1280 if (e_sector[i].foundKey[0])
1281 num_to_bytes(e_sector[i].Key[0], 6, block);
1282 if (e_sector[i].foundKey[1])
1283 num_to_bytes(e_sector[i].Key[1], 6, block+10);
1284 mfEmlSetMem(block, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1);
1285 }
1286 PrintAndLog("Found keys have been transferred to the emulator memory");
1287 }
1288
1289 if (createDumpFile) {
1290 FILE *fkeys = fopen("dumpkeys.bin","wb");
1291 if (fkeys == NULL) {
1292 PrintAndLog("Could not create file dumpkeys.bin");
1293 free(keyBlock);
1294 free(e_sector);
1295 return 1;
1296 }
1297 PrintAndLog("Printing keys to binary file dumpkeys.bin...");
1298
1299 for( i=0; i<SectorsCnt; i++) {
1300 num_to_bytes(e_sector[i].Key[0], 6, tempkey);
1301 fwrite ( tempkey, 1, 6, fkeys );
1302 }
1303 for(i=0; i<SectorsCnt; i++) {
1304 num_to_bytes(e_sector[i].Key[1], 6, tempkey);
1305 fwrite ( tempkey, 1, 6, fkeys );
1306 }
1307 fclose(fkeys);
1308 PrintAndLog("Found keys have been dumped to file dumpkeys.bin. 0xffffffffffff has been inserted for unknown keys.");
1309 }
1310
1311 free(keyBlock);
1312 free(e_sector);
1313 PrintAndLog("");
1314 return 0;
1315 }
1316
1317 int CmdHF14AMf1kSim(const char *Cmd) {
1318 uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
1319 uint8_t exitAfterNReads = 0;
1320 uint8_t flags = (FLAG_UID_IN_EMUL | FLAG_4B_UID_IN_DATA);
1321 int uidlen = 0;
1322 uint8_t pnr = 0;
1323 uint8_t cmdp = param_getchar(Cmd, 0);
1324
1325 if (cmdp == 'h' || cmdp == 'H') return usage_hf14_mf1ksim();
1326
1327 cmdp = param_getchar(Cmd, pnr);
1328 if (cmdp == 'u' || cmdp == 'U') {
1329 param_gethex_ex(Cmd, pnr+1, uid, &uidlen);
1330 switch(uidlen){
1331 case 20: flags = FLAG_10B_UID_IN_DATA; break;
1332 case 14: flags = FLAG_7B_UID_IN_DATA; break;
1333 case 8: flags = FLAG_4B_UID_IN_DATA; break;
1334 default: return usage_hf14_mf1ksim();
1335 }
1336 pnr +=2;
1337 }
1338
1339 cmdp = param_getchar(Cmd, pnr);
1340 if (cmdp == 'n' || cmdp == 'N') {
1341 exitAfterNReads = param_get8(Cmd, pnr+1);
1342 pnr += 2;
1343 }
1344
1345 cmdp = param_getchar(Cmd, pnr);
1346 if (cmdp == 'i' || cmdp == 'I' ) {
1347 flags |= FLAG_INTERACTIVE;
1348 pnr++;
1349 }
1350
1351 cmdp = param_getchar(Cmd, pnr);
1352 if (cmdp == 'x' || cmdp == 'X') {
1353 flags |= FLAG_NR_AR_ATTACK;
1354 }
1355
1356 PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) "
1357 , (uidlen == 0 ) ? "N/A" : sprint_hex(uid, uidlen>>1)
1358 , exitAfterNReads
1359 , flags
1360 , flags);
1361
1362 UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads, 0}};
1363 memcpy(c.d.asBytes, uid, sizeof(uid));
1364 clearCommandBuffer();
1365 SendCommand(&c);
1366
1367 if(flags & FLAG_INTERACTIVE) {
1368 uint8_t data[32];
1369 uint64_t key;
1370 UsbCommand resp;
1371 PrintAndLog("Press pm3-button or send another cmd to abort simulation");
1372 while( !ukbhit() ){
1373 if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500) ) continue;
1374
1375 if ( !(flags & FLAG_NR_AR_ATTACK) ) break;
1376 if ( (resp.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD ) break;
1377
1378 memset(data, 0x00, sizeof(data));
1379 int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];
1380
1381 memcpy(data, resp.d.asBytes, len);
1382 key = 0;
1383 bool found = tryMfk32(data, &key);
1384 found ^= tryMfk32_moebius(data, &key);
1385 if ( found ) break;
1386 }
1387 }
1388 return 0;
1389 }
1390
1391 int CmdHF14AMfSniff(const char *Cmd){
1392 bool wantLogToFile = FALSE;
1393 bool wantDecrypt = FALSE;
1394 //bool wantSaveToEml = FALSE; TODO
1395 bool wantSaveToEmlFile = FALSE;
1396
1397 //var
1398 int tmpchar;
1399 int res = 0;
1400 int len = 0;
1401 int blockLen = 0;
1402 int pckNum = 0;
1403 int num = 0;
1404 uint8_t uid[10];
1405 uint8_t uid_len = 0;
1406 uint8_t atqa[2] = {0x00, 0x00};
1407 uint8_t sak = 0;
1408 bool isTag = FALSE;
1409 uint8_t *buf = NULL;
1410 uint16_t bufsize = 0;
1411 uint8_t *bufPtr = NULL;
1412 uint16_t traceLen = 0;
1413
1414 memset(uid, 0x00, sizeof(uid));
1415
1416 char ctmp = param_getchar(Cmd, 0);
1417 if ( ctmp == 'h' || ctmp == 'H' ) return usage_hf14_sniff();
1418
1419 for (int i = 0; i < 4; i++) {
1420 ctmp = param_getchar(Cmd, i);
1421 if (ctmp == 'l' || ctmp == 'L') wantLogToFile = true;
1422 if (ctmp == 'd' || ctmp == 'D') wantDecrypt = true;
1423 //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO
1424 if (ctmp == 'f' || ctmp == 'F') wantSaveToEmlFile = true;
1425 }
1426
1427 printf("-------------------------------------------------------------------------\n");
1428 printf("Executing mifare sniffing command. \n");
1429 printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");
1430 printf("Press the key on pc keyboard to abort the client.\n");
1431 printf("-------------------------------------------------------------------------\n");
1432
1433 UsbCommand c = {CMD_MIFARE_SNIFFER, {0, 0, 0}};
1434 clearCommandBuffer();
1435 SendCommand(&c);
1436
1437 // wait cycle
1438 while (true) {
1439 printf(".");
1440 fflush(stdout);
1441 if (ukbhit()) {
1442 tmpchar = getchar();
1443 (void)tmpchar;
1444 printf("\naborted via keyboard!\n");
1445 break;
1446 }
1447
1448 UsbCommand resp;
1449 if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {
1450 res = resp.arg[0] & 0xff;
1451 traceLen = resp.arg[1];
1452 len = resp.arg[2];
1453
1454 // we are done?
1455 if (res == 0) {
1456 free(buf);
1457 return 0;
1458 }
1459
1460 if (res == 1) { // there is (more) data to be transferred
1461 if (pckNum == 0) { // first packet, (re)allocate necessary buffer
1462 if (traceLen > bufsize) {
1463 uint8_t *p;
1464 if (buf == NULL) // not yet allocated
1465 p = malloc(traceLen);
1466 else // need more memory
1467 p = realloc(buf, traceLen);
1468
1469 if (p == NULL) {
1470 PrintAndLog("Cannot allocate memory for trace");
1471 free(buf);
1472 return 2;
1473 }
1474 buf = p;
1475 }
1476 bufPtr = buf;
1477 bufsize = traceLen;
1478 memset(buf, 0x00, traceLen);
1479 }
1480 if (bufPtr == NULL) {
1481 PrintAndLog("Cannot allocate memory for trace");
1482 free(buf);
1483 return 2;
1484 }
1485 // what happens if LEN is bigger then TRACELEN --iceman
1486 memcpy(bufPtr, resp.d.asBytes, len);
1487 bufPtr += len;
1488 pckNum++;
1489 }
1490
1491 if (res == 2) { // received all data, start displaying
1492 blockLen = bufPtr - buf;
1493 bufPtr = buf;
1494 printf(">\n");
1495 PrintAndLog("received trace len: %d packages: %d", blockLen, pckNum);
1496 while (bufPtr - buf < blockLen) {
1497 bufPtr += 6; // skip (void) timing information
1498 len = *((uint16_t *)bufPtr);
1499 if(len & 0x8000) {
1500 isTag = true;
1501 len &= 0x7fff;
1502 } else {
1503 isTag = false;
1504 }
1505 bufPtr += 2;
1506 if ((len == 17) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff) && (bufPtr[15] == 0xff) && (bufPtr[16] == 0xff)) {
1507 memcpy(uid, bufPtr + 2, 10);
1508 memcpy(atqa, bufPtr + 2 + 10, 2);
1509 switch (atqa[0] & 0xC0) {
1510 case 0x80: uid_len = 10; break;
1511 case 0x40: uid_len = 7; break;
1512 default: uid_len = 4; break;
1513 }
1514 sak = bufPtr[14];
1515 PrintAndLog("tag select uid| %s atqa:0x%02x%02x sak:0x%02x",
1516 sprint_hex(uid, uid_len),
1517 atqa[1],
1518 atqa[0],
1519 sak);
1520 if (wantLogToFile || wantDecrypt) {
1521 FillFileNameByUID(logHexFileName, uid, ".log", uid_len);
1522 AddLogCurrentDT(logHexFileName);
1523 }
1524 if (wantDecrypt)
1525 mfTraceInit(uid, uid_len, atqa, sak, wantSaveToEmlFile);
1526 } else {
1527 PrintAndLog("%03d| %s |%s", num, isTag ? "TAG" : "RDR", sprint_hex(bufPtr, len));
1528 if (wantLogToFile)
1529 AddLogHex(logHexFileName, isTag ? "TAG| ":"RDR| ", bufPtr, len);
1530 if (wantDecrypt)
1531 mfTraceDecode(bufPtr, len, wantSaveToEmlFile);
1532 num++;
1533 }
1534 bufPtr += len;
1535 bufPtr += ((len-1)/8+1); // ignore parity
1536 }
1537 pckNum = 0;
1538 }
1539 } // resp not NULL
1540 } // while (true)
1541
1542 free(buf);
1543 return 0;
1544 }
1545
1546 int CmdHF14AMfDbg(const char *Cmd) {
1547
1548 char ctmp = param_getchar(Cmd, 0);
1549 if (strlen(Cmd) < 1 || ctmp == 'h'|| ctmp == 'H') return usage_hf14_dbg();
1550
1551 uint8_t dbgMode = param_get8ex(Cmd, 0, 0, 10);
1552 if (dbgMode > 4) return usage_hf14_dbg();
1553
1554 UsbCommand c = {CMD_MIFARE_SET_DBGMODE, {dbgMode, 0, 0}};
1555 SendCommand(&c);
1556 return 0;
1557 }
1558
1559 void printKeyTable( uint8_t sectorscnt, sector *e_sector ){
1560 PrintAndLog("|---|----------------|---|----------------|---|");
1561 PrintAndLog("|sec|key A |res|key B |res|");
1562 PrintAndLog("|---|----------------|---|----------------|---|");
1563 for (uint8_t i = 0; i < sectorscnt; ++i) {
1564 PrintAndLog("|%03d| %012"llx" | %d | %012"llx" | %d |", i,
1565 e_sector[i].Key[0], e_sector[i].foundKey[0],
1566 e_sector[i].Key[1], e_sector[i].foundKey[1]
1567 );
1568 }
1569 PrintAndLog("|---|----------------|---|----------------|---|");
1570 }
1571
1572 // EMULATOR COMMANDS
1573
1574 int CmdHF14AMfEGet(const char *Cmd)
1575 {
1576 uint8_t blockNo = 0;
1577 uint8_t data[16] = {0x00};
1578
1579 if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {
1580 PrintAndLog("Usage: hf mf eget <block number>");
1581 PrintAndLog(" sample: hf mf eget 0 ");
1582 return 0;
1583 }
1584
1585 blockNo = param_get8(Cmd, 0);
1586
1587 PrintAndLog(" ");
1588 if (!mfEmlGetMem(data, blockNo, 1)) {
1589 PrintAndLog("data[%3d]:%s", blockNo, sprint_hex(data, 16));
1590 } else {
1591 PrintAndLog("Command execute timeout");
1592 }
1593
1594 return 0;
1595 }
1596
1597 int CmdHF14AMfEClear(const char *Cmd)
1598 {
1599 if (param_getchar(Cmd, 0) == 'h') {
1600 PrintAndLog("Usage: hf mf eclr");
1601 PrintAndLog("It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF \n");
1602 return 0;
1603 }
1604
1605 UsbCommand c = {CMD_MIFARE_EML_MEMCLR, {0, 0, 0}};
1606 SendCommand(&c);
1607 return 0;
1608 }
1609
1610 int CmdHF14AMfESet(const char *Cmd)
1611 {
1612 uint8_t memBlock[16];
1613 uint8_t blockNo = 0;
1614
1615 memset(memBlock, 0x00, sizeof(memBlock));
1616
1617 if (strlen(Cmd) < 3 || param_getchar(Cmd, 0) == 'h') {
1618 PrintAndLog("Usage: hf mf eset <block number> <block data (32 hex symbols)>");
1619 PrintAndLog(" sample: hf mf eset 1 000102030405060708090a0b0c0d0e0f ");
1620 return 0;
1621 }
1622
1623 blockNo = param_get8(Cmd, 0);
1624
1625 if (param_gethex(Cmd, 1, memBlock, 32)) {
1626 PrintAndLog("block data must include 32 HEX symbols");
1627 return 1;
1628 }
1629
1630 // 1 - blocks count
1631 UsbCommand c = {CMD_MIFARE_EML_MEMSET, {blockNo, 1, 0}};
1632 memcpy(c.d.asBytes, memBlock, 16);
1633 SendCommand(&c);
1634 return 0;
1635 }
1636
1637 int CmdHF14AMfELoad(const char *Cmd)
1638 {
1639 FILE * f;
1640 char filename[FILE_PATH_SIZE];
1641 char *fnameptr = filename;
1642 char buf[64] = {0x00};
1643 uint8_t buf8[64] = {0x00};
1644 int i, len, blockNum, numBlocks;
1645 int nameParamNo = 1;
1646 uint8_t blockWidth = 32;
1647 char ctmp = param_getchar(Cmd, 0);
1648
1649 if ( ctmp == 'h' || ctmp == 'H' || ctmp == 0x00) {
1650 PrintAndLog("It loads emul dump from the file `filename.eml`");
1651 PrintAndLog("Usage: hf mf eload [card memory] <file name w/o `.eml`> [numblocks]");
1652 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K, u = UL");
1653 PrintAndLog("");
1654 PrintAndLog(" sample: hf mf eload filename");
1655 PrintAndLog(" hf mf eload 4 filename");
1656 return 0;
1657 }
1658
1659 switch (ctmp) {
1660 case '0' : numBlocks = 5*4; break;
1661 case '1' :
1662 case '\0': numBlocks = 16*4; break;
1663 case '2' : numBlocks = 32*4; break;
1664 case '4' : numBlocks = 256; break;
1665 case 'U' : // fall through
1666 case 'u' : numBlocks = 255; blockWidth = 8; break;
1667 default: {
1668 numBlocks = 16*4;
1669 nameParamNo = 0;
1670 }
1671 }
1672 uint32_t numblk2 = param_get32ex(Cmd,2,0,10);
1673 if (numblk2 > 0) numBlocks = numblk2;
1674
1675 len = param_getstr(Cmd,nameParamNo,filename);
1676
1677 if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;
1678
1679 fnameptr += len;
1680
1681 sprintf(fnameptr, ".eml");
1682
1683 // open file
1684 f = fopen(filename, "r");
1685 if (f == NULL) {
1686 PrintAndLog("File %s not found or locked", filename);
1687 return 1;
1688 }
1689
1690 blockNum = 0;
1691 while(!feof(f)){
1692 memset(buf, 0, sizeof(buf));
1693
1694 if (fgets(buf, sizeof(buf), f) == NULL) {
1695
1696 if (blockNum >= numBlocks) break;
1697
1698 PrintAndLog("File reading error.");
1699 fclose(f);
1700 return 2;
1701 }
1702
1703 if (strlen(buf) < blockWidth){
1704 if(strlen(buf) && feof(f))
1705 break;
1706 PrintAndLog("File content error. Block data must include %d HEX symbols", blockWidth);
1707 fclose(f);
1708 return 2;
1709 }
1710
1711 for (i = 0; i < blockWidth; i += 2) {
1712 sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);
1713 }
1714 if (mfEmlSetMem_xt(buf8, blockNum, 1, blockWidth/2)) {
1715 PrintAndLog("Cant set emul block: %3d", blockNum);
1716 fclose(f);
1717 return 3;
1718 }
1719 printf(".");
1720 blockNum++;
1721
1722 if (blockNum >= numBlocks) break;
1723 }
1724 fclose(f);
1725 printf("\n");
1726
1727 if ((blockNum != numBlocks)) {
1728 PrintAndLog("File content error. Got %d must be %d blocks.",blockNum, numBlocks);
1729 return 4;
1730 }
1731 PrintAndLog("Loaded %d blocks from file: %s", blockNum, filename);
1732 return 0;
1733 }
1734
1735 int CmdHF14AMfESave(const char *Cmd)
1736 {
1737 FILE * f;
1738 char filename[FILE_PATH_SIZE];
1739 char * fnameptr = filename;
1740 uint8_t buf[64];
1741 int i, j, len, numBlocks;
1742 int nameParamNo = 1;
1743
1744 memset(filename, 0, sizeof(filename));
1745 memset(buf, 0, sizeof(buf));
1746
1747 char ctmp = param_getchar(Cmd, 0);
1748
1749 if ( ctmp == 'h' || ctmp == 'H') {
1750 PrintAndLog("It saves emul dump into the file `filename.eml` or `cardID.eml`");
1751 PrintAndLog(" Usage: hf mf esave [card memory] [file name w/o `.eml`]");
1752 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
1753 PrintAndLog("");
1754 PrintAndLog(" sample: hf mf esave ");
1755 PrintAndLog(" hf mf esave 4");
1756 PrintAndLog(" hf mf esave 4 filename");
1757 return 0;
1758 }
1759
1760 switch (ctmp) {
1761 case '0' : numBlocks = 5*4; break;
1762 case '1' :
1763 case '\0': numBlocks = 16*4; break;
1764 case '2' : numBlocks = 32*4; break;
1765 case '4' : numBlocks = 256; break;
1766 default: {
1767 numBlocks = 16*4;
1768 nameParamNo = 0;
1769 }
1770 }
1771
1772 len = param_getstr(Cmd,nameParamNo,filename);
1773
1774 if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;
1775
1776 // user supplied filename?
1777 if (len < 1) {
1778 // get filename (UID from memory)
1779 if (mfEmlGetMem(buf, 0, 1)) {
1780 PrintAndLog("Can\'t get UID from block: %d", 0);
1781 len = sprintf(fnameptr, "dump");
1782 fnameptr += len;
1783 }
1784 else {
1785 for (j = 0; j < 7; j++, fnameptr += 2)
1786 sprintf(fnameptr, "%02X", buf[j]);
1787 }
1788 } else {
1789 fnameptr += len;
1790 }
1791
1792 // add file extension
1793 sprintf(fnameptr, ".eml");
1794
1795 // open file
1796 f = fopen(filename, "w+");
1797
1798 if ( !f ) {
1799 PrintAndLog("Can't open file %s ", filename);
1800 return 1;
1801 }
1802
1803 // put hex
1804 for (i = 0; i < numBlocks; i++) {
1805 if (mfEmlGetMem(buf, i, 1)) {
1806 PrintAndLog("Cant get block: %d", i);
1807 break;
1808 }
1809 for (j = 0; j < 16; j++)
1810 fprintf(f, "%02X", buf[j]);
1811 fprintf(f,"\n");
1812 }
1813 fclose(f);
1814
1815 PrintAndLog("Saved %d blocks to file: %s", numBlocks, filename);
1816
1817 return 0;
1818 }
1819
1820 int CmdHF14AMfECFill(const char *Cmd)
1821 {
1822 uint8_t keyType = 0;
1823 uint8_t numSectors = 16;
1824
1825 if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {
1826 PrintAndLog("Usage: hf mf ecfill <key A/B> [card memory]");
1827 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
1828 PrintAndLog("");
1829 PrintAndLog("samples: hf mf ecfill A");
1830 PrintAndLog(" hf mf ecfill A 4");
1831 PrintAndLog("Read card and transfer its data to emulator memory.");
1832 PrintAndLog("Keys must be laid in the emulator memory. \n");
1833 return 0;
1834 }
1835
1836 char ctmp = param_getchar(Cmd, 0);
1837 if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {
1838 PrintAndLog("Key type must be A or B");
1839 return 1;
1840 }
1841 if (ctmp != 'A' && ctmp != 'a') keyType = 1;
1842
1843 ctmp = param_getchar(Cmd, 1);
1844 switch (ctmp) {
1845 case '0' : numSectors = 5; break;
1846 case '1' :
1847 case '\0': numSectors = 16; break;
1848 case '2' : numSectors = 32; break;
1849 case '4' : numSectors = 40; break;
1850 default: numSectors = 16;
1851 }
1852
1853 printf("--params: numSectors: %d, keyType:%d", numSectors, keyType);
1854 UsbCommand c = {CMD_MIFARE_EML_CARDLOAD, {numSectors, keyType, 0}};
1855 SendCommand(&c);
1856 return 0;
1857 }
1858
1859 int CmdHF14AMfEKeyPrn(const char *Cmd)
1860 {
1861 int i;
1862 uint8_t numSectors;
1863 uint8_t data[16];
1864 uint64_t keyA, keyB;
1865
1866 char cmdp = param_getchar(Cmd, 0);
1867
1868 if ( cmdp == 'h' || cmdp == 'H' ) {
1869 PrintAndLog("It prints the keys loaded in the emulator memory");
1870 PrintAndLog("Usage: hf mf ekeyprn [card memory]");
1871 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
1872 PrintAndLog("");
1873 PrintAndLog(" sample: hf mf ekeyprn 1");
1874 return 0;
1875 }
1876
1877 switch (cmdp) {
1878 case '0' : numSectors = 5; break;
1879 case '1' :
1880 case '\0': numSectors = 16; break;
1881 case '2' : numSectors = 32; break;
1882 case '4' : numSectors = 40; break;
1883 default: numSectors = 16;
1884 }
1885
1886 PrintAndLog("|---|----------------|----------------|");
1887 PrintAndLog("|sec|key A |key B |");
1888 PrintAndLog("|---|----------------|----------------|");
1889 for (i = 0; i < numSectors; i++) {
1890 if (mfEmlGetMem(data, FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1, 1)) {
1891 PrintAndLog("error get block %d", FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1);
1892 break;
1893 }
1894 keyA = bytes_to_num(data, 6);
1895 keyB = bytes_to_num(data + 10, 6);
1896 PrintAndLog("|%03d| %012"llx" | %012"llx" |", i, keyA, keyB);
1897 }
1898 PrintAndLog("|---|----------------|----------------|");
1899
1900 return 0;
1901 }
1902
1903 // CHINESE MAGIC COMMANDS
1904
1905 int CmdHF14AMfCSetUID(const char *Cmd) {
1906 uint8_t wipeCard = 0;
1907 uint8_t uid[8] = {0x00};
1908 uint8_t oldUid[8] = {0x00};
1909 uint8_t atqa[2] = {0x00};
1910 uint8_t sak[1] = {0x00};
1911 uint8_t atqaPresent = 1;
1912 int res;
1913 char ctmp;
1914 int argi=0;
1915
1916 if (strlen(Cmd) < 1 || param_getchar(Cmd, argi) == 'h') {
1917 PrintAndLog("Set UID, ATQA, and SAK for magic Chinese card (only works with such cards)");
1918 PrintAndLog("If you also want to wipe the card then add 'w' at the end of the command line.");
1919 PrintAndLog("");
1920 PrintAndLog("Usage: hf mf csetuid <UID 8 hex symbols> [ATQA 4 hex symbols SAK 2 hex symbols] [w]");
1921 PrintAndLog("");
1922 PrintAndLog("sample: hf mf csetuid 01020304");
1923 PrintAndLog(" hf mf csetuid 01020304 0004 08 w");
1924 return 0;
1925 }
1926
1927 if (param_getchar(Cmd, argi) && param_gethex(Cmd, argi, uid, 8)) {
1928 PrintAndLog("UID must include 8 HEX symbols");
1929 return 1;
1930 }
1931 argi++;
1932
1933 ctmp = param_getchar(Cmd, argi);
1934 if (ctmp == 'w' || ctmp == 'W') {
1935 wipeCard = 1;
1936 atqaPresent = 0;
1937 }
1938
1939 if (atqaPresent) {
1940 if (param_getchar(Cmd, argi)) {
1941 if (param_gethex(Cmd, argi, atqa, 4)) {
1942 PrintAndLog("ATQA must include 4 HEX symbols");
1943 return 1;
1944 }
1945 argi++;
1946 if (!param_getchar(Cmd, argi) || param_gethex(Cmd, argi, sak, 2)) {
1947 PrintAndLog("SAK must include 2 HEX symbols");
1948 return 1;
1949 }
1950 argi++;
1951 } else
1952 atqaPresent = 0;
1953 }
1954
1955 if(!wipeCard) {
1956 ctmp = param_getchar(Cmd, argi);
1957 if (ctmp == 'w' || ctmp == 'W') {
1958 wipeCard = 1;
1959 }
1960 }
1961
1962 PrintAndLog("--wipe card:%s uid:%s", (wipeCard)?"YES":"NO", sprint_hex(uid, 4));
1963
1964 res = mfCSetUID(uid, (atqaPresent) ? atqa : NULL, (atqaPresent) ? sak : NULL, oldUid, wipeCard);
1965 if (res) {
1966 PrintAndLog("Can't set UID. error=%d", res);
1967 return 1;
1968 }
1969
1970 PrintAndLog("old UID:%s", sprint_hex(oldUid, 4));
1971 PrintAndLog("new UID:%s", sprint_hex(uid, 4));
1972 return 0;
1973 }
1974
1975 int CmdHF14AMfCSetBlk(const char *Cmd) {
1976 uint8_t block[16] = {0x00};
1977 uint8_t blockNo = 0;
1978 uint8_t params = MAGIC_SINGLE;
1979 int res;
1980
1981 if (strlen(Cmd) < 1 || param_getchar(Cmd, 0) == 'h') {
1982 PrintAndLog("Usage: hf mf csetblk <block number> <block data (32 hex symbols)> [w]");
1983 PrintAndLog("sample: hf mf csetblk 1 01020304050607080910111213141516");
1984 PrintAndLog("Set block data for magic Chinese card (only works with such cards)");
1985 PrintAndLog("If you also want wipe the card then add 'w' at the end of the command line");
1986 return 0;
1987 }
1988
1989 blockNo = param_get8(Cmd, 0);
1990
1991 if (param_gethex(Cmd, 1, block, 32)) {
1992 PrintAndLog("block data must include 32 HEX symbols");
1993 return 1;
1994 }
1995
1996 char ctmp = param_getchar(Cmd, 2);
1997 if (ctmp == 'w' || ctmp == 'W')
1998 params |= MAGIC_WIPE;
1999
2000 PrintAndLog("--block number:%2d data:%s", blockNo, sprint_hex(block, 16));
2001
2002 res = mfCSetBlock(blockNo, block, NULL, params);
2003 if (res) {
2004 PrintAndLog("Can't write block. error=%d", res);
2005 return 1;
2006 }
2007 return 0;
2008 }
2009
2010 int CmdHF14AMfCLoad(const char *Cmd) {
2011 FILE * f;
2012 char filename[FILE_PATH_SIZE];
2013 char * fnameptr = filename;
2014 char buf[64] = {0x00};
2015 uint8_t buf8[64] = {0x00};
2016 uint8_t fillFromEmulator = 0;
2017 int i, len, blockNum, flags=0;
2018
2019 memset(filename, 0, sizeof(filename));
2020
2021 char ctmp = param_getchar(Cmd, 0);
2022
2023 if (ctmp == 'h' || ctmp == 'H' || ctmp == 0x00) {
2024 PrintAndLog("It loads magic Chinese card from the file `filename.eml`");
2025 PrintAndLog("or from emulator memory (option `e`)");
2026 PrintAndLog("Usage: hf mf cload <file name w/o `.eml`>");
2027 PrintAndLog(" or: hf mf cload e ");
2028 PrintAndLog(" sample: hf mf cload filename");
2029 return 0;
2030 }
2031
2032 if (ctmp == 'e' || ctmp == 'E') fillFromEmulator = 1;
2033
2034 if (fillFromEmulator) {
2035 for (blockNum = 0; blockNum < 16 * 4; blockNum += 1) {
2036 if (mfEmlGetMem(buf8, blockNum, 1)) {
2037 PrintAndLog("Cant get block: %d", blockNum);
2038 return 2;
2039 }
2040 if (blockNum == 0) flags = MAGIC_INIT + MAGIC_WUPC; // switch on field and send magic sequence
2041 if (blockNum == 1) flags = 0; // just write
2042 if (blockNum == 16 * 4 - 1) flags = MAGIC_HALT + MAGIC_OFF; // Done. Magic Halt and switch off field.
2043
2044 if (mfCSetBlock(blockNum, buf8, NULL, flags)) {
2045 PrintAndLog("Cant set magic card block: %d", blockNum);
2046 return 3;
2047 }
2048 }
2049 return 0;
2050 } else {
2051 len = strlen(Cmd);
2052 if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;
2053
2054 memcpy(filename, Cmd, len);
2055 fnameptr += len;
2056
2057 sprintf(fnameptr, ".eml");
2058
2059 // open file
2060 f = fopen(filename, "r");
2061 if (f == NULL) {
2062 PrintAndLog("File not found or locked.");
2063 return 1;
2064 }
2065
2066 blockNum = 0;
2067 while(!feof(f)){
2068
2069 memset(buf, 0, sizeof(buf));
2070
2071 if (fgets(buf, sizeof(buf), f) == NULL) {
2072 fclose(f);
2073 PrintAndLog("File reading error.");
2074 return 2;
2075 }
2076
2077 if (strlen(buf) < 32) {
2078 if(strlen(buf) && feof(f))
2079 break;
2080 PrintAndLog("File content error. Block data must include 32 HEX symbols");
2081 fclose(f);
2082 return 2;
2083 }
2084 for (i = 0; i < 32; i += 2)
2085 sscanf(&buf[i], "%02x", (unsigned int *)&buf8[i / 2]);
2086
2087 if (blockNum == 0) flags = MAGIC_INIT + MAGIC_WUPC; // switch on field and send magic sequence
2088 if (blockNum == 1) flags = 0; // just write
2089 if (blockNum == 16 * 4 - 1) flags = MAGIC_HALT + MAGIC_OFF; // Done. Switch off field.
2090
2091 if (mfCSetBlock(blockNum, buf8, NULL, flags)) {
2092 PrintAndLog("Can't set magic card block: %d", blockNum);
2093 fclose(f);
2094 return 3;
2095 }
2096 blockNum++;
2097
2098 if (blockNum >= 16 * 4) break; // magic card type - mifare 1K
2099 }
2100 fclose(f);
2101
2102 // 64 or 256blocks.
2103 if (blockNum != 16 * 4 && blockNum != 32 * 4 + 8 * 16){
2104 PrintAndLog("File content error. There must be 64 blocks");
2105 return 4;
2106 }
2107 PrintAndLog("Loaded from file: %s", filename);
2108 return 0;
2109 }
2110 return 0;
2111 }
2112
2113 int CmdHF14AMfCGetBlk(const char *Cmd) {
2114 uint8_t data[16];
2115 uint8_t blockNo = 0;
2116 int res;
2117 memset(data, 0x00, sizeof(data));
2118 char ctmp = param_getchar(Cmd, 0);
2119
2120 if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') {
2121 PrintAndLog("Usage: hf mf cgetblk <block number>");
2122 PrintAndLog("sample: hf mf cgetblk 1");
2123 PrintAndLog("Get block data from magic Chinese card (only works with such cards)\n");
2124 return 0;
2125 }
2126
2127 blockNo = param_get8(Cmd, 0);
2128
2129 PrintAndLog("--block number:%2d ", blockNo);
2130
2131 res = mfCGetBlock(blockNo, data, MAGIC_SINGLE);
2132 if (res) {
2133 PrintAndLog("Can't read block. error=%d", res);
2134 return 1;
2135 }
2136
2137 PrintAndLog("data: %s", sprint_hex(data, sizeof(data)));
2138 return 0;
2139 }
2140
2141 int CmdHF14AMfCGetSc(const char *Cmd) {
2142 uint8_t data[16];
2143 uint8_t sectorNo = 0;
2144 int i, res, flags;
2145 memset(data, 0x00, sizeof(data));
2146 char ctmp = param_getchar(Cmd, 0);
2147
2148 if (strlen(Cmd) < 1 || ctmp == 'h' || ctmp == 'H') {
2149 PrintAndLog("Usage: hf mf cgetsc <sector number>");
2150 PrintAndLog("sample: hf mf cgetsc 0");
2151 PrintAndLog("Get sector data from magic Chinese card (only works with such cards)\n");
2152 return 0;
2153 }
2154
2155 sectorNo = param_get8(Cmd, 0);
2156 if (sectorNo > 15) {
2157 PrintAndLog("Sector number must be in [0..15] as in MIFARE classic.");
2158 return 1;
2159 }
2160
2161 PrintAndLog("--sector number:%d ", sectorNo);
2162 PrintAndLog("block | data");
2163
2164 flags = MAGIC_INIT + MAGIC_WUPC;
2165 for (i = 0; i < 4; i++) {
2166 if (i == 1) flags = 0;
2167 if (i == 3) flags = MAGIC_HALT + MAGIC_OFF;
2168
2169 res = mfCGetBlock(sectorNo * 4 + i, data, flags);
2170 if (res) {
2171 PrintAndLog("Can't read block. %d error=%d", sectorNo * 4 + i, res);
2172 return 1;
2173 }
2174 PrintAndLog(" %3d | %s", sectorNo * 4 + i, sprint_hex(data, sizeof(data)));
2175 }
2176 return 0;
2177 }
2178
2179 int CmdHF14AMfCSave(const char *Cmd) {
2180
2181 FILE * f;
2182 char filename[FILE_PATH_SIZE];
2183 char * fnameptr = filename;
2184 uint8_t fillFromEmulator = 0;
2185 uint8_t buf[64];
2186 int i, j, len, flags;
2187
2188 memset(filename, 0, sizeof(filename));
2189 memset(buf, 0, sizeof(buf));
2190 char ctmp = param_getchar(Cmd, 0);
2191
2192 if ( ctmp == 'h' || ctmp == 'H' ) {
2193 PrintAndLog("It saves `magic Chinese` card dump into the file `filename.eml` or `cardID.eml`");
2194 PrintAndLog("or into emulator memory (option `e`)");
2195 PrintAndLog("Usage: hf mf esave [file name w/o `.eml`][e]");
2196 PrintAndLog(" sample: hf mf esave ");
2197 PrintAndLog(" hf mf esave filename");
2198 PrintAndLog(" hf mf esave e \n");
2199 return 0;
2200 }
2201 if (ctmp == 'e' || ctmp == 'E') fillFromEmulator = 1;
2202
2203 if (fillFromEmulator) {
2204 // put into emulator
2205 flags = MAGIC_INIT + MAGIC_WUPC;
2206 for (i = 0; i < 16 * 4; i++) {
2207 if (i == 1) flags = 0;
2208 if (i == 16 * 4 - 1) flags = MAGIC_HALT + MAGIC_OFF;
2209
2210 if (mfCGetBlock(i, buf, flags)) {
2211 PrintAndLog("Cant get block: %d", i);
2212 break;
2213 }
2214
2215 if (mfEmlSetMem(buf, i, 1)) {
2216 PrintAndLog("Cant set emul block: %d", i);
2217 return 3;
2218 }
2219 }
2220 return 0;
2221 } else {
2222 len = strlen(Cmd);
2223 if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;
2224
2225 // get filename based on UID
2226 if (len < 1) {
2227
2228 if (mfCGetBlock(0, buf, MAGIC_SINGLE)) {
2229 PrintAndLog("Cant get block: %d", 0);
2230 len = sprintf(fnameptr, "dump");
2231 fnameptr += len;
2232 } else {
2233 for (j = 0; j < 7; j++, fnameptr += 2)
2234 sprintf(fnameptr, "%02x", buf[j]);
2235 }
2236 } else {
2237 memcpy(filename, Cmd, len);
2238 fnameptr += len;
2239 }
2240
2241 // add .eml extension
2242 sprintf(fnameptr, ".eml");
2243
2244 // open file
2245 f = fopen(filename, "w+");
2246
2247 if (f == NULL) {
2248 PrintAndLog("File not found or locked.");
2249 return 1;
2250 }
2251
2252 // put hex
2253 flags = MAGIC_INIT + MAGIC_WUPC;
2254 for (i = 0; i < 16 * 4; i++) {
2255 if (i == 1) flags = 0;
2256 if (i == 16 * 4 - 1) flags = MAGIC_HALT + MAGIC_OFF;
2257
2258 if (mfCGetBlock(i, buf, flags)) {
2259 PrintAndLog("Cant get block: %d", i);
2260 break;
2261 }
2262 for (j = 0; j < 16; j++)
2263 fprintf(f, "%02x", buf[j]);
2264 fprintf(f,"\n");
2265 }
2266 fflush(f);
2267 fclose(f);
2268 PrintAndLog("Saved to file: %s", filename);
2269 return 0;
2270 }
2271 }
2272
2273 //needs nt, ar, at, Data to decrypt
2274 int CmdHf14MfDecryptBytes(const char *Cmd){
2275 uint8_t data[50];
2276 uint32_t nt = param_get32ex(Cmd,0,0,16);
2277 uint32_t ar_enc = param_get32ex(Cmd,1,0,16);
2278 uint32_t at_enc = param_get32ex(Cmd,2,0,16);
2279
2280 int len = 0;
2281 param_gethex_ex(Cmd, 3, data, &len);
2282
2283 len /= 2;
2284 int limit = sizeof(data) / 2;
2285
2286 if ( len >= limit )
2287 len = limit;
2288
2289 return tryDecryptWord( nt, ar_enc, at_enc, data, len);
2290 }
2291
2292 static command_t CommandTable[] = {
2293 {"help", CmdHelp, 1, "This help"},
2294 {"dbg", CmdHF14AMfDbg, 0, "Set default debug mode"},
2295 {"rdbl", CmdHF14AMfRdBl, 0, "Read MIFARE classic block"},
2296 {"rdsc", CmdHF14AMfRdSc, 0, "Read MIFARE classic sector"},
2297 {"dump", CmdHF14AMfDump, 0, "Dump MIFARE classic tag to binary file"},
2298 {"restore", CmdHF14AMfRestore, 0, "Restore MIFARE classic binary file to BLANK tag"},
2299 {"wrbl", CmdHF14AMfWrBl, 0, "Write MIFARE classic block"},
2300 {"chk", CmdHF14AMfChk, 0, "Test block keys"},
2301 {"mifare", CmdHF14AMifare, 0, "Read parity error messages."},
2302 {"nested", CmdHF14AMfNested, 0, "Test nested authentication"},
2303 {"hardnested", CmdHF14AMfNestedHard, 0, "Nested attack for hardened Mifare cards"},
2304 {"sniff", CmdHF14AMfSniff, 0, "Sniff card-reader communication"},
2305 {"sim", CmdHF14AMf1kSim, 0, "Simulate MIFARE card"},
2306 {"eclr", CmdHF14AMfEClear, 0, "Clear simulator memory block"},
2307 {"eget", CmdHF14AMfEGet, 0, "Get simulator memory block"},
2308 {"eset", CmdHF14AMfESet, 0, "Set simulator memory block"},
2309 {"eload", CmdHF14AMfELoad, 0, "Load from file emul dump"},
2310 {"esave", CmdHF14AMfESave, 0, "Save to file emul dump"},
2311 {"ecfill", CmdHF14AMfECFill, 0, "Fill simulator memory with help of keys from simulator"},
2312 {"ekeyprn", CmdHF14AMfEKeyPrn, 0, "Print keys from simulator memory"},
2313 {"csetuid", CmdHF14AMfCSetUID, 0, "Set UID for magic Chinese card"},
2314 {"csetblk", CmdHF14AMfCSetBlk, 0, "Write block - Magic Chinese card"},
2315 {"cgetblk", CmdHF14AMfCGetBlk, 0, "Read block - Magic Chinese card"},
2316 {"cgetsc", CmdHF14AMfCGetSc, 0, "Read sector - Magic Chinese card"},
2317 {"cload", CmdHF14AMfCLoad, 0, "Load dump into magic Chinese card"},
2318 {"csave", CmdHF14AMfCSave, 0, "Save dump from magic Chinese card into file or emulator"},
2319 {"decrypt", CmdHf14MfDecryptBytes, 1, "[nt] [ar_enc] [at_enc] [data] - to decrypt snoop or trace"},
2320 {NULL, NULL, 0, NULL}
2321 };
2322
2323 int CmdHFMF(const char *Cmd) {
2324 clearCommandBuffer();
2325 CmdsParse(CommandTable, Cmd);
2326 return 0;
2327 }
2328
2329 int CmdHelp(const char *Cmd) {
2330 CmdsHelp(CommandTable);
2331 return 0;
2332 }
Impressum, Datenschutz