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