uint32_t nt = 0, nr = 0;\r
uint64_t par_list = 0, ks_list = 0, r_key = 0;\r
int16_t isOK = 0;\r
-\r
+ int tmpchar; \r
+ \r
UsbCommand c = {CMD_READER_MIFARE, {true, 0, 0}};\r
\r
// message\r
printf("Press button on the proxmark3 device to abort both proxmark3 and client.\n");\r
printf("-------------------------------------------------------------------------\n");\r
\r
+ clock_t t1 = clock();\r
\r
start:\r
clearCommandBuffer();\r
SendCommand(&c);\r
\r
//flush queue\r
- while (ukbhit()) getchar();\r
+ while (ukbhit()) {\r
+ tmpchar = getchar();\r
+ (void)tmpchar;\r
+ }\r
\r
// wait cycle\r
while (true) {\r
printf(".");\r
fflush(stdout);\r
if (ukbhit()) {\r
- getchar();\r
+ tmpchar = getchar();\r
+ (void)tmpchar;\r
printf("\naborted via keyboard!\n");\r
break;\r
}\r
printf("------------------------------------------------------------------\n");\r
PrintAndLog("Found valid key: %012"llx" \n", r_key);\r
}\r
- \r
- PrintAndLog("");\r
+ t1 = clock() - t1;\r
+ if ( t1 > 0 ){\r
+ PrintAndLog("Time in darkside: %f ticks - %1.2f sec\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC);\r
+ }\r
return 0;\r
}\r
\r
}\r
\r
// Read keys A from file\r
+ size_t bytes_read;\r
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
- if (fread( keyA[sectorNo], 1, 6, fin ) == 0) {\r
+ bytes_read = fread( keyA[sectorNo], 1, 6, fin );\r
+ if ( bytes_read == 0) {\r
PrintAndLog("File reading error.");\r
fclose(fin);\r
return 2;\r
\r
// Read keys B from file\r
for (sectorNo=0; sectorNo<numSectors; sectorNo++) {\r
- if (fread( keyB[sectorNo], 1, 6, fin ) == 0) {\r
+ bytes_read = fread( keyB[sectorNo], 1, 6, fin );\r
+ if ( bytes_read == 0) {\r
PrintAndLog("File reading error.");\r
fclose(fin);\r
return 2;\r
return 1;\r
}\r
\r
+ size_t bytes_read;\r
for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
- if (fread(keyA[sectorNo], 1, 6, fkeys) == 0) {\r
+ bytes_read = fread( keyA[sectorNo], 1, 6, fkeys );\r
+ if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
fclose(fkeys);\r
return 2;\r
}\r
\r
for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
- if (fread(keyB[sectorNo], 1, 6, fkeys) == 0) {\r
+ bytes_read = fread( keyB[sectorNo], 1, 6, fkeys );\r
+ if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpkeys.bin).");\r
fclose(fkeys);\r
return 2;\r
for (sectorNo = 0; sectorNo < numSectors; sectorNo++) {\r
for(blockNo = 0; blockNo < NumBlocksPerSector(sectorNo); blockNo++) {\r
UsbCommand c = {CMD_MIFARE_WRITEBL, {FirstBlockOfSector(sectorNo) + blockNo, keyType, 0}};\r
- memcpy(c.d.asBytes, key, 6);\r
- \r
- if (fread(bldata, 1, 16, fdump) == 0) {\r
+ memcpy(c.d.asBytes, key, 6); \r
+ bytes_read = fread(bldata, 1, 16, fdump);\r
+ if ( bytes_read == 0) {\r
PrintAndLog("File reading error (dumpdata.bin).");\r
fclose(fdump);\r
return 2;\r
}\r
}\r
else { // ------------------------------------ multiple sectors working\r
- clock_t time1;\r
- time1 = clock();\r
+ clock_t t1 = 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
+ t1 = clock() - t1;\r
+ if ( t1 > 0 ) {\r
+ PrintAndLog("Time in nested: %f ticks %1.2f sec (%1.2f sec per key)\n\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/iterations/CLOCKS_PER_SEC);\r
+ }\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
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
if (!p) {\r
PrintAndLog("Cannot allocate memory for defKeys");\r
free(keyBlock);\r
- free(f);\r
+ fclose(f);\r
return 2;\r
}\r
keyBlock = p;\r
}\r
}\r
}\r
- \r
+ // time\r
+ clock_t t1 = 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
+ t1 = clock() - t1;\r
+ if ( t1 > 0 ){\r
+ printf("Time in checkkeys: %f ticks %1.2f sec (%1.2f sec per key)\n\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/keycnt/CLOCKS_PER_SEC);\r
+ }\r
\r
if (transferToEml) {\r
uint8_t block[16];\r
}\r
pnr +=2;\r
}\r
+ \r
if (param_getchar(Cmd, pnr) == 'n') {\r
exitAfterNReads = param_get8(Cmd,pnr+1);\r
pnr += 2;\r
}\r
+ \r
if (param_getchar(Cmd, pnr) == 'i' ) {\r
//Using a flag to signal interactiveness, least significant bit\r
flags |= FLAG_INTERACTIVE;\r
//Using a flag to signal interactiveness, least significant bit\r
flags |= FLAG_NR_AR_ATTACK;\r
}\r
+ \r
PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) ",\r
flags & FLAG_4B_UID_IN_DATA ? sprint_hex(uid,4):\r
flags & FLAG_7B_UID_IN_DATA ? sprint_hex(uid,7): "N/A"\r
- , exitAfterNReads, flags,flags);\r
+ , exitAfterNReads\r
+ , flags\r
+ , flags);\r
\r
\r
UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};\r
\r
UsbCommand resp; \r
PrintAndLog("Press pm3-button or send another cmd to abort simulation");\r
- //while(! WaitForResponseTimeout(CMD_ACK,&resp,1500)) {\r
- //We're waiting only 1.5 s at a time, otherwise we get the\r
- // annoying message about "Waiting for a response... "\r
- //}\r
- while(!ukbhit() ){\r
- if (!WaitForResponseTimeout(CMD_ACK,&resp,1500) ) continue;\r
+\r
+ while( !ukbhit() ){\r
+ if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500) ) continue;\r
\r
if ( !(flags & FLAG_NR_AR_ATTACK) ) break;\r
+ \r
if ( (resp.arg[0] & 0xffff) != CMD_SIMULATE_MIFARE_CARD ) break;\r
\r
- memset(data, 0x00, sizeof(data));\r
- memset(key, 0x00, sizeof(key));\r
- int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];\r
- \r
- memcpy(data, resp.d.asBytes, len);\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
- 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 |= (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
+ memset(data, 0x00, sizeof(data));\r
+ memset(key, 0x00, sizeof(key));\r
+ int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];\r
+ \r
+ memcpy(data, resp.d.asBytes, len);\r
+ \r
+ uint64_t corr_uid = 0;\r
+ \r
+ // this IF? what was I thinking of?\r
+ if ( memcmp(data, "\x00\x00\x00\x00", 4) == 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 |= (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
- }\r
- \r
+ PrintAndLog("--");\r
+ }\r
+ }\r
return 0;\r
}\r
\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
bool wantSaveToEmlFile = 0;\r
\r
//var \r
+ int tmpchar;\r
int res = 0;\r
int len = 0;\r
int blockLen = 0;\r
printf(".");\r
fflush(stdout);\r
if (ukbhit()) {\r
- getchar();\r
+ tmpchar = getchar();\r
+ (void)tmpchar;\r
printf("\naborted via keyboard!\n");\r
break;\r
}\r