X-Git-Url: http://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/39864b0bd41dd5e896bcb8eeabcf2c3932f2203a..bfaecce6ebf50e296a1a4d221411581ff96f91c3:/client/cmdhfmf.c diff --git a/client/cmdhfmf.c b/client/cmdhfmf.c index 98006d41..dff5db37 100644 --- a/client/cmdhfmf.c +++ b/client/cmdhfmf.c @@ -71,17 +71,22 @@ start: if (isOK != 1) return 1; // execute original function from util nonce2key - if (nonce2key(uid, nt, par_list, ks_list, &r_key)) return 2; - printf("------------------------------------------------------------------\n"); - PrintAndLog("Key found:%012llx \n", r_key); + if (nonce2key(uid, nt, par_list, ks_list, &r_key)) + { + isOK = 2; + PrintAndLog("Key not found (lfsr_common_prefix list is null). Nt=%08x", nt); + } else { + printf("------------------------------------------------------------------\n"); + PrintAndLog("Key found:%012llx \n", r_key); - num_to_bytes(r_key, 6, keyBlock); - isOK = mfCheckKeys(0, 0, 1, keyBlock, &r_key); + num_to_bytes(r_key, 6, keyBlock); + isOK = mfCheckKeys(0, 0, 1, keyBlock, &r_key); + } if (!isOK) PrintAndLog("Found valid key:%012llx", r_key); else { - PrintAndLog("Found invalid key. ( Nt=%08x ,Trying use it to run again...", nt); + if (isOK != 2) PrintAndLog("Found invalid key. ( Nt=%08x ,Trying use it to run again...", nt); c.arg[0] = nt; goto start; } @@ -984,10 +989,6 @@ int CmdHF14AMfEGet(const char *Cmd) } blockNo = param_get8(Cmd, 0); - if (blockNo >= 32 * 4 + 8 * 16) { - PrintAndLog("Block number must be in [0..255] as in MIFARE classic."); - return 1; - } PrintAndLog(" "); if (!mfEmlGetMem(data, blockNo, 3)) { @@ -1028,10 +1029,6 @@ int CmdHF14AMfESet(const char *Cmd) } blockNo = param_get8(Cmd, 0); - if (blockNo >= 32 * 4 + 8 * 16) { - PrintAndLog("Block number must be in [0..255] as in MIFARE classic."); - return 1; - } if (param_gethex(Cmd, 1, memBlock, 32)) { PrintAndLog("block data must include 32 HEX symbols"); @@ -1269,10 +1266,6 @@ int CmdHF14AMfCSetBlk(const char *Cmd) } blockNo = param_get8(Cmd, 0); - if (blockNo >= 32 * 4 + 8 * 16) { - PrintAndLog("Block number must be in [0..255] as in MIFARE classic."); - return 1; - } if (param_gethex(Cmd, 1, memBlock, 32)) { PrintAndLog("block data must include 32 HEX symbols"); @@ -1400,10 +1393,6 @@ int CmdHF14AMfCGetBlk(const char *Cmd) { } blockNo = param_get8(Cmd, 0); - if (blockNo >= 32 * 4 + 8 * 16) { - PrintAndLog("Block number must be in [0..255] as in MIFARE classic."); - return 1; - } PrintAndLog("--block number:%02x ", blockNo); @@ -1542,6 +1531,13 @@ int CmdHF14AMfCSave(const char *Cmd) { } int CmdHF14AMfSniff(const char *Cmd){ + // params + bool wantLogToFile = 0; + bool wantDecrypt = 0; + //bool wantSaveToEml = 0; TODO + bool wantSaveToEmlFile = 0; + + //var int res = 0; int len = 0; int blockLen = 0; @@ -1551,16 +1547,31 @@ int CmdHF14AMfSniff(const char *Cmd){ uint8_t atqa[2]; uint8_t sak; bool isTag; + uint32_t parity; uint8_t buf[3000]; uint8_t * bufPtr = buf; memset(buf, 0x00, 3000); if (param_getchar(Cmd, 0) == 'h') { - PrintAndLog("Usage: hf mf sniff "); - PrintAndLog(" sample: hf mf sniff "); + PrintAndLog("It continuously get data from the field and saves it to: log, emulator, emulator file."); + PrintAndLog("You can specify:"); + PrintAndLog(" l - save encrypted sequence to logfile `uid.log`"); + PrintAndLog(" d - decrypt sequence and put it to log file `uid.log`"); + PrintAndLog(" n/a e - decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory"); + PrintAndLog(" r - decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`"); + PrintAndLog("Usage: hf mf sniff [l][d][e][r]"); + PrintAndLog(" sample: hf mf sniff l d e"); return 0; } + for (int i = 0; i < 4; i++) { + char ctmp = param_getchar(Cmd, i); + if (ctmp == 'l' || ctmp == 'L') wantLogToFile = true; + if (ctmp == 'd' || ctmp == 'D') wantDecrypt = true; + //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO + if (ctmp == 'f' || ctmp == 'F') wantSaveToEmlFile = true; + } + printf("-------------------------------------------------------------------------\n"); printf("Executing command. \n"); printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n"); @@ -1604,16 +1615,26 @@ int CmdHF14AMfSniff(const char *Cmd){ num = 0; while (bufPtr - buf + 9 < blockLen) { isTag = bufPtr[3] & 0x80 ? true:false; - bufPtr += 8; + bufPtr += 4; + parity = *((uint32_t *)(bufPtr)); + bufPtr += 4; len = bufPtr[0]; bufPtr++; if ((len == 14) && (bufPtr[0] = 0xff) && (bufPtr[1] = 0xff)) { memcpy(uid, bufPtr + 2, 7); memcpy(atqa, bufPtr + 2 + 7, 2); sak = bufPtr[11]; + PrintAndLog("tag select uid:%s atqa:%02x %02x sak:0x%02x", sprint_hex(uid, 7), atqa[0], atqa[1], sak); + if (wantLogToFile) { + FillFileNameByUID(logHexFileName, uid, ".log", 7); + AddLogCurrentDT(logHexFileName); + } + if (wantDecrypt) mfTraceInit(uid, atqa, sak, wantSaveToEmlFile); } else { PrintAndLog("%s(%d):%s", isTag ? "TAG":"RDR", num, sprint_hex(bufPtr, len)); + if (wantLogToFile) AddLogHex(logHexFileName, isTag ? "TAG: ":"RDR: ", bufPtr, len); + if (wantDecrypt) mfTraceDecode(bufPtr, len, parity, wantSaveToEmlFile); } bufPtr += len; num++;