]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhfmf.c
1d1dc2f433456a197f06e28010877308d14e3caa
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2011,2012 Merlok
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
7 //-----------------------------------------------------------------------------
8 // High frequency MIFARE commands
9 //-----------------------------------------------------------------------------
12 #include "nonce2key/nonce2key.h"
14 static int CmdHelp(const char *Cmd
);
16 int CmdHF14AMifare(const char *Cmd
)
19 uint32_t nt
= 0, nr
= 0;
20 uint64_t par_list
= 0, ks_list
= 0, r_key
= 0;
23 UsbCommand c
= {CMD_READER_MIFARE
, {true, 0, 0}};
26 printf("-------------------------------------------------------------------------\n");
27 printf("Executing command. Expected execution time: 25sec on average :-)\n");
28 printf("Press button on the proxmark3 device to abort both proxmark3 and client.\n");
29 printf("-------------------------------------------------------------------------\n");
37 while (ukbhit()) getchar();
45 printf("\naborted via keyboard!\n");
50 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
52 uid
= (uint32_t)bytes_to_num(resp
.d
.asBytes
+ 0, 4);
53 nt
= (uint32_t)bytes_to_num(resp
.d
.asBytes
+ 4, 4);
54 par_list
= bytes_to_num(resp
.d
.asBytes
+ 8, 8);
55 ks_list
= bytes_to_num(resp
.d
.asBytes
+ 16, 8);
56 nr
= bytes_to_num(resp
.d
.asBytes
+ 24, 4);
59 case -1 : PrintAndLog("Button pressed. Aborted.\n"); break;
60 case -2 : PrintAndLog("Card is not vulnerable to Darkside attack (doesn't send NACK on authentication requests).\n"); break;
61 case -3 : PrintAndLog("Card is not vulnerable to Darkside attack (its random number generator is not predictable).\n"); break;
62 case -4 : PrintAndLog("Card is not vulnerable to Darkside attack (its random number generator seems to be based on the wellknown");
63 PrintAndLog("generating polynomial with 16 effective bits only, but shows unexpected behaviour.\n"); break;
73 if (isOK
!= 1) return 1;
75 // execute original function from util nonce2key
76 if (nonce2key(uid
, nt
, nr
, par_list
, ks_list
, &r_key
)) {
78 PrintAndLog("Key not found (lfsr_common_prefix list is null). Nt=%08x", nt
);
79 PrintAndLog("Failing is expected to happen in 25%% of all cases. Trying again with a different reader nonce...");
84 printf("------------------------------------------------------------------\n");
85 PrintAndLog("Found valid key: %012"llx
" \n", r_key
);
92 int CmdHF14AMfWrBl(const char *Cmd
)
96 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
97 uint8_t bldata
[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
102 PrintAndLog("Usage: hf mf wrbl <block number> <key A/B> <key (12 hex symbols)> <block data (32 hex symbols)>");
103 PrintAndLog(" sample: hf mf wrbl 0 A FFFFFFFFFFFF 000102030405060708090A0B0C0D0E0F");
107 blockNo
= param_get8(Cmd
, 0);
108 cmdp
= param_getchar(Cmd
, 1);
110 PrintAndLog("Key type must be A or B");
113 if (cmdp
!= 'A' && cmdp
!= 'a') keyType
= 1;
114 if (param_gethex(Cmd
, 2, key
, 12)) {
115 PrintAndLog("Key must include 12 HEX symbols");
118 if (param_gethex(Cmd
, 3, bldata
, 32)) {
119 PrintAndLog("Block data must include 32 HEX symbols");
122 PrintAndLog("--block no:%d, key type:%c, key:%s", blockNo
, keyType
?'B':'A', sprint_hex(key
, 6));
123 PrintAndLog("--data: %s", sprint_hex(bldata
, 16));
125 UsbCommand c
= {CMD_MIFARE_WRITEBL
, {blockNo
, keyType
, 0}};
126 memcpy(c
.d
.asBytes
, key
, 6);
127 memcpy(c
.d
.asBytes
+ 10, bldata
, 16);
128 clearCommandBuffer();
132 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
133 uint8_t isOK
= resp
.arg
[0] & 0xff;
134 PrintAndLog("isOk:%02x", isOK
);
136 PrintAndLog("Command execute timeout");
142 int CmdHF14AMfRdBl(const char *Cmd
)
146 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
152 PrintAndLog("Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>");
153 PrintAndLog(" sample: hf mf rdbl 0 A FFFFFFFFFFFF ");
157 blockNo
= param_get8(Cmd
, 0);
158 cmdp
= param_getchar(Cmd
, 1);
160 PrintAndLog("Key type must be A or B");
163 if (cmdp
!= 'A' && cmdp
!= 'a') keyType
= 1;
164 if (param_gethex(Cmd
, 2, key
, 12)) {
165 PrintAndLog("Key must include 12 HEX symbols");
168 PrintAndLog("--block no:%d, key type:%c, key:%s ", blockNo
, keyType
?'B':'A', sprint_hex(key
, 6));
170 UsbCommand c
= {CMD_MIFARE_READBL
, {blockNo
, keyType
, 0}};
171 memcpy(c
.d
.asBytes
, key
, 6);
172 clearCommandBuffer();
176 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
177 uint8_t isOK
= resp
.arg
[0] & 0xff;
178 uint8_t *data
= resp
.d
.asBytes
;
181 PrintAndLog("isOk:%02x data:%s", isOK
, sprint_hex(data
, 16));
183 PrintAndLog("isOk:%02x", isOK
);
185 PrintAndLog("Command execute timeout");
191 int CmdHF14AMfRdSc(const char *Cmd
)
194 uint8_t sectorNo
= 0;
196 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
198 uint8_t *data
= NULL
;
202 PrintAndLog("Usage: hf mf rdsc <sector number> <key A/B> <key (12 hex symbols)>");
203 PrintAndLog(" sample: hf mf rdsc 0 A FFFFFFFFFFFF ");
207 sectorNo
= param_get8(Cmd
, 0);
209 PrintAndLog("Sector number must be less than 40");
212 cmdp
= param_getchar(Cmd
, 1);
213 if (cmdp
!= 'a' && cmdp
!= 'A' && cmdp
!= 'b' && cmdp
!= 'B') {
214 PrintAndLog("Key type must be A or B");
217 if (cmdp
!= 'A' && cmdp
!= 'a') keyType
= 1;
218 if (param_gethex(Cmd
, 2, key
, 12)) {
219 PrintAndLog("Key must include 12 HEX symbols");
222 PrintAndLog("--sector no:%d key type:%c key:%s ", sectorNo
, keyType
?'B':'A', sprint_hex(key
, 6));
224 UsbCommand c
= {CMD_MIFARE_READSC
, {sectorNo
, keyType
, 0}};
225 memcpy(c
.d
.asBytes
, key
, 6);
226 clearCommandBuffer();
231 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
232 isOK
= resp
.arg
[0] & 0xff;
233 data
= resp
.d
.asBytes
;
235 PrintAndLog("isOk:%02x", isOK
);
237 for (i
= 0; i
< (sectorNo
<32?3:15); i
++) {
238 PrintAndLog("data : %s", sprint_hex(data
+ i
* 16, 16));
240 PrintAndLog("trailer: %s", sprint_hex(data
+ (sectorNo
<32?3:15) * 16, 16));
243 PrintAndLog("Command execute timeout");
249 uint8_t FirstBlockOfSector(uint8_t sectorNo
)
254 return 32 * 4 + (sectorNo
- 32) * 16;
258 uint8_t NumBlocksPerSector(uint8_t sectorNo
)
267 int CmdHF14AMfDump(const char *Cmd
)
269 uint8_t sectorNo
, blockNo
;
273 uint8_t rights
[40][4];
274 uint8_t carddata
[256][16];
275 uint8_t numSectors
= 16;
282 char cmdp
= param_getchar(Cmd
, 0);
284 case '0' : numSectors
= 5; break;
286 case '\0': numSectors
= 16; break;
287 case '2' : numSectors
= 32; break;
288 case '4' : numSectors
= 40; break;
289 default: numSectors
= 16;
292 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
293 PrintAndLog("Usage: hf mf dump [card memory]");
294 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
296 PrintAndLog("Samples: hf mf dump");
297 PrintAndLog(" hf mf dump 4");
301 if ((fin
= fopen("dumpkeys.bin","rb")) == NULL
) {
302 PrintAndLog("Could not find file dumpkeys.bin");
306 // Read keys A from file
307 for (sectorNo
=0; sectorNo
<numSectors
; sectorNo
++) {
308 if (fread( keyA
[sectorNo
], 1, 6, fin
) == 0) {
309 PrintAndLog("File reading error.");
315 // Read keys B from file
316 for (sectorNo
=0; sectorNo
<numSectors
; sectorNo
++) {
317 if (fread( keyB
[sectorNo
], 1, 6, fin
) == 0) {
318 PrintAndLog("File reading error.");
326 PrintAndLog("|-----------------------------------------|");
327 PrintAndLog("|------ Reading sector access bits...-----|");
328 PrintAndLog("|-----------------------------------------|");
330 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
331 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + NumBlocksPerSector(sectorNo
) - 1, 0, 0}};
332 memcpy(c
.d
.asBytes
, keyA
[sectorNo
], 6);
333 clearCommandBuffer();
336 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
337 uint8_t isOK
= resp
.arg
[0] & 0xff;
338 uint8_t *data
= resp
.d
.asBytes
;
340 rights
[sectorNo
][0] = ((data
[7] & 0x10)>>2) | ((data
[8] & 0x1)<<1) | ((data
[8] & 0x10)>>4); // C1C2C3 for data area 0
341 rights
[sectorNo
][1] = ((data
[7] & 0x20)>>3) | ((data
[8] & 0x2)<<0) | ((data
[8] & 0x20)>>5); // C1C2C3 for data area 1
342 rights
[sectorNo
][2] = ((data
[7] & 0x40)>>4) | ((data
[8] & 0x4)>>1) | ((data
[8] & 0x40)>>6); // C1C2C3 for data area 2
343 rights
[sectorNo
][3] = ((data
[7] & 0x80)>>5) | ((data
[8] & 0x8)>>2) | ((data
[8] & 0x80)>>7); // C1C2C3 for sector trailer
345 PrintAndLog("Could not get access rights for sector %2d. Trying with defaults...", sectorNo
);
346 rights
[sectorNo
][0] = rights
[sectorNo
][1] = rights
[sectorNo
][2] = 0x00;
347 rights
[sectorNo
][3] = 0x01;
350 PrintAndLog("Command execute timeout when trying to read access rights for sector %2d. Trying with defaults...", sectorNo
);
351 rights
[sectorNo
][0] = rights
[sectorNo
][1] = rights
[sectorNo
][2] = 0x00;
352 rights
[sectorNo
][3] = 0x01;
356 PrintAndLog("|-----------------------------------------|");
357 PrintAndLog("|----- Dumping all blocks to file... -----|");
358 PrintAndLog("|-----------------------------------------|");
361 for (sectorNo
= 0; isOK
&& sectorNo
< numSectors
; sectorNo
++) {
362 for (blockNo
= 0; isOK
&& blockNo
< NumBlocksPerSector(sectorNo
); blockNo
++) {
363 bool received
= false;
365 if (blockNo
== NumBlocksPerSector(sectorNo
) - 1) { // sector trailer. At least the Access Conditions can always be read with key A.
366 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, 0, 0}};
367 memcpy(c
.d
.asBytes
, keyA
[sectorNo
], 6);
368 clearCommandBuffer();
370 received
= WaitForResponseTimeout(CMD_ACK
,&resp
,1500);
371 } else { // data block. Check if it can be read with key A or key B
372 uint8_t data_area
= sectorNo
<32?blockNo
:blockNo
/5;
373 if ((rights
[sectorNo
][data_area
] == 0x03) || (rights
[sectorNo
][data_area
] == 0x05)) { // only key B would work
374 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, 1, 0}};
375 memcpy(c
.d
.asBytes
, keyB
[sectorNo
], 6);
377 received
= WaitForResponseTimeout(CMD_ACK
,&resp
,1500);
378 } else if (rights
[sectorNo
][data_area
] == 0x07) { // no key would work
380 PrintAndLog("Access rights do not allow reading of sector %2d block %3d", sectorNo
, blockNo
);
381 } else { // key A would work
382 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, 0, 0}};
383 memcpy(c
.d
.asBytes
, keyA
[sectorNo
], 6);
384 clearCommandBuffer();
386 received
= WaitForResponseTimeout(CMD_ACK
,&resp
,1500);
391 isOK
= resp
.arg
[0] & 0xff;
392 uint8_t *data
= resp
.d
.asBytes
;
393 if (blockNo
== NumBlocksPerSector(sectorNo
) - 1) { // sector trailer. Fill in the keys.
394 data
[0] = (keyA
[sectorNo
][0]);
395 data
[1] = (keyA
[sectorNo
][1]);
396 data
[2] = (keyA
[sectorNo
][2]);
397 data
[3] = (keyA
[sectorNo
][3]);
398 data
[4] = (keyA
[sectorNo
][4]);
399 data
[5] = (keyA
[sectorNo
][5]);
400 data
[10] = (keyB
[sectorNo
][0]);
401 data
[11] = (keyB
[sectorNo
][1]);
402 data
[12] = (keyB
[sectorNo
][2]);
403 data
[13] = (keyB
[sectorNo
][3]);
404 data
[14] = (keyB
[sectorNo
][4]);
405 data
[15] = (keyB
[sectorNo
][5]);
408 memcpy(carddata
[FirstBlockOfSector(sectorNo
) + blockNo
], data
, 16);
409 PrintAndLog("Successfully read block %2d of sector %2d.", blockNo
, sectorNo
);
411 PrintAndLog("Could not read block %2d of sector %2d", blockNo
, sectorNo
);
417 PrintAndLog("Command execute timeout when trying to read block %2d of sector %2d.", blockNo
, sectorNo
);
424 if ((fout
= fopen("dumpdata.bin","wb")) == NULL
) {
425 PrintAndLog("Could not create file name dumpdata.bin");
428 uint16_t numblocks
= FirstBlockOfSector(numSectors
- 1) + NumBlocksPerSector(numSectors
- 1);
429 fwrite(carddata
, 1, 16*numblocks
, fout
);
431 PrintAndLog("Dumped %d blocks (%d bytes) to file dumpdata.bin", numblocks
, 16*numblocks
);
437 int CmdHF14AMfRestore(const char *Cmd
)
439 uint8_t sectorNo
,blockNo
;
441 uint8_t key
[6] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
442 uint8_t bldata
[16] = {0x00};
450 char cmdp
= param_getchar(Cmd
, 0);
452 case '0' : numSectors
= 5; break;
454 case '\0': numSectors
= 16; break;
455 case '2' : numSectors
= 32; break;
456 case '4' : numSectors
= 40; break;
457 default: numSectors
= 16;
460 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
461 PrintAndLog("Usage: hf mf restore [card memory]");
462 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
464 PrintAndLog("Samples: hf mf restore");
465 PrintAndLog(" hf mf restore 4");
469 if ((fkeys
= fopen("dumpkeys.bin","rb")) == NULL
) {
470 PrintAndLog("Could not find file dumpkeys.bin");
474 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
475 if (fread(keyA
[sectorNo
], 1, 6, fkeys
) == 0) {
476 PrintAndLog("File reading error (dumpkeys.bin).");
482 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
483 if (fread(keyB
[sectorNo
], 1, 6, fkeys
) == 0) {
484 PrintAndLog("File reading error (dumpkeys.bin).");
492 if ((fdump
= fopen("dumpdata.bin","rb")) == NULL
) {
493 PrintAndLog("Could not find file dumpdata.bin");
496 PrintAndLog("Restoring dumpdata.bin to card");
498 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
499 for(blockNo
= 0; blockNo
< NumBlocksPerSector(sectorNo
); blockNo
++) {
500 UsbCommand c
= {CMD_MIFARE_WRITEBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, keyType
, 0}};
501 memcpy(c
.d
.asBytes
, key
, 6);
503 if (fread(bldata
, 1, 16, fdump
) == 0) {
504 PrintAndLog("File reading error (dumpdata.bin).");
509 if (blockNo
== NumBlocksPerSector(sectorNo
) - 1) { // sector trailer
510 bldata
[0] = (keyA
[sectorNo
][0]);
511 bldata
[1] = (keyA
[sectorNo
][1]);
512 bldata
[2] = (keyA
[sectorNo
][2]);
513 bldata
[3] = (keyA
[sectorNo
][3]);
514 bldata
[4] = (keyA
[sectorNo
][4]);
515 bldata
[5] = (keyA
[sectorNo
][5]);
516 bldata
[10] = (keyB
[sectorNo
][0]);
517 bldata
[11] = (keyB
[sectorNo
][1]);
518 bldata
[12] = (keyB
[sectorNo
][2]);
519 bldata
[13] = (keyB
[sectorNo
][3]);
520 bldata
[14] = (keyB
[sectorNo
][4]);
521 bldata
[15] = (keyB
[sectorNo
][5]);
524 PrintAndLog("Writing to block %3d: %s", FirstBlockOfSector(sectorNo
) + blockNo
, sprint_hex(bldata
, 16));
526 memcpy(c
.d
.asBytes
+ 10, bldata
, 16);
527 clearCommandBuffer();
531 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
532 uint8_t isOK
= resp
.arg
[0] & 0xff;
533 PrintAndLog("isOk:%02x", isOK
);
535 PrintAndLog("Command execute timeout");
544 int CmdHF14AMfNested(const char *Cmd
)
546 int i
, j
, res
, iterations
;
547 sector
*e_sector
= NULL
;
550 uint8_t trgBlockNo
= 0;
551 uint8_t trgKeyType
= 0;
552 uint8_t SectorsCnt
= 0;
553 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
554 uint8_t keyBlock
[14*6];
556 bool transferToEml
= false;
558 bool createDumpFile
= false;
560 uint8_t standart
[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
561 uint8_t tempkey
[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
566 PrintAndLog("Usage:");
567 PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]");
568 PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");
569 PrintAndLog(" <target block number> <target key A/B> [t]");
570 PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
571 PrintAndLog("t - transfer keys into emulator memory");
572 PrintAndLog("d - write keys to binary file");
574 PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF ");
575 PrintAndLog(" sample2: hf mf nested 1 0 A FFFFFFFFFFFF t ");
576 PrintAndLog(" sample3: hf mf nested 1 0 A FFFFFFFFFFFF d ");
577 PrintAndLog(" sample4: hf mf nested o 0 A FFFFFFFFFFFF 4 A");
581 cmdp
= param_getchar(Cmd
, 0);
582 blockNo
= param_get8(Cmd
, 1);
583 ctmp
= param_getchar(Cmd
, 2);
585 if (ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B') {
586 PrintAndLog("Key type must be A or B");
590 if (ctmp
!= 'A' && ctmp
!= 'a')
593 if (param_gethex(Cmd
, 3, key
, 12)) {
594 PrintAndLog("Key must include 12 HEX symbols");
598 if (cmdp
== 'o' || cmdp
== 'O') {
600 trgBlockNo
= param_get8(Cmd
, 4);
601 ctmp
= param_getchar(Cmd
, 5);
602 if (ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B') {
603 PrintAndLog("Target key type must be A or B");
606 if (ctmp
!= 'A' && ctmp
!= 'a')
611 case '0': SectorsCnt
= 05; break;
612 case '1': SectorsCnt
= 16; break;
613 case '2': SectorsCnt
= 32; break;
614 case '4': SectorsCnt
= 40; break;
615 default: SectorsCnt
= 16;
619 ctmp
= param_getchar(Cmd
, 4);
620 if (ctmp
== 't' || ctmp
== 'T') transferToEml
= true;
621 else if (ctmp
== 'd' || ctmp
== 'D') createDumpFile
= true;
623 ctmp
= param_getchar(Cmd
, 6);
624 transferToEml
|= (ctmp
== 't' || ctmp
== 'T');
625 transferToEml
|= (ctmp
== 'd' || ctmp
== 'D');
628 PrintAndLog("--target block no:%3d, target key type:%c ", trgBlockNo
, trgKeyType
?'B':'A');
629 int16_t isOK
= mfnested(blockNo
, keyType
, key
, trgBlockNo
, trgKeyType
, keyBlock
, true);
632 case -1 : PrintAndLog("Error: No response from Proxmark.\n"); break;
633 case -2 : PrintAndLog("Button pressed. Aborted.\n"); break;
634 case -3 : PrintAndLog("Tag isn't vulnerable to Nested Attack (random numbers are not predictable).\n"); break;
635 default : PrintAndLog("Unknown Error.\n");
639 key64
= bytes_to_num(keyBlock
, 6);
641 PrintAndLog("Found valid key:%012"llx
, key64
);
643 // transfer key to the emulator
645 uint8_t sectortrailer
;
646 if (trgBlockNo
< 32*4) { // 4 block sector
647 sectortrailer
= (trgBlockNo
& 0x03) + 3;
648 } else { // 16 block sector
649 sectortrailer
= (trgBlockNo
& 0x0f) + 15;
651 mfEmlGetMem(keyBlock
, sectortrailer
, 1);
654 num_to_bytes(key64
, 6, keyBlock
);
656 num_to_bytes(key64
, 6, &keyBlock
[10]);
657 mfEmlSetMem(keyBlock
, sectortrailer
, 1);
660 PrintAndLog("No valid key found");
663 else { // ------------------------------------ multiple sectors working
667 e_sector
= calloc(SectorsCnt
, sizeof(sector
));
668 if (e_sector
== NULL
) return 1;
670 //test current key and additional standard keys first
671 memcpy(keyBlock
, key
, 6);
672 num_to_bytes(0xffffffffffff, 6, (uint8_t*)(keyBlock
+ 1 * 6));
673 num_to_bytes(0x000000000000, 6, (uint8_t*)(keyBlock
+ 2 * 6));
674 num_to_bytes(0xa0a1a2a3a4a5, 6, (uint8_t*)(keyBlock
+ 3 * 6));
675 num_to_bytes(0xb0b1b2b3b4b5, 6, (uint8_t*)(keyBlock
+ 4 * 6));
676 num_to_bytes(0xaabbccddeeff, 6, (uint8_t*)(keyBlock
+ 5 * 6));
677 num_to_bytes(0x4d3a99c351dd, 6, (uint8_t*)(keyBlock
+ 6 * 6));
678 num_to_bytes(0x1a982c7e459a, 6, (uint8_t*)(keyBlock
+ 7 * 6));
679 num_to_bytes(0xd3f7d3f7d3f7, 6, (uint8_t*)(keyBlock
+ 8 * 6));
680 num_to_bytes(0x714c5c886e97, 6, (uint8_t*)(keyBlock
+ 9 * 6));
681 num_to_bytes(0x587ee5f9350f, 6, (uint8_t*)(keyBlock
+ 10 * 6));
682 num_to_bytes(0xa0478cc39091, 6, (uint8_t*)(keyBlock
+ 11 * 6));
683 num_to_bytes(0x533cb6c723f6, 6, (uint8_t*)(keyBlock
+ 12 * 6));
684 num_to_bytes(0x8fd0a4f256e9, 6, (uint8_t*)(keyBlock
+ 13 * 6));
686 PrintAndLog("Testing known keys. Sector count=%d", SectorsCnt
);
687 for (i
= 0; i
< SectorsCnt
; i
++) {
688 for (j
= 0; j
< 2; j
++) {
689 if (e_sector
[i
].foundKey
[j
]) continue;
691 res
= mfCheckKeys(FirstBlockOfSector(i
), j
, true, 6, keyBlock
, &key64
);
694 e_sector
[i
].Key
[j
] = key64
;
695 e_sector
[i
].foundKey
[j
] = 1;
702 PrintAndLog("nested...");
703 bool calibrate
= true;
704 for (i
= 0; i
< NESTED_SECTOR_RETRY
; i
++) {
705 for (uint8_t sectorNo
= 0; sectorNo
< SectorsCnt
; sectorNo
++) {
706 for (trgKeyType
= 0; trgKeyType
< 2; trgKeyType
++) {
707 if (e_sector
[sectorNo
].foundKey
[trgKeyType
]) continue;
708 PrintAndLog("-----------------------------------------------");
709 int16_t isOK
= mfnested(blockNo
, keyType
, key
, FirstBlockOfSector(sectorNo
), trgKeyType
, keyBlock
, calibrate
);
712 case -1 : PrintAndLog("Error: No response from Proxmark.\n"); break;
713 case -2 : PrintAndLog("Button pressed. Aborted.\n"); break;
714 case -3 : PrintAndLog("Tag isn't vulnerable to Nested Attack (random numbers are not predictable).\n"); break;
715 default : PrintAndLog("Unknown Error.\n");
725 key64
= bytes_to_num(keyBlock
, 6);
727 PrintAndLog("Found valid key:%012"llx
, key64
);
728 e_sector
[sectorNo
].foundKey
[trgKeyType
] = 1;
729 e_sector
[sectorNo
].Key
[trgKeyType
] = key64
;
735 printf("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1
)/CLOCKS_PER_SEC
, ((float)clock() - time1
)/iterations
/CLOCKS_PER_SEC
);
737 PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations
);
739 PrintAndLog("|---|----------------|---|----------------|---|");
740 PrintAndLog("|sec|key A |res|key B |res|");
741 PrintAndLog("|---|----------------|---|----------------|---|");
742 for (i
= 0; i
< SectorsCnt
; i
++) {
743 PrintAndLog("|%03d| %012"llx
" | %d | %012"llx
" | %d |", i
,
744 e_sector
[i
].Key
[0], e_sector
[i
].foundKey
[0], e_sector
[i
].Key
[1], e_sector
[i
].foundKey
[1]);
746 PrintAndLog("|---|----------------|---|----------------|---|");
748 // transfer them to the emulator
750 for (i
= 0; i
< SectorsCnt
; i
++) {
751 mfEmlGetMem(keyBlock
, FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1, 1);
752 if (e_sector
[i
].foundKey
[0])
753 num_to_bytes(e_sector
[i
].Key
[0], 6, keyBlock
);
754 if (e_sector
[i
].foundKey
[1])
755 num_to_bytes(e_sector
[i
].Key
[1], 6, &keyBlock
[10]);
756 mfEmlSetMem(keyBlock
, FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1, 1);
761 if (createDumpFile
) {
762 if ((fkeys
= fopen("dumpkeys.bin","wb")) == NULL
) {
763 PrintAndLog("Could not create file dumpkeys.bin");
767 PrintAndLog("Printing keys to binary file dumpkeys.bin...");
768 for(i
=0; i
<SectorsCnt
; i
++) {
769 if (e_sector
[i
].foundKey
[0]){
770 num_to_bytes(e_sector
[i
].Key
[0], 6, tempkey
);
771 fwrite ( tempkey
, 1, 6, fkeys
);
774 fwrite ( &standart
, 1, 6, fkeys
);
777 for(i
=0; i
<SectorsCnt
; i
++) {
778 if (e_sector
[i
].foundKey
[1]){
779 num_to_bytes(e_sector
[i
].Key
[1], 6, tempkey
);
780 fwrite ( tempkey
, 1, 6, fkeys
);
783 fwrite ( &standart
, 1, 6, fkeys
);
794 int CmdHF14AMfChk(const char *Cmd
)
797 PrintAndLog("Usage: hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t|d] [<key (12 hex symbols)>] [<dic (*.dic)>]");
798 PrintAndLog(" * - all sectors");
799 PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
800 PrintAndLog("d - write keys to binary file");
801 PrintAndLog("t - write keys to emulator memory\n");
802 PrintAndLog(" sample: hf mf chk 0 A 1234567890ab keys.dic");
803 PrintAndLog(" hf mf chk *1 ? t");
804 PrintAndLog(" hf mf chk *1 ? d");
809 char filename
[FILE_PATH_SIZE
]={0};
811 uint8_t *keyBlock
= NULL
, *p
;
812 uint8_t stKeyBlock
= 20;
818 uint8_t SectorsCnt
= 1;
822 int transferToEml
= 0;
823 int createDumpFile
= 0;
825 keyBlock
= calloc(stKeyBlock
, 6);
826 if (keyBlock
== NULL
) return 1;
828 uint64_t defaultKeys
[] =
830 0xffffffffffff, // Default key (first key used by program if no user defined key)
831 0x000000000000, // Blank key
832 0xa0a1a2a3a4a5, // NFCForum MAD key
844 int defaultKeysSize
= sizeof(defaultKeys
) / sizeof(uint64_t);
846 for (int defaultKeyCounter
= 0; defaultKeyCounter
< defaultKeysSize
; defaultKeyCounter
++)
848 num_to_bytes(defaultKeys
[defaultKeyCounter
], 6, (uint8_t*)(keyBlock
+ defaultKeyCounter
* 6));
851 if (param_getchar(Cmd
, 0)=='*') {
853 switch(param_getchar(Cmd
+1, 0)) {
854 case '0': SectorsCnt
= 5; break;
855 case '1': SectorsCnt
= 16; break;
856 case '2': SectorsCnt
= 32; break;
857 case '4': SectorsCnt
= 40; break;
858 default: SectorsCnt
= 16;
862 blockNo
= param_get8(Cmd
, 0);
864 ctmp
= param_getchar(Cmd
, 1);
876 PrintAndLog("Key type must be A , B or ?");
880 ctmp
= param_getchar(Cmd
, 2);
881 if (ctmp
== 't' || ctmp
== 'T') transferToEml
= 1;
882 else if (ctmp
== 'd' || ctmp
== 'D') createDumpFile
= 1;
884 for (i
= transferToEml
|| createDumpFile
; param_getchar(Cmd
, 2 + i
); i
++) {
885 if (!param_gethex(Cmd
, 2 + i
, keyBlock
+ 6 * keycnt
, 12)) {
886 if ( stKeyBlock
- keycnt
< 2) {
887 p
= realloc(keyBlock
, 6*(stKeyBlock
+=10));
889 PrintAndLog("Cannot allocate memory for Keys");
895 PrintAndLog("chk key[%2d] %02x%02x%02x%02x%02x%02x", keycnt
,
896 (keyBlock
+ 6*keycnt
)[0],(keyBlock
+ 6*keycnt
)[1], (keyBlock
+ 6*keycnt
)[2],
897 (keyBlock
+ 6*keycnt
)[3], (keyBlock
+ 6*keycnt
)[4], (keyBlock
+ 6*keycnt
)[5], 6);
901 if ( param_getstr(Cmd
, 2 + i
,filename
) >= FILE_PATH_SIZE
) {
902 PrintAndLog("File name too long");
907 if ( (f
= fopen( filename
, "r")) ) {
908 while( fgets(buf
, sizeof(buf
), f
) ){
909 if (strlen(buf
) < 12 || buf
[11] == '\n')
912 while (fgetc(f
) != '\n' && !feof(f
)) ; //goto next line
914 if( buf
[0]=='#' ) continue; //The line start with # is comment, skip
916 if (!isxdigit(buf
[0])){
917 PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf
);
923 if ( stKeyBlock
- keycnt
< 2) {
924 p
= realloc(keyBlock
, 6*(stKeyBlock
+=10));
926 PrintAndLog("Cannot allocate memory for defKeys");
932 memset(keyBlock
+ 6 * keycnt
, 0, 6);
933 num_to_bytes(strtoll(buf
, NULL
, 16), 6, keyBlock
+ 6*keycnt
);
934 PrintAndLog("chk custom key[%2d] %012"llx
, keycnt
, bytes_to_num(keyBlock
+ 6*keycnt
, 6));
936 memset(buf
, 0, sizeof(buf
));
940 PrintAndLog("File: %s: not found or locked.", filename
);
949 PrintAndLog("No key specified, trying default keys");
950 for (;keycnt
< defaultKeysSize
; keycnt
++)
951 PrintAndLog("chk default key[%2d] %02x%02x%02x%02x%02x%02x", keycnt
,
952 (keyBlock
+ 6*keycnt
)[0],(keyBlock
+ 6*keycnt
)[1], (keyBlock
+ 6*keycnt
)[2],
953 (keyBlock
+ 6*keycnt
)[3], (keyBlock
+ 6*keycnt
)[4], (keyBlock
+ 6*keycnt
)[5], 6);
956 // initialize storage for found keys
957 bool validKey
[2][40];
958 uint8_t foundKey
[2][40][6];
959 for (uint16_t t
= 0; t
< 2; t
++) {
960 for (uint16_t sectorNo
= 0; sectorNo
< SectorsCnt
; sectorNo
++) {
961 validKey
[t
][sectorNo
] = false;
962 for (uint16_t i
= 0; i
< 6; i
++) {
963 foundKey
[t
][sectorNo
][i
] = 0xff;
968 for ( int t
= !keyType
; t
< 2; keyType
==2?(t
++):(t
=2) ) {
970 for (int i
= 0; i
< SectorsCnt
; ++i
) {
971 PrintAndLog("--sector:%2d, block:%3d, key type:%C, key count:%2d ", i
, b
, t
?'B':'A', keycnt
);
972 uint32_t max_keys
= keycnt
>USB_CMD_DATA_SIZE
/6?USB_CMD_DATA_SIZE
/6:keycnt
;
973 for (uint32_t c
= 0; c
< keycnt
; c
+=max_keys
) {
974 uint32_t size
= keycnt
-c
>max_keys
?max_keys
:keycnt
-c
;
975 res
= mfCheckKeys(b
, t
, true, size
, &keyBlock
[6*c
], &key64
);
978 PrintAndLog("Found valid key:[%012"llx
"]",key64
);
979 num_to_bytes(key64
, 6, foundKey
[t
][i
]);
980 validKey
[t
][i
] = true;
983 PrintAndLog("Command execute timeout");
986 b
<127?(b
+=4):(b
+=16);
992 for (uint16_t sectorNo
= 0; sectorNo
< SectorsCnt
; sectorNo
++) {
993 if (validKey
[0][sectorNo
] || validKey
[1][sectorNo
]) {
994 mfEmlGetMem(block
, FirstBlockOfSector(sectorNo
) + NumBlocksPerSector(sectorNo
) - 1, 1);
995 for (uint16_t t
= 0; t
< 2; t
++) {
996 if (validKey
[t
][sectorNo
]) {
997 memcpy(block
+ t
*10, foundKey
[t
][sectorNo
], 6);
1000 mfEmlSetMem(block
, FirstBlockOfSector(sectorNo
) + NumBlocksPerSector(sectorNo
) - 1, 1);
1003 PrintAndLog("Found keys have been transferred to the emulator memory");
1006 if (createDumpFile
) {
1007 FILE *fkeys
= fopen("dumpkeys.bin","wb");
1008 if (fkeys
== NULL
) {
1009 PrintAndLog("Could not create file dumpkeys.bin");
1013 for (uint16_t t
= 0; t
< 2; t
++) {
1014 fwrite(foundKey
[t
], 1, 6*SectorsCnt
, fkeys
);
1017 PrintAndLog("Found keys have been dumped to file dumpkeys.bin. 0xffffffffffff has been inserted for unknown keys.");
1025 int CmdHF14AMf1kSim(const char *Cmd
)
1027 uint8_t uid
[7] = {0, 0, 0, 0, 0, 0, 0};
1028 uint8_t exitAfterNReads
= 0;
1031 uint8_t cmdp
= param_getchar(Cmd
, 0);
1033 if (cmdp
== 'h' || cmdp
== 'H') {
1034 PrintAndLog("Usage: hf mf sim u <uid (8 hex symbols)> n <numreads> i x");
1035 PrintAndLog(" h this help");
1036 PrintAndLog(" u (Optional) UID. If not specified, the UID from emulator memory will be used");
1037 PrintAndLog(" n (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");
1038 PrintAndLog(" i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");
1039 PrintAndLog(" x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");
1041 PrintAndLog(" sample: hf mf sim u 0a0a0a0a ");
1045 if (param_getchar(Cmd
, pnr
) == 'u') {
1046 if(param_gethex(Cmd
, pnr
+1, uid
, 8) == 0)
1048 flags
|= FLAG_4B_UID_IN_DATA
; // UID from packet
1049 } else if(param_gethex(Cmd
,pnr
+1,uid
,14) == 0) {
1050 flags
|= FLAG_7B_UID_IN_DATA
;// UID from packet
1052 PrintAndLog("UID, if specified, must include 8 or 14 HEX symbols");
1057 if (param_getchar(Cmd
, pnr
) == 'n') {
1058 exitAfterNReads
= param_get8(Cmd
,pnr
+1);
1061 if (param_getchar(Cmd
, pnr
) == 'i' ) {
1062 //Using a flag to signal interactiveness, least significant bit
1063 flags
|= FLAG_INTERACTIVE
;
1067 if (param_getchar(Cmd
, pnr
) == 'x' ) {
1068 //Using a flag to signal interactiveness, least significant bit
1069 flags
|= FLAG_NR_AR_ATTACK
;
1071 PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) ",
1072 flags
& FLAG_4B_UID_IN_DATA
? sprint_hex(uid
,4):
1073 flags
& FLAG_7B_UID_IN_DATA
? sprint_hex(uid
,7): "N/A"
1074 , exitAfterNReads
, flags
,flags
);
1077 UsbCommand c
= {CMD_SIMULATE_MIFARE_CARD
, {flags
, exitAfterNReads
,0}};
1078 memcpy(c
.d
.asBytes
, uid
, sizeof(uid
));
1079 clearCommandBuffer();
1082 if(flags
& FLAG_INTERACTIVE
)
1084 PrintAndLog("Press pm3-button to abort simulation");
1091 if ( WaitForResponseTimeout(CMD_ACK
,&resp
,1500) ) {
1092 if ( (resp
.arg
[0] & 0xffff) == CMD_SIMULATE_MIFARE_CARD
){
1093 memset(data
, 0x00, sizeof(data
));
1094 memset(key
, 0x00, sizeof(key
));
1095 int len
= (resp
.arg
[1] > sizeof(data
)) ? sizeof(data
) : resp
.arg
[1];
1097 memcpy(data
, resp
.d
.asBytes
, len
);
1099 uint64_t corr_uid
= 0;
1100 if ( memcmp(data
, "\x00\x00\x00\x00", 4) == 0 ) {
1101 corr_uid
= (data
[3] << 24) | (data
[2] << 16) | (data
[1] << 8) | data
[0];
1104 corr_uid
|= (uint64_t)data
[2] << 48;
1105 corr_uid
|= (uint64_t)data
[1] << 40;
1106 corr_uid
|= (uint64_t)data
[0] << 32;
1107 corr_uid
|= data
[7] << 24;
1108 corr_uid
|= data
[6] << 16;
1109 corr_uid
|= data
[5] << 8;
1110 corr_uid
|= data
[4];
1112 tryMfk32(corr_uid
, data
, key
);
1113 //tryMfk64(corr_uid, data, key);
1122 int CmdHF14AMfDbg(const char *Cmd
)
1124 int dbgMode
= param_get32ex(Cmd
, 0, 0, 10);
1126 PrintAndLog("Max debug mode parameter is 4 \n");
1129 if (strlen(Cmd
) < 1 || !param_getchar(Cmd
, 0) || dbgMode
> 4) {
1130 PrintAndLog("Usage: hf mf dbg <debug level>");
1131 PrintAndLog(" 0 - no debug messages");
1132 PrintAndLog(" 1 - error messages");
1133 PrintAndLog(" 2 - plus information messages");
1134 PrintAndLog(" 3 - plus debug messages");
1135 PrintAndLog(" 4 - print even debug messages in timing critical functions");
1136 PrintAndLog(" Note: this option therefore may cause malfunction itself");
1140 UsbCommand c
= {CMD_MIFARE_SET_DBGMODE
, {dbgMode
, 0, 0}};
1146 int CmdHF14AMfEGet(const char *Cmd
)
1148 uint8_t blockNo
= 0;
1149 uint8_t data
[16] = {0x00};
1151 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1152 PrintAndLog("Usage: hf mf eget <block number>");
1153 PrintAndLog(" sample: hf mf eget 0 ");
1157 blockNo
= param_get8(Cmd
, 0);
1160 if (!mfEmlGetMem(data
, blockNo
, 1)) {
1161 PrintAndLog("data[%3d]:%s", blockNo
, sprint_hex(data
, 16));
1163 PrintAndLog("Command execute timeout");
1169 int CmdHF14AMfEClear(const char *Cmd
)
1171 if (param_getchar(Cmd
, 0) == 'h') {
1172 PrintAndLog("Usage: hf mf eclr");
1173 PrintAndLog("It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF \n");
1177 UsbCommand c
= {CMD_MIFARE_EML_MEMCLR
, {0, 0, 0}};
1182 int CmdHF14AMfESet(const char *Cmd
)
1184 uint8_t memBlock
[16];
1185 uint8_t blockNo
= 0;
1187 memset(memBlock
, 0x00, sizeof(memBlock
));
1189 if (strlen(Cmd
) < 3 || param_getchar(Cmd
, 0) == 'h') {
1190 PrintAndLog("Usage: hf mf eset <block number> <block data (32 hex symbols)>");
1191 PrintAndLog(" sample: hf mf eset 1 000102030405060708090a0b0c0d0e0f ");
1195 blockNo
= param_get8(Cmd
, 0);
1197 if (param_gethex(Cmd
, 1, memBlock
, 32)) {
1198 PrintAndLog("block data must include 32 HEX symbols");
1203 UsbCommand c
= {CMD_MIFARE_EML_MEMSET
, {blockNo
, 1, 0}};
1204 memcpy(c
.d
.asBytes
, memBlock
, 16);
1209 int CmdHF14AMfELoad(const char *Cmd
)
1212 char filename
[FILE_PATH_SIZE
];
1213 char *fnameptr
= filename
;
1214 char buf
[64] = {0x00};
1215 uint8_t buf8
[64] = {0x00};
1216 int i
, len
, blockNum
, numBlocks
;
1217 int nameParamNo
= 1;
1218 uint8_t blockWidth
= 32;
1219 char ctmp
= param_getchar(Cmd
, 0);
1221 if ( ctmp
== 'h' || ctmp
== 'H' || ctmp
== 0x00) {
1222 PrintAndLog("It loads emul dump from the file `filename.eml`");
1223 PrintAndLog("Usage: hf mf eload [card memory] <file name w/o `.eml`>");
1224 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K, u = UL");
1226 PrintAndLog(" sample: hf mf eload filename");
1227 PrintAndLog(" hf mf eload 4 filename");
1232 case '0' : numBlocks
= 5*4; break;
1234 case '\0': numBlocks
= 16*4; break;
1235 case '2' : numBlocks
= 32*4; break;
1236 case '4' : numBlocks
= 256; break;
1237 case 'U' : // fall through , NTAG 215 has 135blocks a 540 bytes.
1238 case 'u' : numBlocks
= 135; blockWidth
= 8; break;
1245 len
= param_getstr(Cmd
,nameParamNo
,filename
);
1247 if (len
> FILE_PATH_SIZE
- 4) len
= FILE_PATH_SIZE
- 4;
1251 sprintf(fnameptr
, ".eml");
1254 f
= fopen(filename
, "r");
1256 PrintAndLog("File %s not found or locked", filename
);
1262 memset(buf
, 0, sizeof(buf
));
1264 if (fgets(buf
, sizeof(buf
), f
) == NULL
) {
1266 if (blockNum
>= numBlocks
) break;
1268 PrintAndLog("File reading error.");
1273 if (strlen(buf
) < blockWidth
){
1274 if(strlen(buf
) && feof(f
))
1276 PrintAndLog("File content error. Block data must include %d HEX symbols", blockWidth
);
1281 for (i
= 0; i
< blockWidth
; i
+= 2) {
1282 sscanf(&buf
[i
], "%02x", (unsigned int *)&buf8
[i
/ 2]);
1284 if (mfEmlSetMem_xt(buf8
, blockNum
, 1, blockWidth
/2)) {
1285 PrintAndLog("Cant set emul block: %3d", blockNum
);
1292 if (blockNum
>= numBlocks
) break;
1297 if ((blockNum
!= numBlocks
)) {
1298 PrintAndLog("File content error. Got %d must be %d blocks.",blockNum
, numBlocks
);
1301 PrintAndLog("Loaded %d blocks from file: %s", blockNum
, filename
);
1305 int CmdHF14AMfESave(const char *Cmd
)
1308 char filename
[FILE_PATH_SIZE
];
1309 char * fnameptr
= filename
;
1311 int i
, j
, len
, numBlocks
;
1312 int nameParamNo
= 1;
1314 memset(filename
, 0, sizeof(filename
));
1315 memset(buf
, 0, sizeof(buf
));
1317 char ctmp
= param_getchar(Cmd
, 0);
1319 if ( ctmp
== 'h' || ctmp
== 'H') {
1320 PrintAndLog("It saves emul dump into the file `filename.eml` or `cardID.eml`");
1321 PrintAndLog(" Usage: hf mf esave [card memory] [file name w/o `.eml`]");
1322 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
1324 PrintAndLog(" sample: hf mf esave ");
1325 PrintAndLog(" hf mf esave 4");
1326 PrintAndLog(" hf mf esave 4 filename");
1331 case '0' : numBlocks
= 5*4; break;
1333 case '\0': numBlocks
= 16*4; break;
1334 case '2' : numBlocks
= 32*4; break;
1335 case '4' : numBlocks
= 256; break;
1342 len
= param_getstr(Cmd
,nameParamNo
,filename
);
1344 if (len
> FILE_PATH_SIZE
- 4) len
= FILE_PATH_SIZE
- 4;
1346 // user supplied filename?
1348 // get filename (UID from memory)
1349 if (mfEmlGetMem(buf
, 0, 1)) {
1350 PrintAndLog("Can\'t get UID from block: %d", 0);
1351 len
= sprintf(fnameptr
, "dump");
1355 for (j
= 0; j
< 7; j
++, fnameptr
+= 2)
1356 sprintf(fnameptr
, "%02X", buf
[j
]);
1362 // add file extension
1363 sprintf(fnameptr
, ".eml");
1366 f
= fopen(filename
, "w+");
1369 PrintAndLog("Can't open file %s ", filename
);
1374 for (i
= 0; i
< numBlocks
; i
++) {
1375 if (mfEmlGetMem(buf
, i
, 1)) {
1376 PrintAndLog("Cant get block: %d", i
);
1379 for (j
= 0; j
< 16; j
++)
1380 fprintf(f
, "%02X", buf
[j
]);
1385 PrintAndLog("Saved %d blocks to file: %s", numBlocks
, filename
);
1390 int CmdHF14AMfECFill(const char *Cmd
)
1392 uint8_t keyType
= 0;
1393 uint8_t numSectors
= 16;
1395 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1396 PrintAndLog("Usage: hf mf ecfill <key A/B> [card memory]");
1397 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
1399 PrintAndLog("samples: hf mf ecfill A");
1400 PrintAndLog(" hf mf ecfill A 4");
1401 PrintAndLog("Read card and transfer its data to emulator memory.");
1402 PrintAndLog("Keys must be laid in the emulator memory. \n");
1406 char ctmp
= param_getchar(Cmd
, 0);
1407 if (ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B') {
1408 PrintAndLog("Key type must be A or B");
1411 if (ctmp
!= 'A' && ctmp
!= 'a') keyType
= 1;
1413 ctmp
= param_getchar(Cmd
, 1);
1415 case '0' : numSectors
= 5; break;
1417 case '\0': numSectors
= 16; break;
1418 case '2' : numSectors
= 32; break;
1419 case '4' : numSectors
= 40; break;
1420 default: numSectors
= 16;
1423 printf("--params: numSectors: %d, keyType:%d", numSectors
, keyType
);
1424 UsbCommand c
= {CMD_MIFARE_EML_CARDLOAD
, {numSectors
, keyType
, 0}};
1429 int CmdHF14AMfEKeyPrn(const char *Cmd
)
1434 uint64_t keyA
, keyB
;
1436 char cmdp
= param_getchar(Cmd
, 0);
1438 if ( cmdp
== 'h' || cmdp
== 'H' ) {
1439 PrintAndLog("It prints the keys loaded in the emulator memory");
1440 PrintAndLog("Usage: hf mf ekeyprn [card memory]");
1441 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
1443 PrintAndLog(" sample: hf mf ekeyprn 1");
1448 case '0' : numSectors
= 5; break;
1450 case '\0': numSectors
= 16; break;
1451 case '2' : numSectors
= 32; break;
1452 case '4' : numSectors
= 40; break;
1453 default: numSectors
= 16;
1456 PrintAndLog("|---|----------------|----------------|");
1457 PrintAndLog("|sec|key A |key B |");
1458 PrintAndLog("|---|----------------|----------------|");
1459 for (i
= 0; i
< numSectors
; i
++) {
1460 if (mfEmlGetMem(data
, FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1, 1)) {
1461 PrintAndLog("error get block %d", FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1);
1464 keyA
= bytes_to_num(data
, 6);
1465 keyB
= bytes_to_num(data
+ 10, 6);
1466 PrintAndLog("|%03d| %012"llx
" | %012"llx
" |", i
, keyA
, keyB
);
1468 PrintAndLog("|---|----------------|----------------|");
1473 int CmdHF14AMfCSetUID(const char *Cmd
)
1475 uint8_t wipeCard
= 0;
1476 uint8_t uid
[8] = {0x00};
1477 uint8_t oldUid
[8] = {0x00};
1478 uint8_t atqa
[2] = {0x00};
1479 uint8_t sak
[1] = {0x00};
1480 uint8_t atqaPresent
= 1;
1485 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, argi
) == 'h') {
1486 PrintAndLog("Usage: hf mf csetuid <UID 8 hex symbols> [ATQA 4 hex symbols SAK 2 hex symbols] [w]");
1487 PrintAndLog("sample: hf mf csetuid 01020304");
1488 PrintAndLog("sample: hf mf csetuid 01020304 0004 08 w");
1489 PrintAndLog("Set UID, ATQA, and SAK for magic Chinese card (only works with such cards)");
1490 PrintAndLog("If you also want to wipe the card then add 'w' at the end of the command line.");
1494 if (param_getchar(Cmd
, argi
) && param_gethex(Cmd
, argi
, uid
, 8)) {
1495 PrintAndLog("UID must include 8 HEX symbols");
1500 ctmp
= param_getchar(Cmd
, argi
);
1501 if (ctmp
== 'w' || ctmp
== 'W') {
1507 if (param_getchar(Cmd
, argi
)) {
1508 if (param_gethex(Cmd
, argi
, atqa
, 4)) {
1509 PrintAndLog("ATQA must include 4 HEX symbols");
1513 if (!param_getchar(Cmd
, argi
) || param_gethex(Cmd
, argi
, sak
, 2)) {
1514 PrintAndLog("SAK must include 2 HEX symbols");
1523 ctmp
= param_getchar(Cmd
, argi
);
1524 if (ctmp
== 'w' || ctmp
== 'W') {
1529 PrintAndLog("--wipe card:%s uid:%s", (wipeCard
)?"YES":"NO", sprint_hex(uid
, 4));
1531 res
= mfCSetUID(uid
, (atqaPresent
)?atqa
:NULL
, (atqaPresent
)?sak
:NULL
, oldUid
, wipeCard
);
1533 PrintAndLog("Can't set UID. error=%d", res
);
1537 PrintAndLog("old UID:%s", sprint_hex(oldUid
, 4));
1538 PrintAndLog("new UID:%s", sprint_hex(uid
, 4));
1542 int CmdHF14AMfCSetBlk(const char *Cmd
)
1544 uint8_t block
[16] = {0x00};
1545 uint8_t blockNo
= 0;
1546 uint8_t params
= MAGIC_SINGLE
;
1549 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1550 PrintAndLog("Usage: hf mf csetblk <block number> <block data (32 hex symbols)> [w]");
1551 PrintAndLog("sample: hf mf csetblk 1 01020304050607080910111213141516");
1552 PrintAndLog("Set block data for magic Chinese card (only works with such cards)");
1553 PrintAndLog("If you also want wipe the card then add 'w' at the end of the command line");
1557 blockNo
= param_get8(Cmd
, 0);
1559 if (param_gethex(Cmd
, 1, block
, 32)) {
1560 PrintAndLog("block data must include 32 HEX symbols");
1564 char ctmp
= param_getchar(Cmd
, 2);
1565 if (ctmp
== 'w' || ctmp
== 'W')
1566 params
|= MAGIC_WIPE
;
1568 PrintAndLog("--block number:%2d data:%s", blockNo
, sprint_hex(block
, 16));
1570 res
= mfCSetBlock(blockNo
, block
, NULL
, params
);
1572 PrintAndLog("Can't write block. error=%d", res
);
1578 int CmdHF14AMfCLoad(const char *Cmd
)
1581 char filename
[FILE_PATH_SIZE
];
1582 char * fnameptr
= filename
;
1583 char buf
[64] = {0x00};
1584 uint8_t buf8
[64] = {0x00};
1585 uint8_t fillFromEmulator
= 0;
1586 int i
, len
, blockNum
, flags
=0;
1588 memset(filename
, 0, sizeof(filename
));
1590 char ctmp
= param_getchar(Cmd
, 0);
1592 if (ctmp
== 'h' || ctmp
== 'H' || ctmp
== 0x00) {
1593 PrintAndLog("It loads magic Chinese card from the file `filename.eml`");
1594 PrintAndLog("or from emulator memory (option `e`)");
1595 PrintAndLog("Usage: hf mf cload <file name w/o `.eml`>");
1596 PrintAndLog(" or: hf mf cload e ");
1597 PrintAndLog(" sample: hf mf cload filename");
1601 if (ctmp
== 'e' || ctmp
== 'E') fillFromEmulator
= 1;
1603 if (fillFromEmulator
) {
1604 for (blockNum
= 0; blockNum
< 16 * 4; blockNum
+= 1) {
1605 if (mfEmlGetMem(buf8
, blockNum
, 1)) {
1606 PrintAndLog("Cant get block: %d", blockNum
);
1609 if (blockNum
== 0) flags
= MAGIC_INIT
+ MAGIC_WUPC
; // switch on field and send magic sequence
1610 if (blockNum
== 1) flags
= 0; // just write
1611 if (blockNum
== 16 * 4 - 1) flags
= MAGIC_HALT
+ MAGIC_OFF
; // Done. Magic Halt and switch off field.
1613 if (mfCSetBlock(blockNum
, buf8
, NULL
, flags
)) {
1614 PrintAndLog("Cant set magic card block: %d", blockNum
);
1621 if (len
> FILE_PATH_SIZE
- 4) len
= FILE_PATH_SIZE
- 4;
1623 memcpy(filename
, Cmd
, len
);
1626 sprintf(fnameptr
, ".eml");
1629 f
= fopen(filename
, "r");
1631 PrintAndLog("File not found or locked.");
1638 memset(buf
, 0, sizeof(buf
));
1640 if (fgets(buf
, sizeof(buf
), f
) == NULL
) {
1642 PrintAndLog("File reading error.");
1646 if (strlen(buf
) < 32) {
1647 if(strlen(buf
) && feof(f
))
1649 PrintAndLog("File content error. Block data must include 32 HEX symbols");
1653 for (i
= 0; i
< 32; i
+= 2)
1654 sscanf(&buf
[i
], "%02x", (unsigned int *)&buf8
[i
/ 2]);
1656 if (blockNum
== 0) flags
= MAGIC_INIT
+ MAGIC_WUPC
; // switch on field and send magic sequence
1657 if (blockNum
== 1) flags
= 0; // just write
1658 if (blockNum
== 16 * 4 - 1) flags
= MAGIC_HALT
+ MAGIC_OFF
; // Done. Switch off field.
1660 if (mfCSetBlock(blockNum
, buf8
, NULL
, flags
)) {
1661 PrintAndLog("Can't set magic card block: %d", blockNum
);
1666 if (blockNum
>= 16 * 4) break; // magic card type - mifare 1K
1671 if (blockNum
!= 16 * 4 && blockNum
!= 32 * 4 + 8 * 16){
1672 PrintAndLog("File content error. There must be 64 blocks");
1675 PrintAndLog("Loaded from file: %s", filename
);
1681 int CmdHF14AMfCGetBlk(const char *Cmd
) {
1683 uint8_t blockNo
= 0;
1685 memset(data
, 0x00, sizeof(data
));
1686 char ctmp
= param_getchar(Cmd
, 0);
1688 if (strlen(Cmd
) < 1 || ctmp
== 'h' || ctmp
== 'H') {
1689 PrintAndLog("Usage: hf mf cgetblk <block number>");
1690 PrintAndLog("sample: hf mf cgetblk 1");
1691 PrintAndLog("Get block data from magic Chinese card (only works with such cards)\n");
1695 blockNo
= param_get8(Cmd
, 0);
1697 PrintAndLog("--block number:%2d ", blockNo
);
1699 res
= mfCGetBlock(blockNo
, data
, MAGIC_SINGLE
);
1701 PrintAndLog("Can't read block. error=%d", res
);
1705 PrintAndLog("data:%s", sprint_hex(data
, sizeof(data
)));
1709 int CmdHF14AMfCGetSc(const char *Cmd
) {
1711 uint8_t sectorNo
= 0;
1713 memset(data
, 0x00, sizeof(data
));
1714 char ctmp
= param_getchar(Cmd
, 0);
1716 if (strlen(Cmd
) < 1 || ctmp
== 'h' || ctmp
== 'H') {
1717 PrintAndLog("Usage: hf mf cgetsc <sector number>");
1718 PrintAndLog("sample: hf mf cgetsc 0");
1719 PrintAndLog("Get sector data from magic Chinese card (only works with such cards)\n");
1723 sectorNo
= param_get8(Cmd
, 0);
1724 if (sectorNo
> 15) {
1725 PrintAndLog("Sector number must be in [0..15] as in MIFARE classic.");
1729 PrintAndLog("--sector number:%d ", sectorNo
);
1730 PrintAndLog("block | data");
1732 flags
= MAGIC_INIT
+ MAGIC_WUPC
;
1733 for (i
= 0; i
< 4; i
++) {
1734 if (i
== 1) flags
= 0;
1735 if (i
== 3) flags
= MAGIC_HALT
+ MAGIC_OFF
;
1737 res
= mfCGetBlock(sectorNo
* 4 + i
, data
, flags
);
1739 PrintAndLog("Can't read block. %d error=%d", sectorNo
* 4 + i
, res
);
1742 PrintAndLog(" %3d | %s", sectorNo
* 4 + i
, sprint_hex(data
, sizeof(data
)));
1747 int CmdHF14AMfCSave(const char *Cmd
) {
1750 char filename
[FILE_PATH_SIZE
];
1751 char * fnameptr
= filename
;
1752 uint8_t fillFromEmulator
= 0;
1754 int i
, j
, len
, flags
;
1756 memset(filename
, 0, sizeof(filename
));
1757 memset(buf
, 0, sizeof(buf
));
1758 char ctmp
= param_getchar(Cmd
, 0);
1760 if ( ctmp
== 'h' || ctmp
== 'H' ) {
1761 PrintAndLog("It saves `magic Chinese` card dump into the file `filename.eml` or `cardID.eml`");
1762 PrintAndLog("or into emulator memory (option `e`)");
1763 PrintAndLog("Usage: hf mf esave [file name w/o `.eml`][e]");
1764 PrintAndLog(" sample: hf mf esave ");
1765 PrintAndLog(" hf mf esave filename");
1766 PrintAndLog(" hf mf esave e \n");
1769 if (ctmp
== 'e' || ctmp
== 'E') fillFromEmulator
= 1;
1771 if (fillFromEmulator
) {
1772 // put into emulator
1773 flags
= MAGIC_INIT
+ MAGIC_WUPC
;
1774 for (i
= 0; i
< 16 * 4; i
++) {
1775 if (i
== 1) flags
= 0;
1776 if (i
== 16 * 4 - 1) flags
= MAGIC_HALT
+ MAGIC_OFF
;
1778 if (mfCGetBlock(i
, buf
, flags
)) {
1779 PrintAndLog("Cant get block: %d", i
);
1783 if (mfEmlSetMem(buf
, i
, 1)) {
1784 PrintAndLog("Cant set emul block: %d", i
);
1791 if (len
> FILE_PATH_SIZE
- 4) len
= FILE_PATH_SIZE
- 4;
1793 // get filename based on UID
1796 if (mfCGetBlock(0, buf
, MAGIC_SINGLE
)) {
1797 PrintAndLog("Cant get block: %d", 0);
1798 len
= sprintf(fnameptr
, "dump");
1801 for (j
= 0; j
< 7; j
++, fnameptr
+= 2)
1802 sprintf(fnameptr
, "%02x", buf
[j
]);
1805 memcpy(filename
, Cmd
, len
);
1809 // add .eml extension
1810 sprintf(fnameptr
, ".eml");
1813 f
= fopen(filename
, "w+");
1816 PrintAndLog("File not found or locked.");
1821 flags
= MAGIC_INIT
+ MAGIC_WUPC
;
1822 for (i
= 0; i
< 16 * 4; i
++) {
1823 if (i
== 1) flags
= 0;
1824 if (i
== 16 * 4 - 1) flags
= MAGIC_HALT
+ MAGIC_OFF
;
1826 if (mfCGetBlock(i
, buf
, flags
)) {
1827 PrintAndLog("Cant get block: %d", i
);
1830 for (j
= 0; j
< 16; j
++)
1831 fprintf(f
, "%02x", buf
[j
]);
1836 PrintAndLog("Saved to file: %s", filename
);
1841 int CmdHF14AMfSniff(const char *Cmd
){
1843 bool wantLogToFile
= 0;
1844 bool wantDecrypt
= 0;
1845 //bool wantSaveToEml = 0; TODO
1846 bool wantSaveToEmlFile
= 0;
1856 uint8_t atqa
[2] = {0x00};
1859 uint8_t *buf
= NULL
;
1860 uint16_t bufsize
= 0;
1861 uint8_t *bufPtr
= NULL
;
1863 char ctmp
= param_getchar(Cmd
, 0);
1864 if ( ctmp
== 'h' || ctmp
== 'H' ) {
1865 PrintAndLog("It continuously gets data from the field and saves it to: log, emulator, emulator file.");
1866 PrintAndLog("You can specify:");
1867 PrintAndLog(" l - save encrypted sequence to logfile `uid.log`");
1868 PrintAndLog(" d - decrypt sequence and put it to log file `uid.log`");
1869 PrintAndLog(" n/a e - decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory");
1870 PrintAndLog(" f - decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`");
1871 PrintAndLog("Usage: hf mf sniff [l][d][e][f]");
1872 PrintAndLog(" sample: hf mf sniff l d e");
1876 for (int i
= 0; i
< 4; i
++) {
1877 ctmp
= param_getchar(Cmd
, i
);
1878 if (ctmp
== 'l' || ctmp
== 'L') wantLogToFile
= true;
1879 if (ctmp
== 'd' || ctmp
== 'D') wantDecrypt
= true;
1880 //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO
1881 if (ctmp
== 'f' || ctmp
== 'F') wantSaveToEmlFile
= true;
1884 printf("-------------------------------------------------------------------------\n");
1885 printf("Executing command. \n");
1886 printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");
1887 printf("Press the key on pc keyboard to abort the client.\n");
1888 printf("-------------------------------------------------------------------------\n");
1890 UsbCommand c
= {CMD_MIFARE_SNIFFER
, {0, 0, 0}};
1891 clearCommandBuffer();
1900 printf("\naborted via keyboard!\n");
1905 if (WaitForResponseTimeout(CMD_ACK
,&resp
,2000)) {
1906 res
= resp
.arg
[0] & 0xff;
1907 uint16_t traceLen
= resp
.arg
[1];
1910 if (res
== 0) return 0; // we are done
1912 if (res
== 1) { // there is (more) data to be transferred
1913 if (pckNum
== 0) { // first packet, (re)allocate necessary buffer
1914 if (traceLen
> bufsize
) {
1916 if (buf
== NULL
) { // not yet allocated
1917 p
= malloc(traceLen
);
1918 } else { // need more memory
1919 p
= realloc(buf
, traceLen
);
1922 PrintAndLog("Cannot allocate memory for trace");
1930 memset(buf
, 0x00, traceLen
);
1932 memcpy(bufPtr
, resp
.d
.asBytes
, len
);
1937 if (res
== 2) { // received all data, start displaying
1938 blockLen
= bufPtr
- buf
;
1941 PrintAndLog("received trace len: %d packages: %d", blockLen
, pckNum
);
1942 while (bufPtr
- buf
< blockLen
) {
1943 bufPtr
+= 6; // skip (void) timing information
1944 len
= *((uint16_t *)bufPtr
);
1952 if ((len
== 14) && (bufPtr
[0] == 0xff) && (bufPtr
[1] == 0xff) && (bufPtr
[12] == 0xff) && (bufPtr
[13] == 0xff)) {
1953 memcpy(uid
, bufPtr
+ 2, 7);
1954 memcpy(atqa
, bufPtr
+ 2 + 7, 2);
1955 uid_len
= (atqa
[0] & 0xC0) == 0x40 ? 7 : 4;
1957 PrintAndLog("tag select uid:%s atqa:0x%02x%02x sak:0x%02x",
1958 sprint_hex(uid
+ (7 - uid_len
), uid_len
),
1962 if (wantLogToFile
|| wantDecrypt
) {
1963 FillFileNameByUID(logHexFileName
, uid
+ (7 - uid_len
), ".log", uid_len
);
1964 AddLogCurrentDT(logHexFileName
);
1967 mfTraceInit(uid
, atqa
, sak
, wantSaveToEmlFile
);
1969 PrintAndLog("%s(%d):%s", isTag
? "TAG":"RDR", num
, sprint_hex(bufPtr
, len
));
1971 AddLogHex(logHexFileName
, isTag
? "TAG: ":"RDR: ", bufPtr
, len
);
1973 mfTraceDecode(bufPtr
, len
, wantSaveToEmlFile
);
1977 bufPtr
+= ((len
-1)/8+1); // ignore parity
1988 //needs nt, ar, at, Data to decrypt
1989 int CmdHf14MfDecryptBytes(const char *Cmd
){
1992 uint32_t nt
= param_get32ex(Cmd
,0,0,16);
1993 uint32_t ar_enc
= param_get32ex(Cmd
,1,0,16);
1994 uint32_t at_enc
= param_get32ex(Cmd
,2,0,16);
1997 param_gethex_ex(Cmd
, 3, data
, &len
);
2000 int limit
= sizeof(data
) / 2;
2005 return tryDecryptWord( nt
, ar_enc
, at_enc
, data
, len
);
2008 static command_t CommandTable
[] =
2010 {"help", CmdHelp
, 1, "This help"},
2011 {"dbg", CmdHF14AMfDbg
, 0, "Set default debug mode"},
2012 {"rdbl", CmdHF14AMfRdBl
, 0, "Read MIFARE classic block"},
2013 {"rdsc", CmdHF14AMfRdSc
, 0, "Read MIFARE classic sector"},
2014 {"dump", CmdHF14AMfDump
, 0, "Dump MIFARE classic tag to binary file"},
2015 {"restore", CmdHF14AMfRestore
, 0, "Restore MIFARE classic binary file to BLANK tag"},
2016 {"wrbl", CmdHF14AMfWrBl
, 0, "Write MIFARE classic block"},
2017 {"chk", CmdHF14AMfChk
, 0, "Test block keys"},
2018 {"mifare", CmdHF14AMifare
, 0, "Read parity error messages."},
2019 {"nested", CmdHF14AMfNested
, 0, "Test nested authentication"},
2020 {"sniff", CmdHF14AMfSniff
, 0, "Sniff card-reader communication"},
2021 {"sim", CmdHF14AMf1kSim
, 0, "Simulate MIFARE card"},
2022 {"eclr", CmdHF14AMfEClear
, 0, "Clear simulator memory block"},
2023 {"eget", CmdHF14AMfEGet
, 0, "Get simulator memory block"},
2024 {"eset", CmdHF14AMfESet
, 0, "Set simulator memory block"},
2025 {"eload", CmdHF14AMfELoad
, 0, "Load from file emul dump"},
2026 {"esave", CmdHF14AMfESave
, 0, "Save to file emul dump"},
2027 {"ecfill", CmdHF14AMfECFill
, 0, "Fill simulator memory with help of keys from simulator"},
2028 {"ekeyprn", CmdHF14AMfEKeyPrn
, 0, "Print keys from simulator memory"},
2029 {"csetuid", CmdHF14AMfCSetUID
, 0, "Set UID for magic Chinese card"},
2030 {"csetblk", CmdHF14AMfCSetBlk
, 0, "Write block - Magic Chinese card"},
2031 {"cgetblk", CmdHF14AMfCGetBlk
, 0, "Read block - Magic Chinese card"},
2032 {"cgetsc", CmdHF14AMfCGetSc
, 0, "Read sector - Magic Chinese card"},
2033 {"cload", CmdHF14AMfCLoad
, 0, "Load dump into magic Chinese card"},
2034 {"csave", CmdHF14AMfCSave
, 0, "Save dump from magic Chinese card into file or emulator"},
2035 {"decrypt", CmdHf14MfDecryptBytes
, 1, "[nt] [ar_enc] [at_enc] [data] - to decrypt snoop or trace"},
2036 {NULL
, NULL
, 0, NULL
}
2039 int CmdHFMF(const char *Cmd
)
2042 WaitForResponseTimeout(CMD_ACK
,NULL
,100);
2043 CmdsParse(CommandTable
, Cmd
);
2047 int CmdHelp(const char *Cmd
)
2049 CmdsHelp(CommandTable
);