]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmfu.c
ADD: @marshmellows fixes
[proxmark3-svn] / client / cmdhfmfu.c
index 1f98cbb915111b4749b4dbba34cd8cab004d4530..aed77d82ac5aa49355b0fedbb81b084a74480a4b 100644 (file)
@@ -270,11 +270,16 @@ static int ul_print_default( uint8_t *data){
                PrintAndLog("      BCC1 : %02X, crc should be %02X", data[8], crc1 );
        
        PrintAndLog("  Internal : %02X, %sdefault", data[9], (data[9]==0x48)?"":"not " );
-       PrintAndLog("      Lock : %s - %s", sprint_hex(data+10, 2),printBits( 2, data+10) );
 
-       // if Page3 has NDEF magic number, its not a OTP..
-       if ( data[12] != 0xE1 )
-               PrintAndLog("OneTimePad : %s\n", sprint_hex(data + 12, 4));
+       PrintAndLog("      Lock : %s - %s",
+                               sprint_hex(data+10, 2),
+                               printBits(2, data+10)
+               );
+
+       PrintAndLog("OneTimePad : %s - %s\n",
+                               sprint_hex(data + 12, 4),
+                               printBits(4, data+12)
+               );
 
        return 0;
 }
@@ -342,8 +347,7 @@ static int ulc_print_3deskey( uint8_t *data){
        PrintAndLog("         deskey1 [45/0x2D]: %s [%.4s]", sprint_hex(data+4 ,4),data+4);
        PrintAndLog("         deskey2 [46/0x2E]: %s [%.4s]", sprint_hex(data+8 ,4),data+8);
        PrintAndLog("         deskey2 [47/0x2F]: %s [%.4s]", sprint_hex(data+12,4),data+12);
-       
-       PrintAndLog("\n 3des key : %s", sprint_hex(SwapEndian64(data, 16), 16));
+       PrintAndLog("\n 3des key : %s", sprint_hex(SwapEndian64(data, 16, 8), 16));
        return 0;
 }
 
