Chg: 'hf mf autopwn' - skip extra checks if all keys found on first check

This commit is contained in:
iceman1001 2019-10-08 19:49:34 +02:00
commit 3a63b72741

View file

@ -1644,7 +1644,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
int block_cnt = MIFARE_1K_MAXBLOCK; int block_cnt = MIFARE_1K_MAXBLOCK;
uint8_t tmp_key[6] = {0}; uint8_t tmp_key[6] = {0};
bool know_target_key = false; bool know_target_key = false;
// For the timier // For the timer
uint64_t t1; uint64_t t1;
// Parameters and dictionary file // Parameters and dictionary file
char filename[FILE_PATH_SIZE] = {0}; char filename[FILE_PATH_SIZE] = {0};
@ -1666,6 +1666,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
bool verbose = false; bool verbose = false;
bool has_filename = false; bool has_filename = false;
bool errors = false; bool errors = false;
uint8_t num_found_keys = 0;
// Parse the options given by the user // Parse the options given by the user
while ((ctmp = param_getchar(Cmd, cmdp)) && !errors) { while ((ctmp = param_getchar(Cmd, cmdp)) && !errors) {
@ -1819,6 +1820,9 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
// Store the key for the nested / hardnested attack (if supplied by the user) // Store the key for the nested / hardnested attack (if supplied by the user)
e_sector[blockNo].Key[keyType] = key64; e_sector[blockNo].Key[keyType] = key64;
e_sector[blockNo].foundKey[keyType] = 'U';
++num_found_keys;
} else { } else {
know_target_key = false; know_target_key = false;
PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"), PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector:"_RED_("%3d") " key type: "_RED_("%c") " key: " _RED_("%s"),
@ -1855,11 +1859,14 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
sprint_hex(key, sizeof(key)) sprint_hex(key, sizeof(key))
); );
} }
++num_found_keys;
} }
} }
} }
} }
if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP KNOWN KEY ATTACK =======================")); if (verbose) PrintAndLogEx(INFO, _YELLOW_("======================= STOP KNOWN KEY ATTACK ======================="));
if (num_found_keys == sectors_cnt * 2)
goto all_found;
} }
bool load_success = true; bool load_success = true;
@ -1873,7 +1880,6 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
load_success = false; load_success = false;
} }
} }
if (has_filename == false || load_success == false) { if (has_filename == false || load_success == false) {
@ -1905,6 +1911,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, (keyBlock + (6 * k)), &key64) == PM3_SUCCESS) { if (mfCheckKeys(FirstBlockOfSector(i), j, true, 1, (keyBlock + (6 * k)), &key64) == PM3_SUCCESS) {
e_sector[i].Key[j] = bytes_to_num((keyBlock + (6 * k)), 6); e_sector[i].Key[j] = bytes_to_num((keyBlock + (6 * k)), 6);
e_sector[i].foundKey[j] = 'D'; e_sector[i].foundKey[j] = 'D';
++num_found_keys;
break; break;
} }
} }
@ -2205,6 +2212,8 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack
} }
} }
all_found:
// Show the results to the user // Show the results to the user
PrintAndLogEx(NORMAL, ""); PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "found Keys:"); PrintAndLogEx(INFO, "found Keys:");