]>
cvs.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhfmf.c
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 //-----------------------------------------------------------------------------
10 #include "../include/mifare.h"
13 static int CmdHelp(const char *Cmd
);
15 int CmdHF14AMifare(const char *Cmd
)
18 uint32_t nt
= 0, nr
= 0;
19 uint64_t par_list
= 0, ks_list
= 0, r_key
= 0;
21 uint8_t keyBlock
[8] = {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 the key on the proxmark3 device to abort both proxmark3 and client.\n");
29 printf("-------------------------------------------------------------------------\n");
37 while (ukbhit()) getchar();
46 printf("\naborted via keyboard!\n");
51 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1000)) {
52 isOK
= resp
.arg
[0] & 0xff;
53 uid
= (uint32_t)bytes_to_num(resp
.d
.asBytes
+ 0, 4);
54 nt
= (uint32_t)bytes_to_num(resp
.d
.asBytes
+ 4, 4);
55 par_list
= bytes_to_num(resp
.d
.asBytes
+ 8, 8);
56 ks_list
= bytes_to_num(resp
.d
.asBytes
+ 16, 8);
57 nr
= bytes_to_num(resp
.d
.asBytes
+ 24, 4);
59 if (!isOK
) PrintAndLog("Proxmark can't get statistic info. Execution aborted.\n");
67 if (isOK
!= 1) return 1;
69 // execute original function from util nonce2key
70 if (nonce2key(uid
, nt
, nr
, par_list
, ks_list
, &r_key
))
73 PrintAndLog("Key not found (lfsr_common_prefix list is null). Nt=%08x", nt
);
75 printf("------------------------------------------------------------------\n");
76 PrintAndLog("Key found:%012"llx
" \n", r_key
);
78 num_to_bytes(r_key
, 6, keyBlock
);
79 isOK
= mfCheckKeys(0, 0, 1, keyBlock
, &r_key
);
82 PrintAndLog("Found valid key:%012"llx
, r_key
);
85 if (isOK
!= 2) PrintAndLog("Found invalid key. ");
86 PrintAndLog("Failing is expected to happen in 25%% of all cases. Trying again with a different reader nonce...");
94 int CmdHF14AMfWrBl(const char *Cmd
)
98 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
99 uint8_t bldata
[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
104 PrintAndLog("Usage: hf mf wrbl <block number> <key A/B> <key (12 hex symbols)> <block data (32 hex symbols)>");
105 PrintAndLog(" sample: hf mf wrbl 0 A FFFFFFFFFFFF 000102030405060708090A0B0C0D0E0F");
109 blockNo
= param_get8(Cmd
, 0);
110 cmdp
= param_getchar(Cmd
, 1);
112 PrintAndLog("Key type must be A or B");
115 if (cmdp
!= 'A' && cmdp
!= 'a') keyType
= 1;
116 if (param_gethex(Cmd
, 2, key
, 12)) {
117 PrintAndLog("Key must include 12 HEX symbols");
120 if (param_gethex(Cmd
, 3, bldata
, 32)) {
121 PrintAndLog("Block data must include 32 HEX symbols");
124 PrintAndLog("--block no:%d, key type:%c, key:%s", blockNo
, keyType
?'B':'A', sprint_hex(key
, 6));
125 PrintAndLog("--data: %s", sprint_hex(bldata
, 16));
127 UsbCommand c
= {CMD_MIFARE_WRITEBL
, {blockNo
, keyType
, 0}};
128 memcpy(c
.d
.asBytes
, key
, 6);
129 memcpy(c
.d
.asBytes
+ 10, bldata
, 16);
133 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
134 uint8_t isOK
= resp
.arg
[0] & 0xff;
135 PrintAndLog("isOk:%02x", isOK
);
137 PrintAndLog("Command execute timeout");
143 /* dublett finns i CMDHFMFU.C
144 int CmdHF14AMfUWrBl(const char *Cmd)
148 uint8_t bldata[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
152 PrintAndLog("Usage: hf mf uwrbl <block number> <block data (8 hex symbols)> <w>");
153 PrintAndLog(" sample: hf mf uwrbl 0 01020304");
157 blockNo = param_get8(Cmd, 0);
158 if (param_gethex(Cmd, 1, bldata, 8)) {
159 PrintAndLog("Block data must include 8 HEX symbols");
163 if (strchr(Cmd,'w') != 0) {
170 PrintAndLog("Access Denied");
172 PrintAndLog("--specialblock no:%d", blockNo);
173 PrintAndLog("--data: %s", sprint_hex(bldata, 4));
174 UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};
175 memcpy(d.d.asBytes,bldata, 4);
178 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
179 uint8_t isOK = resp.arg[0] & 0xff;
180 PrintAndLog("isOk:%02x", isOK);
182 PrintAndLog("Command execute timeout");
188 PrintAndLog("Access Denied");
190 PrintAndLog("--specialblock no:%d", blockNo);
191 PrintAndLog("--data: %s", sprint_hex(bldata, 4));
192 UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};
193 memcpy(d.d.asBytes,bldata, 4);
196 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
197 uint8_t isOK = resp.arg[0] & 0xff;
198 PrintAndLog("isOk:%02x", isOK);
200 PrintAndLog("Command execute timeout");
206 PrintAndLog("Access Denied");
208 PrintAndLog("--specialblock no:%d", blockNo);
209 PrintAndLog("--data: %s", sprint_hex(bldata, 4));
210 UsbCommand c = {CMD_MIFAREU_WRITEBL, {blockNo}};
211 memcpy(c.d.asBytes, bldata, 4);
214 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
215 uint8_t isOK = resp.arg[0] & 0xff;
216 PrintAndLog("isOk:%02x", isOK);
218 PrintAndLog("Command execute timeout");
223 PrintAndLog("--specialblock no:%d", blockNo);
224 PrintAndLog("--data: %s", sprint_hex(bldata, 4));
225 UsbCommand d = {CMD_MIFAREU_WRITEBL, {blockNo}};
226 memcpy(d.d.asBytes,bldata, 4);
229 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
230 uint8_t isOK = resp.arg[0] & 0xff;
231 PrintAndLog("isOk:%02x", isOK);
233 PrintAndLog("Command execute timeout");
237 PrintAndLog("--block no:%d", blockNo);
238 PrintAndLog("--data: %s", sprint_hex(bldata, 4));
239 UsbCommand e = {CMD_MIFAREU_WRITEBL, {blockNo}};
240 memcpy(e.d.asBytes,bldata, 4);
243 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
244 uint8_t isOK = resp.arg[0] & 0xff;
245 PrintAndLog("isOk:%02x", isOK);
247 PrintAndLog("Command execute timeout");
254 int CmdHF14AMfRdBl(const char *Cmd
)
258 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
264 PrintAndLog("Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>");
265 PrintAndLog(" sample: hf mf rdbl 0 A FFFFFFFFFFFF ");
269 blockNo
= param_get8(Cmd
, 0);
270 cmdp
= param_getchar(Cmd
, 1);
272 PrintAndLog("Key type must be A or B");
275 if (cmdp
!= 'A' && cmdp
!= 'a') keyType
= 1;
276 if (param_gethex(Cmd
, 2, key
, 12)) {
277 PrintAndLog("Key must include 12 HEX symbols");
280 PrintAndLog("--block no:%d, key type:%c, key:%s ", blockNo
, keyType
?'B':'A', sprint_hex(key
, 6));
282 UsbCommand c
= {CMD_MIFARE_READBL
, {blockNo
, keyType
, 0}};
283 memcpy(c
.d
.asBytes
, key
, 6);
287 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
288 uint8_t isOK
= resp
.arg
[0] & 0xff;
289 uint8_t *data
= resp
.d
.asBytes
;
292 PrintAndLog("isOk:%02x data:%s", isOK
, sprint_hex(data
, 16));
294 PrintAndLog("isOk:%02x", isOK
);
296 PrintAndLog("Command execute timeout");
302 /* dublett finns i CMDHFMFU.C
303 int CmdHF14AMfURdBl(const char *Cmd)
308 PrintAndLog("Usage: hf mf urdbl <block number>");
309 PrintAndLog(" sample: hf mf urdbl 0");
313 blockNo = param_get8(Cmd, 0);
314 PrintAndLog("--block no:%d", blockNo);
316 UsbCommand c = {CMD_MIFAREU_READBL, {blockNo}};
320 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
321 uint8_t isOK = resp.arg[0] & 0xff;
322 uint8_t *data = resp.d.asBytes;
325 PrintAndLog("isOk:%02x data:%s", isOK, sprint_hex(data, 4));
327 PrintAndLog("isOk:%02x", isOK);
329 PrintAndLog("Command execute timeout");
336 /* dublett finns i CMDHFMFU.C
337 int CmdHF14AMfURdCard(const char *Cmd)
340 uint8_t sectorNo = 0;
341 uint8_t *lockbytes_t=NULL;
342 uint8_t lockbytes[2]={0,0};
343 bool bit[16]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
346 uint8_t * data = NULL;
349 PrintAndLog("Sector number must be less than 16");
352 PrintAndLog("Attempting to Read Ultralight... ");
354 UsbCommand c = {CMD_MIFAREU_READCARD, {sectorNo}};
358 if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) {
359 isOK = resp.arg[0] & 0xff;
360 data = resp.d.asBytes;
362 PrintAndLog("isOk:%02x", isOK);
364 for (i = 0; i < 16; i++) {
368 lockbytes_t=data+(i*4);
369 lockbytes[0]=lockbytes_t[2];
370 lockbytes[1]=lockbytes_t[3];
371 for(int j=0; j<16; j++){
372 bit[j]=lockbytes[j/8] & ( 1 <<(7-j%8));
374 //PrintAndLog("LB %02x %02x", lockbytes[0],lockbytes[1]);
375 //PrintAndLog("LB2b %02x %02x %02x %02x %02x %02x %02x %02x",bit[8],bit[9],bit[10],bit[11],bit[12],bit[13],bit[14],bit[15]);
376 PrintAndLog("Block %3d:%s ", i,sprint_hex(data + i * 4, 4));
379 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[4]);
382 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[3]);
385 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[2]);
388 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[1]);
391 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[0]);
394 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[15]);
397 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[14]);
400 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[13]);
403 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[12]);
406 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[11]);
409 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[10]);
412 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[9]);
415 PrintAndLog("Block %3d:%s [%d]", i,sprint_hex(data + i * 4, 4),bit[8]);
418 PrintAndLog("Block %3d:%s ", i,sprint_hex(data + i * 4, 4));
423 PrintAndLog("Command execute timeout");
429 int CmdHF14AMfRdSc(const char *Cmd
)
432 uint8_t sectorNo
= 0;
434 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
436 uint8_t *data
= NULL
;
440 PrintAndLog("Usage: hf mf rdsc <sector number> <key A/B> <key (12 hex symbols)>");
441 PrintAndLog(" sample: hf mf rdsc 0 A FFFFFFFFFFFF ");
445 sectorNo
= param_get8(Cmd
, 0);
447 PrintAndLog("Sector number must be less than 40");
450 cmdp
= param_getchar(Cmd
, 1);
451 if (cmdp
!= 'a' && cmdp
!= 'A' && cmdp
!= 'b' && cmdp
!= 'B') {
452 PrintAndLog("Key type must be A or B");
455 if (cmdp
!= 'A' && cmdp
!= 'a') keyType
= 1;
456 if (param_gethex(Cmd
, 2, key
, 12)) {
457 PrintAndLog("Key must include 12 HEX symbols");
460 PrintAndLog("--sector no:%d key type:%c key:%s ", sectorNo
, keyType
?'B':'A', sprint_hex(key
, 6));
462 UsbCommand c
= {CMD_MIFARE_READSC
, {sectorNo
, keyType
, 0}};
463 memcpy(c
.d
.asBytes
, key
, 6);
468 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
469 isOK
= resp
.arg
[0] & 0xff;
470 data
= resp
.d
.asBytes
;
472 PrintAndLog("isOk:%02x", isOK
);
474 for (i
= 0; i
< (sectorNo
<32?3:15); i
++) {
475 PrintAndLog("data : %s", sprint_hex(data
+ i
* 16, 16));
477 PrintAndLog("trailer: %s", sprint_hex(data
+ (sectorNo
<32?3:15) * 16, 16));
480 PrintAndLog("Command execute timeout");
487 uint8_t FirstBlockOfSector(uint8_t sectorNo
)
492 return 32 * 4 + (sectorNo
- 32) * 16;
497 uint8_t NumBlocksPerSector(uint8_t sectorNo
)
507 int CmdHF14AMfDump(const char *Cmd
)
509 uint8_t sectorNo
, blockNo
;
513 uint8_t rights
[40][4];
514 uint8_t numSectors
= 16;
521 int size
= GetCardSize();
522 char cmdp
= param_getchar(Cmd
, 0);
524 PrintAndLog("Got %d",size
);
529 cmdp
= (char)48+size
;
532 case '0' : numSectors
= 5; break;
534 case '\0': numSectors
= 16; break;
535 case '2' : numSectors
= 32; break;
536 case '4' : numSectors
= 40; break;
537 default: numSectors
= 16;
540 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
541 PrintAndLog("Usage: hf mf dump [card memory]");
542 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
544 PrintAndLog("Samples: hf mf dump");
545 PrintAndLog(" hf mf dump 4");
549 if ((fin
= fopen("dumpkeys.bin","rb")) == NULL
) {
550 PrintAndLog("Could not find file dumpkeys.bin");
554 if ((fout
= fopen("dumpdata.bin","wb")) == NULL
) {
555 PrintAndLog("Could not create file name dumpdata.bin");
559 // Read keys A from file
560 for (sectorNo
=0; sectorNo
<numSectors
; sectorNo
++) {
561 if (fread( keyA
[sectorNo
], 1, 6, fin
) == 0) {
562 PrintAndLog("File reading error.");
567 // Read keys B from file
568 for (sectorNo
=0; sectorNo
<numSectors
; sectorNo
++) {
569 if (fread( keyB
[sectorNo
], 1, 6, fin
) == 0) {
570 PrintAndLog("File reading error.");
575 PrintAndLog("|-----------------------------------------|");
576 PrintAndLog("|------ Reading sector access bits...-----|");
577 PrintAndLog("|-----------------------------------------|");
579 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
580 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + NumBlocksPerSector(sectorNo
) - 1, 0, 0}};
581 memcpy(c
.d
.asBytes
, keyA
[sectorNo
], 6);
584 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
585 uint8_t isOK
= resp
.arg
[0] & 0xff;
586 uint8_t *data
= resp
.d
.asBytes
;
588 rights
[sectorNo
][0] = ((data
[7] & 0x10)>>4) | ((data
[8] & 0x1)<<1) | ((data
[8] & 0x10)>>2);
589 rights
[sectorNo
][1] = ((data
[7] & 0x20)>>5) | ((data
[8] & 0x2)<<0) | ((data
[8] & 0x20)>>3);
590 rights
[sectorNo
][2] = ((data
[7] & 0x40)>>6) | ((data
[8] & 0x4)>>1) | ((data
[8] & 0x40)>>4);
591 rights
[sectorNo
][3] = ((data
[7] & 0x80)>>7) | ((data
[8] & 0x8)>>2) | ((data
[8] & 0x80)>>5);
593 PrintAndLog("Could not get access rights for sector %2d.", sectorNo
);
596 PrintAndLog("Command execute timeout");
600 PrintAndLog("|-----------------------------------------|");
601 PrintAndLog("|----- Dumping all blocks to file... -----|");
602 PrintAndLog("|-----------------------------------------|");
604 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
605 for (blockNo
= 0; blockNo
< NumBlocksPerSector(sectorNo
); blockNo
++) {
606 bool received
= false;
608 if (blockNo
== NumBlocksPerSector(sectorNo
) - 1) { // sector trailer. At least the Access Conditions can always be read with key A.
609 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, 0, 0}};
610 memcpy(c
.d
.asBytes
, keyA
[sectorNo
], 6);
612 received
= WaitForResponseTimeout(CMD_ACK
,&resp
,1500);
613 } else { // data block. Check if it can be read with key A or key B
614 uint8_t data_area
= sectorNo
<32?blockNo
:blockNo
/5;
615 if ((rights
[sectorNo
][data_area
] == 3) || (rights
[sectorNo
][data_area
] == 5)) { // only key B would work
616 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, 1, 0}};
617 memcpy(c
.d
.asBytes
, keyB
[sectorNo
], 6);
619 received
= WaitForResponseTimeout(CMD_ACK
,&resp
,1500);
620 } else if (rights
[sectorNo
][data_area
] == 7) { // no key would work
621 PrintAndLog("Access rights do not allow reading of sector %2d block %3d", sectorNo
, blockNo
);
622 } else { // key A would work
623 UsbCommand c
= {CMD_MIFARE_READBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, 0, 0}};
624 memcpy(c
.d
.asBytes
, keyA
[sectorNo
], 6);
626 received
= WaitForResponseTimeout(CMD_ACK
,&resp
,1500);
631 uint8_t isOK
= resp
.arg
[0] & 0xff;
632 uint8_t *data
= resp
.d
.asBytes
;
633 if (blockNo
== NumBlocksPerSector(sectorNo
) - 1) { // sector trailer. Fill in the keys.
634 data
[0] = (keyA
[sectorNo
][0]);
635 data
[1] = (keyA
[sectorNo
][1]);
636 data
[2] = (keyA
[sectorNo
][2]);
637 data
[3] = (keyA
[sectorNo
][3]);
638 data
[4] = (keyA
[sectorNo
][4]);
639 data
[5] = (keyA
[sectorNo
][5]);
640 data
[10] = (keyB
[sectorNo
][0]);
641 data
[11] = (keyB
[sectorNo
][1]);
642 data
[12] = (keyB
[sectorNo
][2]);
643 data
[13] = (keyB
[sectorNo
][3]);
644 data
[14] = (keyB
[sectorNo
][4]);
645 data
[15] = (keyB
[sectorNo
][5]);
648 fwrite ( data
, 1, 16, fout
);
649 PrintAndLog("Dumped block %2d of sector %2d into 'dumpdata.bin'", blockNo
, sectorNo
);
651 PrintAndLog("Could not read block %2d of sector %2d", blockNo
, sectorNo
);
655 PrintAndLog("Command execute timeout");
666 int CmdHF14AMfRestore(const char *Cmd
)
669 uint8_t sectorNo
,blockNo
;
671 uint8_t key
[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
672 uint8_t bldata
[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
680 char cmdp
= param_getchar(Cmd
, 0);
682 case '0' : numSectors
= 5; break;
684 case '\0': numSectors
= 16; break;
685 case '2' : numSectors
= 32; break;
686 case '4' : numSectors
= 40; break;
687 default: numSectors
= 16;
690 if (strlen(Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H') {
691 PrintAndLog("Usage: hf mf restore [card memory]");
692 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
694 PrintAndLog("Samples: hf mf restore");
695 PrintAndLog(" hf mf restore 4");
699 if ((fdump
= fopen("dumpdata.bin","rb")) == NULL
) {
700 PrintAndLog("Could not find file dumpdata.bin");
703 if ((fkeys
= fopen("dumpkeys.bin","rb")) == NULL
) {
704 PrintAndLog("Could not find file dumpkeys.bin");
708 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
709 if (fread(keyA
[sectorNo
], 1, 6, fkeys
) == 0) {
710 PrintAndLog("File reading error (dumpkeys.bin).");
715 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
716 if (fread(keyB
[sectorNo
], 1, 6, fkeys
) == 0) {
717 PrintAndLog("File reading error (dumpkeys.bin).");
722 PrintAndLog("Restoring dumpdata.bin to card");
724 for (sectorNo
= 0; sectorNo
< numSectors
; sectorNo
++) {
725 for(blockNo
= 0; blockNo
< NumBlocksPerSector(sectorNo
); blockNo
++) {
726 UsbCommand c
= {CMD_MIFARE_WRITEBL
, {FirstBlockOfSector(sectorNo
) + blockNo
, keyType
, 0}};
727 memcpy(c
.d
.asBytes
, key
, 6);
729 if (fread(bldata
, 1, 16, fdump
) == 0) {
730 PrintAndLog("File reading error (dumpdata.bin).");
734 if (blockNo
== NumBlocksPerSector(sectorNo
) - 1) { // sector trailer
735 bldata
[0] = (keyA
[sectorNo
][0]);
736 bldata
[1] = (keyA
[sectorNo
][1]);
737 bldata
[2] = (keyA
[sectorNo
][2]);
738 bldata
[3] = (keyA
[sectorNo
][3]);
739 bldata
[4] = (keyA
[sectorNo
][4]);
740 bldata
[5] = (keyA
[sectorNo
][5]);
741 bldata
[10] = (keyB
[sectorNo
][0]);
742 bldata
[11] = (keyB
[sectorNo
][1]);
743 bldata
[12] = (keyB
[sectorNo
][2]);
744 bldata
[13] = (keyB
[sectorNo
][3]);
745 bldata
[14] = (keyB
[sectorNo
][4]);
746 bldata
[15] = (keyB
[sectorNo
][5]);
749 PrintAndLog("Writing to block %3d: %s", FirstBlockOfSector(sectorNo
) + blockNo
, sprint_hex(bldata
, 16));
751 memcpy(c
.d
.asBytes
+ 10, bldata
, 16);
755 if (WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
756 uint8_t isOK
= resp
.arg
[0] & 0xff;
757 PrintAndLog("isOk:%02x", isOK
);
759 PrintAndLog("Command execute timeout");
770 int CmdHF14AMfNested(const char *Cmd
)
772 int i
, j
, res
, iterations
;
773 sector
*e_sector
= NULL
;
776 uint8_t trgBlockNo
= 0;
777 uint8_t trgKeyType
= 0;
778 uint8_t SectorsCnt
= 0;
779 uint8_t key
[6] = {0, 0, 0, 0, 0, 0};
780 uint8_t keyBlock
[13*6];
782 bool transferToEml
= false;
784 bool createDumpFile
= false;
786 uint8_t standart
[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
787 uint8_t tempkey
[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
792 PrintAndLog("Usage:");
793 PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]");
794 PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");
795 PrintAndLog(" <target block number> <target key A/B> [t]");
796 PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
797 PrintAndLog("t - transfer keys into emulator memory");
798 PrintAndLog("d - write keys to binary file");
800 PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF ");
801 PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF t ");
802 PrintAndLog(" sample1: hf mf nested 1 0 A FFFFFFFFFFFF d ");
803 PrintAndLog(" sample2: hf mf nested o 0 A FFFFFFFFFFFF 4 A");
807 cmdp
= param_getchar(Cmd
, 0);
808 blockNo
= param_get8(Cmd
, 1);
809 ctmp
= param_getchar(Cmd
, 2);
811 if (ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B') {
812 PrintAndLog("Key type must be A or B");
816 if (ctmp
!= 'A' && ctmp
!= 'a')
819 if (param_gethex(Cmd
, 3, key
, 12)) {
820 PrintAndLog("Key must include 12 HEX symbols");
824 if (cmdp
== 'o' || cmdp
== 'O') {
826 trgBlockNo
= param_get8(Cmd
, 4);
827 ctmp
= param_getchar(Cmd
, 5);
828 if (ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B') {
829 PrintAndLog("Target key type must be A or B");
832 if (ctmp
!= 'A' && ctmp
!= 'a')
839 case '0': SectorsCnt
= 05; break;
840 case '1': SectorsCnt
= 16; break;
841 case '2': SectorsCnt
= 32; break;
842 case '4': SectorsCnt
= 40; break;
843 default: SectorsCnt
= 16;
847 ctmp
= param_getchar(Cmd
, 4);
848 if (ctmp
== 't' || ctmp
== 'T') transferToEml
= true;
849 else if (ctmp
== 'd' || ctmp
== 'D') createDumpFile
= true;
851 ctmp
= param_getchar(Cmd
, 6);
852 transferToEml
|= (ctmp
== 't' || ctmp
== 'T');
853 transferToEml
|= (ctmp
== 'd' || ctmp
== 'D');
856 PrintAndLog("--target block no:%3d, target key type:%c ", trgBlockNo
, trgKeyType
?'B':'A');
857 if (mfnested(blockNo
, keyType
, key
, trgBlockNo
, trgKeyType
, keyBlock
, true)) {
858 PrintAndLog("Nested error.");
861 key64
= bytes_to_num(keyBlock
, 6);
863 PrintAndLog("Found valid key:%012"llx
, key64
);
865 // transfer key to the emulator
867 uint8_t sectortrailer
;
868 if (trgBlockNo
< 32*4) { // 4 block sector
869 sectortrailer
= (trgBlockNo
& 0x03) + 3;
870 } else { // 16 block sector
871 sectortrailer
= (trgBlockNo
& 0x0f) + 15;
873 mfEmlGetMem(keyBlock
, sectortrailer
, 1);
876 num_to_bytes(key64
, 6, keyBlock
);
878 num_to_bytes(key64
, 6, &keyBlock
[10]);
879 mfEmlSetMem(keyBlock
, sectortrailer
, 1);
882 PrintAndLog("No valid key found");
885 else { // ------------------------------------ multiple sectors working
889 e_sector
= calloc(SectorsCnt
, sizeof(sector
));
890 if (e_sector
== NULL
) return 1;
892 //test current key and additional standard keys first
893 memcpy(keyBlock
, key
, 6);
894 num_to_bytes(0xffffffffffff, 6, (uint8_t*)(keyBlock
+ 1 * 6));
895 num_to_bytes(0x000000000000, 6, (uint8_t*)(keyBlock
+ 2 * 6));
896 num_to_bytes(0xa0a1a2a3a4a5, 6, (uint8_t*)(keyBlock
+ 3 * 6));
897 num_to_bytes(0xb0b1b2b3b4b5, 6, (uint8_t*)(keyBlock
+ 4 * 6));
898 num_to_bytes(0xaabbccddeeff, 6, (uint8_t*)(keyBlock
+ 5 * 6));
899 num_to_bytes(0x4d3a99c351dd, 6, (uint8_t*)(keyBlock
+ 6 * 6));
900 num_to_bytes(0x1a982c7e459a, 6, (uint8_t*)(keyBlock
+ 7 * 6));
901 num_to_bytes(0xd3f7d3f7d3f7, 6, (uint8_t*)(keyBlock
+ 8 * 6));
902 num_to_bytes(0x714c5c886e97, 6, (uint8_t*)(keyBlock
+ 9 * 6));
903 num_to_bytes(0x587ee5f9350f, 6, (uint8_t*)(keyBlock
+ 10 * 6));
904 num_to_bytes(0xa0478cc39091, 6, (uint8_t*)(keyBlock
+ 11 * 6));
905 num_to_bytes(0x533cb6c723f6, 6, (uint8_t*)(keyBlock
+ 12 * 6));
906 num_to_bytes(0x8fd0a4f256e9, 6, (uint8_t*)(keyBlock
+ 13 * 6));
908 PrintAndLog("Testing known keys. Sector count=%d", SectorsCnt
);
909 for (i
= 0; i
< SectorsCnt
; i
++) {
910 for (j
= 0; j
< 2; j
++) {
911 if (e_sector
[i
].foundKey
[j
]) continue;
913 res
= mfCheckKeys(FirstBlockOfSector(i
), j
, 6, keyBlock
, &key64
);
916 e_sector
[i
].Key
[j
] = key64
;
917 e_sector
[i
].foundKey
[j
] = 1;
925 PrintAndLog("nested...");
926 bool calibrate
= true;
927 for (i
= 0; i
< NESTED_SECTOR_RETRY
; i
++) {
928 for (uint8_t sectorNo
= 0; sectorNo
< SectorsCnt
; sectorNo
++) {
929 for (trgKeyType
= 0; trgKeyType
< 2; trgKeyType
++) {
930 if (e_sector
[sectorNo
].foundKey
[trgKeyType
]) continue;
931 PrintAndLog("-----------------------------------------------");
932 if(mfnested(blockNo
, keyType
, key
, FirstBlockOfSector(sectorNo
), trgKeyType
, keyBlock
, calibrate
)) {
933 PrintAndLog("Nested error.\n");
942 key64
= bytes_to_num(keyBlock
, 6);
944 PrintAndLog("Found valid key:%012"llx
, key64
);
945 e_sector
[sectorNo
].foundKey
[trgKeyType
] = 1;
946 e_sector
[sectorNo
].Key
[trgKeyType
] = key64
;
952 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
);
954 PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations
);
956 PrintAndLog("|---|----------------|---|----------------|---|");
957 PrintAndLog("|sec|key A |res|key B |res|");
958 PrintAndLog("|---|----------------|---|----------------|---|");
959 for (i
= 0; i
< SectorsCnt
; i
++) {
960 PrintAndLog("|%03d| %012"llx
" | %d | %012"llx
" | %d |", i
,
961 e_sector
[i
].Key
[0], e_sector
[i
].foundKey
[0], e_sector
[i
].Key
[1], e_sector
[i
].foundKey
[1]);
963 PrintAndLog("|---|----------------|---|----------------|---|");
965 // transfer them to the emulator
967 for (i
= 0; i
< SectorsCnt
; i
++) {
968 mfEmlGetMem(keyBlock
, FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1, 1);
969 if (e_sector
[i
].foundKey
[0])
970 num_to_bytes(e_sector
[i
].Key
[0], 6, keyBlock
);
971 if (e_sector
[i
].foundKey
[1])
972 num_to_bytes(e_sector
[i
].Key
[1], 6, &keyBlock
[10]);
973 mfEmlSetMem(keyBlock
, FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1, 1);
978 if (createDumpFile
) {
979 if ((fkeys
= fopen("dumpkeys.bin","wb")) == NULL
) {
980 PrintAndLog("Could not create file dumpkeys.bin");
984 PrintAndLog("Printing keys to binary file dumpkeys.bin...");
985 for(i
=0; i
<SectorsCnt
; i
++) {
986 if (e_sector
[i
].foundKey
[0]){
987 num_to_bytes(e_sector
[i
].Key
[0], 6, tempkey
);
988 fwrite ( tempkey
, 1, 6, fkeys
);
991 fwrite ( &standart
, 1, 6, fkeys
);
994 for(i
=0; i
<SectorsCnt
; i
++) {
995 if (e_sector
[i
].foundKey
[1]){
996 num_to_bytes(e_sector
[i
].Key
[1], 6, tempkey
);
997 fwrite ( tempkey
, 1, 6, fkeys
);
1000 fwrite ( &standart
, 1, 6, fkeys
);
1013 static uint32_t get_trailer_block (uint32_t uiBlock
)
1015 // Test if we are in the small or big sectors
1016 uint32_t trailer_block
= 0;
1017 if (uiBlock
< 128) {
1018 trailer_block
= uiBlock
+ (3 - (uiBlock
% 4));
1020 trailer_block
= uiBlock
+ (15 - (uiBlock
% 16));
1022 return trailer_block
;
1026 int CmdHF14AMfChk(const char *Cmd
)
1029 char filename
[256]={0};
1031 uint8_t *keyBlock
= NULL
, *p
;
1032 uint8_t stKeyBlock
= 20;
1037 uint8_t blockNo
= 0;
1038 uint8_t SectorsCnt
= 1;
1039 uint8_t keyType
= 0;
1042 int transferToEml
= 0;
1043 int createDumpFile
= 0;
1045 keyBlock
= calloc(stKeyBlock
, 6);
1046 if (keyBlock
== NULL
) return 1;
1048 uint64_t defaultKeys
[] =
1050 0xffffffffffff, // Default key (first key used by program if no user defined key)
1051 0x000000000000, // Blank key
1052 0xa0a1a2a3a4a5, // NFCForum MAD key
1064 int defaultKeysSize
= sizeof(defaultKeys
) / sizeof(uint64_t);
1066 for (int defaultKeyCounter
= 0; defaultKeyCounter
< defaultKeysSize
; defaultKeyCounter
++)
1068 num_to_bytes(defaultKeys
[defaultKeyCounter
], 6, (uint8_t*)(keyBlock
+ defaultKeyCounter
* 6));
1071 if (strlen(Cmd
)<3) {
1072 PrintAndLog("Usage: hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t] [<key (12 hex symbols)>] [<dic (*.dic)>]");
1073 PrintAndLog(" * - all sectors");
1074 PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
1075 // PrintAndLog("d - write keys to binary file\n");
1077 PrintAndLog(" sample: hf mf chk 0 A 1234567890ab keys.dic");
1078 PrintAndLog(" hf mf chk *1 ? t");
1082 if (param_getchar(Cmd
, 0)=='*') {
1084 switch(param_getchar(Cmd
+1, 0)) {
1085 case '0': SectorsCnt
= 5; break;
1086 case '1': SectorsCnt
= 16; break;
1087 case '2': SectorsCnt
= 32; break;
1088 case '4': SectorsCnt
= 40; break;
1089 default: SectorsCnt
= 16;
1093 blockNo
= param_get8(Cmd
, 0);
1095 ctmp
= param_getchar(Cmd
, 1);
1107 PrintAndLog("Key type must be A , B or ?");
1111 ctmp
= param_getchar(Cmd
, 2);
1112 if (ctmp
== 't' || ctmp
== 'T') transferToEml
= 1;
1113 else if (ctmp
== 'd' || ctmp
== 'D') createDumpFile
= 1;
1115 for (i
= transferToEml
|| createDumpFile
; param_getchar(Cmd
, 2 + i
); i
++) {
1116 if (!param_gethex(Cmd
, 2 + i
, keyBlock
+ 6 * keycnt
, 12)) {
1117 if ( stKeyBlock
- keycnt
< 2) {
1118 p
= realloc(keyBlock
, 6*(stKeyBlock
+=10));
1120 PrintAndLog("Cannot allocate memory for Keys");
1126 PrintAndLog("chk key[%2d] %02x%02x%02x%02x%02x%02x", keycnt
,
1127 (keyBlock
+ 6*keycnt
)[0],(keyBlock
+ 6*keycnt
)[1], (keyBlock
+ 6*keycnt
)[2],
1128 (keyBlock
+ 6*keycnt
)[3], (keyBlock
+ 6*keycnt
)[4], (keyBlock
+ 6*keycnt
)[5], 6);
1131 // May be a dic file
1132 if ( param_getstr(Cmd
, 2 + i
,filename
) > 255 ) {
1133 PrintAndLog("File name too long");
1138 if ( (f
= fopen( filename
, "r")) ) {
1139 while( fgets(buf
, sizeof(buf
), f
) ){
1140 if (strlen(buf
) < 12 || buf
[11] == '\n')
1143 while (fgetc(f
) != '\n' && !feof(f
)) ; //goto next line
1145 if( buf
[0]=='#' ) continue; //The line start with # is comment, skip
1147 if (!isxdigit(buf
[0])){
1148 PrintAndLog("File content error. '%s' must include 12 HEX symbols",buf
);
1154 if ( stKeyBlock
- keycnt
< 2) {
1155 p
= realloc(keyBlock
, 6*(stKeyBlock
+=10));
1157 PrintAndLog("Cannot allocate memory for defKeys");
1163 memset(keyBlock
+ 6 * keycnt
, 0, 6);
1164 num_to_bytes(strtoll(buf
, NULL
, 16), 6, keyBlock
+ 6*keycnt
);
1165 PrintAndLog("chk custom key[%2d] %012"llx
, keycnt
, bytes_to_num(keyBlock
+ 6*keycnt
, 6));
1167 memset(buf
, 0, sizeof(buf
));
1170 PrintAndLog("File: %s: not found or locked.", filename
);
1179 PrintAndLog("No key specified, trying default keys");
1180 for (;keycnt
< defaultKeysSize
; keycnt
++)
1181 PrintAndLog("chk default key[%2d] %02x%02x%02x%02x%02x%02x", keycnt
,
1182 (keyBlock
+ 6*keycnt
)[0],(keyBlock
+ 6*keycnt
)[1], (keyBlock
+ 6*keycnt
)[2],
1183 (keyBlock
+ 6*keycnt
)[3], (keyBlock
+ 6*keycnt
)[4], (keyBlock
+ 6*keycnt
)[5], 6);
1186 for ( int t
= !keyType
; t
< 2; keyType
==2?(t
++):(t
=2) ) {
1188 for (int i
= 0; i
< SectorsCnt
; ++i
) {
1189 PrintAndLog("--SectorsCnt:%2d, block no:%3d, key type:%C, key count:%2d ", i
, b
, t
?'B':'A', keycnt
);
1190 uint32_t max_keys
= keycnt
>USB_CMD_DATA_SIZE
/6?USB_CMD_DATA_SIZE
/6:keycnt
;
1191 for (uint32_t c
= 0; c
< keycnt
; c
+=max_keys
) {
1192 uint32_t size
= keycnt
-c
>max_keys
?max_keys
:keycnt
-c
;
1193 res
= mfCheckKeys(b
, t
, size
, &keyBlock
[6*c
], &key64
);
1196 PrintAndLog("Found valid key:[%012"llx
"]",key64
);
1197 if (transferToEml
) {
1199 mfEmlGetMem(block
, get_trailer_block(b
), 1);
1200 num_to_bytes(key64
, 6, block
+ t
*10);
1201 mfEmlSetMem(block
, get_trailer_block(b
), 1);
1205 PrintAndLog("Command execute timeout");
1208 b
<127?(b
+=4):(b
+=16);
1216 if (createDumpFile) {
1217 if ((fkeys = fopen("dumpkeys.bin","wb")) == NULL) {
1218 PrintAndLog("Could not create file dumpkeys.bin");
1222 PrintAndLog("Printing keys to binary file dumpkeys.bin...");
1223 for(i=0; i<16; i++) {
1224 if (e_sector[i].foundKey[0]){
1225 num_to_bytes(e_sector[i].Key[0], 6, tempkey);
1226 fwrite ( tempkey, 1, 6, fkeys );
1229 fwrite ( &standart, 1, 6, fkeys );
1232 for(i=0; i<16; i++) {
1233 if (e_sector[i].foundKey[1]){
1234 num_to_bytes(e_sector[i].Key[1], 6, tempkey);
1235 fwrite ( tempkey, 1, 6, fkeys );
1238 fwrite ( &standart, 1, 6, fkeys );
1247 int CmdHF14AMf1kSim(const char *Cmd
)
1249 uint8_t uid
[7] = {0, 0, 0, 0, 0, 0, 0};
1250 uint8_t exitAfterNReads
= 0;
1253 if (param_getchar(Cmd
, 0) == 'h') {
1254 PrintAndLog("Usage: hf mf sim u <uid (8 hex symbols)> n <numreads> i x");
1255 PrintAndLog(" u (Optional) UID. If not specified, the UID from emulator memory will be used");
1256 PrintAndLog(" n (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");
1257 PrintAndLog(" i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");
1258 PrintAndLog(" x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");
1259 PrintAndLog(" sample: hf mf sim u 0a0a0a0a ");
1263 if (param_getchar(Cmd
, pnr
) == 'u') {
1264 if(param_gethex(Cmd
, pnr
+1, uid
, 8) == 0)
1266 flags
|= FLAG_4B_UID_IN_DATA
; // UID from packet
1267 } else if(param_gethex(Cmd
,pnr
+1,uid
,14) == 0) {
1268 flags
|= FLAG_7B_UID_IN_DATA
;// UID from packet
1270 PrintAndLog("UID, if specified, must include 8 or 14 HEX symbols");
1275 if (param_getchar(Cmd
, pnr
) == 'n') {
1276 exitAfterNReads
= param_get8(Cmd
,pnr
+1);
1279 if (param_getchar(Cmd
, pnr
) == 'i' ) {
1280 //Using a flag to signal interactiveness, least significant bit
1281 flags
|= FLAG_INTERACTIVE
;
1285 if (param_getchar(Cmd
, pnr
) == 'x' ) {
1286 //Using a flag to signal interactiveness, least significant bit
1287 flags
|= FLAG_NR_AR_ATTACK
;
1289 PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) ",
1290 flags
& FLAG_4B_UID_IN_DATA
? sprint_hex(uid
,4):
1291 flags
& FLAG_7B_UID_IN_DATA
? sprint_hex(uid
,7): "N/A"
1292 , exitAfterNReads
, flags
,flags
);
1295 UsbCommand c
= {CMD_SIMULATE_MIFARE_CARD
, {flags
, exitAfterNReads
,0}};
1296 memcpy(c
.d
.asBytes
, uid
, sizeof(uid
));
1299 if(flags
& FLAG_INTERACTIVE
)
1302 PrintAndLog("Press pm3-button to abort simulation");
1303 while(! WaitForResponseTimeout(CMD_ACK
,&resp
,1500)) {
1304 //We're waiting only 1.5 s at a time, otherwise we get the
1305 // annoying message about "Waiting for a response... "
1313 int CmdHF14AMfDbg(const char *Cmd
)
1315 int dbgMode
= param_get32ex(Cmd
, 0, 0, 10);
1317 PrintAndLog("Max debug mode parameter is 4 \n");
1320 if (strlen(Cmd
) < 1 || !param_getchar(Cmd
, 0) || dbgMode
> 4) {
1321 PrintAndLog("Usage: hf mf dbg <debug level>");
1322 PrintAndLog(" 0 - no debug messages");
1323 PrintAndLog(" 1 - error messages");
1324 PrintAndLog(" 2 - plus information messages");
1325 PrintAndLog(" 3 - plus debug messages");
1326 PrintAndLog(" 4 - print even debug messages in timing critical functions");
1327 PrintAndLog(" Note: this option therefore may cause malfunction itself");
1331 UsbCommand c
= {CMD_MIFARE_SET_DBGMODE
, {dbgMode
, 0, 0}};
1337 int CmdHF14AMfEGet(const char *Cmd
)
1339 uint8_t blockNo
= 0;
1342 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1343 PrintAndLog("Usage: hf mf eget <block number>");
1344 PrintAndLog(" sample: hf mf eget 0 ");
1348 blockNo
= param_get8(Cmd
, 0);
1351 if (!mfEmlGetMem(data
, blockNo
, 1)) {
1352 PrintAndLog("data[%3d]:%s", blockNo
, sprint_hex(data
, 16));
1354 PrintAndLog("Command execute timeout");
1361 int CmdHF14AMfEClear(const char *Cmd
)
1363 if (param_getchar(Cmd
, 0) == 'h') {
1364 PrintAndLog("Usage: hf mf eclr");
1365 PrintAndLog("It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF \n");
1369 UsbCommand c
= {CMD_MIFARE_EML_MEMCLR
, {0, 0, 0}};
1375 int CmdHF14AMfESet(const char *Cmd
)
1377 uint8_t memBlock
[16];
1378 uint8_t blockNo
= 0;
1380 memset(memBlock
, 0x00, sizeof(memBlock
));
1382 if (strlen(Cmd
) < 3 || param_getchar(Cmd
, 0) == 'h') {
1383 PrintAndLog("Usage: hf mf eset <block number> <block data (32 hex symbols)>");
1384 PrintAndLog(" sample: hf mf eset 1 000102030405060708090a0b0c0d0e0f ");
1388 blockNo
= param_get8(Cmd
, 0);
1390 if (param_gethex(Cmd
, 1, memBlock
, 32)) {
1391 PrintAndLog("block data must include 32 HEX symbols");
1396 UsbCommand c
= {CMD_MIFARE_EML_MEMSET
, {blockNo
, 1, 0}};
1397 memcpy(c
.d
.asBytes
, memBlock
, 16);
1403 int CmdHF14AMfELoad(const char *Cmd
)
1407 char *fnameptr
= filename
;
1410 int i
, len
, blockNum
;
1412 memset(filename
, 0, sizeof(filename
));
1413 memset(buf
, 0, sizeof(buf
));
1415 if (param_getchar(Cmd
, 0) == 'h' || param_getchar(Cmd
, 0)== 0x00) {
1416 PrintAndLog("It loads emul dump from the file `filename.eml`");
1417 PrintAndLog("Usage: hf mf eload <file name w/o `.eml`>");
1418 PrintAndLog(" sample: hf mf eload filename");
1423 if (len
> 14) len
= 14;
1425 memcpy(filename
, Cmd
, len
);
1428 sprintf(fnameptr
, ".eml");
1431 f
= fopen(filename
, "r");
1433 PrintAndLog("File not found or locked.");
1439 memset(buf
, 0, sizeof(buf
));
1440 if (fgets(buf
, sizeof(buf
), f
) == NULL
) {
1441 if((blockNum
== 16*4) || (blockNum
== 32*4 + 8*16)) { // supports both old (1K) and new (4K) .eml files)
1444 PrintAndLog("File reading error.");
1447 if (strlen(buf
) < 32){
1448 if(strlen(buf
) && feof(f
))
1450 PrintAndLog("File content error. Block data must include 32 HEX symbols");
1453 for (i
= 0; i
< 32; i
+= 2) {
1454 sscanf(&buf
[i
], "%02x", (unsigned int *)&buf8
[i
/ 2]);
1455 // PrintAndLog("data[%02d]:%s", blockNum, sprint_hex(buf8, 16));
1457 if (mfEmlSetMem(buf8
, blockNum
, 1)) {
1458 PrintAndLog("Cant set emul block: %3d", blockNum
);
1463 if (blockNum
>= 32*4 + 8*16) break;
1467 if ((blockNum
!= 16*4) && (blockNum
!= 32*4 + 8*16)) {
1468 PrintAndLog("File content error. There must be 64 or 256 blocks.");
1471 PrintAndLog("Loaded %d blocks from file: %s", blockNum
, filename
);
1476 int CmdHF14AMfESave(const char *Cmd
)
1480 char * fnameptr
= filename
;
1484 memset(filename
, 0, sizeof(filename
));
1485 memset(buf
, 0, sizeof(buf
));
1487 if (param_getchar(Cmd
, 0) == 'h') {
1488 PrintAndLog("It saves emul dump into the file `filename.eml` or `cardID.eml`");
1489 PrintAndLog("Usage: hf mf esave [file name w/o `.eml`]");
1490 PrintAndLog(" sample: hf mf esave ");
1491 PrintAndLog(" hf mf esave filename");
1496 if (len
> 14) len
= 14;
1500 if (mfEmlGetMem(buf
, 0, 1)) {
1501 PrintAndLog("Cant get block: %d", 0);
1504 for (j
= 0; j
< 7; j
++, fnameptr
+= 2)
1505 sprintf(fnameptr
, "%02x", buf
[j
]);
1507 memcpy(filename
, Cmd
, len
);
1511 sprintf(fnameptr
, ".eml");
1514 f
= fopen(filename
, "w+");
1517 for (i
= 0; i
< 32*4 + 8*16; i
++) {
1518 if (mfEmlGetMem(buf
, i
, 1)) {
1519 PrintAndLog("Cant get block: %d", i
);
1522 for (j
= 0; j
< 16; j
++)
1523 fprintf(f
, "%02x", buf
[j
]);
1528 PrintAndLog("Saved to file: %s", filename
);
1534 int CmdHF14AMfECFill(const char *Cmd
)
1536 uint8_t keyType
= 0;
1537 uint8_t numSectors
= 16;
1539 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1540 PrintAndLog("Usage: hf mf ecfill <key A/B> [card memory]");
1541 PrintAndLog(" [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K");
1543 PrintAndLog("samples: hf mf ecfill A");
1544 PrintAndLog(" hf mf ecfill A 4");
1545 PrintAndLog("Read card and transfer its data to emulator memory.");
1546 PrintAndLog("Keys must be laid in the emulator memory. \n");
1550 char ctmp
= param_getchar(Cmd
, 0);
1551 if (ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B') {
1552 PrintAndLog("Key type must be A or B");
1555 if (ctmp
!= 'A' && ctmp
!= 'a') keyType
= 1;
1557 ctmp
= param_getchar(Cmd
, 1);
1559 case '0' : numSectors
= 5; break;
1561 case '\0': numSectors
= 16; break;
1562 case '2' : numSectors
= 32; break;
1563 case '4' : numSectors
= 40; break;
1564 default: numSectors
= 16;
1567 printf("--params: numSectors: %d, keyType:%d", numSectors
, keyType
);
1568 UsbCommand c
= {CMD_MIFARE_EML_CARDLOAD
, {numSectors
, keyType
, 0}};
1574 int CmdHF14AMfEKeyPrn(const char *Cmd
)
1578 uint64_t keyA
, keyB
;
1580 PrintAndLog("|---|----------------|----------------|");
1581 PrintAndLog("|sec|key A |key B |");
1582 PrintAndLog("|---|----------------|----------------|");
1583 for (i
= 0; i
< 40; i
++) {
1584 if (mfEmlGetMem(data
, FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1, 1)) {
1585 PrintAndLog("error get block %d", FirstBlockOfSector(i
) + NumBlocksPerSector(i
) - 1);
1588 keyA
= bytes_to_num(data
, 6);
1589 keyB
= bytes_to_num(data
+ 10, 6);
1590 PrintAndLog("|%03d| %012"llx
" | %012"llx
" |", i
, keyA
, keyB
);
1592 PrintAndLog("|---|----------------|----------------|");
1598 int CmdHF14AMfCSetUID(const char *Cmd
)
1600 uint8_t wipeCard
= 0;
1605 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1606 PrintAndLog("Usage: hf mf csetuid <UID 8 hex symbols> <w>");
1607 PrintAndLog("sample: hf mf csetuid 01020304 w");
1608 PrintAndLog("Set UID for magic Chinese card (only works with!!!)");
1609 PrintAndLog("If you want wipe card then add 'w' into command line. \n");
1613 if (param_getchar(Cmd
, 0) && param_gethex(Cmd
, 0, uid
, 8)) {
1614 PrintAndLog("UID must include 8 HEX symbols");
1618 char ctmp
= param_getchar(Cmd
, 1);
1619 if (ctmp
== 'w' || ctmp
== 'W') wipeCard
= 1;
1621 PrintAndLog("--wipe card:%02x uid:%s", wipeCard
, sprint_hex(uid
, 4));
1623 res
= mfCSetUID(uid
, oldUid
, wipeCard
);
1625 PrintAndLog("Can't set UID. error=%d", res
);
1629 PrintAndLog("old UID:%s", sprint_hex(oldUid
, 4));
1633 int CmdHF14AMfCSetBlk(const char *Cmd
)
1636 uint8_t memBlock
[16];
1637 uint8_t blockNo
= 0;
1639 memset(memBlock
, 0x00, sizeof(memBlock
));
1641 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1642 PrintAndLog("Usage: hf mf csetblk <block number> <block data (32 hex symbols)>");
1643 PrintAndLog("sample: hf mf csetblk 1 01020304050607080910111213141516");
1644 PrintAndLog("Set block data for magic Chinese card (only works with!!!)");
1645 PrintAndLog("If you want wipe card then add 'w' into command line. \n");
1649 blockNo
= param_get8(Cmd
, 0);
1651 if (param_gethex(Cmd
, 1, memBlock
, 32)) {
1652 PrintAndLog("block data must include 32 HEX symbols");
1656 PrintAndLog("--block number:%2d data:%s", blockNo
, sprint_hex(memBlock
, 16));
1658 res
= mfCSetBlock(blockNo
, memBlock
, uid
, 0, CSETBLOCK_SINGLE_OPER
);
1660 PrintAndLog("Can't write block. error=%d", res
);
1664 PrintAndLog("UID:%s", sprint_hex(uid
, 4));
1669 int CmdHF14AMfCLoad(const char *Cmd
)
1673 char * fnameptr
= filename
;
1676 uint8_t fillFromEmulator
= 0;
1677 int i
, len
, blockNum
, flags
;
1679 memset(filename
, 0, sizeof(filename
));
1680 memset(buf
, 0, sizeof(buf
));
1682 if (param_getchar(Cmd
, 0) == 'h' || param_getchar(Cmd
, 0)== 0x00) {
1683 PrintAndLog("It loads magic Chinese card (only works with!!!) from the file `filename.eml`");
1684 PrintAndLog("or from emulator memory (option `e`)");
1685 PrintAndLog("Usage: hf mf cload <file name w/o `.eml`>");
1686 PrintAndLog(" or: hf mf cload e ");
1687 PrintAndLog(" sample: hf mf cload filename");
1691 char ctmp
= param_getchar(Cmd
, 0);
1692 if (ctmp
== 'e' || ctmp
== 'E') fillFromEmulator
= 1;
1694 if (fillFromEmulator
) {
1695 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
1696 for (blockNum
= 0; blockNum
< 16 * 4; blockNum
+= 1) {
1697 if (mfEmlGetMem(buf8
, blockNum
, 1)) {
1698 PrintAndLog("Cant get block: %d", blockNum
);
1702 if (blockNum
== 2) flags
= 0;
1703 if (blockNum
== 16 * 4 - 1) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
1705 if (mfCSetBlock(blockNum
, buf8
, NULL
, 0, flags
)) {
1706 PrintAndLog("Cant set magic card block: %d", blockNum
);
1713 if (len
> 14) len
= 14;
1715 memcpy(filename
, Cmd
, len
);
1718 sprintf(fnameptr
, ".eml");
1721 f
= fopen(filename
, "r");
1723 PrintAndLog("File not found or locked.");
1728 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
1730 memset(buf
, 0, sizeof(buf
));
1731 if (fgets(buf
, sizeof(buf
), f
) == NULL
) {
1732 PrintAndLog("File reading error.");
1736 if (strlen(buf
) < 32){
1737 if(strlen(buf
) && feof(f
))
1739 PrintAndLog("File content error. Block data must include 32 HEX symbols");
1742 for (i
= 0; i
< 32; i
+= 2)
1743 sscanf(&buf
[i
], "%02x", (unsigned int *)&buf8
[i
/ 2]);
1745 if (blockNum
== 2) flags
= 0;
1746 if (blockNum
== 16 * 4 - 1) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
1748 if (mfCSetBlock(blockNum
, buf8
, NULL
, 0, flags
)) {
1749 PrintAndLog("Can't set magic card block: %d", blockNum
);
1754 if (blockNum
>= 16 * 4) break; // magic card type - mifare 1K
1758 if (blockNum
!= 16 * 4 && blockNum
!= 32 * 4 + 8 * 16){
1759 PrintAndLog("File content error. There must be 64 blocks");
1762 PrintAndLog("Loaded from file: %s", filename
);
1767 int CmdHF14AMfCGetBlk(const char *Cmd
) {
1768 uint8_t memBlock
[16];
1769 uint8_t blockNo
= 0;
1771 memset(memBlock
, 0x00, sizeof(memBlock
));
1773 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1774 PrintAndLog("Usage: hf mf cgetblk <block number>");
1775 PrintAndLog("sample: hf mf cgetblk 1");
1776 PrintAndLog("Get block data from magic Chinese card (only works with!!!)\n");
1780 blockNo
= param_get8(Cmd
, 0);
1782 PrintAndLog("--block number:%2d ", blockNo
);
1784 res
= mfCGetBlock(blockNo
, memBlock
, CSETBLOCK_SINGLE_OPER
);
1786 PrintAndLog("Can't read block. error=%d", res
);
1790 PrintAndLog("block data:%s", sprint_hex(memBlock
, 16));
1795 int CmdHF14AMfCGetSc(const char *Cmd
) {
1796 uint8_t memBlock
[16];
1797 uint8_t sectorNo
= 0;
1799 memset(memBlock
, 0x00, sizeof(memBlock
));
1801 if (strlen(Cmd
) < 1 || param_getchar(Cmd
, 0) == 'h') {
1802 PrintAndLog("Usage: hf mf cgetsc <sector number>");
1803 PrintAndLog("sample: hf mf cgetsc 0");
1804 PrintAndLog("Get sector data from magic Chinese card (only works with!!!)\n");
1808 sectorNo
= param_get8(Cmd
, 0);
1809 if (sectorNo
> 15) {
1810 PrintAndLog("Sector number must be in [0..15] as in MIFARE classic.");
1814 PrintAndLog("--sector number:%d ", sectorNo
);
1816 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
1817 for (i
= 0; i
< 4; i
++) {
1818 if (i
== 1) flags
= 0;
1819 if (i
== 3) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
1821 res
= mfCGetBlock(sectorNo
* 4 + i
, memBlock
, flags
);
1823 PrintAndLog("Can't read block. %d error=%d", sectorNo
* 4 + i
, res
);
1827 PrintAndLog("block %3d data:%s", sectorNo
* 4 + i
, sprint_hex(memBlock
, 16));
1833 int CmdHF14AMfCSave(const char *Cmd
) {
1837 char * fnameptr
= filename
;
1838 uint8_t fillFromEmulator
= 0;
1840 int i
, j
, len
, flags
;
1842 memset(filename
, 0, sizeof(filename
));
1843 memset(buf
, 0, sizeof(buf
));
1845 if (param_getchar(Cmd
, 0) == 'h') {
1846 PrintAndLog("It saves `magic Chinese` card dump into the file `filename.eml` or `cardID.eml`");
1847 PrintAndLog("or into emulator memory (option `e`)");
1848 PrintAndLog("Usage: hf mf esave [file name w/o `.eml`][e]");
1849 PrintAndLog(" sample: hf mf esave ");
1850 PrintAndLog(" hf mf esave filename");
1851 PrintAndLog(" hf mf esave e \n");
1855 char ctmp
= param_getchar(Cmd
, 0);
1856 if (ctmp
== 'e' || ctmp
== 'E') fillFromEmulator
= 1;
1858 if (fillFromEmulator
) {
1859 // put into emulator
1860 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
1861 for (i
= 0; i
< 16 * 4; i
++) {
1862 if (i
== 1) flags
= 0;
1863 if (i
== 16 * 4 - 1) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
1865 if (mfCGetBlock(i
, buf
, flags
)) {
1866 PrintAndLog("Cant get block: %d", i
);
1870 if (mfEmlSetMem(buf
, i
, 1)) {
1871 PrintAndLog("Cant set emul block: %d", i
);
1878 if (len
> 14) len
= 14;
1882 if (mfCGetBlock(0, buf
, CSETBLOCK_SINGLE_OPER
)) {
1883 PrintAndLog("Cant get block: %d", 0);
1886 for (j
= 0; j
< 7; j
++, fnameptr
+= 2)
1887 sprintf(fnameptr
, "%02x", buf
[j
]);
1889 memcpy(filename
, Cmd
, len
);
1893 sprintf(fnameptr
, ".eml");
1896 f
= fopen(filename
, "w+");
1899 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
1900 for (i
= 0; i
< 16 * 4; i
++) {
1901 if (i
== 1) flags
= 0;
1902 if (i
== 16 * 4 - 1) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
1904 if (mfCGetBlock(i
, buf
, flags
)) {
1905 PrintAndLog("Cant get block: %d", i
);
1908 for (j
= 0; j
< 16; j
++)
1909 fprintf(f
, "%02x", buf
[j
]);
1914 PrintAndLog("Saved to file: %s", filename
);
1921 int CmdHF14AMfSniff(const char *Cmd
){
1923 bool wantLogToFile
= 0;
1924 bool wantDecrypt
= 0;
1925 //bool wantSaveToEml = 0; TODO
1926 bool wantSaveToEmlFile
= 0;
1941 uint8_t * bufPtr
= buf
;
1942 memset(buf
, 0x00, 3000);
1944 if (param_getchar(Cmd
, 0) == 'h') {
1945 PrintAndLog("It continuously gets data from the field and saves it to: log, emulator, emulator file.");
1946 PrintAndLog("You can specify:");
1947 PrintAndLog(" l - save encrypted sequence to logfile `uid.log`");
1948 PrintAndLog(" d - decrypt sequence and put it to log file `uid.log`");
1949 PrintAndLog(" n/a e - decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory");
1950 PrintAndLog(" r - decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`");
1951 PrintAndLog("Usage: hf mf sniff [l][d][e][r]");
1952 PrintAndLog(" sample: hf mf sniff l d e");
1956 for (int i
= 0; i
< 4; i
++) {
1957 char ctmp
= param_getchar(Cmd
, i
);
1958 if (ctmp
== 'l' || ctmp
== 'L') wantLogToFile
= true;
1959 if (ctmp
== 'd' || ctmp
== 'D') wantDecrypt
= true;
1960 //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO
1961 if (ctmp
== 'f' || ctmp
== 'F') wantSaveToEmlFile
= true;
1964 printf("-------------------------------------------------------------------------\n");
1965 printf("Executing command. \n");
1966 printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");
1967 printf("Press the key on pc keyboard to abort the client.\n");
1968 printf("-------------------------------------------------------------------------\n");
1970 UsbCommand c
= {CMD_MIFARE_SNIFFER
, {0, 0, 0}};
1971 clearCommandBuffer();
1980 printf("\naborted via keyboard!\n");
1985 if (WaitForResponseTimeout(CMD_ACK
,&resp
,2000)) {
1986 res
= resp
.arg
[0] & 0xff;
1990 if (res
== 0) return 0;
1994 memset(buf
, 0x00, 3000);
1996 memcpy(bufPtr
, resp
.d
.asBytes
, len
);
2001 blockLen
= bufPtr
- buf
;
2004 PrintAndLog("received trace len: %d packages: %d", blockLen
, pckNum
);
2006 while (bufPtr
- buf
+ 9 < blockLen
) {
2007 isTag
= bufPtr
[3] & 0x80 ? true:false;
2009 parity
= *((uint32_t *)(bufPtr
));
2013 if ((len
== 14) && (bufPtr
[0] == 0xff) && (bufPtr
[1] == 0xff)) {
2014 memcpy(uid
, bufPtr
+ 2, 7);
2015 memcpy(atqa
, bufPtr
+ 2 + 7, 2);
2016 uid_len
= (atqa
[0] & 0xC0) == 0x40 ? 7 : 4;
2019 PrintAndLog("tag select uid:%s atqa:0x%02x%02x sak:0x%02x",
2020 sprint_hex(uid
+ (7 - uid_len
), uid_len
),
2024 if (wantLogToFile
|| wantDecrypt
) {
2025 FillFileNameByUID(logHexFileName
, uid
+ (7 - uid_len
), ".log", uid_len
);
2026 AddLogCurrentDT(logHexFileName
);
2029 mfTraceInit(uid
, atqa
, sak
, wantSaveToEmlFile
);
2031 PrintAndLog("%s(%d):%s", isTag
? "TAG":"RDR", num
, sprint_hex(bufPtr
, len
));
2033 AddLogHex(logHexFileName
, isTag
? "TAG: ":"RDR: ", bufPtr
, len
);
2035 mfTraceDecode(bufPtr
, len
, parity
, wantSaveToEmlFile
);
2047 // Tries to identify cardsize.
2048 // Returns <num> where num is:
2050 // 0 - MINI (320bytes)
2056 UsbCommand c
= {CMD_READER_ISO_14443a
, {ISO14A_CONNECT
, 0, 0}};
2060 WaitForResponse(CMD_ACK
,&resp
);
2062 if(resp
.arg
[0] == 0) {
2063 PrintAndLog("iso14443a card select failed");
2067 iso14a_card_select_t
*card
= (iso14a_card_select_t
*)resp
.d
.asBytes
;
2069 PrintAndLog("Trying to detect card size.");
2073 atqa
= (card
->atqa
[1] & 0xff) << 8;
2074 atqa
+= card
->atqa
[0] & 0xff;
2077 // https://code.google.com/p/libnfc/source/browse/libnfc/target-subr.c
2079 PrintAndLog("found ATAQ: %04X SAK: %02X", atqa
, sak
);
2082 // NXP MIFARE Mini 0.3k
2083 if ( (atqa
&& 0xff0f == 0x0004) && (sak
== 0x09) ) return 0;
2085 // MIFARE Classic 1K
2086 if ( (atqa
&& 0xff0f == 0x0004) && (sak
== 0x08) ) return 1;
2088 // MIFARE Classik 4K
2089 if ( (atqa
&& 0xff0f == 0x0002) && (sak
== 0x18) ) return 4;
2091 // SmartMX with MIFARE 1K emulation
2092 if ( (atqa
&& 0xf0ff == 0x0004) ) return 1;
2094 // SmartMX with MIFARE 4K emulation
2095 if ( (atqa
&& 0xf0ff == 0x0002) ) return 4;
2097 // Infineon MIFARE CLASSIC 1K
2098 if ( (atqa
&& 0xffff == 0x0004) && (sak
== 0x88) ) return 1;
2100 // MFC 4K emulated by Nokia 6212 Classic
2101 if ( (atqa
&& 0xffff == 0x0002) && (sak
== 0x38) ) return 4;
2103 // MFC 4K emulated by Nokia 6131 NFC
2104 if ( (atqa
&& 0xffff == 0x0008) && (sak
== 0x38) ) return 4;
2106 // MIFARE Plus (4 Byte UID or 4 Byte RID)
2107 // MIFARE Plus (7 Byte UID)
2109 (atqa
&& 0xffff == 0x0002) ||
2110 (atqa
&& 0xffff == 0x0004) ||
2111 (atqa
&& 0xffff == 0x0042) ||
2112 (atqa
&& 0xffff == 0x0044)
2135 static command_t CommandTable
[] =
2137 {"help", CmdHelp
, 1, "This help"},
2138 {"dbg", CmdHF14AMfDbg
, 0, "Set default debug mode"},
2139 {"rdbl", CmdHF14AMfRdBl
, 0, "Read MIFARE classic block"},
2140 //{"urdbl", CmdHF14AMfURdBl, 0, "Read MIFARE Ultralight block"},
2141 //{"urdcard", CmdHF14AMfURdCard, 0,"Read MIFARE Ultralight Card"},
2142 //{"uwrbl", CmdHF14AMfUWrBl, 0,"Write MIFARE Ultralight block"},
2143 {"rdsc", CmdHF14AMfRdSc
, 0, "Read MIFARE classic sector"},
2144 {"dump", CmdHF14AMfDump
, 0, "Dump MIFARE classic tag to binary file"},
2145 {"restore", CmdHF14AMfRestore
, 0, "Restore MIFARE classic binary file to BLANK tag"},
2146 {"wrbl", CmdHF14AMfWrBl
, 0, "Write MIFARE classic block"},
2147 {"chk", CmdHF14AMfChk
, 0, "Test block keys"},
2148 {"mifare", CmdHF14AMifare
, 0, "Read parity error messages."},
2149 {"nested", CmdHF14AMfNested
, 0, "Test nested authentication"},
2150 {"sniff", CmdHF14AMfSniff
, 0, "Sniff card-reader communication"},
2151 {"sim", CmdHF14AMf1kSim
, 0, "Simulate MIFARE card"},
2152 {"eclr", CmdHF14AMfEClear
, 0, "Clear simulator memory block"},
2153 {"eget", CmdHF14AMfEGet
, 0, "Get simulator memory block"},
2154 {"eset", CmdHF14AMfESet
, 0, "Set simulator memory block"},
2155 {"eload", CmdHF14AMfELoad
, 0, "Load from file emul dump"},
2156 {"esave", CmdHF14AMfESave
, 0, "Save to file emul dump"},
2157 {"ecfill", CmdHF14AMfECFill
, 0, "Fill simulator memory with help of keys from simulator"},
2158 {"ekeyprn", CmdHF14AMfEKeyPrn
, 0, "Print keys from simulator memory"},
2159 {"csetuid", CmdHF14AMfCSetUID
, 0, "Set UID for magic Chinese card"},
2160 {"csetblk", CmdHF14AMfCSetBlk
, 0, "Write block into magic Chinese card"},
2161 {"cgetblk", CmdHF14AMfCGetBlk
, 0, "Read block from magic Chinese card"},
2162 {"cgetsc", CmdHF14AMfCGetSc
, 0, "Read sector from magic Chinese card"},
2163 {"cload", CmdHF14AMfCLoad
, 0, "Load dump into magic Chinese card"},
2164 {"csave", CmdHF14AMfCSave
, 0, "Save dump from magic Chinese card into file or emulator"},
2165 {NULL
, NULL
, 0, NULL
}
2168 int CmdHFMF(const char *Cmd
)
2171 WaitForResponseTimeout(CMD_ACK
,NULL
,100);
2173 CmdsParse(CommandTable
, Cmd
);
2177 int CmdHelp(const char *Cmd
)
2179 CmdsHelp(CommandTable
);