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