]>
git.zerfleddert.de Git - proxmark3-svn/blob - client/cmdhfmf.c
a4461e37b9bf76f40b94cfbef9a8899ecfe708aa
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2011,2012 Merlok
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
7 //-----------------------------------------------------------------------------
8 // High frequency MIFARE commands
9 //-----------------------------------------------------------------------------
20 #include "cmdhfmfhard.h"
23 #include "util_posix.h"
26 #include "mifare/mifarehost.h"
28 #include "mifare/mfkey.h"
29 #include "hardnested/hardnested_bf_core.h"
30 #include "cliparser/cliparser.h"
32 #include "mifare/mifaredefault.h"
33 #include "mifare/mifare4.h"
34 #include "mifare/mad.h"
35 #include "mifare/ndef.h"
38 #define NESTED_SECTOR_RETRY 10 // how often we try mfested() until we give up
40 static int CmdHelp ( const char * Cmd
);
42 int CmdHF14AMifare ( const char * Cmd
)
46 isOK
= mfDarkside (& key
);
48 case - 1 : PrintAndLog ( "Button pressed. Aborted." ); return 1 ;
49 case - 2 : PrintAndLog ( "Card is not vulnerable to Darkside attack (doesn't send NACK on authentication requests)." ); return 1 ;
50 case - 3 : PrintAndLog ( "Card is not vulnerable to Darkside attack (its random number generator is not predictable)." ); return 1 ;
51 case - 4 : PrintAndLog ( "Card is not vulnerable to Darkside attack (its random number generator seems to be based on the wellknown" );
52 PrintAndLog ( "generating polynomial with 16 effective bits only, but shows unexpected behaviour." ); return 1 ;
53 case - 5 : PrintAndLog ( "Aborted via keyboard." ); return 1 ;
54 default : PrintAndLog ( "Found valid key:%012" PRIx64
" \n " , key
);
62 int CmdHF14AMfWrBl ( const char * Cmd
)
66 uint8_t key
[ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 };
67 uint8_t bldata
[ 16 ] = { 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
72 PrintAndLog ( "Usage: hf mf wrbl <block number> <key A/B> <key (12 hex symbols)> <block data (32 hex symbols)>" );
73 PrintAndLog ( " sample: hf mf wrbl 0 A FFFFFFFFFFFF 000102030405060708090A0B0C0D0E0F" );
77 blockNo
= param_get8 ( Cmd
, 0 );
78 cmdp
= param_getchar ( Cmd
, 1 );
80 PrintAndLog ( "Key type must be A or B" );
83 if ( cmdp
!= 'A' && cmdp
!= 'a' ) keyType
= 1 ;
84 if ( param_gethex ( Cmd
, 2 , key
, 12 )) {
85 PrintAndLog ( "Key must include 12 HEX symbols" );
88 if ( param_gethex ( Cmd
, 3 , bldata
, 32 )) {
89 PrintAndLog ( "Block data must include 32 HEX symbols" );
92 PrintAndLog ( "--block no:%d, key type:%c, key:%s" , blockNo
, keyType
? 'B' : 'A' , sprint_hex ( key
, 6 ));
93 PrintAndLog ( "--data: %s" , sprint_hex ( bldata
, 16 ));
95 UsbCommand c
= { CMD_MIFARE_WRITEBL
, { blockNo
, keyType
, 0 }};
96 memcpy ( c
. d
. asBytes
, key
, 6 );
97 memcpy ( c
. d
. asBytes
+ 10 , bldata
, 16 );
101 if ( WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 )) {
102 uint8_t isOK
= resp
. arg
[ 0 ] & 0xff ;
103 PrintAndLog ( "isOk:%02x" , isOK
);
105 PrintAndLog ( "Command execute timeout" );
111 int CmdHF14AMfRdBl ( const char * Cmd
)
115 uint8_t key
[ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 };
121 PrintAndLog ( "Usage: hf mf rdbl <block number> <key A/B> <key (12 hex symbols)>" );
122 PrintAndLog ( " sample: hf mf rdbl 0 A FFFFFFFFFFFF " );
126 blockNo
= param_get8 ( Cmd
, 0 );
127 cmdp
= param_getchar ( Cmd
, 1 );
129 PrintAndLog ( "Key type must be A or B" );
132 if ( cmdp
!= 'A' && cmdp
!= 'a' ) keyType
= 1 ;
133 if ( param_gethex ( Cmd
, 2 , key
, 12 )) {
134 PrintAndLog ( "Key must include 12 HEX symbols" );
137 PrintAndLog ( "--block no:%d, key type:%c, key:%s " , blockNo
, keyType
? 'B' : 'A' , sprint_hex ( key
, 6 ));
139 UsbCommand c
= { CMD_MIFARE_READBL
, { blockNo
, keyType
, 0 }};
140 memcpy ( c
. d
. asBytes
, key
, 6 );
144 if ( WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 )) {
145 uint8_t isOK
= resp
. arg
[ 0 ] & 0xff ;
146 uint8_t * data
= resp
. d
. asBytes
;
149 PrintAndLog ( "isOk:%02x data:%s" , isOK
, sprint_hex ( data
, 16 ));
151 PrintAndLog ( "isOk:%02x" , isOK
);
155 if ( mfIsSectorTrailer ( blockNo
) && ( data
[ 6 ] || data
[ 7 ] || data
[ 8 ])) {
156 PrintAndLogEx ( NORMAL
, "Trailer decoded:" );
157 int bln
= mfFirstBlockOfSector ( mfSectorNum ( blockNo
));
158 int blinc
= ( mfNumBlocksPerSector ( mfSectorNum ( blockNo
)) > 4 ) ? 5 : 1 ;
159 for ( int i
= 0 ; i
< 4 ; i
++) {
160 PrintAndLogEx ( NORMAL
, "Access block %d%s: %s" , bln
, (( blinc
> 1 ) && ( i
< 3 ) ? "+" : "" ) , mfGetAccessConditionsDesc ( i
, & data
[ 6 ]));
163 PrintAndLogEx ( NORMAL
, "UserData: %s" , sprint_hex_inrow (& data
[ 9 ], 1 ));
166 PrintAndLog ( "Command execute timeout" );
173 int CmdHF14AMfRdSc ( const char * Cmd
)
176 uint8_t sectorNo
= 0 ;
178 uint8_t key
[ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 };
180 uint8_t * data
= NULL
;
184 PrintAndLog ( "Usage: hf mf rdsc <sector number> <key A/B> <key (12 hex symbols)>" );
185 PrintAndLog ( " sample: hf mf rdsc 0 A FFFFFFFFFFFF " );
189 sectorNo
= param_get8 ( Cmd
, 0 );
191 PrintAndLog ( "Sector number must be less than 40" );
194 cmdp
= param_getchar ( Cmd
, 1 );
195 if ( cmdp
!= 'a' && cmdp
!= 'A' && cmdp
!= 'b' && cmdp
!= 'B' ) {
196 PrintAndLog ( "Key type must be A or B" );
199 if ( cmdp
!= 'A' && cmdp
!= 'a' ) keyType
= 1 ;
200 if ( param_gethex ( Cmd
, 2 , key
, 12 )) {
201 PrintAndLog ( "Key must include 12 HEX symbols" );
204 PrintAndLog ( "--sector no:%d key type:%c key:%s " , sectorNo
, keyType
? 'B' : 'A' , sprint_hex ( key
, 6 ));
206 UsbCommand c
= { CMD_MIFARE_READSC
, { sectorNo
, keyType
, 0 }};
207 memcpy ( c
. d
. asBytes
, key
, 6 );
212 if ( WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 )) {
213 isOK
= resp
. arg
[ 0 ] & 0xff ;
214 data
= resp
. d
. asBytes
;
216 PrintAndLog ( "isOk:%02x" , isOK
);
218 for ( i
= 0 ; i
< ( sectorNo
< 32 ? 3 : 15 ); i
++) {
219 PrintAndLog ( "data : %s" , sprint_hex ( data
+ i
* 16 , 16 ));
221 PrintAndLog ( "trailer: %s" , sprint_hex ( data
+ ( sectorNo
< 32 ? 3 : 15 ) * 16 , 16 ));
223 PrintAndLogEx ( NORMAL
, "Trailer decoded:" );
224 int bln
= mfFirstBlockOfSector ( sectorNo
);
225 int blinc
= ( mfNumBlocksPerSector ( sectorNo
) > 4 ) ? 5 : 1 ;
226 for ( i
= 0 ; i
< 4 ; i
++) {
227 PrintAndLogEx ( NORMAL
, "Access block %d%s: %s" , bln
, (( blinc
> 1 ) && ( i
< 3 ) ? "+" : "" ) , mfGetAccessConditionsDesc ( i
, &( data
+ ( sectorNo
< 32 ? 3 : 15 ) * 16 )[ 6 ]));
230 PrintAndLogEx ( NORMAL
, "UserData: %s" , sprint_hex_inrow (&( data
+ ( sectorNo
< 32 ? 3 : 15 ) * 16 )[ 9 ], 1 ));
233 PrintAndLog ( "Command execute timeout" );
239 uint8_t FirstBlockOfSector ( uint8_t sectorNo
)
244 return 32 * 4 + ( sectorNo
- 32 ) * 16 ;
248 uint8_t NumBlocksPerSector ( uint8_t sectorNo
)
257 static int ParamCardSizeSectors ( const char c
) {
260 case '0' : numSectors
= 5 ; break ;
261 case '2' : numSectors
= 32 ; break ;
262 case '4' : numSectors
= 40 ; break ;
263 default : numSectors
= 16 ;
268 static int ParamCardSizeBlocks ( const char c
) {
269 int numBlocks
= 16 * 4 ;
271 case '0' : numBlocks
= 5 * 4 ; break ;
272 case '2' : numBlocks
= 32 * 4 ; break ;
273 case '4' : numBlocks
= 32 * 4 + 8 * 16 ; break ;
274 default : numBlocks
= 16 * 4 ;
279 int CmdHF14AMfDump ( const char * Cmd
)
281 uint8_t sectorNo
, blockNo
;
283 uint8_t keys
[ 2 ][ 40 ][ 6 ];
284 uint8_t rights
[ 40 ][ 4 ];
285 uint8_t carddata
[ 256 ][ 16 ];
286 uint8_t numSectors
= 16 ;
293 char cmdp
= param_getchar ( Cmd
, 0 );
294 numSectors
= ParamCardSizeSectors ( cmdp
);
296 if ( strlen ( Cmd
) > 3 || cmdp
== 'h' || cmdp
== 'H' ) {
297 PrintAndLog ( "Usage: hf mf dump [card memory] [k|m]" );
298 PrintAndLog ( " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K" );
299 PrintAndLog ( " k: Always try using both Key A and Key B for each sector, even if access bits would prohibit it" );
300 PrintAndLog ( " m: When missing access bits or keys, replace that block with NULL" );
302 PrintAndLog ( "Samples: hf mf dump" );
303 PrintAndLog ( " hf mf dump 4" );
304 PrintAndLog ( " hf mf dump 4 m" );
308 char opts
= param_getchar ( Cmd
, 1 );
309 bool useBothKeysAlways
= false ;
310 if ( opts
== 'k' || opts
== 'K' ) useBothKeysAlways
= true ;
311 bool nullMissingKeys
= false ;
312 if ( opts
== 'm' || opts
== 'M' ) nullMissingKeys
= true ;
314 if (( fin
= fopen ( "dumpkeys.bin" , "rb" )) == NULL
) {
315 PrintAndLog ( "Could not find file dumpkeys.bin" );
319 // Read keys from file
320 for ( int group
= 0 ; group
<= 1 ; group
++) {
321 for ( sectorNo
= 0 ; sectorNo
< numSectors
; sectorNo
++) {
322 size_t bytes_read
= fread ( keys
[ group
][ sectorNo
], 1 , 6 , fin
);
323 if ( bytes_read
!= 6 ) {
324 PrintAndLog ( "File reading error." );
333 PrintAndLog ( "|-----------------------------------------|" );
334 PrintAndLog ( "|------ Reading sector access bits...-----|" );
335 PrintAndLog ( "|-----------------------------------------|" );
337 for ( sectorNo
= 0 ; sectorNo
< numSectors
; sectorNo
++) {
338 for ( tries
= 0 ; tries
< 3 ; tries
++) {
339 UsbCommand c
= { CMD_MIFARE_READBL
, { FirstBlockOfSector ( sectorNo
) + NumBlocksPerSector ( sectorNo
) - 1 , 0 , 0 }};
340 // At least the Access Conditions can always be read with key A.
341 memcpy ( c
. d
. asBytes
, keys
[ 0 ][ sectorNo
], 6 );
344 if ( WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 )) {
345 uint8_t isOK
= resp
. arg
[ 0 ] & 0xff ;
346 uint8_t * data
= resp
. d
. asBytes
;
348 rights
[ sectorNo
][ 0 ] = (( data
[ 7 ] & 0x10 )>> 2 ) | (( data
[ 8 ] & 0x1 )<< 1 ) | (( data
[ 8 ] & 0x10 )>> 4 ); // C1C2C3 for data area 0
349 rights
[ sectorNo
][ 1 ] = (( data
[ 7 ] & 0x20 )>> 3 ) | (( data
[ 8 ] & 0x2 )<< 0 ) | (( data
[ 8 ] & 0x20 )>> 5 ); // C1C2C3 for data area 1
350 rights
[ sectorNo
][ 2 ] = (( data
[ 7 ] & 0x40 )>> 4 ) | (( data
[ 8 ] & 0x4 )>> 1 ) | (( data
[ 8 ] & 0x40 )>> 6 ); // C1C2C3 for data area 2
351 rights
[ sectorNo
][ 3 ] = (( data
[ 7 ] & 0x80 )>> 5 ) | (( data
[ 8 ] & 0x8 )>> 2 ) | (( data
[ 8 ] & 0x80 )>> 7 ); // C1C2C3 for sector trailer
353 } else if ( tries
== 2 ) { // on last try set defaults
354 PrintAndLog ( "Could not get access rights for sector %2d. Trying with defaults..." , sectorNo
);
355 rights
[ sectorNo
][ 0 ] = rights
[ sectorNo
][ 1 ] = rights
[ sectorNo
][ 2 ] = 0x00 ;
356 rights
[ sectorNo
][ 3 ] = 0x01 ;
359 PrintAndLog ( "Command execute timeout when trying to read access rights for sector %2d. Trying with defaults..." , sectorNo
);
360 rights
[ sectorNo
][ 0 ] = rights
[ sectorNo
][ 1 ] = rights
[ sectorNo
][ 2 ] = 0x00 ;
361 rights
[ sectorNo
][ 3 ] = 0x01 ;
366 PrintAndLog ( "|-----------------------------------------|" );
367 PrintAndLog ( "|----- Dumping all blocks to file... -----|" );
368 PrintAndLog ( "|-----------------------------------------|" );
371 for ( sectorNo
= 0 ; isOK
&& sectorNo
< numSectors
; sectorNo
++) {
372 for ( blockNo
= 0 ; isOK
&& blockNo
< NumBlocksPerSector ( sectorNo
); blockNo
++) {
373 bool received
= false ;
374 for ( tries
= 0 ; tries
< 3 ; tries
++) {
375 if ( blockNo
== NumBlocksPerSector ( sectorNo
) - 1 ) { // sector trailer. At least the Access Conditions can always be read with key A.
376 UsbCommand c
= { CMD_MIFARE_READBL
, { FirstBlockOfSector ( sectorNo
) + blockNo
, 0 , 0 }};
377 memcpy ( c
. d
. asBytes
, keys
[ 0 ][ sectorNo
], 6 );
379 received
= WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 );
380 } else if ( useBothKeysAlways
) {
381 // Always try both keys, even if access conditions wouldn't work.
382 for ( int k
= 0 ; k
<= 1 ; k
++) {
383 UsbCommand c
= { CMD_MIFARE_READBL
, { FirstBlockOfSector ( sectorNo
) + blockNo
, 1 , 0 }};
384 memcpy ( c
. d
. asBytes
, keys
[ k
][ sectorNo
], 6 );
386 received
= WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 );
388 // Don't try the other one on success.
389 if ( resp
. arg
[ 0 ] & 0xff ) break ;
391 } else { // data block. Check if it can be read with key A or key B
392 uint8_t data_area
= sectorNo
< 32 ? blockNo
: blockNo
/ 5 ;
393 if (( rights
[ sectorNo
][ data_area
] == 0x03 ) || ( rights
[ sectorNo
][ data_area
] == 0x05 )) { // only key B would work
394 UsbCommand c
= { CMD_MIFARE_READBL
, { FirstBlockOfSector ( sectorNo
) + blockNo
, 1 , 0 }};
395 memcpy ( c
. d
. asBytes
, keys
[ 1 ][ sectorNo
], 6 );
397 received
= WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 );
398 } else if ( rights
[ sectorNo
][ data_area
] == 0x07 ) { // no key would work
399 PrintAndLog ( "Access rights do not allow reading of sector %2d block %3d" , sectorNo
, blockNo
);
400 if ( nullMissingKeys
) {
401 memset ( resp
. d
. asBytes
, 0 , 16 );
403 PrintAndLog ( " ... filling the block with NULL" );
409 } else { // key A would work
410 UsbCommand c
= { CMD_MIFARE_READBL
, { FirstBlockOfSector ( sectorNo
) + blockNo
, 0 , 0 }};
411 memcpy ( c
. d
. asBytes
, keys
[ 0 ][ sectorNo
], 6 );
413 received
= WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 );
417 isOK
= resp
. arg
[ 0 ] & 0xff ;
423 isOK
= resp
. arg
[ 0 ] & 0xff ;
424 uint8_t * data
= resp
. d
. asBytes
;
425 if ( blockNo
== NumBlocksPerSector ( sectorNo
) - 1 ) { // sector trailer. Fill in the keys.
426 memcpy ( data
, keys
[ 0 ][ sectorNo
], 6 );
427 memcpy ( data
+ 10 , keys
[ 1 ][ sectorNo
], 6 );
430 memcpy ( carddata
[ FirstBlockOfSector ( sectorNo
) + blockNo
], data
, 16 );
431 PrintAndLog ( "Successfully read block %2d of sector %2d." , blockNo
, sectorNo
);
433 PrintAndLog ( "Could not read block %2d of sector %2d" , blockNo
, sectorNo
);
439 PrintAndLog ( "Command execute timeout when trying to read block %2d of sector %2d." , blockNo
, sectorNo
);
446 if (( fout
= fopen ( "dumpdata.bin" , "wb" )) == NULL
) {
447 PrintAndLog ( "Could not create file name dumpdata.bin" );
450 uint16_t numblocks
= FirstBlockOfSector ( numSectors
- 1 ) + NumBlocksPerSector ( numSectors
- 1 );
451 fwrite ( carddata
, 1 , 16 * numblocks
, fout
);
453 PrintAndLog ( "Dumped %d blocks (%d bytes) to file dumpdata.bin" , numblocks
, 16 * numblocks
);
459 int CmdHF14AMfRestore ( const char * Cmd
)
461 uint8_t sectorNo
, blockNo
;
463 uint8_t key
[ 6 ] = { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
464 uint8_t bldata
[ 16 ] = { 0x00 };
472 char cmdp
= param_getchar ( Cmd
, 0 );
474 case '0' : numSectors
= 5 ; break ;
476 case '\0' : numSectors
= 16 ; break ;
477 case '2' : numSectors
= 32 ; break ;
478 case '4' : numSectors
= 40 ; break ;
479 default : numSectors
= 16 ;
482 if ( strlen ( Cmd
) > 1 || cmdp
== 'h' || cmdp
== 'H' ) {
483 PrintAndLog ( "Usage: hf mf restore [card memory]" );
484 PrintAndLog ( " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K" );
486 PrintAndLog ( "Samples: hf mf restore" );
487 PrintAndLog ( " hf mf restore 4" );
491 if (( fkeys
= fopen ( "dumpkeys.bin" , "rb" )) == NULL
) {
492 PrintAndLog ( "Could not find file dumpkeys.bin" );
496 for ( sectorNo
= 0 ; sectorNo
< numSectors
; sectorNo
++) {
497 size_t bytes_read
= fread ( keyA
[ sectorNo
], 1 , 6 , fkeys
);
498 if ( bytes_read
!= 6 ) {
499 PrintAndLog ( "File reading error (dumpkeys.bin)." );
505 for ( sectorNo
= 0 ; sectorNo
< numSectors
; sectorNo
++) {
506 size_t bytes_read
= fread ( keyB
[ sectorNo
], 1 , 6 , fkeys
);
507 if ( bytes_read
!= 6 ) {
508 PrintAndLog ( "File reading error (dumpkeys.bin)." );
516 if (( fdump
= fopen ( "dumpdata.bin" , "rb" )) == NULL
) {
517 PrintAndLog ( "Could not find file dumpdata.bin" );
520 PrintAndLog ( "Restoring dumpdata.bin to card" );
522 for ( sectorNo
= 0 ; sectorNo
< numSectors
; sectorNo
++) {
523 for ( blockNo
= 0 ; blockNo
< NumBlocksPerSector ( sectorNo
); blockNo
++) {
524 UsbCommand c
= { CMD_MIFARE_WRITEBL
, { FirstBlockOfSector ( sectorNo
) + blockNo
, keyType
, 0 }};
525 memcpy ( c
. d
. asBytes
, key
, 6 );
527 size_t bytes_read
= fread ( bldata
, 1 , 16 , fdump
);
528 if ( bytes_read
!= 16 ) {
529 PrintAndLog ( "File reading error (dumpdata.bin)." );
534 if ( blockNo
== NumBlocksPerSector ( sectorNo
) - 1 ) { // sector trailer
535 bldata
[ 0 ] = ( keyA
[ sectorNo
][ 0 ]);
536 bldata
[ 1 ] = ( keyA
[ sectorNo
][ 1 ]);
537 bldata
[ 2 ] = ( keyA
[ sectorNo
][ 2 ]);
538 bldata
[ 3 ] = ( keyA
[ sectorNo
][ 3 ]);
539 bldata
[ 4 ] = ( keyA
[ sectorNo
][ 4 ]);
540 bldata
[ 5 ] = ( keyA
[ sectorNo
][ 5 ]);
541 bldata
[ 10 ] = ( keyB
[ sectorNo
][ 0 ]);
542 bldata
[ 11 ] = ( keyB
[ sectorNo
][ 1 ]);
543 bldata
[ 12 ] = ( keyB
[ sectorNo
][ 2 ]);
544 bldata
[ 13 ] = ( keyB
[ sectorNo
][ 3 ]);
545 bldata
[ 14 ] = ( keyB
[ sectorNo
][ 4 ]);
546 bldata
[ 15 ] = ( keyB
[ sectorNo
][ 5 ]);
549 PrintAndLog ( "Writing to block %3d: %s" , FirstBlockOfSector ( sectorNo
) + blockNo
, sprint_hex ( bldata
, 16 ));
551 memcpy ( c
. d
. asBytes
+ 10 , bldata
, 16 );
555 if ( WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 )) {
556 uint8_t isOK
= resp
. arg
[ 0 ] & 0xff ;
557 PrintAndLog ( "isOk:%02x" , isOK
);
559 PrintAndLog ( "Command execute timeout" );
568 //----------------------------------------------
570 //----------------------------------------------
572 static void parseParamTDS ( const char * Cmd
, const uint8_t indx
, bool * paramT
, bool * paramD
, uint8_t * timeout
) {
574 int len
= param_getlength ( Cmd
, indx
);
575 if ( len
> 0 && len
< 4 ){
576 param_getstr ( Cmd
, indx
, ctmp3
, sizeof ( ctmp3
));
578 * paramT
|= ( ctmp3
[ 0 ] == 't' || ctmp3
[ 0 ] == 'T' );
579 * paramD
|= ( ctmp3
[ 0 ] == 'd' || ctmp3
[ 0 ] == 'D' );
580 bool paramS1
= * paramT
|| * paramD
;
582 // slow and very slow
583 if ( ctmp3
[ 0 ] == 's' || ctmp3
[ 0 ] == 'S' || ctmp3
[ 1 ] == 's' || ctmp3
[ 1 ] == 'S' ) {
584 * timeout
= 11 ; // slow
586 if (! paramS1
&& ( ctmp3
[ 1 ] == 's' || ctmp3
[ 1 ] == 'S' )) {
587 * timeout
= 53 ; // very slow
589 if ( paramS1
&& ( ctmp3
[ 2 ] == 's' || ctmp3
[ 2 ] == 'S' )) {
590 * timeout
= 53 ; // very slow
596 int CmdHF14AMfNested ( const char * Cmd
)
598 int i
, j
, res
, iterations
;
599 sector_t
* e_sector
= NULL
;
602 uint8_t trgBlockNo
= 0 ;
603 uint8_t trgKeyType
= 0 ;
604 uint8_t SectorsCnt
= 0 ;
605 uint8_t key
[ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 };
606 uint8_t keyBlock
[ MifareDefaultKeysSize
* 6 ];
608 // timeout in units. (ms * 106)/10 or us*0.0106
609 uint8_t btimeout14a
= MF_CHKKEYS_DEFTIMEOUT
; // fast by default
611 bool autosearchKey
= false ;
613 bool transferToEml
= false ;
614 bool createDumpFile
= false ;
616 uint8_t standart
[ 6 ] = { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
617 uint8_t tempkey
[ 6 ] = { 0xFF , 0xFF , 0xFF , 0xFF , 0xFF , 0xFF };
622 PrintAndLog ( "Usage:" );
623 PrintAndLog ( " all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t|d|s|ss]" );
624 PrintAndLog ( " all sectors autosearch key: hf mf nested <card memory> * [t|d|s|ss]" );
625 PrintAndLog ( " one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>" );
626 PrintAndLog ( " <target block number> <target key A/B> [t]" );
628 PrintAndLog ( "card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K" );
629 PrintAndLog ( "t - transfer keys to emulator memory" );
630 PrintAndLog ( "d - write keys to binary file dumpkeys.bin" );
631 PrintAndLog ( "s - Slow (1ms) check keys (required by some non standard cards)" );
632 PrintAndLog ( "ss - Very slow (5ms) check keys" );
634 PrintAndLog ( " sample1: hf mf nested 1 0 A FFFFFFFFFFFF " );
635 PrintAndLog ( " sample2: hf mf nested 1 0 A FFFFFFFFFFFF t " );
636 PrintAndLog ( " sample3: hf mf nested 1 0 A FFFFFFFFFFFF d " );
637 PrintAndLog ( " sample4: hf mf nested o 0 A FFFFFFFFFFFF 4 A" );
638 PrintAndLog ( " sample5: hf mf nested 1 * t" );
639 PrintAndLog ( " sample6: hf mf nested 1 * ss" );
644 cmdp
= param_getchar ( Cmd
, 0 );
645 if ( cmdp
== 'o' || cmdp
== 'O' ) {
649 SectorsCnt
= ParamCardSizeSectors ( cmdp
);
652 // <block number>. number or autosearch key (*)
653 if ( param_getchar ( Cmd
, 1 ) == '*' ) {
654 autosearchKey
= true ;
656 parseParamTDS ( Cmd
, 2 , & transferToEml
, & createDumpFile
, & btimeout14a
);
658 PrintAndLog ( "--nested. sectors:%2d, block no:*, eml:%c, dmp=%c checktimeout=%d us" ,
659 SectorsCnt
, transferToEml
? 'y' : 'n' , createDumpFile
? 'y' : 'n' , (( int ) btimeout14a
* 10000 ) / 106 );
661 blockNo
= param_get8 ( Cmd
, 1 );
663 ctmp
= param_getchar ( Cmd
, 2 );
664 if ( ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B' ) {
665 PrintAndLog ( "Key type must be A or B" );
669 if ( ctmp
!= 'A' && ctmp
!= 'a' )
672 if ( param_gethex ( Cmd
, 3 , key
, 12 )) {
673 PrintAndLog ( "Key must include 12 HEX symbols" );
677 // check if we can authenticate to sector
678 res
= mfCheckKeys ( blockNo
, keyType
, true , 1 , key
, & key64
);
680 PrintAndLog ( "Can't authenticate to block:%3d key type:%c key:%s" , blockNo
, keyType
? 'B' : 'A' , sprint_hex ( key
, 6 ));
686 trgBlockNo
= param_get8 ( Cmd
, 4 );
688 ctmp
= param_getchar ( Cmd
, 5 );
689 if ( ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B' ) {
690 PrintAndLog ( "Target key type must be A or B" );
693 if ( ctmp
!= 'A' && ctmp
!= 'a' )
696 parseParamTDS ( Cmd
, 6 , & transferToEml
, & createDumpFile
, & btimeout14a
);
698 parseParamTDS ( Cmd
, 4 , & transferToEml
, & createDumpFile
, & btimeout14a
);
701 PrintAndLog ( "--nested. sectors:%2d, block no:%3d, key type:%c, eml:%c, dmp=%c checktimeout=%d us" ,
702 SectorsCnt
, blockNo
, keyType
? 'B' : 'A' , transferToEml
? 'y' : 'n' , createDumpFile
? 'y' : 'n' , (( int ) btimeout14a
* 10000 ) / 106 );
706 if ( cmdp
== 'o' ) { // ------------------------------------ one sector working
707 PrintAndLog ( "--target block no:%3d, target key type:%c " , trgBlockNo
, trgKeyType
? 'B' : 'A' );
708 int16_t isOK
= mfnested ( blockNo
, keyType
, key
, trgBlockNo
, trgKeyType
, keyBlock
, true );
711 case - 1 : PrintAndLog ( "Error: No response from Proxmark. \n " ); break ;
712 case - 2 : PrintAndLog ( "Button pressed. Aborted. \n " ); break ;
713 case - 3 : PrintAndLog ( "Tag isn't vulnerable to Nested Attack (random numbers are not predictable). \n " ); break ;
714 default : PrintAndLog ( "Unknown Error. \n " );
718 key64
= bytes_to_num ( keyBlock
, 6 );
720 PrintAndLog ( "Found valid key:%012" PRIx64
, key64
);
722 // transfer key to the emulator
724 uint8_t sectortrailer
;
725 if ( trgBlockNo
< 32 * 4 ) { // 4 block sector
726 sectortrailer
= trgBlockNo
| 0x03 ;
727 } else { // 16 block sector
728 sectortrailer
= trgBlockNo
| 0x0f ;
730 mfEmlGetMem ( keyBlock
, sectortrailer
, 1 );
733 num_to_bytes ( key64
, 6 , keyBlock
);
735 num_to_bytes ( key64
, 6 , & keyBlock
[ 10 ]);
736 mfEmlSetMem ( keyBlock
, sectortrailer
, 1 );
737 PrintAndLog ( "Key transferred to emulator memory." );
740 PrintAndLog ( "No valid key found" );
743 else { // ------------------------------------ multiple sectors working
745 msclock1
= msclock ();
747 e_sector
= calloc ( SectorsCnt
, sizeof ( sector_t
));
748 if ( e_sector
== NULL
) return 1 ;
750 //test current key and additional standard keys first
751 for ( int defaultKeyCounter
= 0 ; defaultKeyCounter
< MifareDefaultKeysSize
; defaultKeyCounter
++){
752 num_to_bytes ( MifareDefaultKeys
[ defaultKeyCounter
], 6 , ( uint8_t *)( keyBlock
+ defaultKeyCounter
* 6 ));
755 PrintAndLog ( "Testing known keys. Sector count=%d" , SectorsCnt
);
756 mfCheckKeysSec ( SectorsCnt
, 2 , btimeout14a
, true , MifareDefaultKeysSize
, keyBlock
, e_sector
);
758 // get known key from array
759 bool keyFound
= false ;
761 for ( i
= 0 ; i
< SectorsCnt
; i
++) {
762 for ( j
= 0 ; j
< 2 ; j
++) {
763 if ( e_sector
[ i
]. foundKey
[ j
]) {
767 num_to_bytes ( e_sector
[ i
]. Key
[ j
], 6 , key
);
775 // Can't found a key....
777 PrintAndLog ( "Can't found any of the known keys." );
781 PrintAndLog ( "--auto key. block no:%3d, key type:%c key:%s" , blockNo
, keyType
? 'B' : 'A' , sprint_hex ( key
, 6 ));
786 PrintAndLog ( "nested..." );
787 bool calibrate
= true ;
788 for ( i
= 0 ; i
< NESTED_SECTOR_RETRY
; i
++) {
789 for ( uint8_t sectorNo
= 0 ; sectorNo
< SectorsCnt
; sectorNo
++) {
790 for ( trgKeyType
= 0 ; trgKeyType
< 2 ; trgKeyType
++) {
791 if ( e_sector
[ sectorNo
]. foundKey
[ trgKeyType
]) continue ;
792 PrintAndLog ( "-----------------------------------------------" );
793 int16_t isOK
= mfnested ( blockNo
, keyType
, key
, FirstBlockOfSector ( sectorNo
), trgKeyType
, keyBlock
, calibrate
);
796 case - 1 : PrintAndLog ( "Error: No response from Proxmark. \n " ); break ;
797 case - 2 : PrintAndLog ( "Button pressed. Aborted. \n " ); break ;
798 case - 3 : PrintAndLog ( "Tag isn't vulnerable to Nested Attack (random numbers are not predictable). \n " ); break ;
799 default : PrintAndLog ( "Unknown Error. \n " );
809 key64
= bytes_to_num ( keyBlock
, 6 );
811 PrintAndLog ( "Found valid key:%012" PRIx64
, key64
);
812 e_sector
[ sectorNo
]. foundKey
[ trgKeyType
] = 1 ;
813 e_sector
[ sectorNo
]. Key
[ trgKeyType
] = key64
;
815 // try to check this key as a key to the other sectors
816 mfCheckKeysSec ( SectorsCnt
, 2 , btimeout14a
, true , 1 , keyBlock
, e_sector
);
822 // print nested statistic
823 PrintAndLog ( " \n\n ----------------------------------------------- \n Nested statistic: \n Iterations count: %d" , iterations
);
824 PrintAndLog ( "Time in nested: %1.3f (%1.3f sec per key)" , (( float )( msclock () - msclock1
))/ 1000.0 , (( float )( msclock () - msclock1
))/ iterations
/ 1000.0 );
827 PrintAndLog ( "|---|----------------|---|----------------|---|" );
828 PrintAndLog ( "|sec|key A |res|key B |res|" );
829 PrintAndLog ( "|---|----------------|---|----------------|---|" );
830 for ( i
= 0 ; i
< SectorsCnt
; i
++) {
831 PrintAndLog ( "|%03d| %012" PRIx64
" | %d | %012" PRIx64
" | %d |" , i
,
832 e_sector
[ i
]. Key
[ 0 ], e_sector
[ i
]. foundKey
[ 0 ], e_sector
[ i
]. Key
[ 1 ], e_sector
[ i
]. foundKey
[ 1 ]);
834 PrintAndLog ( "|---|----------------|---|----------------|---|" );
836 // transfer keys to the emulator memory
838 for ( i
= 0 ; i
< SectorsCnt
; i
++) {
839 mfEmlGetMem ( keyBlock
, FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 , 1 );
840 if ( e_sector
[ i
]. foundKey
[ 0 ])
841 num_to_bytes ( e_sector
[ i
]. Key
[ 0 ], 6 , keyBlock
);
842 if ( e_sector
[ i
]. foundKey
[ 1 ])
843 num_to_bytes ( e_sector
[ i
]. Key
[ 1 ], 6 , & keyBlock
[ 10 ]);
844 mfEmlSetMem ( keyBlock
, FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 , 1 );
846 PrintAndLog ( "Keys transferred to emulator memory." );
850 if ( createDumpFile
) {
851 if (( fkeys
= fopen ( "dumpkeys.bin" , "wb" )) == NULL
) {
852 PrintAndLog ( "Could not create file dumpkeys.bin" );
856 PrintAndLog ( "Printing keys to binary file dumpkeys.bin..." );
857 for ( i
= 0 ; i
< SectorsCnt
; i
++) {
858 if ( e_sector
[ i
]. foundKey
[ 0 ]){
859 num_to_bytes ( e_sector
[ i
]. Key
[ 0 ], 6 , tempkey
);
860 fwrite ( tempkey
, 1 , 6 , fkeys
);
863 fwrite ( & standart
, 1 , 6 , fkeys
);
866 for ( i
= 0 ; i
< SectorsCnt
; i
++) {
867 if ( e_sector
[ i
]. foundKey
[ 1 ]){
868 num_to_bytes ( e_sector
[ i
]. Key
[ 1 ], 6 , tempkey
);
869 fwrite ( tempkey
, 1 , 6 , fkeys
);
872 fwrite ( & standart
, 1 , 6 , fkeys
);
884 int CmdHF14AMfNestedHard ( const char * Cmd
)
888 uint8_t trgBlockNo
= 0 ;
889 uint8_t trgKeyType
= 0 ;
890 uint8_t key
[ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 };
891 uint8_t trgkey
[ 6 ] = { 0 , 0 , 0 , 0 , 0 , 0 };
894 ctmp
= param_getchar ( Cmd
, 0 );
896 if ( ctmp
!= 'R' && ctmp
!= 'r' && ctmp
!= 'T' && ctmp
!= 't' && strlen ( Cmd
) < 20 ) {
897 PrintAndLog ( "Usage:" );
898 PrintAndLog ( " hf mf hardnested <block number> <key A|B> <key (12 hex symbols)>" );
899 PrintAndLog ( " <target block number> <target key A|B> [known target key (12 hex symbols)] [w] [s]" );
900 PrintAndLog ( " or hf mf hardnested r [known target key]" );
902 PrintAndLog ( "Options: " );
903 PrintAndLog ( " w: Acquire nonces and write them to binary file nonces.bin" );
904 PrintAndLog ( " s: Slower acquisition (required by some non standard cards)" );
905 PrintAndLog ( " r: Read nonces.bin and start attack" );
906 PrintAndLog ( " iX: set type of SIMD instructions. Without this flag programs autodetect it." );
907 PrintAndLog ( " i5: AVX512" );
908 PrintAndLog ( " i2: AVX2" );
909 PrintAndLog ( " ia: AVX" );
910 PrintAndLog ( " is: SSE2" );
911 PrintAndLog ( " im: MMX" );
912 PrintAndLog ( " in: none (use CPU regular instruction set)" );
914 PrintAndLog ( " sample1: hf mf hardnested 0 A FFFFFFFFFFFF 4 A" );
915 PrintAndLog ( " sample2: hf mf hardnested 0 A FFFFFFFFFFFF 4 A w" );
916 PrintAndLog ( " sample3: hf mf hardnested 0 A FFFFFFFFFFFF 4 A w s" );
917 PrintAndLog ( " sample4: hf mf hardnested r" );
919 PrintAndLog ( "Add the known target key to check if it is present in the remaining key space:" );
920 PrintAndLog ( " sample5: hf mf hardnested 0 A A0A1A2A3A4A5 4 A FFFFFFFFFFFF" );
924 bool know_target_key
= false ;
925 bool nonce_file_read
= false ;
926 bool nonce_file_write
= false ;
932 if ( ctmp
== 'R' || ctmp
== 'r' ) {
933 nonce_file_read
= true ;
935 if (! param_gethex ( Cmd
, 1 , trgkey
, 12 )) {
936 know_target_key
= true ;
939 } else if ( ctmp
== 'T' || ctmp
== 't' ) {
940 tests
= param_get32ex ( Cmd
, 1 , 100 , 10 );
942 if (! param_gethex ( Cmd
, 2 , trgkey
, 12 )) {
943 know_target_key
= true ;
947 blockNo
= param_get8 ( Cmd
, 0 );
948 ctmp
= param_getchar ( Cmd
, 1 );
949 if ( ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B' ) {
950 PrintAndLog ( "Key type must be A or B" );
953 if ( ctmp
!= 'A' && ctmp
!= 'a' ) {
957 if ( param_gethex ( Cmd
, 2 , key
, 12 )) {
958 PrintAndLog ( "Key must include 12 HEX symbols" );
962 trgBlockNo
= param_get8 ( Cmd
, 3 );
963 ctmp
= param_getchar ( Cmd
, 4 );
964 if ( ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B' ) {
965 PrintAndLog ( "Target key type must be A or B" );
968 if ( ctmp
!= 'A' && ctmp
!= 'a' ) {
974 if (! param_gethex ( Cmd
, 5 , trgkey
, 12 )) {
975 know_target_key
= true ;
980 while (( ctmp
= param_getchar ( Cmd
, i
))) {
981 if ( ctmp
== 's' || ctmp
== 'S' ) {
983 } else if ( ctmp
== 'w' || ctmp
== 'W' ) {
984 nonce_file_write
= true ;
985 } else if ( param_getlength ( Cmd
, i
) == 2 && ctmp
== 'i' ) {
988 PrintAndLog ( "Possible options are w , s and/or iX" );
995 SetSIMDInstr ( SIMD_AUTO
);
997 while (( ctmp
= param_getchar ( Cmd
, iindx
))) {
998 if ( param_getlength ( Cmd
, iindx
) == 2 && ctmp
== 'i' ) {
999 switch ( param_getchar_indx ( Cmd
, 1 , iindx
)) {
1001 SetSIMDInstr ( SIMD_AVX512
);
1004 SetSIMDInstr ( SIMD_AVX2
);
1007 SetSIMDInstr ( SIMD_AVX
);
1010 SetSIMDInstr ( SIMD_SSE2
);
1013 SetSIMDInstr ( SIMD_MMX
);
1016 SetSIMDInstr ( SIMD_NONE
);
1019 PrintAndLog ( "Unknown SIMD type. %c" , param_getchar_indx ( Cmd
, 1 , iindx
));
1027 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 " ,
1030 trgkey
[ 0 ], trgkey
[ 1 ], trgkey
[ 2 ], trgkey
[ 3 ], trgkey
[ 4 ], trgkey
[ 5 ],
1031 know_target_key
? "" : " (not set)" ,
1032 nonce_file_write
? "write" : nonce_file_read
? "read" : "none" ,
1036 int16_t isOK
= mfnestedhard ( blockNo
, keyType
, key
, trgBlockNo
, trgKeyType
, know_target_key
? trgkey
: NULL
, nonce_file_read
, nonce_file_write
, slow
, tests
);
1040 case 1 : PrintAndLog ( "Error: No response from Proxmark. \n " ); break ;
1041 case 2 : PrintAndLog ( "Button pressed. Aborted. \n " ); break ;
1051 int CmdHF14AMfChk ( const char * Cmd
)
1053 if ( strlen ( Cmd
)< 3 ) {
1054 PrintAndLog ( "Usage: hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t|d|s|ss] [<key (12 hex symbols)>] [<dic (*.dic)>]" );
1055 PrintAndLog ( " * - all sectors" );
1056 PrintAndLog ( "card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K" );
1057 PrintAndLog ( "d - write keys to binary file (not used when <block number> supplied)" );
1058 PrintAndLog ( "t - write keys to emulator memory" );
1059 PrintAndLog ( "s - slow execute. timeout 1ms" );
1060 PrintAndLog ( "ss - very slow execute. timeout 5ms" );
1061 PrintAndLog ( " sample: hf mf chk 0 A 1234567890ab keys.dic" );
1062 PrintAndLog ( " hf mf chk *1 ? t" );
1063 PrintAndLog ( " hf mf chk *1 ? d" );
1064 PrintAndLog ( " hf mf chk *1 ? s" );
1065 PrintAndLog ( " hf mf chk *1 ? dss" );
1070 char filename
[ FILE_PATH_SIZE
]={ 0 };
1072 uint8_t * keyBlock
= NULL
, * p
;
1073 uint16_t stKeyBlock
= 20 ;
1078 uint8_t blockNo
= 0 ;
1079 uint8_t SectorsCnt
= 0 ;
1080 uint8_t keyType
= 0 ;
1082 // timeout in units. (ms * 106)/10 or us*0.0106
1083 uint8_t btimeout14a
= MF_CHKKEYS_DEFTIMEOUT
; // fast by default
1084 bool param3InUse
= false ;
1085 bool transferToEml
= 0 ;
1086 bool createDumpFile
= 0 ;
1087 bool singleBlock
= false ; // Flag to ID if a single or multi key check
1088 uint8_t keyFoundCount
= 0 ; // Counter to display the number of keys found/transfered to emulator
1090 sector_t
* e_sector
= NULL
;
1092 keyBlock
= calloc ( stKeyBlock
, 6 );
1093 if ( keyBlock
== NULL
) return 1 ;
1095 int defaultKeysSize
= MifareDefaultKeysSize
;
1096 for ( int defaultKeyCounter
= 0 ; defaultKeyCounter
< defaultKeysSize
; defaultKeyCounter
++){
1097 num_to_bytes ( MifareDefaultKeys
[ defaultKeyCounter
], 6 , ( uint8_t *)( keyBlock
+ defaultKeyCounter
* 6 ));
1100 if ( param_getchar ( Cmd
, 0 )== '*' ) {
1101 SectorsCnt
= ParamCardSizeSectors ( param_getchar ( Cmd
+ 1 , 0 ));
1104 blockNo
= param_get8 ( Cmd
, 0 );
1105 // Singe Key check, so Set Sector count to cover sectors (1 to sector that contains the block)
1106 // 1 and 2 Cards : Sector = blockNo/4 + 1
1107 // Sectors 0 - 31 : 4 blocks per sector : Blocks 0 - 127
1108 // Sectors 32 - 39 : 16 blocks per sector : Blocks 128 - 255 (4K)
1109 if ( blockNo
< 128 ) SectorsCnt
= ( blockNo
/ 4 ) + 1 ;
1110 else SectorsCnt
= 32 + (( blockNo
- 128 )/ 16 ) + 1 ;
1112 singleBlock
= true ; // Set flag for single key check
1115 ctmp
= param_getchar ( Cmd
, 1 );
1116 clen
= param_getlength ( Cmd
, 1 );
1129 PrintAndLog ( "Key type must be A , B or ?" );
1135 parseParamTDS ( Cmd
, 2 , & transferToEml
, & createDumpFile
, & btimeout14a
);
1137 if ( singleBlock
& createDumpFile
) {
1138 PrintAndLog ( " block key check (<block no>) and write to dump file (d) combination is not supported " );
1139 PrintAndLog ( " please remove option d and try again" );
1143 param3InUse
= transferToEml
| createDumpFile
| ( btimeout14a
!= MF_CHKKEYS_DEFTIMEOUT
);
1145 PrintAndLog ( "--chk keys. sectors:%2d, block no:%3d, key type:%c, eml:%c, dmp=%c checktimeout=%d us" ,
1146 SectorsCnt
, blockNo
, keyType
? 'B' : 'A' , transferToEml
? 'y' : 'n' , createDumpFile
? 'y' : 'n' , (( int ) btimeout14a
* 10000 ) / 106 );
1148 for ( i
= param3InUse
; param_getchar ( Cmd
, 2 + i
); i
++) {
1149 if (! param_gethex ( Cmd
, 2 + i
, keyBlock
+ 6 * keycnt
, 12 )) {
1150 if ( stKeyBlock
- keycnt
< 2 ) {
1151 p
= realloc ( keyBlock
, 6 *( stKeyBlock
+= 10 ));
1153 PrintAndLog ( "Cannot allocate memory for Keys" );
1159 PrintAndLog ( "chk key[%2d] %02x%02x%02x%02x%02x%02x" , keycnt
,
1160 ( keyBlock
+ 6 * keycnt
)[ 0 ], ( keyBlock
+ 6 * keycnt
)[ 1 ], ( keyBlock
+ 6 * keycnt
)[ 2 ],
1161 ( keyBlock
+ 6 * keycnt
)[ 3 ], ( keyBlock
+ 6 * keycnt
)[ 4 ], ( keyBlock
+ 6 * keycnt
)[ 5 ], 6 );
1164 // May be a dic file
1165 if ( param_getstr ( Cmd
, 2 + i
, filename
, sizeof ( filename
)) >= FILE_PATH_SIZE
) {
1166 PrintAndLog ( "File name too long" );
1171 if ( ( f
= fopen ( filename
, "r" )) ) {
1172 while ( fgets ( buf
, sizeof ( buf
), f
) ){
1173 if ( strlen ( buf
) < 12 || buf
[ 11 ] == ' \n ' )
1176 while ( fgetc ( f
) != ' \n ' && ! feof ( f
)) ; //goto next line
1178 if ( buf
[ 0 ]== '#' ) continue ; //The line start with # is comment, skip
1180 if (! isxdigit (( unsigned char ) buf
[ 0 ])){
1181 PrintAndLog ( "File content error. '%s' must include 12 HEX symbols" , buf
);
1187 if ( stKeyBlock
- keycnt
< 2 ) {
1188 p
= realloc ( keyBlock
, 6 *( stKeyBlock
+= 10 ));
1190 PrintAndLog ( "Cannot allocate memory for defKeys" );
1197 memset ( keyBlock
+ 6 * keycnt
, 0 , 6 );
1198 num_to_bytes ( strtoll ( buf
, NULL
, 16 ), 6 , keyBlock
+ 6 * keycnt
);
1199 PrintAndLog ( "chk custom key[%2d] %012" PRIx64
, keycnt
, bytes_to_num ( keyBlock
+ 6 * keycnt
, 6 ));
1201 memset ( buf
, 0 , sizeof ( buf
));
1205 PrintAndLog ( "File: %s: not found or locked." , filename
);
1212 // fill with default keys
1214 PrintAndLog ( "No key specified, trying default keys" );
1215 for (; keycnt
< defaultKeysSize
; keycnt
++)
1216 PrintAndLog ( "chk default key[%2d] %02x%02x%02x%02x%02x%02x" , keycnt
,
1217 ( keyBlock
+ 6 * keycnt
)[ 0 ], ( keyBlock
+ 6 * keycnt
)[ 1 ], ( keyBlock
+ 6 * keycnt
)[ 2 ],
1218 ( keyBlock
+ 6 * keycnt
)[ 3 ], ( keyBlock
+ 6 * keycnt
)[ 4 ], ( keyBlock
+ 6 * keycnt
)[ 5 ], 6 );
1221 // initialize storage for found keys
1222 e_sector
= calloc ( SectorsCnt
, sizeof ( sector_t
));
1223 if ( e_sector
== NULL
) {
1227 for ( uint8_t keyAB
= 0 ; keyAB
< 2 ; keyAB
++) {
1228 for ( uint16_t sectorNo
= 0 ; sectorNo
< SectorsCnt
; sectorNo
++) {
1229 e_sector
[ sectorNo
]. Key
[ keyAB
] = 0xffffffffffff ;
1230 e_sector
[ sectorNo
]. foundKey
[ keyAB
] = 0 ;
1235 bool foundAKey
= false ;
1236 uint32_t max_keys
= keycnt
> USB_CMD_DATA_SIZE
/ 6 ? USB_CMD_DATA_SIZE
/ 6 : keycnt
;
1238 // !SingleKey, so all key check (if SectorsCnt > 0)
1240 PrintAndLog ( "To cancel this operation press the button on the proxmark..." );
1242 for ( uint32_t c
= 0 ; c
< keycnt
; c
+= max_keys
) {
1244 uint32_t size
= keycnt
- c
> max_keys
? max_keys
: keycnt
- c
;
1245 res
= mfCheckKeysSec ( SectorsCnt
, keyType
, btimeout14a
, true , size
, & keyBlock
[ 6 * c
], e_sector
); // timeout is (ms * 106)/10 or us*0.0106
1256 PrintAndLog ( "Command execute timeout" );
1260 int keyAB
= keyType
;
1262 for ( uint32_t c
= 0 ; c
< keycnt
; c
+= max_keys
) {
1264 uint32_t size
= keycnt
- c
> max_keys
? max_keys
: keycnt
- c
;
1265 res
= mfCheckKeys ( blockNo
, keyAB
& 0x01 , true , size
, & keyBlock
[ 6 * c
], & key64
);
1269 // Use the common format below
1270 // PrintAndLog("Found valid key:[%d:%c]%012" PRIx64, blockNo, (keyAB & 0x01)?'B':'A', key64);
1273 // Store the Single Key for display list
1274 // For a single block check, SectorsCnt = Sector that contains the block
1275 e_sector
[ SectorsCnt
- 1 ]. foundKey
[( keyAB
& 0x01 )] = true ; // flag key found
1276 e_sector
[ SectorsCnt
- 1 ]. Key
[( keyAB
& 0x01 )] = key64
; // Save key data
1280 PrintAndLog ( "Command execute timeout" );
1283 } while (-- keyAB
> 0 );
1290 PrintAndLog ( "|---|----------------|---|----------------|---|" );
1291 PrintAndLog ( "|sec|key A |res|key B |res|" );
1292 PrintAndLog ( "|---|----------------|---|----------------|---|" );
1293 for ( i
= 0 ; i
< SectorsCnt
; i
++) {
1294 // If a block key check, only print a line if a key was found.
1295 if (! singleBlock
|| ( e_sector
[ i
]. foundKey
[ 0 ]) || ( e_sector
[ i
]. foundKey
[ 1 ]) ){
1296 PrintAndLog ( "|%03d| %012" PRIx64
" | %d | %012" PRIx64
" | %d |" , i
,
1297 e_sector
[ i
]. Key
[ 0 ], e_sector
[ i
]. foundKey
[ 0 ], e_sector
[ i
]. Key
[ 1 ], e_sector
[ i
]. foundKey
[ 1 ]);
1300 PrintAndLog ( "|---|----------------|---|----------------|---|" );
1304 PrintAndLog ( "No valid keys found." );
1307 if ( transferToEml
) {
1309 for ( uint16_t sectorNo
= 0 ; sectorNo
< SectorsCnt
; sectorNo
++) {
1310 if ( e_sector
[ sectorNo
]. foundKey
[ 0 ] || e_sector
[ sectorNo
]. foundKey
[ 1 ]) {
1311 mfEmlGetMem ( block
, FirstBlockOfSector ( sectorNo
) + NumBlocksPerSector ( sectorNo
) - 1 , 1 );
1312 for ( uint16_t t
= 0 ; t
< 2 ; t
++) {
1313 if ( e_sector
[ sectorNo
]. foundKey
[ t
]) {
1314 num_to_bytes ( e_sector
[ sectorNo
]. Key
[ t
], 6 , block
+ t
* 10 );
1315 keyFoundCount
++; // Key found count for information
1318 mfEmlSetMem ( block
, FirstBlockOfSector ( sectorNo
) + NumBlocksPerSector ( sectorNo
) - 1 , 1 );
1321 // Updated to show the actual number of keys found/transfered.
1322 PrintAndLog ( "%d keys(s) found have been transferred to the emulator memory" , keyFoundCount
);
1325 if ( createDumpFile
&& ! singleBlock
) {
1326 FILE * fkeys
= fopen ( "dumpkeys.bin" , "wb" );
1327 if ( fkeys
== NULL
) {
1328 PrintAndLog ( "Could not create file dumpkeys.bin" );
1334 for ( uint8_t t
= 0 ; t
< 2 ; t
++) {
1335 for ( uint8_t sectorNo
= 0 ; sectorNo
< SectorsCnt
; sectorNo
++) {
1336 num_to_bytes ( e_sector
[ sectorNo
]. Key
[ t
], 6 , mkey
);
1337 fwrite ( mkey
, 1 , 6 , fkeys
);
1341 PrintAndLog ( "Found keys have been dumped to file dumpkeys.bin. 0xffffffffffff has been inserted for unknown keys." );
1350 void readerAttack ( nonces_t ar_resp
[], bool setEmulatorMem
, bool doStandardAttack
) {
1351 #define ATTACK_KEY_COUNT 7 // keep same as define in iso14443a.c -> Mifare1ksim()
1352 // cannot be more than 7 or it will overrun c.d.asBytes(512)
1358 st_t sector_trailer
[ ATTACK_KEY_COUNT
];
1359 memset ( sector_trailer
, 0x00 , sizeof ( sector_trailer
));
1361 uint8_t stSector
[ ATTACK_KEY_COUNT
];
1362 memset ( stSector
, 0x00 , sizeof ( stSector
));
1363 uint8_t key_cnt
[ ATTACK_KEY_COUNT
];
1364 memset ( key_cnt
, 0x00 , sizeof ( key_cnt
));
1366 for ( uint8_t i
= 0 ; i
< ATTACK_KEY_COUNT
; i
++) {
1367 if ( ar_resp
[ i
]. ar2
> 0 ) {
1368 //PrintAndLog("DEBUG: Trying sector %d, cuid %08x, nt %08x, ar %08x, nr %08x, ar2 %08x, nr2 %08x",ar_resp[i].sector, ar_resp[i].cuid,ar_resp[i].nonce,ar_resp[i].ar,ar_resp[i].nr,ar_resp[i].ar2,ar_resp[i].nr2);
1369 if ( doStandardAttack
&& mfkey32 ( ar_resp
[ i
], & key
)) {
1370 PrintAndLog ( " Found Key%s for sector %02d: [%04x%08x]" , ( ar_resp
[ i
]. keytype
) ? "B" : "A" , ar_resp
[ i
]. sector
, ( uint32_t ) ( key
>> 32 ), ( uint32_t ) ( key
& 0xFFFFFFFF ));
1372 for ( uint8_t ii
= 0 ; ii
< ATTACK_KEY_COUNT
; ii
++) {
1373 if ( key_cnt
[ ii
]== 0 || stSector
[ ii
]== ar_resp
[ i
]. sector
) {
1374 if ( ar_resp
[ i
]. keytype
== 0 ) {
1376 sector_trailer
[ ii
]. keyA
= key
;
1377 stSector
[ ii
] = ar_resp
[ i
]. sector
;
1382 sector_trailer
[ ii
]. keyB
= key
;
1383 stSector
[ ii
] = ar_resp
[ i
]. sector
;
1389 } else if ( mfkey32_moebius ( ar_resp
[ i
+ ATTACK_KEY_COUNT
], & key
)) {
1390 uint8_t sectorNum
= ar_resp
[ i
+ ATTACK_KEY_COUNT
]. sector
;
1391 uint8_t keyType
= ar_resp
[ i
+ ATTACK_KEY_COUNT
]. keytype
;
1393 PrintAndLog ( "M-Found Key%s for sector %02d: [%012" PRIx64
"]"
1394 , keyType
? "B" : "A"
1399 for ( uint8_t ii
= 0 ; ii
< ATTACK_KEY_COUNT
; ii
++) {
1400 if ( key_cnt
[ ii
]== 0 || stSector
[ ii
]== sectorNum
) {
1403 sector_trailer
[ ii
]. keyA
= key
;
1404 stSector
[ ii
] = sectorNum
;
1409 sector_trailer
[ ii
]. keyB
= key
;
1410 stSector
[ ii
] = sectorNum
;
1420 //set emulator memory for keys
1421 if ( setEmulatorMem
) {
1422 for ( uint8_t i
= 0 ; i
< ATTACK_KEY_COUNT
; i
++) {
1424 uint8_t memBlock
[ 16 ];
1425 memset ( memBlock
, 0x00 , sizeof ( memBlock
));
1427 memset ( cmd1
, 0x00 , sizeof ( cmd1
));
1428 snprintf ( cmd1
, sizeof ( cmd1
), "%04x%08xFF078069%04x%08x" ,( uint32_t ) ( sector_trailer
[ i
]. keyA
>> 32 ), ( uint32_t ) ( sector_trailer
[ i
]. keyA
& 0xFFFFFFFF ),( uint32_t ) ( sector_trailer
[ i
]. keyB
>> 32 ), ( uint32_t ) ( sector_trailer
[ i
]. keyB
& 0xFFFFFFFF ));
1429 PrintAndLog ( "Setting Emulator Memory Block %02d: [%s]" , stSector
[ i
]* 4 + 3 , cmd1
);
1430 if ( param_gethex ( cmd1
, 0 , memBlock
, 32 )) {
1431 PrintAndLog ( "block data must include 32 HEX symbols" );
1435 UsbCommand c
= { CMD_MIFARE_EML_MEMSET
, {( stSector
[ i
]* 4 + 3 ), 1 , 0 }};
1436 memcpy ( c
. d
. asBytes
, memBlock
, 16 );
1437 clearCommandBuffer ();
1443 //un-comment to use as well moebius attack
1444 for (uint8_t i = ATTACK_KEY_COUNT; i<ATTACK_KEY_COUNT*2; i++) {
1445 if (ar_resp[i].ar2 > 0) {
1446 if (tryMfk32_moebius(ar_resp[i], &key)) {
1447 PrintAndLog("M-Found Key%s for sector %02d: [%04x%08x]", (ar_resp[i].keytype) ? "B" : "A", ar_resp[i].sector, (uint32_t) (key>>32), (uint32_t) (key &0xFFFFFFFF));
1453 int usage_hf14_mfsim ( void ) {
1454 PrintAndLog ( "Usage: hf mf sim [h] [*<card memory>] [u <uid (8, 14, or 20 hex symbols)>] [n <numreads>] [i] [x]" );
1455 PrintAndLog ( "options:" );
1456 PrintAndLog ( " h (Optional) this help" );
1457 PrintAndLog ( " card memory: 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other, default> - 1K" );
1458 PrintAndLog ( " u (Optional) UID 4 or 7 bytes. If not specified, the UID 4B from emulator memory will be used" );
1459 PrintAndLog ( " n (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite" );
1460 PrintAndLog ( " i (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted" );
1461 PrintAndLog ( " x (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)" );
1462 PrintAndLog ( " e (Optional) set keys found from 'reader attack' to emulator memory (implies x and i)" );
1463 PrintAndLog ( " f (Optional) get UIDs to use for 'reader attack' from file 'f <filename.txt>' (implies x and i)" );
1464 PrintAndLog ( " r (Optional) Generate random nonces instead of sequential nonces. Standard reader attack won't work with this option, only moebius attack works." );
1465 PrintAndLog ( "samples:" );
1466 PrintAndLog ( " hf mf sim u 0a0a0a0a" );
1467 PrintAndLog ( " hf mf sim *4" );
1468 PrintAndLog ( " hf mf sim u 11223344556677" );
1469 PrintAndLog ( " hf mf sim f uids.txt" );
1470 PrintAndLog ( " hf mf sim u 0a0a0a0a e" );
1475 int CmdHF14AMfSim ( const char * Cmd
) {
1477 uint8_t uid
[ 7 ] = { 0 };
1478 uint8_t exitAfterNReads
= 0 ;
1481 bool setEmulatorMem
= false ;
1482 bool attackFromFile
= false ;
1484 char filename
[ FILE_PATH_SIZE
];
1485 memset ( filename
, 0x00 , sizeof ( filename
));
1490 bool errors
= false ;
1491 uint8_t cardsize
= '1' ;
1493 while ( param_getchar ( Cmd
, cmdp
) != 0x00 ) {
1494 switch ( param_getchar ( Cmd
, cmdp
)) {
1496 cardsize
= param_getchar ( Cmd
+ 1 , cmdp
);
1502 default : cardsize
= '1' ;
1508 setEmulatorMem
= true ;
1510 flags
|= FLAG_INTERACTIVE
;
1511 flags
|= FLAG_NR_AR_ATTACK
;
1516 len
= param_getstr ( Cmd
, cmdp
+ 1 , filename
, sizeof ( filename
));
1518 PrintAndLog ( "error no filename found" );
1521 attackFromFile
= true ;
1523 flags
|= FLAG_INTERACTIVE
;
1524 flags
|= FLAG_NR_AR_ATTACK
;
1529 return usage_hf14_mfsim ();
1532 flags
|= FLAG_INTERACTIVE
;
1537 exitAfterNReads
= param_get8 ( Cmd
, cmdp
+ 1 );
1542 flags
|= FLAG_RANDOM_NONCE
;
1548 if ( param_gethex_ex ( Cmd
, cmdp
+ 1 , uid
, & uidlen
)) {
1549 return usage_hf14_mfsim ();
1552 case 14 : flags
= FLAG_7B_UID_IN_DATA
; break ;
1553 case 8 : flags
= FLAG_4B_UID_IN_DATA
; break ;
1554 default : return usage_hf14_mfsim ();
1560 flags
|= FLAG_NR_AR_ATTACK
;
1564 PrintAndLog ( "Unknown parameter '%c'" , param_getchar ( Cmd
, cmdp
));
1571 if ( errors
) return usage_hf14_mfsim ();
1574 if ( attackFromFile
) {
1577 f
= fopen ( filename
, "r" );
1579 PrintAndLog ( "File %s not found or locked" , filename
);
1582 PrintAndLog ( "Loading file and simulating. Press keyboard to abort" );
1583 while (! feof ( f
) && ! ukbhit ()){
1584 memset ( buf
, 0 , sizeof ( buf
));
1585 memset ( uid
, 0 , sizeof ( uid
));
1587 if ( fgets ( buf
, sizeof ( buf
), f
) == NULL
) {
1588 if ( count
> 0 ) break ;
1590 PrintAndLog ( "File reading error." );
1594 if (! strlen ( buf
) && feof ( f
)) break ;
1596 uidlen
= strlen ( buf
)- 1 ;
1598 case 14 : flags
|= FLAG_7B_UID_IN_DATA
; break ;
1599 case 8 : flags
|= FLAG_4B_UID_IN_DATA
; break ;
1601 PrintAndLog ( "uid in file wrong length at %d (length: %d) [%s]" , count
, uidlen
, buf
);
1606 for ( uint8_t i
= 0 ; i
< uidlen
; i
+= 2 ) {
1607 sscanf (& buf
[ i
], "%02x" , ( unsigned int *)& uid
[ i
/ 2 ]);
1610 PrintAndLog ( "mf sim cardsize: %s, uid: %s, numreads:%d, flags:%d (0x%02x) - press button to abort" ,
1611 cardsize
== '0' ? "Mini" :
1612 cardsize
== '2' ? "2K" :
1613 cardsize
== '4' ? "4K" : "1K" ,
1614 flags
& FLAG_4B_UID_IN_DATA
? sprint_hex ( uid
, 4 ):
1615 flags
& FLAG_7B_UID_IN_DATA
? sprint_hex ( uid
, 7 ): "N/A" ,
1620 UsbCommand c
= { CMD_SIMULATE_MIFARE_CARD
, { flags
, exitAfterNReads
, cardsize
}};
1621 memcpy ( c
. d
. asBytes
, uid
, sizeof ( uid
));
1622 clearCommandBuffer ();
1625 while (! WaitForResponseTimeout ( CMD_ACK
,& resp
, 1500 )) {
1626 //We're waiting only 1.5 s at a time, otherwise we get the
1627 // annoying message about "Waiting for a response... "
1630 nonces_t ar_resp
[ ATTACK_KEY_COUNT
* 2 ];
1631 memcpy ( ar_resp
, resp
. d
. asBytes
, sizeof ( ar_resp
));
1632 // We can skip the standard attack if we have RANDOM_NONCE set.
1633 readerAttack ( ar_resp
, setEmulatorMem
, !( flags
& FLAG_RANDOM_NONCE
));
1634 if (( bool ) resp
. arg
[ 1 ]) {
1635 PrintAndLog ( "Device button pressed - quitting" );
1643 } else { //not from file
1645 PrintAndLog ( "mf sim cardsize: %s, uid: %s, numreads:%d, flags:%d (0x%02x) " ,
1646 cardsize
== '0' ? "Mini" :
1647 cardsize
== '2' ? "2K" :
1648 cardsize
== '4' ? "4K" : "1K" ,
1649 flags
& FLAG_4B_UID_IN_DATA
? sprint_hex ( uid
, 4 ):
1650 flags
& FLAG_7B_UID_IN_DATA
? sprint_hex ( uid
, 7 ): "N/A" ,
1655 UsbCommand c
= { CMD_SIMULATE_MIFARE_CARD
, { flags
, exitAfterNReads
, cardsize
}};
1656 memcpy ( c
. d
. asBytes
, uid
, sizeof ( uid
));
1657 clearCommandBuffer ();
1660 if ( flags
& FLAG_INTERACTIVE
) {
1661 PrintAndLog ( "Press pm3-button to abort simulation" );
1662 while (! WaitForResponseTimeout ( CMD_ACK
, & resp
, 1500 )) {
1663 //We're waiting only 1.5 s at a time, otherwise we get the
1664 // annoying message about "Waiting for a response... "
1667 if ( flags
& FLAG_NR_AR_ATTACK
) {
1668 nonces_t ar_resp
[ ATTACK_KEY_COUNT
* 2 ];
1669 memcpy ( ar_resp
, resp
. d
. asBytes
, sizeof ( ar_resp
));
1670 // We can skip the standard attack if we have RANDOM_NONCE set.
1671 readerAttack ( ar_resp
, setEmulatorMem
, !( flags
& FLAG_RANDOM_NONCE
));
1679 int CmdHF14AMfDbg ( const char * Cmd
)
1681 int dbgMode
= param_get32ex ( Cmd
, 0 , 0 , 10 );
1683 PrintAndLog ( "Max debug mode parameter is 4 \n " );
1686 if ( strlen ( Cmd
) < 1 || ! param_getchar ( Cmd
, 0 ) || dbgMode
> 4 ) {
1687 PrintAndLog ( "Usage: hf mf dbg <debug level>" );
1688 PrintAndLog ( " 0 - no debug messages" );
1689 PrintAndLog ( " 1 - error messages" );
1690 PrintAndLog ( " 2 - plus information messages" );
1691 PrintAndLog ( " 3 - plus debug messages" );
1692 PrintAndLog ( " 4 - print even debug messages in timing critical functions" );
1693 PrintAndLog ( " Note: this option therefore may cause malfunction itself" );
1697 UsbCommand c
= { CMD_MIFARE_SET_DBGMODE
, { dbgMode
, 0 , 0 }};
1703 int CmdHF14AMfEGet ( const char * Cmd
)
1705 uint8_t blockNo
= 0 ;
1706 uint8_t data
[ 16 ] = { 0x00 };
1708 if ( strlen ( Cmd
) < 1 || param_getchar ( Cmd
, 0 ) == 'h' ) {
1709 PrintAndLog ( "Usage: hf mf eget <block number>" );
1710 PrintAndLog ( " sample: hf mf eget 0 " );
1714 blockNo
= param_get8 ( Cmd
, 0 );
1717 if (! mfEmlGetMem ( data
, blockNo
, 1 )) {
1718 PrintAndLog ( "data[%3d]:%s" , blockNo
, sprint_hex ( data
, 16 ));
1720 PrintAndLog ( "Command execute timeout" );
1726 int CmdHF14AMfEClear ( const char * Cmd
)
1728 if ( param_getchar ( Cmd
, 0 ) == 'h' ) {
1729 PrintAndLog ( "Usage: hf mf eclr" );
1730 PrintAndLog ( "It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF \n " );
1734 UsbCommand c
= { CMD_MIFARE_EML_MEMCLR
, { 0 , 0 , 0 }};
1740 int CmdHF14AMfESet ( const char * Cmd
)
1742 uint8_t memBlock
[ 16 ];
1743 uint8_t blockNo
= 0 ;
1745 memset ( memBlock
, 0x00 , sizeof ( memBlock
));
1747 if ( strlen ( Cmd
) < 3 || param_getchar ( Cmd
, 0 ) == 'h' ) {
1748 PrintAndLog ( "Usage: hf mf eset <block number> <block data (32 hex symbols)>" );
1749 PrintAndLog ( " sample: hf mf eset 1 000102030405060708090a0b0c0d0e0f " );
1753 blockNo
= param_get8 ( Cmd
, 0 );
1755 if ( param_gethex ( Cmd
, 1 , memBlock
, 32 )) {
1756 PrintAndLog ( "block data must include 32 HEX symbols" );
1761 return mfEmlSetMem ( memBlock
, blockNo
, 1 );
1765 int CmdHF14AMfELoad ( const char * Cmd
)
1768 char filename
[ FILE_PATH_SIZE
];
1769 char * fnameptr
= filename
;
1770 char buf
[ 64 ] = { 0x00 };
1771 uint8_t buf8
[ 64 ] = { 0x00 };
1772 int i
, len
, blockNum
, numBlocks
;
1773 int nameParamNo
= 1 ;
1775 char ctmp
= param_getchar ( Cmd
, 0 );
1777 if ( ctmp
== 'h' || ctmp
== 0x00 ) {
1778 PrintAndLog ( "It loads emul dump from the file `filename.eml`" );
1779 PrintAndLog ( "Usage: hf mf eload [card memory] <file name w/o `.eml`>" );
1780 PrintAndLog ( " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K" );
1782 PrintAndLog ( " sample: hf mf eload filename" );
1783 PrintAndLog ( " hf mf eload 4 filename" );
1788 case '0' : numBlocks
= 5 * 4 ; break ;
1790 case '\0' : numBlocks
= 16 * 4 ; break ;
1791 case '2' : numBlocks
= 32 * 4 ; break ;
1792 case '4' : numBlocks
= 256 ; break ;
1799 len
= param_getstr ( Cmd
, nameParamNo
, filename
, sizeof ( filename
));
1801 if ( len
> FILE_PATH_SIZE
- 5 ) len
= FILE_PATH_SIZE
- 5 ;
1805 sprintf ( fnameptr
, ".eml" );
1808 f
= fopen ( filename
, "r" );
1810 PrintAndLog ( "File %s not found or locked" , filename
);
1816 memset ( buf
, 0 , sizeof ( buf
));
1818 if ( fgets ( buf
, sizeof ( buf
), f
) == NULL
) {
1820 if ( blockNum
>= numBlocks
) break ;
1822 PrintAndLog ( "File reading error." );
1827 if ( strlen ( buf
) < 32 ){
1828 if ( strlen ( buf
) && feof ( f
))
1830 PrintAndLog ( "File content error. Block data must include 32 HEX symbols" );
1835 for ( i
= 0 ; i
< 32 ; i
+= 2 ) {
1836 sscanf (& buf
[ i
], "%02x" , ( unsigned int *)& buf8
[ i
/ 2 ]);
1839 if ( mfEmlSetMem ( buf8
, blockNum
, 1 )) {
1840 PrintAndLog ( "Cant set emul block: %3d" , blockNum
);
1847 if ( blockNum
>= numBlocks
) break ;
1852 if (( blockNum
!= numBlocks
)) {
1853 PrintAndLog ( "File content error. Got %d must be %d blocks." , blockNum
, numBlocks
);
1856 PrintAndLog ( "Loaded %d blocks from file: %s" , blockNum
, filename
);
1861 int CmdHF14AMfESave ( const char * Cmd
)
1864 char filename
[ FILE_PATH_SIZE
];
1865 char * fnameptr
= filename
;
1867 int i
, j
, len
, numBlocks
;
1868 int nameParamNo
= 1 ;
1870 memset ( filename
, 0 , sizeof ( filename
));
1871 memset ( buf
, 0 , sizeof ( buf
));
1873 char ctmp
= param_getchar ( Cmd
, 0 );
1875 if ( ctmp
== 'h' || ctmp
== 'H' ) {
1876 PrintAndLog ( "It saves emul dump into the file `filename.eml` or `cardID.eml`" );
1877 PrintAndLog ( " Usage: hf mf esave [card memory] [file name w/o `.eml`]" );
1878 PrintAndLog ( " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K" );
1880 PrintAndLog ( " sample: hf mf esave " );
1881 PrintAndLog ( " hf mf esave 4" );
1882 PrintAndLog ( " hf mf esave 4 filename" );
1887 case '0' : numBlocks
= 5 * 4 ; break ;
1889 case '\0' : numBlocks
= 16 * 4 ; break ;
1890 case '2' : numBlocks
= 32 * 4 ; break ;
1891 case '4' : numBlocks
= 256 ; break ;
1898 len
= param_getstr ( Cmd
, nameParamNo
, filename
, sizeof ( filename
));
1900 if ( len
> FILE_PATH_SIZE
- 5 ) len
= FILE_PATH_SIZE
- 5 ;
1902 // user supplied filename?
1904 // get filename (UID from memory)
1905 if ( mfEmlGetMem ( buf
, 0 , 1 )) {
1906 PrintAndLog ( "Can \' t get UID from block: %d" , 0 );
1907 len
= sprintf ( fnameptr
, "dump" );
1911 for ( j
= 0 ; j
< 7 ; j
++, fnameptr
+= 2 )
1912 sprintf ( fnameptr
, "%02X" , buf
[ j
]);
1918 // add file extension
1919 sprintf ( fnameptr
, ".eml" );
1922 f
= fopen ( filename
, "w+" );
1925 PrintAndLog ( "Can't open file %s " , filename
);
1930 for ( i
= 0 ; i
< numBlocks
; i
++) {
1931 if ( mfEmlGetMem ( buf
, i
, 1 )) {
1932 PrintAndLog ( "Cant get block: %d" , i
);
1935 for ( j
= 0 ; j
< 16 ; j
++)
1936 fprintf ( f
, "%02X" , buf
[ j
]);
1941 PrintAndLog ( "Saved %d blocks to file: %s" , numBlocks
, filename
);
1947 int CmdHF14AMfECFill ( const char * Cmd
)
1949 uint8_t keyType
= 0 ;
1950 uint8_t numSectors
= 16 ;
1952 if ( strlen ( Cmd
) < 1 || param_getchar ( Cmd
, 0 ) == 'h' ) {
1953 PrintAndLog ( "Usage: hf mf ecfill <key A/B> [card memory]" );
1954 PrintAndLog ( " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K" );
1956 PrintAndLog ( "samples: hf mf ecfill A" );
1957 PrintAndLog ( " hf mf ecfill A 4" );
1958 PrintAndLog ( "Read card and transfer its data to emulator memory." );
1959 PrintAndLog ( "Keys must be laid in the emulator memory. \n " );
1963 char ctmp
= param_getchar ( Cmd
, 0 );
1964 if ( ctmp
!= 'a' && ctmp
!= 'A' && ctmp
!= 'b' && ctmp
!= 'B' ) {
1965 PrintAndLog ( "Key type must be A or B" );
1968 if ( ctmp
!= 'A' && ctmp
!= 'a' ) keyType
= 1 ;
1970 ctmp
= param_getchar ( Cmd
, 1 );
1972 case '0' : numSectors
= 5 ; break ;
1974 case '\0' : numSectors
= 16 ; break ;
1975 case '2' : numSectors
= 32 ; break ;
1976 case '4' : numSectors
= 40 ; break ;
1977 default : numSectors
= 16 ;
1980 printf ( "--params: numSectors: %d, keyType:%d \n " , numSectors
, keyType
);
1981 UsbCommand c
= { CMD_MIFARE_EML_CARDLOAD
, { numSectors
, keyType
, 0 }};
1987 int CmdHF14AMfEKeyPrn ( const char * Cmd
)
1990 uint8_t numSectors
= 16 ;
1992 uint64_t keyA
, keyB
;
1993 bool createDumpFile
= false ;
1995 if ( param_getchar ( Cmd
, 0 ) == 'h' ) {
1996 PrintAndLog ( "It prints the keys loaded in the emulator memory" );
1997 PrintAndLog ( "Usage: hf mf ekeyprn [card memory] [d]" );
1998 PrintAndLog ( " [card memory]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K" );
1999 PrintAndLog ( " [d] : write keys to binary file dumpkeys.bin" );
2001 PrintAndLog ( " sample: hf mf ekeyprn 1" );
2006 while ( param_getchar ( Cmd
, cmdp
) != 0x00 ) {
2007 switch ( param_getchar ( Cmd
, cmdp
)) {
2008 case '0' : numSectors
= 5 ; break ;
2010 case '\0' : numSectors
= 16 ; break ;
2011 case '2' : numSectors
= 32 ; break ;
2012 case '4' : numSectors
= 40 ; break ;
2014 case 'D' : createDumpFile
= true ; break ;
2019 PrintAndLog ( "|---|----------------|----------------|" );
2020 PrintAndLog ( "|sec|key A |key B |" );
2021 PrintAndLog ( "|---|----------------|----------------|" );
2022 for ( i
= 0 ; i
< numSectors
; i
++) {
2023 if ( mfEmlGetMem ( data
, FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 , 1 )) {
2024 PrintAndLog ( "error get block %d" , FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 );
2027 keyA
= bytes_to_num ( data
, 6 );
2028 keyB
= bytes_to_num ( data
+ 10 , 6 );
2029 PrintAndLog ( "|%03d| %012" PRIx64
" | %012" PRIx64
" |" , i
, keyA
, keyB
);
2031 PrintAndLog ( "|---|----------------|----------------|" );
2034 if ( createDumpFile
) {
2036 if (( fkeys
= fopen ( "dumpkeys.bin" , "wb" )) == NULL
) {
2037 PrintAndLog ( "Could not create file dumpkeys.bin" );
2040 PrintAndLog ( "Printing keys to binary file dumpkeys.bin..." );
2041 for ( i
= 0 ; i
< numSectors
; i
++) {
2042 if ( mfEmlGetMem ( data
, FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 , 1 )) {
2043 PrintAndLog ( "error get block %d" , FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 );
2046 fwrite ( data
+ 6 , 1 , 6 , fkeys
);
2048 for ( i
= 0 ; i
< numSectors
; i
++) {
2049 if ( mfEmlGetMem ( data
, FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 , 1 )) {
2050 PrintAndLog ( "error get block %d" , FirstBlockOfSector ( i
) + NumBlocksPerSector ( i
) - 1 );
2053 fwrite ( data
+ 10 , 1 , 6 , fkeys
);
2062 int CmdHF14AMfCSetUID ( const char * Cmd
)
2064 uint8_t uid
[ 8 ] = { 0x00 };
2065 uint8_t oldUid
[ 8 ] = { 0x00 };
2066 uint8_t atqa
[ 2 ] = { 0x00 };
2067 uint8_t sak
[ 1 ] = { 0x00 };
2068 uint8_t atqaPresent
= 0 ;
2071 uint8_t needHelp
= 0 ;
2074 if ( param_getchar ( Cmd
, 0 ) && param_gethex ( Cmd
, 0 , uid
, 8 )) {
2075 PrintAndLog ( "UID must include 8 HEX symbols" );
2079 if ( param_getlength ( Cmd
, 1 ) > 1 && param_getlength ( Cmd
, 2 ) > 1 ) {
2083 if ( param_gethex ( Cmd
, 1 , atqa
, 4 )) {
2084 PrintAndLog ( "ATQA must include 4 HEX symbols" );
2088 if ( param_gethex ( Cmd
, 2 , sak
, 2 )) {
2089 PrintAndLog ( "SAK must include 2 HEX symbols" );
2094 while ( param_getchar ( Cmd
, cmdp
) != 0x00 )
2096 switch ( param_getchar ( Cmd
, cmdp
))
2103 PrintAndLog ( "ERROR: Unknown parameter '%c'" , param_getchar ( Cmd
, cmdp
));
2110 if ( strlen ( Cmd
) < 1 || needHelp
) {
2112 PrintAndLog ( "Usage: hf mf csetuid <UID 8 hex symbols> [ATQA 4 hex symbols SAK 2 hex symbols]" );
2113 PrintAndLog ( "sample: hf mf csetuid 01020304" );
2114 PrintAndLog ( "sample: hf mf csetuid 01020304 0004 08" );
2115 PrintAndLog ( "Set UID, ATQA, and SAK for magic Chinese card (only works with such cards)" );
2119 PrintAndLog ( "uid:%s" , sprint_hex ( uid
, 4 ));
2121 PrintAndLog ( "--atqa:%s sak:%02x" , sprint_hex ( atqa
, 2 ), sak
[ 0 ]);
2124 res
= mfCSetUID ( uid
, ( atqaPresent
)? atqa
: NULL
, ( atqaPresent
)? sak
: NULL
, oldUid
);
2126 PrintAndLog ( "Can't set UID. Error=%d" , res
);
2130 PrintAndLog ( "old UID:%s" , sprint_hex ( oldUid
, 4 ));
2131 PrintAndLog ( "new UID:%s" , sprint_hex ( uid
, 4 ));
2135 int CmdHF14AMfCWipe ( const char * Cmd
)
2138 int numBlocks
= 16 * 4 ;
2139 bool wipeCard
= false ;
2140 bool fillCard
= false ;
2142 if ( strlen ( Cmd
) < 1 || param_getchar ( Cmd
, 0 ) == 'h' ) {
2143 PrintAndLog ( "Usage: hf mf cwipe [card size] [w] [f]" );
2144 PrintAndLog ( "sample: hf mf cwipe 1 w f" );
2145 PrintAndLog ( "[card size]: 0 = 320 bytes (Mifare Mini), 1 = 1K (default), 2 = 2K, 4 = 4K" );
2146 PrintAndLog ( "w - Wipe magic Chinese card (only works with gen:1a cards)" );
2147 PrintAndLog ( "f - Fill the card with default data and keys (works with gen:1a and gen:1b cards only)" );
2151 gen
= mfCIdentify ();
2152 if (( gen
!= 1 ) && ( gen
!= 2 ))
2155 numBlocks
= ParamCardSizeBlocks ( param_getchar ( Cmd
, 0 ));
2158 while ( param_getchar ( Cmd
, cmdp
) != 0x00 ){
2159 switch ( param_getchar ( Cmd
, cmdp
)) {
2174 if (! wipeCard
&& ! fillCard
)
2177 PrintAndLog ( "--blocks count:%2d wipe:%c fill:%c" , numBlocks
, ( wipeCard
)? 'y' : 'n' , ( fillCard
)? 'y' : 'n' );
2180 /* generation 1b magic card */
2182 PrintAndLog ( "WARNING: can't wipe magic card 1b generation" );
2184 res
= mfCWipe ( numBlocks
, true , false , fillCard
);
2186 /* generation 1a magic card by default */
2187 res
= mfCWipe ( numBlocks
, false , wipeCard
, fillCard
);
2191 PrintAndLog ( "Can't wipe. error=%d" , res
);
2198 int CmdHF14AMfCSetBlk ( const char * Cmd
)
2200 uint8_t memBlock
[ 16 ] = { 0x00 };
2201 uint8_t blockNo
= 0 ;
2202 bool wipeCard
= false ;
2205 if ( strlen ( Cmd
) < 1 || param_getchar ( Cmd
, 0 ) == 'h' ) {
2206 PrintAndLog ( "Usage: hf mf csetblk <block number> <block data (32 hex symbols)> [w]" );
2207 PrintAndLog ( "sample: hf mf csetblk 1 01020304050607080910111213141516" );
2208 PrintAndLog ( "Set block data for magic Chinese card (only works with such cards)" );
2209 PrintAndLog ( "If you also want wipe the card then add 'w' at the end of the command line" );
2213 gen
= mfCIdentify ();
2214 if (( gen
!= 1 ) && ( gen
!= 2 ))
2217 blockNo
= param_get8 ( Cmd
, 0 );
2219 if ( param_gethex ( Cmd
, 1 , memBlock
, 32 )) {
2220 PrintAndLog ( "block data must include 32 HEX symbols" );
2224 char ctmp
= param_getchar ( Cmd
, 2 );
2225 wipeCard
= ( ctmp
== 'w' || ctmp
== 'W' );
2226 PrintAndLog ( "--block number:%2d data:%s" , blockNo
, sprint_hex ( memBlock
, 16 ));
2229 /* generation 1b magic card */
2230 res
= mfCSetBlock ( blockNo
, memBlock
, NULL
, wipeCard
, CSETBLOCK_SINGLE_OPER
| CSETBLOCK_MAGIC_1B
);
2232 /* generation 1a magic card by default */
2233 res
= mfCSetBlock ( blockNo
, memBlock
, NULL
, wipeCard
, CSETBLOCK_SINGLE_OPER
);
2237 PrintAndLog ( "Can't write block. error=%d" , res
);
2244 int CmdHF14AMfCLoad ( const char * Cmd
)
2247 char filename
[ FILE_PATH_SIZE
] = { 0x00 };
2248 char * fnameptr
= filename
;
2249 char buf
[ 256 ] = { 0x00 };
2250 uint8_t buf8
[ 256 ] = { 0x00 };
2251 uint8_t fillFromEmulator
= 0 ;
2252 int i
, len
, blockNum
, flags
= 0 , gen
= 0 , numblock
= 64 ;
2254 if ( param_getchar ( Cmd
, 0 ) == 'h' || param_getchar ( Cmd
, 0 )== 0x00 ) {
2255 PrintAndLog ( "It loads magic Chinese card from the file `filename.eml`" );
2256 PrintAndLog ( "or from emulator memory (option `e`). 4K card: (option `4`)" );
2257 PrintAndLog ( "Usage: hf mf cload [file name w/o `.eml`][e][4]" );
2258 PrintAndLog ( " or: hf mf cload e [4]" );
2259 PrintAndLog ( "Sample: hf mf cload filename" );
2260 PrintAndLog ( " hf mf cload filname 4" );
2261 PrintAndLog ( " hf mf cload e" );
2262 PrintAndLog ( " hf mf cload e 4" );
2266 char ctmp
= param_getchar ( Cmd
, 0 );
2267 if ( ctmp
== 'e' || ctmp
== 'E' ) fillFromEmulator
= 1 ;
2268 ctmp
= param_getchar ( Cmd
, 1 );
2269 if ( ctmp
== '4' ) numblock
= 256 ;
2271 gen
= mfCIdentify ();
2272 PrintAndLog ( "Loading magic mifare %dK" , numblock
== 256 ? 4 : 1 );
2274 if ( fillFromEmulator
) {
2275 for ( blockNum
= 0 ; blockNum
< numblock
; blockNum
+= 1 ) {
2276 if ( mfEmlGetMem ( buf8
, blockNum
, 1 )) {
2277 PrintAndLog ( "Cant get block: %d" , blockNum
);
2280 if ( blockNum
== 0 ) flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
; // switch on field and send magic sequence
2281 if ( blockNum
== 1 ) flags
= 0 ; // just write
2282 if ( blockNum
== numblock
- 1 ) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
; // Done. Magic Halt and switch off field.
2285 /* generation 1b magic card */
2286 flags
|= CSETBLOCK_MAGIC_1B
;
2287 if ( mfCSetBlock ( blockNum
, buf8
, NULL
, 0 , flags
)) {
2288 PrintAndLog ( "Cant set magic card block: %d" , blockNum
);
2294 param_getstr ( Cmd
, 0 , filename
, sizeof ( filename
));
2296 len
= strlen ( filename
);
2297 if ( len
> FILE_PATH_SIZE
- 5 ) len
= FILE_PATH_SIZE
- 5 ;
2299 //memcpy(filename, Cmd, len);
2302 sprintf ( fnameptr
, ".eml" );
2305 f
= fopen ( filename
, "r" );
2307 PrintAndLog ( "File not found or locked." );
2314 memset ( buf
, 0 , sizeof ( buf
));
2316 if ( fgets ( buf
, sizeof ( buf
), f
) == NULL
) {
2318 PrintAndLog ( "File reading error." );
2322 if ( strlen ( buf
) < 32 ) {
2323 if ( strlen ( buf
) && feof ( f
))
2325 PrintAndLog ( "File content error. Block data must include 32 HEX symbols" );
2329 for ( i
= 0 ; i
< 32 ; i
+= 2 )
2330 sscanf (& buf
[ i
], "%02x" , ( unsigned int *)& buf8
[ i
/ 2 ]);
2332 if ( blockNum
== 0 ) flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
; // switch on field and send magic sequence
2333 if ( blockNum
== 1 ) flags
= 0 ; // just write
2334 if ( blockNum
== numblock
- 1 ) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
; // Done. Switch off field.
2337 /* generation 1b magic card */
2338 flags
|= CSETBLOCK_MAGIC_1B
;
2339 if ( mfCSetBlock ( blockNum
, buf8
, NULL
, 0 , flags
)) {
2340 PrintAndLog ( "Can't set magic card block: %d" , blockNum
);
2346 if ( blockNum
>= numblock
) break ; // magic card type - mifare 1K 64 blocks, mifare 4k 256 blocks
2350 //if (blockNum != 16 * 4 && blockNum != 32 * 4 + 8 * 16){
2351 if ( blockNum
!= numblock
){
2352 PrintAndLog ( "File content error. There must be %d blocks" , numblock
);
2355 PrintAndLog ( "Loaded from file: %s" , filename
);
2361 int CmdHF14AMfCGetBlk ( const char * Cmd
) {
2362 uint8_t memBlock
[ 16 ];
2363 uint8_t blockNo
= 0 ;
2365 memset ( memBlock
, 0x00 , sizeof ( memBlock
));
2367 if ( strlen ( Cmd
) < 1 || param_getchar ( Cmd
, 0 ) == 'h' ) {
2368 PrintAndLog ( "Usage: hf mf cgetblk <block number>" );
2369 PrintAndLog ( "sample: hf mf cgetblk 1" );
2370 PrintAndLog ( "Get block data from magic Chinese card (only works with such cards) \n " );
2374 gen
= mfCIdentify ();
2376 blockNo
= param_get8 ( Cmd
, 0 );
2378 PrintAndLog ( "--block number:%2d " , blockNo
);
2381 /* generation 1b magic card */
2382 res
= mfCGetBlock ( blockNo
, memBlock
, CSETBLOCK_SINGLE_OPER
| CSETBLOCK_MAGIC_1B
);
2384 /* generation 1a magic card by default */
2385 res
= mfCGetBlock ( blockNo
, memBlock
, CSETBLOCK_SINGLE_OPER
);
2388 PrintAndLog ( "Can't read block. error=%d" , res
);
2392 PrintAndLog ( "block data:%s" , sprint_hex ( memBlock
, 16 ));
2394 if ( mfIsSectorTrailer ( blockNo
)) {
2395 PrintAndLogEx ( NORMAL
, "Trailer decoded:" );
2396 PrintAndLogEx ( NORMAL
, "Key A: %s" , sprint_hex_inrow ( memBlock
, 6 ));
2397 PrintAndLogEx ( NORMAL
, "Key B: %s" , sprint_hex_inrow (& memBlock
[ 10 ], 6 ));
2398 int bln
= mfFirstBlockOfSector ( mfSectorNum ( blockNo
));
2399 int blinc
= ( mfNumBlocksPerSector ( mfSectorNum ( blockNo
)) > 4 ) ? 5 : 1 ;
2400 for ( int i
= 0 ; i
< 4 ; i
++) {
2401 PrintAndLogEx ( NORMAL
, "Access block %d%s: %s" , bln
, (( blinc
> 1 ) && ( i
< 3 ) ? "+" : "" ) , mfGetAccessConditionsDesc ( i
, & memBlock
[ 6 ]));
2404 PrintAndLogEx ( NORMAL
, "UserData: %s" , sprint_hex_inrow (& memBlock
[ 9 ], 1 ));
2410 int CmdHF14AMfCGetSc ( const char * Cmd
) {
2411 uint8_t memBlock
[ 16 ] = { 0x00 };
2412 uint8_t sectorNo
= 0 ;
2413 int i
, res
, flags
, gen
= 0 , baseblock
= 0 , sect_size
= 4 ;
2415 if ( strlen ( Cmd
) < 1 || param_getchar ( Cmd
, 0 ) == 'h' ) {
2416 PrintAndLog ( "Usage: hf mf cgetsc <sector number>" );
2417 PrintAndLog ( "sample: hf mf cgetsc 0" );
2418 PrintAndLog ( "Get sector data from magic Chinese card (only works with such cards) \n " );
2422 sectorNo
= param_get8 ( Cmd
, 0 );
2424 if ( sectorNo
> 39 ) {
2425 PrintAndLog ( "Sector number must be in [0..15] in MIFARE classic 1k and [0..39] in MIFARE classic 4k." );
2429 PrintAndLog ( "--sector number:%d " , sectorNo
);
2431 gen
= mfCIdentify ();
2433 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
2434 if ( sectorNo
< 32 ) {
2435 baseblock
= sectorNo
* 4 ;
2437 baseblock
= 128 + 16 * ( sectorNo
- 32 );
2440 if ( sectorNo
> 31 ) sect_size
= 16 ;
2442 for ( i
= 0 ; i
< sect_size
; i
++) {
2443 if ( i
== 1 ) flags
= 0 ;
2444 if ( i
== sect_size
- 1 ) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
2447 /* generation 1b magic card */
2448 flags
|= CSETBLOCK_MAGIC_1B
;
2450 res
= mfCGetBlock ( baseblock
+ i
, memBlock
, flags
);
2452 PrintAndLog ( "Can't read block. %d error=%d" , baseblock
+ i
, res
);
2456 PrintAndLog ( "block %3d data:%s" , baseblock
+ i
, sprint_hex ( memBlock
, 16 ));
2458 if ( mfIsSectorTrailer ( baseblock
+ i
)) {
2459 PrintAndLogEx ( NORMAL
, "Trailer decoded:" );
2460 PrintAndLogEx ( NORMAL
, "Key A: %s" , sprint_hex_inrow ( memBlock
, 6 ));
2461 PrintAndLogEx ( NORMAL
, "Key B: %s" , sprint_hex_inrow (& memBlock
[ 10 ], 6 ));
2462 int bln
= baseblock
;
2463 int blinc
= ( mfNumBlocksPerSector ( sectorNo
) > 4 ) ? 5 : 1 ;
2464 for ( int i
= 0 ; i
< 4 ; i
++) {
2465 PrintAndLogEx ( NORMAL
, "Access block %d%s: %s" , bln
, (( blinc
> 1 ) && ( i
< 3 ) ? "+" : "" ) , mfGetAccessConditionsDesc ( i
, & memBlock
[ 6 ]));
2468 PrintAndLogEx ( NORMAL
, "UserData: %s" , sprint_hex_inrow (& memBlock
[ 9 ], 1 ));
2475 int CmdHF14AMfCSave ( const char * Cmd
) {
2478 char filename
[ FILE_PATH_SIZE
] = { 0x00 };
2479 char * fnameptr
= filename
;
2480 uint8_t fillFromEmulator
= 0 ;
2481 uint8_t buf
[ 256 ] = { 0x00 };
2482 int i
, j
, len
, flags
, gen
= 0 , numblock
= 64 ;
2484 // memset(filename, 0, sizeof(filename));
2485 // memset(buf, 0, sizeof(buf));
2487 if ( param_getchar ( Cmd
, 0 ) == 'h' ) {
2488 PrintAndLog ( "It saves `magic Chinese` card dump into the file `filename.eml` or `cardID.eml`" );
2489 PrintAndLog ( "or into emulator memory (option `e`). 4K card: (option `4`)" );
2490 PrintAndLog ( "Usage: hf mf csave [file name w/o `.eml`][e][4]" );
2491 PrintAndLog ( "Sample: hf mf csave " );
2492 PrintAndLog ( " hf mf csave filename" );
2493 PrintAndLog ( " hf mf csave e" );
2494 PrintAndLog ( " hf mf csave 4" );
2495 PrintAndLog ( " hf mf csave filename 4" );
2496 PrintAndLog ( " hf mf csave e 4" );
2500 char ctmp
= param_getchar ( Cmd
, 0 );
2501 if ( ctmp
== 'e' || ctmp
== 'E' ) fillFromEmulator
= 1 ;
2502 if ( ctmp
== '4' ) numblock
= 256 ;
2503 ctmp
= param_getchar ( Cmd
, 1 );
2504 if ( ctmp
== '4' ) numblock
= 256 ;
2506 gen
= mfCIdentify ();
2507 PrintAndLog ( "Saving magic mifare %dK" , numblock
== 256 ? 4 : 1 );
2509 if ( fillFromEmulator
) {
2510 // put into emulator
2511 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
2512 for ( i
= 0 ; i
< numblock
; i
++) {
2513 if ( i
== 1 ) flags
= 0 ;
2514 if ( i
== numblock
- 1 ) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
2517 /* generation 1b magic card */
2518 flags
|= CSETBLOCK_MAGIC_1B
;
2520 if ( mfCGetBlock ( i
, buf
, flags
)) {
2521 PrintAndLog ( "Cant get block: %d" , i
);
2525 if ( mfEmlSetMem ( buf
, i
, 1 )) {
2526 PrintAndLog ( "Cant set emul block: %d" , i
);
2532 param_getstr ( Cmd
, 0 , filename
, sizeof ( filename
));
2534 len
= strlen ( filename
);
2535 if ( len
> FILE_PATH_SIZE
- 5 ) len
= FILE_PATH_SIZE
- 5 ;
2537 ctmp
= param_getchar ( Cmd
, 0 );
2538 if ( len
< 1 || ( ctmp
== '4' )) {
2541 flags
= CSETBLOCK_SINGLE_OPER
;
2543 /* generation 1b magic card */
2544 flags
|= CSETBLOCK_MAGIC_1B
;
2545 if ( mfCGetBlock ( 0 , buf
, flags
)) {
2546 PrintAndLog ( "Cant get block: %d" , 0 );
2547 len
= sprintf ( fnameptr
, "dump" );
2551 for ( j
= 0 ; j
< 7 ; j
++, fnameptr
+= 2 )
2552 sprintf ( fnameptr
, "%02x" , buf
[ j
]);
2555 //memcpy(filename, Cmd, len);
2559 sprintf ( fnameptr
, ".eml" );
2562 f
= fopen ( filename
, "w+" );
2565 PrintAndLog ( "File not found or locked." );
2570 flags
= CSETBLOCK_INIT_FIELD
+ CSETBLOCK_WUPC
;
2571 for ( i
= 0 ; i
< numblock
; i
++) {
2572 if ( i
== 1 ) flags
= 0 ;
2573 if ( i
== numblock
- 1 ) flags
= CSETBLOCK_HALT
+ CSETBLOCK_RESET_FIELD
;
2576 /* generation 1b magic card */
2577 flags
|= CSETBLOCK_MAGIC_1B
;
2578 if ( mfCGetBlock ( i
, buf
, flags
)) {
2579 PrintAndLog ( "Cant get block: %d" , i
);
2582 for ( j
= 0 ; j
< 16 ; j
++)
2583 fprintf ( f
, "%02x" , buf
[ j
]);
2588 PrintAndLog ( "Saved to file: %s" , filename
);
2595 int CmdHF14AMfSniff ( const char * Cmd
){
2597 bool wantLogToFile
= 0 ;
2598 bool wantDecrypt
= 0 ;
2599 //bool wantSaveToEml = 0; TODO
2600 bool wantSaveToEmlFile
= 0 ;
2611 uint8_t atqa
[ 2 ] = { 0x00 };
2614 uint8_t * buf
= NULL
;
2615 uint16_t bufsize
= 0 ;
2616 uint8_t * bufPtr
= NULL
;
2619 char ctmp
= param_getchar ( Cmd
, 0 );
2620 if ( ctmp
== 'h' || ctmp
== 'H' ) {
2621 PrintAndLog ( "It continuously gets data from the field and saves it to: log, emulator, emulator file." );
2622 PrintAndLog ( "You can specify:" );
2623 PrintAndLog ( " l - save encrypted sequence to logfile `uid.log`" );
2624 PrintAndLog ( " d - decrypt sequence and put it to log file `uid.log`" );
2625 PrintAndLog ( " n/a e - decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory" );
2626 PrintAndLog ( " f - decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`" );
2627 PrintAndLog ( "Usage: hf mf sniff [l][d][e][f]" );
2628 PrintAndLog ( " sample: hf mf sniff l d e" );
2632 for ( int i
= 0 ; i
< 4 ; i
++) {
2633 ctmp
= param_getchar ( Cmd
, i
);
2634 if ( ctmp
== 'l' || ctmp
== 'L' ) wantLogToFile
= true ;
2635 if ( ctmp
== 'd' || ctmp
== 'D' ) wantDecrypt
= true ;
2636 //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO
2637 if ( ctmp
== 'f' || ctmp
== 'F' ) wantSaveToEmlFile
= true ;
2640 printf ( "------------------------------------------------------------------------- \n " );
2641 printf ( "Executing command. \n " );
2642 printf ( "Press the key on the proxmark3 device to abort both proxmark3 and client. \n " );
2643 printf ( "Press the key on pc keyboard to abort the client. \n " );
2644 printf ( "------------------------------------------------------------------------- \n " );
2646 UsbCommand c
= { CMD_MIFARE_SNIFFER
, { 0 , 0 , 0 }};
2647 clearCommandBuffer ();
2656 printf ( " \n aborted via keyboard! \n " );
2661 if ( WaitForResponseTimeoutW ( CMD_ACK
, & resp
, 2000 , false )) {
2662 res
= resp
. arg
[ 0 ] & 0xff ;
2663 uint16_t traceLen
= resp
. arg
[ 1 ];
2666 if ( res
== 0 ) { // we are done
2670 if ( res
== 1 ) { // there is (more) data to be transferred
2671 if ( pckNum
== 0 ) { // first packet, (re)allocate necessary buffer
2672 if ( traceLen
> bufsize
|| buf
== NULL
) {
2674 if ( buf
== NULL
) { // not yet allocated
2675 p
= malloc ( traceLen
);
2676 } else { // need more memory
2677 p
= realloc ( buf
, traceLen
);
2680 PrintAndLog ( "Cannot allocate memory for trace" );
2688 memset ( buf
, 0x00 , traceLen
);
2690 memcpy ( bufPtr
, resp
. d
. asBytes
, len
);
2695 if ( res
== 2 ) { // received all data, start displaying
2696 blockLen
= bufPtr
- buf
;
2699 PrintAndLog ( "received trace len: %d packages: %d" , blockLen
, pckNum
);
2700 while ( bufPtr
- buf
< blockLen
) {
2701 bufPtr
+= 6 ; // skip (void) timing information
2702 len
= *(( uint16_t *) bufPtr
);
2709 parlen
= ( len
- 1 ) / 8 + 1 ;
2711 if (( len
== 14 ) && ( bufPtr
[ 0 ] == 0xff ) && ( bufPtr
[ 1 ] == 0xff ) && ( bufPtr
[ 12 ] == 0xff ) && ( bufPtr
[ 13 ] == 0xff )) {
2712 memcpy ( uid
, bufPtr
+ 2 , 7 );
2713 memcpy ( atqa
, bufPtr
+ 2 + 7 , 2 );
2714 uid_len
= ( atqa
[ 0 ] & 0xC0 ) == 0x40 ? 7 : 4 ;
2716 PrintAndLog ( "tag select uid:%s atqa:0x%02x%02x sak:0x%02x" ,
2717 sprint_hex ( uid
+ ( 7 - uid_len
), uid_len
),
2721 if ( wantLogToFile
|| wantDecrypt
) {
2722 FillFileNameByUID ( logHexFileName
, uid
+ ( 7 - uid_len
), ".log" , uid_len
);
2723 AddLogCurrentDT ( logHexFileName
);
2726 mfTraceInit ( uid
, atqa
, sak
, wantSaveToEmlFile
);
2728 oddparitybuf ( bufPtr
, len
, parity
);
2729 PrintAndLog ( "%s(%d):%s [%s] c[%s]%c" ,
2730 isTag
? "TAG" : "RDR" ,
2732 sprint_hex ( bufPtr
, len
),
2733 printBitsPar ( bufPtr
+ len
, len
),
2734 printBitsPar ( parity
, len
),
2735 memcmp ( bufPtr
+ len
, parity
, len
/ 8 + 1 ) ? '!' : ' ' );
2737 AddLogHex ( logHexFileName
, isTag
? "TAG: " : "RDR: " , bufPtr
, len
);
2739 mfTraceDecode ( bufPtr
, len
, bufPtr
[ len
], wantSaveToEmlFile
);
2743 bufPtr
+= parlen
; // ignore parity
2752 msleep ( 300 ); // wait for exiting arm side.
2753 PrintAndLog ( "Done." );
2757 //needs nt, ar, at, Data to decrypt
2758 int CmdDecryptTraceCmds ( const char * Cmd
){
2761 param_gethex_ex ( Cmd
, 3 , data
, & len
);
2762 return tryDecryptWord ( param_get32ex ( Cmd
, 0 , 0 , 16 ), param_get32ex ( Cmd
, 1 , 0 , 16 ), param_get32ex ( Cmd
, 2 , 0 , 16 ), data
, len
/ 2 );
2765 int CmdHF14AMfAuth4 ( const char * cmd
) {
2766 uint8_t keyn
[ 20 ] = { 0 };
2768 uint8_t key
[ 16 ] = { 0 };
2771 CLIParserInit ( "hf mf auth4" ,
2772 "Executes AES authentication command in ISO14443-4" ,
2773 "Usage: \n\t hf mf auth4 4000 000102030405060708090a0b0c0d0e0f -> executes authentication \n "
2774 " \t hf mf auth4 9003 FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF -> executes authentication \n " );
2776 void * argtable
[] = {
2778 arg_str1 ( NULL
, NULL
, "<Key Num (HEX 2 bytes)>" , NULL
),
2779 arg_str1 ( NULL
, NULL
, "<Key Value (HEX 16 bytes)>" , NULL
),
2782 CLIExecWithReturn ( cmd
, argtable
, true );
2784 CLIGetHexWithReturn ( 1 , keyn
, & keynlen
);
2785 CLIGetHexWithReturn ( 2 , key
, & keylen
);
2789 PrintAndLog ( "ERROR: <Key Num> must be 2 bytes long instead of: %d" , keynlen
);
2794 PrintAndLog ( "ERROR: <Key Value> must be 16 bytes long instead of: %d" , keylen
);
2798 return MifareAuth4 ( NULL
, keyn
, key
, true , false , true );
2801 // https://www.nxp.com/docs/en/application-note/AN10787.pdf
2802 int CmdHF14AMfMAD ( const char * cmd
) {
2804 CLIParserInit ( "hf mf mad" ,
2805 "Checks and prints Mifare Application Directory (MAD)" ,
2806 "Usage: \n\t hf mf mad -> shows MAD if exists \n "
2807 " \t hf mf mad -a 03e1 -k ffffffffffff -b -> shows NDEF data if exists. read card with custom key and key B \n " );
2809 void * argtable
[] = {
2811 arg_lit0 ( "vV" , "verbose" , "show technical data" ),
2812 arg_str0 ( "aA" , "aid" , "print all sectors with aid" , NULL
),
2813 arg_str0 ( "kK" , "key" , "key for printing sectors" , NULL
),
2814 arg_lit0 ( "bB" , "keyb" , "use key B for access printing sectors (by default: key A)" ),
2817 CLIExecWithReturn ( cmd
, argtable
, true );
2818 bool verbose
= arg_get_lit ( 1 );
2819 uint8_t aid
[ 2 ] = { 0 };
2821 CLIGetHexWithReturn ( 2 , aid
, & aidlen
);
2822 uint8_t key
[ 6 ] = { 0 };
2824 CLIGetHexWithReturn ( 3 , key
, & keylen
);
2825 bool keyB
= arg_get_lit ( 4 );
2829 if ( aidlen
!= 2 && keylen
> 0 ) {
2830 PrintAndLogEx ( WARNING
, "do not need a key without aid." );
2833 uint8_t sector0
[ 16 * 4 ] = { 0 };
2834 uint8_t sector10
[ 16 * 4 ] = { 0 };
2835 if ( mfReadSector ( MF_MAD1_SECTOR
, MF_KEY_A
, ( uint8_t *) g_mifare_mad_key
, sector0
)) {
2836 PrintAndLogEx ( ERR
, "read sector 0 error. card don't have MAD or don't have MAD on default keys." );
2841 for ( int i
= 0 ; i
< 4 ; i
++)
2842 PrintAndLogEx ( NORMAL
, "[%d] %s" , i
, sprint_hex (& sector0
[ i
* 16 ], 16 ));
2845 bool haveMAD2
= false ;
2846 MAD1DecodeAndPrint ( sector0
, verbose
, & haveMAD2
);
2849 if ( mfReadSector ( MF_MAD2_SECTOR
, MF_KEY_A
, ( uint8_t *) g_mifare_mad_key
, sector10
)) {
2850 PrintAndLogEx ( ERR
, "read sector 0x10 error. card don't have MAD or don't have MAD on default keys." );
2854 MAD2DecodeAndPrint ( sector10
, verbose
);
2858 uint16_t aaid
= ( aid
[ 0 ] << 8 ) + aid
[ 1 ];
2859 PrintAndLogEx ( NORMAL
, " \n -------------- AID 0x%04x ---------------" , aaid
);
2861 uint16_t mad
[ 7 + 8 + 8 + 8 + 8 ] = { 0 };
2863 if ( MADDecode ( sector0
, sector10
, mad
, & madlen
)) {
2864 PrintAndLogEx ( ERR
, "can't decode mad." );
2868 uint8_t akey
[ 6 ] = { 0 };
2869 memcpy ( akey
, g_mifare_ndef_key
, 6 );
2871 memcpy ( akey
, key
, 6 );
2874 for ( int i
= 0 ; i
< madlen
; i
++) {
2875 if ( aaid
== mad
[ i
]) {
2876 uint8_t vsector
[ 16 * 4 ] = { 0 };
2877 if ( mfReadSector ( i
+ 1 , keyB
? MF_KEY_B
: MF_KEY_A
, akey
, vsector
)) {
2878 PrintAndLogEx ( NORMAL
, "" );
2879 PrintAndLogEx ( ERR
, "read sector %d error." , i
+ 1 );
2883 for ( int j
= 0 ; j
< ( verbose
? 4 : 3 ); j
++)
2884 PrintAndLogEx ( NORMAL
, " [%03d] %s" , ( i
+ 1 ) * 4 + j
, sprint_hex (& vsector
[ j
* 16 ], 16 ));
2892 int CmdHFMFNDEF ( const char * cmd
) {
2894 CLIParserInit ( "hf mf ndef" ,
2895 "Prints NFC Data Exchange Format (NDEF)" ,
2896 "Usage: \n\t hf mf ndef -> shows NDEF data \n "
2897 " \t hf mf ndef -a 03e1 -k ffffffffffff -b -> shows NDEF data with custom AID, key and with key B \n " );
2899 void * argtable
[] = {
2901 arg_litn ( "vV" , "verbose" , 0 , 2 , "show technical data" ),
2902 arg_str0 ( "aA" , "aid" , "replace default aid for NDEF" , NULL
),
2903 arg_str0 ( "kK" , "key" , "replace default key for NDEF" , NULL
),
2904 arg_lit0 ( "bB" , "keyb" , "use key B for access sectors (by default: key A)" ),
2907 CLIExecWithReturn ( cmd
, argtable
, true );
2909 bool verbose
= arg_get_lit ( 1 );
2910 bool verbose2
= arg_get_lit ( 1 ) > 1 ;
2911 uint8_t aid
[ 2 ] = { 0 };
2913 CLIGetHexWithReturn ( 2 , aid
, & aidlen
);
2914 uint8_t key
[ 6 ] = { 0 };
2916 CLIGetHexWithReturn ( 3 , key
, & keylen
);
2917 bool keyB
= arg_get_lit ( 4 );
2921 uint16_t ndefAID
= 0x03e1 ;
2923 ndefAID
= ( aid
[ 0 ] << 8 ) + aid
[ 1 ];
2925 uint8_t ndefkey
[ 6 ] = { 0 };
2926 memcpy ( ndefkey
, g_mifare_ndef_key
, 6 );
2928 memcpy ( ndefkey
, key
, 6 );
2931 uint8_t sector0
[ 16 * 4 ] = { 0 };
2932 uint8_t sector10
[ 16 * 4 ] = { 0 };
2933 uint8_t data
[ 4096 ] = { 0 };
2936 PrintAndLogEx ( NORMAL
, "" );
2938 if ( mfReadSector ( MF_MAD1_SECTOR
, MF_KEY_A
, ( uint8_t *) g_mifare_mad_key
, sector0
)) {
2939 PrintAndLogEx ( ERR
, "read sector 0 error. card don't have MAD or don't have MAD on default keys." );
2943 bool haveMAD2
= false ;
2944 int res
= MADCheck ( sector0
, NULL
, verbose
, & haveMAD2
);
2946 PrintAndLogEx ( ERR
, "MAD error %d." , res
);
2951 if ( mfReadSector ( MF_MAD2_SECTOR
, MF_KEY_A
, ( uint8_t *) g_mifare_mad_key
, sector10
)) {
2952 PrintAndLogEx ( ERR
, "read sector 0x10 error. card don't have MAD or don't have MAD on default keys." );
2957 uint16_t mad
[ 7 + 8 + 8 + 8 + 8 ] = { 0 };
2959 if ( MADDecode ( sector0
, ( haveMAD2
? sector10
: NULL
), mad
, & madlen
)) {
2960 PrintAndLogEx ( ERR
, "can't decode mad." );
2964 printf ( "data reading:" );
2965 for ( int i
= 0 ; i
< madlen
; i
++) {
2966 if ( ndefAID
== mad
[ i
]) {
2967 uint8_t vsector
[ 16 * 4 ] = { 0 };
2968 if ( mfReadSector ( i
+ 1 , keyB
? MF_KEY_B
: MF_KEY_A
, ndefkey
, vsector
)) {
2969 PrintAndLogEx ( ERR
, "read sector %d error." , i
+ 1 );
2973 memcpy (& data
[ datalen
], vsector
, 16 * 3 );
2982 PrintAndLogEx ( ERR
, "no NDEF data." );
2987 PrintAndLogEx ( NORMAL
, "NDEF data:" );
2988 dump_buffer ( data
, datalen
, stdout
, 1 );
2991 NDEFDecodeAndPrint ( data
, datalen
, verbose
);
2996 static command_t CommandTable
[] =
2998 { "help" , CmdHelp
, 1 , "This help" },
2999 { "dbg" , CmdHF14AMfDbg
, 0 , "Set default debug mode" },
3000 { "rdbl" , CmdHF14AMfRdBl
, 0 , "Read MIFARE classic block" },
3001 { "rdsc" , CmdHF14AMfRdSc
, 0 , "Read MIFARE classic sector" },
3002 { "dump" , CmdHF14AMfDump
, 0 , "Dump MIFARE classic tag to binary file" },
3003 { "restore" , CmdHF14AMfRestore
, 0 , "Restore MIFARE classic binary file to BLANK tag" },
3004 { "wrbl" , CmdHF14AMfWrBl
, 0 , "Write MIFARE classic block" },
3005 { "auth4" , CmdHF14AMfAuth4
, 0 , "ISO14443-4 AES authentication" },
3006 { "chk" , CmdHF14AMfChk
, 0 , "Test block keys" },
3007 { "mifare" , CmdHF14AMifare
, 0 , "Read parity error messages." },
3008 { "hardnested" , CmdHF14AMfNestedHard
, 0 , "Nested attack for hardened Mifare cards" },
3009 { "nested" , CmdHF14AMfNested
, 0 , "Test nested authentication" },
3010 { "sniff" , CmdHF14AMfSniff
, 0 , "Sniff card-reader communication" },
3011 { "sim" , CmdHF14AMfSim
, 0 , "Simulate MIFARE card" },
3012 { "eclr" , CmdHF14AMfEClear
, 0 , "Clear simulator memory" },
3013 { "eget" , CmdHF14AMfEGet
, 0 , "Get simulator memory block" },
3014 { "eset" , CmdHF14AMfESet
, 0 , "Set simulator memory block" },
3015 { "eload" , CmdHF14AMfELoad
, 0 , "Load from file emul dump" },
3016 { "esave" , CmdHF14AMfESave
, 0 , "Save to file emul dump" },
3017 { "ecfill" , CmdHF14AMfECFill
, 0 , "Fill simulator memory with help of keys from simulator" },
3018 { "ekeyprn" , CmdHF14AMfEKeyPrn
, 0 , "Print keys from simulator memory" },
3019 { "cwipe" , CmdHF14AMfCWipe
, 0 , "Wipe magic Chinese card" },
3020 { "csetuid" , CmdHF14AMfCSetUID
, 0 , "Set UID for magic Chinese card" },
3021 { "csetblk" , CmdHF14AMfCSetBlk
, 0 , "Write block - Magic Chinese card" },
3022 { "cgetblk" , CmdHF14AMfCGetBlk
, 0 , "Read block - Magic Chinese card" },
3023 { "cgetsc" , CmdHF14AMfCGetSc
, 0 , "Read sector - Magic Chinese card" },
3024 { "cload" , CmdHF14AMfCLoad
, 0 , "Load dump into magic Chinese card" },
3025 { "csave" , CmdHF14AMfCSave
, 0 , "Save dump from magic Chinese card into file or emulator" },
3026 { "decrypt" , CmdDecryptTraceCmds
, 1 , "[nt] [ar_enc] [at_enc] [data] - to decrypt snoop or trace" },
3027 { "mad" , CmdHF14AMfMAD
, 0 , "Checks and prints MAD" },
3028 { "ndef" , CmdHFMFNDEF
, 0 , "Prints NDEF records from card" },
3029 { NULL
, NULL
, 0 , NULL
}
3032 int CmdHFMF ( const char * Cmd
)
3034 ( void ) WaitForResponseTimeout ( CMD_ACK
, NULL
, 100 );
3035 CmdsParse ( CommandTable
, Cmd
);
3039 int CmdHelp ( const char * Cmd
)
3041 CmdsHelp ( CommandTable
);