printf("Press button on the proxmark3 device to abort both proxmark3 and client.\n");\r
printf("-------------------------------------------------------------------------\n");\r
\r
+ time_t time1 = clock();\r
\r
start:\r
clearCommandBuffer();\r
PrintAndLog("Found valid key: %012"llx" \n", r_key);\r
}\r
\r
+ PrintAndLog("Time in darkside: %1.0f seconds", (float)(clock() - time1)/CLOCKS_PER_SEC);\r
PrintAndLog("");\r
return 0;\r
}\r
}\r
}\r
else { // ------------------------------------ multiple sectors working\r
- clock_t time1;\r
- time1 = clock();\r
+ clock_t time1 = clock();\r
\r
e_sector = calloc(SectorsCnt, sizeof(sector));\r
if (e_sector == NULL) return 1;\r
}\r
}\r
\r
- printf("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1)/CLOCKS_PER_SEC, ((float)clock() - time1)/iterations/CLOCKS_PER_SEC);\r
+ // 20160116 If Sector A is found, but not Sector B, try just reading it of the tag?\r
+ PrintAndLog("testing to read B...");\r
+ for (i = 0; i < SectorsCnt; i++) {\r
+ // KEY A but not KEY B\r
+ if ( e_sector[i].foundKey[0] && !e_sector[i].foundKey[1] ) {\r
+ \r
+ uint8_t sectrail = (FirstBlockOfSector(i) + NumBlocksPerSector(i) - 1);\r
+ \r
+ UsbCommand c = {CMD_MIFARE_READBL, {sectrail, 0, 0}};\r
+ num_to_bytes(e_sector[i].Key[0], 6, c.d.asBytes); // KEY A\r
+ clearCommandBuffer();\r
+ SendCommand(&c);\r
+\r
+ UsbCommand resp;\r
+ if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500)) continue;\r
+ \r
+ uint8_t isOK = resp.arg[0] & 0xff;\r
+ uint8_t *data = resp.d.asBytes;\r
+\r
+ if (isOK) {\r
+\r
+ key64 = bytes_to_num(data+10, 6);\r
+ if (key64) {\r
+ PrintAndLog("Data:%s", sprint_hex(data+10, 6));\r
+ e_sector[i].foundKey[1] = 1;\r
+ e_sector[i].Key[1] = key64;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ \r
+ PrintAndLog("Time in nested: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1)/CLOCKS_PER_SEC, ((float)clock() - time1)/iterations/CLOCKS_PER_SEC);\r
\r
PrintAndLog("-----------------------------------------------\nIterations count: %d\n\n", iterations);\r
//print them\r
PrintAndLog("|---|----------------|---|----------------|---|");\r
for (i = 0; i < SectorsCnt; i++) {\r
PrintAndLog("|%03d| %012"llx" | %d | %012"llx" | %d |", i,\r
- e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[1], e_sector[i].foundKey[1]);\r
+ e_sector[i].Key[0], \r
+ e_sector[i].foundKey[0], \r
+ e_sector[i].Key[1], \r
+ e_sector[i].foundKey[1]\r
+ );\r
}\r
PrintAndLog("|---|----------------|---|----------------|---|");\r
\r
char ctmp;\r
ctmp = param_getchar(Cmd, 0);\r
\r
- if (ctmp != 'R' && ctmp != 'r' && strlen(Cmd) < 20) {\r
+ if (ctmp != 'R' && ctmp != 'r' && ctmp != 'T' && ctmp != 't' && strlen(Cmd) < 20) {\r
PrintAndLog("Usage:");\r
PrintAndLog(" hf mf hardnested <block number> <key A|B> <key (12 hex symbols)>");\r
PrintAndLog(" <target block number> <target key A|B> [known target key (12 hex symbols)] [w] [s]");\r
bool nonce_file_read = false;\r
bool nonce_file_write = false;\r
bool slow = false;\r
+ int tests = 0;\r
+ \r
\r
if (ctmp == 'R' || ctmp == 'r') {\r
nonce_file_read = true;\r
if (!param_gethex(Cmd, 1, trgkey, 12)) {\r
know_target_key = true;\r
}\r
-\r
+ } else if (ctmp == 'T' || ctmp == 't') {\r
+ tests = param_get32ex(Cmd, 1, 100, 10);\r
} else {\r
-\r
blockNo = param_get8(Cmd, 0);\r
ctmp = param_getchar(Cmd, 1);\r
if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {\r
}\r
}\r
\r
- 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 ", \r
+ 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 ", \r
trgBlockNo, \r
trgKeyType?'B':'A', \r
trgkey[0], trgkey[1], trgkey[2], trgkey[3], trgkey[4], trgkey[5],\r
know_target_key?"":" (not set)",\r
nonce_file_write?"write":nonce_file_read?"read":"none",\r
- slow?"Yes":"No");\r
+ slow?"Yes":"No",\r
+ tests);\r
\r
- int16_t isOK = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, know_target_key?trgkey:NULL, nonce_file_read, nonce_file_write, slow);\r
+ int16_t isOK = mfnestedhard(blockNo, keyType, key, trgBlockNo, trgKeyType, know_target_key?trgkey:NULL, nonce_file_read, nonce_file_write, slow, tests);\r
\r
if (isOK) {\r
switch (isOK) {\r
break;\r
default:\r
PrintAndLog("Key type must be A , B or ?");\r
+ free(keyBlock);\r
return 1;\r
};\r
\r
if (!p) {\r
PrintAndLog("Cannot allocate memory for defKeys");\r
free(keyBlock);\r
+ fclose(f);\r
return 2;\r
}\r
keyBlock = p;\r
}\r
}\r
}\r
- \r
+ // time\r
+ time_t time1 = clock();\r
+ \r
for ( int t = !keyType; t < 2; keyType==2?(t++):(t=2) ) {\r
int b=blockNo;\r
for (int i = 0; i < SectorsCnt; ++i) {\r
b<127?(b+=4):(b+=16); \r
}\r
}\r
+ printf("Time in checkkeys: %1.3f (%1.3f sec per key)\n\n", ((float)clock() - time1)/CLOCKS_PER_SEC, ((float)clock() - time1)/keycnt/CLOCKS_PER_SEC);\r
+ \r
\r
if (transferToEml) {\r
uint8_t block[16];\r
\r
uint64_t corr_uid = 0;\r
if ( memcmp(data, "\x00\x00\x00\x00", 4) == 0 ) {\r
- corr_uid = (data[3] << 24) | (data[2] << 16) | (data[1] << 8) | data[0];\r
+ corr_uid = ((uint64_t)(data[3] << 24)) | (data[2] << 16) | (data[1] << 8) | data[0];\r
tryMfk32(corr_uid, data, key);\r
} else {\r
corr_uid |= (uint64_t)data[2] << 48; \r
corr_uid |= (uint64_t)data[1] << 40; \r
corr_uid |= (uint64_t)data[0] << 32;\r
- corr_uid |= data[7] << 24;\r
- corr_uid |= data[6] << 16;\r
- corr_uid |= data[5] << 8;\r
- corr_uid |= data[4];\r
+ corr_uid |= (uint64_t)data[7] << 24;\r
+ corr_uid |= (uint64_t)data[6] << 16;\r
+ corr_uid |= (uint64_t)data[5] << 8;\r
+ corr_uid |= (uint64_t)data[4];\r
tryMfk64(corr_uid, data, key);\r
}\r
PrintAndLog("--");\r
\r
len = param_getstr(Cmd,nameParamNo,filename);\r
\r
- if (len > FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4;\r
+ if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
\r
fnameptr += len;\r
\r
\r
len = param_getstr(Cmd,nameParamNo,filename);\r
\r
- if (len > FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4;\r
+ if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
\r
// user supplied filename?\r
if (len < 1) {\r
return 0;\r
} else {\r
len = strlen(Cmd);\r
- if (len > FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4;\r
+ if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
\r
memcpy(filename, Cmd, len);\r
fnameptr += len;\r
\r
if (mfCSetBlock(blockNum, buf8, NULL, flags)) {\r
PrintAndLog("Can't set magic card block: %d", blockNum);\r
+ fclose(f);\r
return 3;\r
}\r
blockNum++;\r
return 0;\r
} else {\r
len = strlen(Cmd);\r
- if (len > FILE_PATH_SIZE - 4) len = FILE_PATH_SIZE - 4;\r
+ if (len > FILE_PATH_SIZE - 5) len = FILE_PATH_SIZE - 5;\r
\r
// get filename based on UID\r
if (len < 1) {\r