@@ -2495,15 +2495,20 @@ static int CmdHF14AMfNestedStatic(const char *Cmd) {
24952495 PrintAndLogEx (SUCCESS , "Time in check keys " _YELLOW_ ("%.0f" ) " seconds\n" , (float )t2 / 1000.0 );
24962496 PrintAndLogEx (SUCCESS , "--- " _CYAN_ ("Enter static nested key recovery" ) " --------------" );
24972497
2498+ // Decryption backup logic for special card 0x009080A2(keyB NT1 dist is 160 & 320, not 161 & 321).
2499+ bool forceDetectDist ;
2500+
24982501 // nested sectors
24992502 for (trgKeyType = MF_KEY_A ; trgKeyType <= MF_KEY_B ; ++ trgKeyType ) {
25002503 for (uint8_t sectorNo = 0 ; sectorNo < SectorsCnt ; ++ sectorNo ) {
25012504
2502- for ( int i = 0 ; i < 1 ; i ++ ) {
2505+ forceDetectDist = 0 ; // Fist decrypt, auto detect dist for NT2_1 & NT2_2.
25032506
2504- if ( e_sector [ sectorNo ]. foundKey [ trgKeyType ]) continue ;
2507+ for ( int i = 0 ; i < 2 ; i ++ ) {
25052508
2506- int16_t isOK = mf_static_nested (blockNo , keyType , key , mfFirstBlockOfSector (sectorNo ), trgKeyType , keyBlock );
2509+ if (e_sector [sectorNo ].foundKey [trgKeyType ]) continue ;
2510+
2511+ int16_t isOK = mf_static_nested (blockNo , keyType , key , mfFirstBlockOfSector (sectorNo ), trgKeyType , keyBlock , forceDetectDist );
25072512 switch (isOK ) {
25082513 case PM3_ETIMEOUT :
25092514 PrintAndLogEx (ERR , "command execution time out" );
@@ -2512,11 +2517,15 @@ static int CmdHF14AMfNestedStatic(const char *Cmd) {
25122517 PrintAndLogEx (WARNING , "aborted via keyboard." );
25132518 break ;
25142519 case PM3_ESOFT :
2520+ // No any key found?
2521+ // Try to force decryption using measured nonce instead of automatic detection (some card types may misjudge)
2522+ forceDetectDist = 1 ;
2523+ PrintAndLogEx (WARNING , "No key found, next try..." );
25152524 continue ;
25162525 case PM3_SUCCESS :
25172526 e_sector [sectorNo ].foundKey [trgKeyType ] = 1 ;
25182527 e_sector [sectorNo ].Key [trgKeyType ] = bytes_to_num (keyBlock , 6 );
2519-
2528+ i = 2 ; // Key found, no next retry.
25202529 // mf_check_keys_fast(SectorsCnt, true, true, 2, 1, keyBlock, e_sector, false, false);
25212530 continue ;
25222531 default :
@@ -3018,6 +3027,10 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
30183027 uint64_t key64 = 0 ;
30193028 bool calibrate = true;
30203029
3030+ // staticNested parameter
3031+ bool force_detect_dist ;
3032+ int static_nested_retry_i = 0 ;
3033+
30213034 // Attack key storage variables
30223035 uint8_t * keyBlock = NULL ;
30233036 uint32_t key_cnt = 0 ;
@@ -3694,28 +3707,37 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
36943707 (current_key_type_i == MF_KEY_B ) ? 'B' : 'A' );
36953708 }
36963709
3697- isOK = mf_static_nested (mfFirstBlockOfSector (sectorno ), keytype , key , mfFirstBlockOfSector (current_sector_i ), current_key_type_i , tmp_key );
3698- DropField ();
3699- switch (isOK ) {
3700- case PM3_ETIMEOUT : {
3701- PrintAndLogEx (ERR , "\nError: No response from Proxmark3" );
3702- free (e_sector );
3703- free (fptr );
3704- return isOK ;
3705- }
3706- case PM3_EOPABORTED : {
3707- PrintAndLogEx (WARNING , "\nButton pressed, user aborted" );
3708- free (e_sector );
3709- free (fptr );
3710- return isOK ;
3711- }
3712- case PM3_SUCCESS : {
3713- e_sector [current_sector_i ].Key [current_key_type_i ] = bytes_to_num (tmp_key , MIFARE_KEY_SIZE );
3714- e_sector [current_sector_i ].foundKey [current_key_type_i ] = 'C' ;
3715- break ;
3716- }
3717- default : {
3718- break ;
3710+ force_detect_dist = 0 ; // First time to decrypt staticnested tag, we can auto detect dist by tag type.
3711+ for (static_nested_retry_i = 0 ; static_nested_retry_i < 2 ; static_nested_retry_i ++ ) {
3712+ isOK = mf_static_nested (mfFirstBlockOfSector (sectorno ), keytype , key , mfFirstBlockOfSector (current_sector_i ), current_key_type_i , tmp_key , force_detect_dist );
3713+ DropField ();
3714+ switch (isOK ) {
3715+ case PM3_ETIMEOUT : {
3716+ PrintAndLogEx (ERR , "\nError: No response from Proxmark3" );
3717+ free (e_sector );
3718+ free (fptr );
3719+ return isOK ;
3720+ }
3721+ case PM3_EOPABORTED : {
3722+ PrintAndLogEx (WARNING , "\nButton pressed, user aborted" );
3723+ free (e_sector );
3724+ free (fptr );
3725+ return isOK ;
3726+ }
3727+ case PM3_ESOFT : {
3728+ PrintAndLogEx (WARNING , "No key found, next try..." );
3729+ force_detect_dist = 1 ;
3730+ continue ;
3731+ }
3732+ case PM3_SUCCESS : {
3733+ e_sector [current_sector_i ].Key [current_key_type_i ] = bytes_to_num (tmp_key , MIFARE_KEY_SIZE );
3734+ e_sector [current_sector_i ].foundKey [current_key_type_i ] = 'C' ;
3735+ static_nested_retry_i = 2 ; // Key found, no next retry.
3736+ break ;
3737+ }
3738+ default : {
3739+ break ;
3740+ }
37193741 }
37203742 }
37213743 }
0 commit comments