@@ -355,7 +359,7 @@ static int ulc_print_configuration( uint8_t *data){
 
        bool validAuth = (data[8] >= 0x03 && data[8] <= 0x30);
        if ( validAuth )
-               PrintAndLog("           Auth0 [42/0x2A]: %s Pages above %d/0x%02X needs authentication", sprint_hex(data+8, 4), data[8],data[8] );
+               PrintAndLog("           Auth0 [42/0x2A]: %s page %d/0x%02X and above need authentication", sprint_hex(data+8, 4), data[8],data[8] );
        else{
                if ( data[8] == 0){
                        PrintAndLog("           Auth0 [42/0x2A]: %s default", sprint_hex(data+8, 4) );
@@ -382,7 +386,7 @@ static int ulev1_print_configuration( uint8_t *data){
         
        PrintAndLog(" cfg0 [16/0x10]: %s", sprint_hex(data, 4));
        if ( data[3] < 0xff )
-               PrintAndLog("                    - pages above %d needs authentication",data[3]);
+               PrintAndLog("                    - page %d and above need authentication",data[3]);
        else 
                PrintAndLog("                    - pages don't need authentication");
        PrintAndLog("                    - strong modulation mode %s", (strg_mod_en) ? "enabled":"disabled");
@@ -473,7 +477,7 @@ static int ul_magic_test(){
        iso14a_card_select_t card;
        int status = ul_select(&card);
        if ( status < 1 ){
-               PrintAndLog("Error: couldn't select ul_magic_test");
+               PrintAndLog("iso14443a card select failed");
                ul_switch_off_field();
                return UL_ERROR;
        }
@@ -640,7 +644,6 @@ int CmdHF14AMfUInfo(const char *Cmd){
        status = ul_read(0, data, sizeof(data));
        if ( status == -1 ){
                PrintAndLog("Error: tag didn't answer to READ A");
-               ul_switch_off_field();
                return status;
        }
 
@@ -652,11 +655,9 @@ int CmdHF14AMfUInfo(const char *Cmd){
                uint8_t ulc_conf[16] = {0x00};
                status = ul_read(0x28, ulc_conf, sizeof(ulc_conf));
                if ( status == -1 ){
-                       PrintAndLog("Error: tag didn't answer to READ - possibly locked");
-                       ul_switch_off_field();
+                       PrintAndLog("Error: tag didn't answer to READ UL-C");
                        return status;
                } 
-
                ulc_print_configuration(ulc_conf);
 
                if ((tagtype & MAGIC)){
@@ -665,24 +666,25 @@ int CmdHF14AMfUInfo(const char *Cmd){
                        status = ul_read(0x2C, ulc_deskey, sizeof(ulc_deskey));
                        if ( status == -1 ){
                                PrintAndLog("Error: tag didn't answer to READ magic");
-                               ul_switch_off_field();
                                return status;
                        }
                        ulc_print_3deskey(ulc_deskey);
 
                } else {
-                       
                        // if we called info with key, just return 
-                       if ( hasAuthKey ) return 0;
+                       if ( hasAuthKey ) return 1;
                        
+                       // also try to diversify default keys..  look into CmdHF14AMfuGenDiverseKeys
                        PrintAndLog("Trying some default 3des keys");
                        ul_switch_off_field();
                        for (uint8_t i = 0; i < KEYS_3DES_COUNT; ++i ){
                                key = default_3des_keys[i];
                                if (try3DesAuthentication(key) == 1){
                                        PrintAndLog("Found default 3des key: "); //%s", sprint_hex(key,16));
-                                       ulc_print_3deskey(SwapEndian64(key,16));
-                                       return 0;
+                                       uint8_t keySwap[16];
+                                       memcpy(keySwap, SwapEndian64(key,16,8), 16);
+                                       ulc_print_3deskey(keySwap);
+                                       return 1;
                                }
                        }
                }
@@ -696,7 +698,6 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status = ulev1_readSignature( ulev1_signature, sizeof(ulev1_signature));
                if ( status == -1 ){
                        PrintAndLog("Error: tag didn't answer to READ SIGNATURE");
-                       ul_switch_off_field();
                        return status;
                }               
                ulev1_print_signature( ulev1_signature, sizeof(ulev1_signature));
@@ -710,6 +711,11 @@ int CmdHF14AMfUInfo(const char *Cmd){
                }
                // save AUTHENTICATION LIMITS for later:
                authlim = (ulev1_conf[4] & 0x07);
+               bool allZeros = true;
+               for (uint8_t idx=0; idx<8; idx++)
+                       if (ulev1_conf[idx]) allZeros = false;
+
+               if (allZeros) authlim=7;
                ulev1_print_configuration(ulev1_conf);
        }
        
@@ -719,13 +725,12 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status  = ulev1_getVersion(version, sizeof(version));
                if ( status == -1 ){
                        PrintAndLog("Error: tag didn't answer to GET_VERSION");
-                       ul_switch_off_field();
                        return status;
                }
                ulev1_print_version(version);
 
                // if we called info with key, just return 
-               if ( hasAuthKey ) return 0;
+               if ( hasAuthKey ) return 1;
                
                // AUTHLIMIT, (number of failed authentications)
                // 0 = limitless.
@@ -753,7 +758,6 @@ int CmdHF14AMfUInfo(const char *Cmd){
                status = ul_read(3, cc, sizeof(cc));
                if ( status == -1 ){
                        PrintAndLog("Error: tag didn't answer to READ ntag");
-                       ul_switch_off_field();
                        return status;
                }
                ntag_print_CC(cc);      
@@ -761,7 +765,7 @@ int CmdHF14AMfUInfo(const char *Cmd){
        
        ul_switch_off_field();
        PrintAndLog("");
-       return 0;
+       return 1;
 }
 
 //
@@ -980,7 +984,7 @@ int CmdHF14AMfUDump(const char *Cmd){
        if(errors) return usage_hf_mfu_dump();
        
        if (swapEndian)
-               keyPtr = SwapEndian64(data, 16);
+               keyPtr = SwapEndian64(data, 16, 8);
 
        TagTypeUL_t tagtype = GetHF14AMfU_Type();
        if (tagtype == UL_ERROR) return -1;
@@ -1108,7 +1112,7 @@ int CmdHF14AMfUDump(const char *Cmd){
                sprintf(fnameptr,"%02X%02X%02X%02X%02X%02X%02X.bin",
                        data[0], data[1], data[2], data[4], data[5], data[6], data[7]);
        } else {
-               sprintf(fnameptr + fileNlen," .bin");
+               sprintf(fnameptr + fileNlen,".bin");
        }
 
        if ((fout = fopen(filename,"wb")) == NULL) { 
Impressum, Datenschutz