From 1f1929a4aa2e013f3ed656a07c5841afa2727779 Mon Sep 17 00:00:00 2001 From: iceman Date: Tue, 12 Jan 2016 15:57:53 +0100 Subject: [PATCH 1/4] CHG: maybe this init works better? --- client/cmdhfmfhard.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/cmdhfmfhard.c b/client/cmdhfmfhard.c index e2d6da74e..2c1ed7c42 100644 --- a/client/cmdhfmfhard.c +++ b/client/cmdhfmfhard.c @@ -686,8 +686,8 @@ static void Check_for_FilterFlipProperties(void) static void simulate_MFplus_RNG(uint32_t test_cuid, uint64_t test_key, uint32_t *nt_enc, uint8_t *par_enc) { - struct Crypto1State sim_cs; - sim_cs.odd = sim_cs.even = 0; + struct Crypto1State sim_cs = {0, 0}; +// sim_cs.odd = sim_cs.even = 0; // init cryptostate with key: for(int8_t i = 47; i > 0; i -= 2) { From ca3ed459283f056e713ab7fd5333ce2d79cc50b0 Mon Sep 17 00:00:00 2001 From: iceman Date: Tue, 9 Feb 2016 15:04:08 +0100 Subject: [PATCH 2/4] :syntax sugger --- client/proxmark3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/proxmark3.c b/client/proxmark3.c index 091f6d08a..21108cd54 100644 --- a/client/proxmark3.c +++ b/client/proxmark3.c @@ -278,6 +278,6 @@ int main(int argc, char* argv[]) { // clean up mutex pthread_mutex_destroy(&print_lock); - + exit(0); } From 847f7404ffe293e263532dd3773b6f5b03038f98 Mon Sep 17 00:00:00 2001 From: iceman Date: Wed, 10 Feb 2016 13:20:23 +0100 Subject: [PATCH 3/4] CHG: added some timing messages, --- client/cmdhfmf.c | 59 +++++++++++++++++++++++++----------------------- 1 file changed, 31 insertions(+), 28 deletions(-) diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index d354952b1..80c072f50 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -53,7 +53,7 @@ start: // wait cycle while (true) { - printf("."); + printf("."); fflush(stdout); if (ukbhit()) { tmpchar = getchar(); @@ -63,22 +63,21 @@ start: } UsbCommand resp; - if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) { + if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { isOK = resp.arg[0]; - uid = (uint32_t)bytes_to_num(resp.d.asBytes + 0, 4); - nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4); - par_list = bytes_to_num(resp.d.asBytes + 8, 8); - ks_list = bytes_to_num(resp.d.asBytes + 16, 8); - nr = bytes_to_num(resp.d.asBytes + 24, 4); - printf("\n\n"); switch (isOK) { case -1 : PrintAndLog("Button pressed. Aborted.\n"); break; case -2 : PrintAndLog("Card is not vulnerable to Darkside attack (doesn't send NACK on authentication requests).\n"); break; case -3 : PrintAndLog("Card is not vulnerable to Darkside attack (its random number generator is not predictable).\n"); break; case -4 : PrintAndLog("Card is not vulnerable to Darkside attack (its random number generator seems to be based on the wellknown"); - PrintAndLog("generating polynomial with 16 effective bits only, but shows unexpected behaviour.\n"); break; + PrintAndLog("generating polynomial with 16 effective bits only, but shows unexpected behaviour.\n"); break; default: ; } + uid = (uint32_t)bytes_to_num(resp.d.asBytes, 4); + nt = (uint32_t)bytes_to_num(resp.d.asBytes + 4, 4); + par_list = bytes_to_num(resp.d.asBytes + 8, 8); + ks_list = bytes_to_num(resp.d.asBytes + 16, 8); + nr = bytes_to_num(resp.d.asBytes + 24, 4); break; } } @@ -707,12 +706,13 @@ int CmdHF14AMfNested(const char *Cmd) clock_t t2 = clock() - t1; if ( t2 > 0 ) PrintAndLog("Time to check 6 known keys: %.0f ticks %4.2f sec", (float)t2, ((float)t2)/CLOCKS_PER_SEC); - + + PrintAndLog("enter nested..."); // nested sectors iterations = 0; - PrintAndLog("enter nested..."); bool calibrate = true; + for (i = 0; i < NESTED_SECTOR_RETRY; i++) { for (uint8_t sectorNo = 0; sectorNo < SectorsCnt; ++sectorNo) { for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) { @@ -731,7 +731,7 @@ int CmdHF14AMfNested(const char *Cmd) case -5 : calibrate = false; iterations++; - e_sector[sectorNo].foundKey[trgKeyType] = 1; + e_sector[sectorNo].foundKey[trgKeyType] = TRUE; e_sector[sectorNo].Key[trgKeyType] = bytes_to_num(keyBlock, 6); continue; @@ -742,6 +742,10 @@ int CmdHF14AMfNested(const char *Cmd) } } } + + t1 = clock() - t1; + if ( t1 > 0 ) + PrintAndLog("Time in nested: %.0f ticks %4.2f sec (%4.2f sec per key)\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/iterations/CLOCKS_PER_SEC); // 20160116 If Sector A is found, but not Sector B, try just reading it of the tag? PrintAndLog("trying to read key B..."); @@ -759,7 +763,7 @@ int CmdHF14AMfNested(const char *Cmd) SendCommand(&c); UsbCommand resp; - if ( !WaitForResponseTimeout(CMD_ACK,&resp,1500)) continue; + if ( !WaitForResponseTimeout(CMD_ACK, &resp, 1500)) continue; uint8_t isOK = resp.arg[0] & 0xff; if (!isOK) continue; @@ -768,15 +772,12 @@ int CmdHF14AMfNested(const char *Cmd) key64 = bytes_to_num(data+10, 6); if (key64) { PrintAndLog("Data:%s", sprint_hex(data+10, 6)); - e_sector[i].foundKey[1] = 1; + e_sector[i].foundKey[1] = TRUE; e_sector[i].Key[1] = key64; } } } - - t1 = clock() - t1; - if ( t1 > 0 ) - PrintAndLog("Time in nested: %.0f ticks %4.2f sec (%4.2f sec per key)\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/iterations/CLOCKS_PER_SEC); + //print them printKeyTable( SectorsCnt, e_sector ); @@ -1047,7 +1048,7 @@ int CmdHF14AMfChk(const char *Cmd) } keyBlock = p; } - PrintAndLog("check key[%2d] %02x%02x%02x%02x%02x%02x", keycnt, + PrintAndLog("key[%2d] %02x%02x%02x%02x%02x%02x", keycnt, (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2], (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6); keycnt++; @@ -1087,7 +1088,7 @@ int CmdHF14AMfChk(const char *Cmd) } memset(keyBlock + 6 * keycnt, 0, 6); num_to_bytes(strtoll(buf, NULL, 16), 6, keyBlock + 6*keycnt); - PrintAndLog("check custom key[%2d] %012"llx, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6)); + PrintAndLog("check key[%2d] %012"llx, keycnt, bytes_to_num(keyBlock + 6*keycnt, 6)); keycnt++; memset(buf, 0, sizeof(buf)); } @@ -1104,7 +1105,7 @@ int CmdHF14AMfChk(const char *Cmd) if (keycnt == 0) { PrintAndLog("No key specified, trying default keys"); for (;keycnt < defaultKeysSize; keycnt++) - PrintAndLog("check default key[%2d] %02x%02x%02x%02x%02x%02x", keycnt, + PrintAndLog("key[%2d] %02x%02x%02x%02x%02x%02x", keycnt, (keyBlock + 6*keycnt)[0],(keyBlock + 6*keycnt)[1], (keyBlock + 6*keycnt)[2], (keyBlock + 6*keycnt)[3], (keyBlock + 6*keycnt)[4], (keyBlock + 6*keycnt)[5], 6); } @@ -1117,27 +1118,27 @@ int CmdHF14AMfChk(const char *Cmd) } uint8_t trgKeyType = 0; + uint32_t max_keys = keycnt > (USB_CMD_DATA_SIZE/6) ? (USB_CMD_DATA_SIZE/6) : keycnt; // time clock_t t1 = clock(); // check keys. for (trgKeyType = 0; trgKeyType < 2; ++trgKeyType) { + int b = blockNo; for (int i = 0; i < SectorsCnt; ++i) { // skip already found keys. if (e_sector[i].foundKey[trgKeyType]) continue; - uint32_t max_keys = keycnt > (USB_CMD_DATA_SIZE/6) ? (USB_CMD_DATA_SIZE/6) : keycnt; - for (uint32_t c = 0; c < keycnt; c += max_keys) { uint32_t size = keycnt-c > max_keys ? max_keys : keycnt-c; res = mfCheckKeys(b, trgKeyType, true, size, &keyBlock[6*c], &key64); if (!res) { - PrintAndLog("Sector:%3d Block:%3d, key type: %C -- Found key [%012"llx"]", i, b, trgKeyType ? 'B':'A', key64); + //PrintAndLog("Sector:%3d Block:%3d, key type: %C -- Found key [%012"llx"]", i, b, trgKeyType ? 'B':'A', key64); e_sector[i].Key[trgKeyType] = key64; e_sector[i].foundKey[trgKeyType] = TRUE; @@ -1150,6 +1151,11 @@ int CmdHF14AMfChk(const char *Cmd) b < 127 ? ( b +=4 ) : ( b += 16 ); } } + + t1 = clock() - t1; + if ( t1 > 0 ) + printf("Time in checkkeys: %.0f ticks %1.2f sec (%1.2f sec per key)\n\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/keycnt/CLOCKS_PER_SEC); + // 20160116 If Sector A is found, but not Sector B, try just reading it of the tag? PrintAndLog("testing to read B..."); for (i = 0; i < SectorsCnt; i++) { @@ -1180,10 +1186,7 @@ int CmdHF14AMfChk(const char *Cmd) } } } - - t1 = clock() - t1; - if ( t1 > 0 ) - printf("Time in checkkeys: %.0f ticks %1.2f sec (%1.2f sec per key)\n\n", (float)t1, ((float)t1)/CLOCKS_PER_SEC, ((float)t1)/keycnt/CLOCKS_PER_SEC); + //print them printKeyTable( SectorsCnt, e_sector ); From 719b2377bee69506572b54af1e210b62c296675c Mon Sep 17 00:00:00 2001 From: iceman Date: Wed, 10 Feb 2016 13:22:48 +0100 Subject: [PATCH 4/4] chg: what? --- client/cmdmain.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/client/cmdmain.c b/client/cmdmain.c index e75211e68..1357c436d 100644 --- a/client/cmdmain.c +++ b/client/cmdmain.c @@ -120,6 +120,7 @@ int getCommand(UsbCommand* response) //Pick out the next unread command UsbCommand* last_unread = &cmdBuffer[cmd_tail]; memcpy(response, last_unread, sizeof(UsbCommand)); + //Increment tail - this is a circular buffer, so modulo buffer size cmd_tail = (cmd_tail +1 ) % CMD_BUFFER_SIZE; @@ -146,10 +147,10 @@ bool WaitForResponseTimeout(uint32_t cmd, UsbCommand* response, size_t ms_timeou for ( size_t dm_seconds = 0; dm_seconds < ms_timeout/10; dm_seconds++ ) { while( getCommand(response) ) { - if(response->cmd == cmd){ - return true; - } + if(response->cmd == cmd) + return true; } + msleep(10); // XXX ugh if (dm_seconds == 200) { // Two seconds elapsed PrintAndLog("Waiting for a response from the proxmark..."); @@ -180,28 +181,25 @@ void UsbCommandReceived(UsbCommand *UC) switch(UC->cmd) { // First check if we are handling a debug message case CMD_DEBUG_PRINT_STRING: { - char s[USB_CMD_DATA_SIZE+1] = {0x00}; - size_t len = MIN(UC->arg[0],USB_CMD_DATA_SIZE); - memcpy(s,UC->d.asBytes,len); - PrintAndLog("#db# %s ", s); - return; + char s[USB_CMD_DATA_SIZE+1]; + memset(s, 0x00, sizeof(s)); + size_t len = MIN(UC->arg[0], USB_CMD_DATA_SIZE); + memcpy(s, UC->d.asBytes, len); + PrintAndLog("#db# %s", s); } break; - case CMD_DEBUG_PRINT_INTEGERS: { - PrintAndLog("#db# %08x, %08x, %08x \r\n", UC->arg[0], UC->arg[1], UC->arg[2]); - return; - } break; + case CMD_DEBUG_PRINT_INTEGERS: + PrintAndLog("#db# %08x, %08x, %08x", UC->arg[0], UC->arg[1], UC->arg[2]); + break; - case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K: { - memcpy(sample_buf+(UC->arg[0]),UC->d.asBytes,UC->arg[1]); - return; - } break; + case CMD_DOWNLOADED_RAW_ADC_SAMPLES_125K: + memcpy( sample_buf + (UC->arg[0]), UC->d.asBytes, UC->arg[1]); + break; default: { storeCommand(UC); break; } } - }