X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/8b6a93df9152de16e16fd4158775954228245613..17331e14ee99bebaef8d84fba44a90818bc5c817:/client/mifarehost.c diff --git a/client/mifarehost.c b/client/mifarehost.c index 70d2413a..14674b16 100644 --- a/client/mifarehost.c +++ b/client/mifarehost.c @@ -12,9 +12,9 @@ #include #include #include "mifarehost.h" +#include "proxmark3.h" // MIFARE - int compar_int(const void * a, const void * b) { return (*(uint64_t*)b - *(uint64_t*)a); } @@ -59,12 +59,12 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo fnVector * vector = NULL; countKeys *ck; int lenVector = 0; - UsbCommand * resp = NULL; + UsbCommand resp; memset(resultKeys, 0x00, 16 * 6); // flush queue - while (WaitForResponseTimeout(CMD_ACK, 500) != NULL) ; + WaitForResponseTimeout(CMD_ACK,NULL,100); UsbCommand c = {CMD_MIFARE_NESTED, {blockNo, keyType, trgBlockNo + trgKeyType * 0x100}}; memcpy(c.d.asBytes, key, 6); @@ -81,18 +81,16 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo break; } - resp = WaitForResponseTimeout(CMD_ACK, 1500); - - if (resp != NULL) { - isEOF = resp->arg[0] & 0xff; + if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { + isEOF = resp.arg[0] & 0xff; if (isEOF) break; - len = resp->arg[1] & 0xff; + len = resp.arg[1] & 0xff; if (len == 0) continue; - memcpy(&uid, resp->d.asBytes, 4); - PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, resp->arg[2] & 0xff, (resp->arg[2] >> 8) & 0xff); + memcpy(&uid, resp.d.asBytes, 4); + PrintAndLog("uid:%08x len=%d trgbl=%d trgkey=%x", uid, len, resp.arg[2] & 0xff, (resp.arg[2] >> 8) & 0xff); vector = (fnVector *) realloc((void *)vector, (lenVector + len) * sizeof(fnVector) + 200); if (vector == NULL) { PrintAndLog("Memory allocation error for fnVector. len: %d bytes: %d", lenVector + len, (lenVector + len) * sizeof(fnVector)); @@ -100,12 +98,12 @@ int mfnested(uint8_t blockNo, uint8_t keyType, uint8_t * key, uint8_t trgBlockNo } for (i = 0; i < len; i++) { - vector[lenVector + i].blockNo = resp->arg[2] & 0xff; - vector[lenVector + i].keyType = (resp->arg[2] >> 8) & 0xff; + vector[lenVector + i].blockNo = resp.arg[2] & 0xff; + vector[lenVector + i].keyType = (resp.arg[2] >> 8) & 0xff; vector[lenVector + i].uid = uid; - memcpy(&vector[lenVector + i].nt, (void *)(resp->d.asBytes + 8 + i * 8 + 0), 4); - memcpy(&vector[lenVector + i].ks1, (void *)(resp->d.asBytes + 8 + i * 8 + 4), 4); + memcpy(&vector[lenVector + i].nt, (void *)(resp.d.asBytes + 8 + i * 8 + 0), 4); + memcpy(&vector[lenVector + i].ks1, (void *)(resp.d.asBytes + 8 + i * 8 + 4), 4); } lenVector += len; @@ -187,14 +185,12 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * key UsbCommand c = {CMD_MIFARE_CHKKEYS, {blockNo, keyType, keycnt}}; memcpy(c.d.asBytes, keyBlock, 6 * keycnt); - SendCommand(&c); - UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 3000); - - if (resp == NULL) return 1; - if ((resp->arg[0] & 0xff) != 0x01) return 2; - *key = bytes_to_num(resp->d.asBytes, 6); + UsbCommand resp; + if (!WaitForResponseTimeout(CMD_ACK,&resp,3000)) return 1; + if ((resp.arg[0] & 0xff) != 0x01) return 2; + *key = bytes_to_num(resp.d.asBytes, 6); return 0; } @@ -202,13 +198,11 @@ int mfCheckKeys (uint8_t blockNo, uint8_t keyType, uint8_t keycnt, uint8_t * key int mfEmlGetMem(uint8_t *data, int blockNum, int blocksCount) { UsbCommand c = {CMD_MIFARE_EML_MEMGET, {blockNum, blocksCount, 0}}; - - SendCommand(&c); - - UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500); + SendCommand(&c); - if (resp == NULL) return 1; - memcpy(data, resp->d.asBytes, blocksCount * 16); + UsbCommand resp; + if (!WaitForResponseTimeout(CMD_ACK,&resp,1500)) return 1; + memcpy(data, resp.d.asBytes, blocksCount * 16); return 0; } @@ -241,11 +235,10 @@ int mfCSetBlock(uint8_t blockNo, uint8_t *data, uint8_t *uid, int wantWipe, uint memcpy(c.d.asBytes, data, 16); SendCommand(&c); - UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500); - - if (resp != NULL) { - isOK = resp->arg[0] & 0xff; - if (uid != NULL) memcpy(uid, resp->d.asBytes, 4); + UsbCommand resp; + if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { + isOK = resp.arg[0] & 0xff; + if (uid != NULL) memcpy(uid, resp.d.asBytes, 4); if (!isOK) return 2; } else { PrintAndLog("Command execute timeout"); @@ -260,11 +253,10 @@ int mfCGetBlock(uint8_t blockNo, uint8_t *data, uint8_t params) { UsbCommand c = {CMD_MIFARE_EML_CGETBLOCK, {params, 0, blockNo}}; SendCommand(&c); - UsbCommand * resp = WaitForResponseTimeout(CMD_ACK, 1500); - - if (resp != NULL) { - isOK = resp->arg[0] & 0xff; - memcpy(data, resp->d.asBytes, 16); + UsbCommand resp; + if (WaitForResponseTimeout(CMD_ACK,&resp,1500)) { + isOK = resp.arg[0] & 0xff; + memcpy(data, resp.d.asBytes, 16); if (!isOK) return 2; } else { PrintAndLog("Command execute timeout"); @@ -295,9 +287,12 @@ uint32_t ks3; uint32_t uid; // serial number uint32_t nt; // tag challenge +uint32_t nt_par; uint32_t nr_enc; // encrypted reader challenge uint32_t ar_enc; // encrypted reader response +uint32_t nr_ar_par; uint32_t at_enc; // encrypted tag response +uint32_t at_par; int isTraceCardEmpty(void) { return ((traceCard[0] == 0) && (traceCard[1] == 0) && (traceCard[2] == 0) && (traceCard[3] == 0)); @@ -401,7 +396,7 @@ void mf_crypto1_decrypt(struct Crypto1State *pcs, uint8_t *data, int len, bool i } -int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { +int mfTraceDecode(uint8_t *data_src, int len, uint32_t parity, bool wantSaveToEmlFile) { uint8_t data[64]; if (traceState == TRACE_ERROR) return 1; @@ -504,6 +499,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { traceState = TRACE_AUTH2; nt = bytes_to_num(data, 4); + nt_par = parity; return 0; } else { traceState = TRACE_ERROR; @@ -517,6 +513,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { nr_enc = bytes_to_num(data, 4); ar_enc = bytes_to_num(data + 4, 4); + nr_ar_par = parity; return 0; } else { traceState = TRACE_ERROR; @@ -529,6 +526,7 @@ int mfTraceDecode(uint8_t *data_src, int len, bool wantSaveToEmlFile) { traceState = TRACE_IDLE; at_enc = bytes_to_num(data, 4); + at_par = parity; // decode key here) if (!traceCrypto1) {