]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmf.c
FIX: this fixes the "hf mf sniff l d f" command, which has been broken for a while...
[proxmark3-svn] / client / cmdhfmf.c
index 797b5657d3e1c0e73e982e1fffc913941cc5d25c..ec5d4487ce90068bc63794b2db2f85c5050a570d 100644 (file)
 #include "nonce2key/nonce2key.h"\r
 \r
 static int CmdHelp(const char *Cmd);\r
+int usage_hf14_mifare(void){\r
+       PrintAndLog("Usage:  hf mf mifare [h] <block number>");\r
+       PrintAndLog("options:");\r
+       PrintAndLog("           h    this help");\r
+       PrintAndLog("           <block number>  (Optional) target other key A than block 0.");\r
+       PrintAndLog("sample:");\r
+       PrintAndLog("           hf mf mifare");\r
+       PrintAndLog("           hf mf mifare 16");\r
+       return 0;\r
+}\r
+int usage_hf14_mf1ksim(void){\r
+       PrintAndLog("Usage:  hf mf sim  [h] u <uid (8,14,20 hex symbols)> n <numreads> i x");\r
+       PrintAndLog("options:");\r
+       PrintAndLog("           h    this help");\r
+       PrintAndLog("           u    (Optional) UID 4,7 or 10bytes. If not specified, the UID 4b from emulator memory will be used");\r
+       PrintAndLog("           n    (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");\r
+       PrintAndLog("           i    (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");\r
+       PrintAndLog("           x    (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");\r
+       PrintAndLog("samples:");\r
+       PrintAndLog("           hf mf sim u 0a0a0a0a");\r
+       PrintAndLog("           hf mf sim u 11223344556677");\r
+       PrintAndLog("           hf mf sim u 112233445566778899AA");     \r
+       return 0;\r
+}\r
+int usage_hf14_dbg(void){\r
+       PrintAndLog("Usage:  hf mf dbg [h] <debug level>");\r
+       PrintAndLog("options:");\r
+       PrintAndLog("           h    this help");       \r
+       PrintAndLog("       <debug level>  (Optional) see list for valid levels");\r
+       PrintAndLog("           0 - no debug messages");\r
+       PrintAndLog("           1 - error messages");\r
+       PrintAndLog("           2 - plus information messages");\r
+       PrintAndLog("           3 - plus debug messages");\r
+       PrintAndLog("           4 - print even debug messages in timing critical functions");\r
+       PrintAndLog("               Note: this option therefore may cause malfunction itself");\r
+       PrintAndLog("samples:");\r
+       PrintAndLog("           hf mf dbg 3");\r
+       return 0;\r
+}\r
+int usage_hf14_sniff(void){\r
+       PrintAndLog("It continuously gets data from the field and saves it to: log, emulator, emulator file.");\r
+       PrintAndLog("Usage:  hf mf sniff [h] [l] [d] [f]");\r
+       PrintAndLog("options:");\r
+       PrintAndLog("           h    this help");\r
+       PrintAndLog("           l    save encrypted sequence to logfile `uid.log`");\r
+       PrintAndLog("           d    decrypt sequence and put it to log file `uid.log`");\r
+//     PrintAndLog(" n/a   e     decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory");\r
+       PrintAndLog("           f    decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`");\r
+       PrintAndLog("sample:");\r
+       PrintAndLog("           hf mf sniff l d f");\r
+       return 0;\r
+}\r
 \r
-int CmdHF14AMifare(const char *Cmd)\r
-{\r
+int CmdHF14AMifare(const char *Cmd) {\r
        uint32_t uid = 0;\r
        uint32_t nt = 0, nr = 0;\r
        uint64_t par_list = 0, ks_list = 0, r_key = 0;\r
@@ -24,21 +75,16 @@ int CmdHF14AMifare(const char *Cmd)
        uint8_t blockNo = 0;\r
        \r
        char cmdp = param_getchar(Cmd, 0);      \r
-       if ( cmdp == 'H' || cmdp == 'h') {\r
-               PrintAndLog("Usage:  hf mf mifare <block number>");\r
-               PrintAndLog("        sample: hf mf mifare 0");\r
-               return 0;\r
-       }       \r
+       if ( cmdp == 'H' || cmdp == 'h') return usage_hf14_mifare();\r
        \r
        blockNo = param_get8(Cmd, 0);\r
        UsbCommand c = {CMD_READER_MIFARE, {true, blockNo, 0}};\r
 \r
        // message\r
        printf("-------------------------------------------------------------------------\n");\r
-       printf("Executing command. Expected execution time: 25sec on average  :-)\n");\r
+       printf("Executing darkside attack. Expected execution time: 25sec on average :-)\n");\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
@@ -65,7 +111,13 @@ start:
                UsbCommand resp;\r
                if (WaitForResponseTimeout(CMD_ACK, &resp, 1500)) {\r
                        isOK  = resp.arg[0];\r
-                       printf("\n\n");\r
+                       printf("\n");\r
+                       uid = (uint32_t)bytes_to_num(resp.d.asBytes +  0, 4);\r
+                       nt =  (uint32_t)bytes_to_num(resp.d.asBytes +  4, 4);\r
+                       par_list = bytes_to_num(resp.d.asBytes +  8, 8);\r
+                       ks_list = bytes_to_num(resp.d.asBytes +  16, 8);\r
+                       nr = bytes_to_num(resp.d.asBytes + 24, 4);\r
+\r
                        switch (isOK) {\r
                                case -1 : PrintAndLog("Button pressed. Aborted.\n"); break;\r
                                case -2 : PrintAndLog("Card is not vulnerable to Darkside attack (doesn't send NACK on authentication requests).\n"); break;\r
@@ -74,17 +126,19 @@ start:
                                                  PrintAndLog("generating polynomial with 16 effective bits only, but shows unexpected behaviour.\n"); break;\r
                                default: ;\r
                        }\r
-                       uid = (uint32_t)bytes_to_num(resp.d.asBytes +  0, 4);\r
-                       nt =  (uint32_t)bytes_to_num(resp.d.asBytes +  4, 4);\r
-                       par_list = bytes_to_num(resp.d.asBytes +  8, 8);\r
-                       ks_list = bytes_to_num(resp.d.asBytes +  16, 8);\r
-                       nr = bytes_to_num(resp.d.asBytes + 24, 4);\r
                        break;\r
                }\r
        }       \r
-\r
        printf("\n");\r
        \r
+       // par == 0\r
+       if (isOK == -1 && par_list == 0) {\r
+               if (!nonce2key_ex(uid, nt, nr, ks_list, &r_key) ){\r
+                       PrintAndLog("Found valid key: %012"llx" \n", r_key);\r
+                       goto END;\r
+               }\r
+       }\r
+       \r
        // error\r
        if (isOK != 1) return 1;\r
        \r
@@ -98,7 +152,7 @@ start:
        } else {\r
                PrintAndLog("Found valid key: %012"llx" \n", r_key);\r
        }\r
-       \r
+END:\r
        t1 = clock() - t1;\r
        if ( t1 > 0 )\r
                PrintAndLog("Time in darkside: %.0f ticks\n", (float)t1);\r
@@ -280,8 +334,7 @@ uint8_t NumBlocksPerSector(uint8_t sectorNo)
        }\r
 }\r
 \r
-int CmdHF14AMfDump(const char *Cmd)\r
-{\r
+int CmdHF14AMfDump(const char *Cmd) {\r
        uint8_t sectorNo, blockNo;\r
        \r
        uint8_t keyA[40][6];\r
@@ -453,8 +506,7 @@ int CmdHF14AMfDump(const char *Cmd)
        return 0;\r
 }\r
 \r
-int CmdHF14AMfRestore(const char *Cmd)\r
-{\r
+int CmdHF14AMfRestore(const char *Cmd) {\r
        uint8_t sectorNo,blockNo;\r
        uint8_t keyType = 0;\r
        uint8_t key[6] = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};\r
@@ -563,8 +615,7 @@ int CmdHF14AMfRestore(const char *Cmd)
        return 0;\r
 }\r
 \r
-int CmdHF14AMfNested(const char *Cmd)\r
-{\r
+int CmdHF14AMfNested(const char *Cmd) {\r
        int i, j, res, iterations;\r
        sector *e_sector = NULL;\r
        uint8_t blockNo = 0;\r
@@ -830,8 +881,7 @@ int CmdHF14AMfNested(const char *Cmd)
        return 0;\r
 }\r
 \r
-int CmdHF14AMfNestedHard(const char *Cmd)\r
-{\r
+int CmdHF14AMfNestedHard(const char *Cmd) {\r
        uint8_t blockNo = 0;\r
        uint8_t keyType = 0;\r
        uint8_t trgBlockNo = 0;\r
@@ -946,8 +996,7 @@ int CmdHF14AMfNestedHard(const char *Cmd)
        return 0;\r
 }\r
 \r
-int CmdHF14AMfChk(const char *Cmd)\r
-{\r
+int CmdHF14AMfChk(const char *Cmd) {\r
        if (strlen(Cmd)<3) {\r
                PrintAndLog("Usage:  hf mf chk <block number>|<*card memory> <key type (A/B/?)> [t|d] [<key (12 hex symbols)>] [<dic (*.dic)>]");\r
                PrintAndLog("          * - all sectors");\r
@@ -1236,116 +1285,242 @@ int CmdHF14AMfChk(const char *Cmd)
        return 0;\r
 }\r
 \r
-\r
 int CmdHF14AMf1kSim(const char *Cmd) {\r
        uint8_t uid[10] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0};\r
        uint8_t exitAfterNReads = 0;\r
-       uint8_t flags = 0;\r
+       uint8_t flags = (FLAG_UID_IN_EMUL | FLAG_4B_UID_IN_DATA);\r
        int uidlen = 0;\r
+       uint8_t pnr = 0;\r
        uint8_t cmdp = param_getchar(Cmd, 0);\r
 \r
-       if (cmdp == 'h' || cmdp == 'H') {\r
-               PrintAndLog("Usage:  hf mf sim  u <uid (8 hex symbols)> n <numreads> i x");\r
-               PrintAndLog("           h    this help");\r
-               PrintAndLog("           u    (Optional) UID 4,7 or 10bytes. If not specified, the UID from emulator memory will be used");\r
-               PrintAndLog("           n    (Optional) Automatically exit simulation after <numreads> blocks have been read by reader. 0 = infinite");\r
-               PrintAndLog("           i    (Optional) Interactive, means that console will not be returned until simulation finishes or is aborted");\r
-               PrintAndLog("           x    (Optional) Crack, performs the 'reader attack', nr/ar attack against a legitimate reader, fishes out the key(s)");\r
-               PrintAndLog("samples:");\r
-               PrintAndLog("           hf mf sim u 0a0a0a0a");\r
-               PrintAndLog("           hf mf sim u 11223344556677");\r
-               PrintAndLog("           hf mf sim u 112233445566778899AA");\r
-               return 0;\r
-       }\r
-       uint8_t pnr = 0;\r
-       if (param_getchar(Cmd, pnr) == 'u') {\r
-               \r
+       if (cmdp == 'h' || cmdp == 'H') return usage_hf14_mf1ksim();\r
+\r
+       cmdp = param_getchar(Cmd, pnr);\r
+       if (cmdp == 'u' || cmdp == 'U') {\r
                param_gethex_ex(Cmd, pnr+1, uid, &uidlen);\r
                switch(uidlen){\r
-                       case 20: flags |= FLAG_10B_UID_IN_DATA; break;\r
-                       case 14: flags |= FLAG_7B_UID_IN_DATA; break;\r
-                       case  8: flags |= FLAG_4B_UID_IN_DATA; break;\r
-                       default:\r
-                               PrintAndLog("UID, if specified, must include 8, 14 or 20 HEX symbols , %d", uidlen>>1);\r
-                               return 1;\r
+                       case 20: flags = FLAG_10B_UID_IN_DATA;  break;\r
+                       case 14: flags = FLAG_7B_UID_IN_DATA; break;\r
+                       case  8: flags = FLAG_4B_UID_IN_DATA; break;\r
+                       default: return usage_hf14_mf1ksim();\r
                }\r
                pnr +=2;\r
        }\r
-       \r
-       if (param_getchar(Cmd, pnr) == 'n') {\r
-               exitAfterNReads = param_get8(Cmd,pnr+1);\r
+\r
+       cmdp = param_getchar(Cmd, pnr); \r
+       if (cmdp == 'n' || cmdp == 'N') {\r
+               exitAfterNReads = param_get8(Cmd, pnr+1);\r
                pnr += 2;\r
        }\r
-       \r
-       if (param_getchar(Cmd, pnr) == 'i' ) {\r
+\r
+       cmdp = param_getchar(Cmd, pnr);         \r
+       if (cmdp == 'i' || cmdp == 'I' ) {\r
                flags |= FLAG_INTERACTIVE;\r
                pnr++;\r
        }\r
 \r
-       if (param_getchar(Cmd, pnr) == 'x' ) {\r
+       cmdp = param_getchar(Cmd, pnr); \r
+       if (cmdp == 'x' || cmdp == 'X') {\r
                flags |= FLAG_NR_AR_ATTACK;\r
        }\r
        \r
        PrintAndLog(" uid:%s, numreads:%d, flags:%d (0x%02x) "\r
-                               , (uidlen == 0 ) ? "N/A" : sprint_hex(uid, uidlen)\r
+                               , (uidlen == 0 ) ? "N/A" : sprint_hex(uid, uidlen>>1)\r
                                , exitAfterNReads\r
                                , flags\r
                                , flags);\r
 \r
-       UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads,0}};\r
+       UsbCommand c = {CMD_SIMULATE_MIFARE_CARD, {flags, exitAfterNReads, 0}};\r
        memcpy(c.d.asBytes, uid, sizeof(uid));\r
        clearCommandBuffer();\r
        SendCommand(&c);\r
 \r
-       if(flags & FLAG_INTERACTIVE)\r
-       {               \r
-               uint8_t data[40];\r
-               uint8_t key[6];\r
-\r
+       if(flags & FLAG_INTERACTIVE) {          \r
+               uint8_t data[32];\r
+               uint64_t key;\r
                UsbCommand resp;                \r
                PrintAndLog("Press pm3-button or send another cmd to abort simulation");\r
-\r
                while( !ukbhit() ){\r
                        if (!WaitForResponseTimeout(CMD_ACK, &resp, 1500) ) continue;\r
 \r
                        if ( !(flags & FLAG_NR_AR_ATTACK) ) break;\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
+                       memset(data, 0x00, sizeof(data));       \r
                        int len = (resp.arg[1] > sizeof(data)) ? sizeof(data) : resp.arg[1];\r
-                       \r
-                       memcpy(data, resp.d.asBytes, len);\r
-                       \r
-                       // CUID is always 4 first bytes.\r
-                       uint64_t cuid = bytes_to_num(data, 4 );\r
-                       \r
-                       // this needs to be fixed. ICEMAN\r
-                       if ( memcmp(data, "\x00\x00\x00\x00", 4) == 0 ) {\r
-                               tryMfk32(cuid, data, key);\r
-                       } else {\r
-                               tryMfk64(cuid, data, key);\r
-                       }\r
+\r
+                       memcpy(data, resp.d.asBytes, len);                      \r
+                       key = 0;\r
+                       bool found = tryMfk32(data, &key);\r
+                       found ^= tryMfk32_moebius(data, &key);\r
+                       if ( found ) break;\r
                }\r
        }\r
        return 0;\r
 }\r
 \r
+int CmdHF14AMfSniff(const char *Cmd){\r
+       bool wantLogToFile = FALSE;\r
+       bool wantDecrypt = FALSE;\r
+       //bool wantSaveToEml = FALSE; TODO\r
+       bool wantSaveToEmlFile = FALSE;\r
+\r
+       //var \r
+       int tmpchar;\r
+       int res = 0;\r
+       int len = 0;\r
+       int blockLen = 0;\r
+       int pckNum = 0;\r
+       int num = 0;\r
+       uint8_t uid[10];\r
+       uint8_t uid_len = 0;\r
+       uint8_t atqa[2] = {0x00, 0x00};\r
+       uint8_t sak = 0;\r
+       bool isTag = FALSE;\r
+       uint8_t *buf = NULL;\r
+       uint16_t bufsize = 0;\r
+       uint8_t *bufPtr = NULL;\r
+       uint16_t traceLen = 0;\r
+       \r
+       memset(uid, 0x00, sizeof(uid));\r
+       \r
+       char ctmp = param_getchar(Cmd, 0);\r
+       if ( ctmp == 'h' || ctmp == 'H' ) return usage_hf14_sniff();\r
+       \r
+       for (int i = 0; i < 4; i++) {\r
+               ctmp = param_getchar(Cmd, i);\r
+               if (ctmp == 'l' || ctmp == 'L') wantLogToFile = true;\r
+               if (ctmp == 'd' || ctmp == 'D') wantDecrypt = true;\r
+               //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO\r
+               if (ctmp == 'f' || ctmp == 'F') wantSaveToEmlFile = true;\r
+       }\r
+       \r
+       printf("-------------------------------------------------------------------------\n");\r
+       printf("Executing mifare sniffing command. \n");\r
+       printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");\r
+       printf("Press the key on pc keyboard to abort the client.\n");\r
+       printf("-------------------------------------------------------------------------\n");\r
+\r
+       UsbCommand c = {CMD_MIFARE_SNIFFER, {0, 0, 0}};\r
+       clearCommandBuffer();\r
+       SendCommand(&c);\r
+\r
+       // wait cycle\r
+       while (true) {\r
+               printf(".");\r
+               fflush(stdout);\r
+               if (ukbhit()) {\r
+                       tmpchar = getchar();\r
+                       (void)tmpchar;\r
+                       printf("\naborted via keyboard!\n");\r
+                       break;\r
+               }\r
+               \r
+               UsbCommand resp;\r
+               if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) {\r
+                       res = resp.arg[0] & 0xff;\r
+                       traceLen = resp.arg[1];\r
+                       len = resp.arg[2];\r
+\r
+                       // we are done?\r
+                       if (res == 0) {\r
+                               free(buf);\r
+                               return 0;\r
+                       }\r
+\r
+                       if (res == 1) {                                                         // there is (more) data to be transferred\r
+                               if (pckNum == 0) {                                              // first packet, (re)allocate necessary buffer\r
+                                       if (traceLen > bufsize) {\r
+                                               uint8_t *p;\r
+                                               if (buf == NULL)                                // not yet allocated\r
+                                                       p = malloc(traceLen);\r
+                                               else                                            // need more memory\r
+                                                       p = realloc(buf, traceLen);\r
+                                               \r
+                                               if (p == NULL) {\r
+                                                       PrintAndLog("Cannot allocate memory for trace");\r
+                                                       free(buf);\r
+                                                       return 2;\r
+                                               }\r
+                                               buf = p;\r
+                                       }\r
+                                       bufPtr = buf;\r
+                                       bufsize = traceLen;\r
+                                       memset(buf, 0x00, traceLen);\r
+                               }\r
+                               if (bufPtr == NULL) {\r
+                                       PrintAndLog("Cannot allocate memory for trace");\r
+                                       free(buf);\r
+                                       return 2;\r
+                               }\r
+                               // what happens if LEN is bigger then TRACELEN --iceman\r
+                               memcpy(bufPtr, resp.d.asBytes, len);\r
+                               bufPtr += len;\r
+                               pckNum++;\r
+                       }\r
+\r
+                       if (res == 2) {                                                         // received all data, start displaying\r
+                               blockLen = bufPtr - buf;\r
+                               bufPtr = buf;\r
+                               printf(">\n");\r
+                               PrintAndLog("received trace len: %d packages: %d", blockLen, pckNum);\r
+                               while (bufPtr - buf < blockLen) {\r
+                                       bufPtr += 6;                                            // skip (void) timing information\r
+                                       len = *((uint16_t *)bufPtr);\r
+                                       if(len & 0x8000) {\r
+                                               isTag = true;\r
+                                               len &= 0x7fff;\r
+                                       } else {\r
+                                               isTag = false;\r
+                                       }\r
+                                       bufPtr += 2;\r
+                                       if ((len == 17) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff) && (bufPtr[15] == 0xff) && (bufPtr[16] == 0xff)) {\r
+                                               memcpy(uid, bufPtr + 2, 10);\r
+                                               memcpy(atqa, bufPtr + 2 + 10, 2);\r
+                                               switch (atqa[0] & 0xC0) {\r
+                                                       case 0x80: uid_len = 10; break;\r
+                                                       case 0x40: uid_len = 7; break;\r
+                                                       default:   uid_len = 4; break;\r
+                                               }\r
+                                               sak = bufPtr[14];\r
+                                               PrintAndLog("tag select uid| %s atqa:0x%02x%02x sak:0x%02x", \r
+                                                       sprint_hex(uid, uid_len),\r
+                                                       atqa[1], \r
+                                                       atqa[0], \r
+                                                       sak);\r
+                                               if (wantLogToFile || wantDecrypt) {\r
+                                                       FillFileNameByUID(logHexFileName, uid, ".log", uid_len);\r
+                                                       AddLogCurrentDT(logHexFileName);\r
+                                               }                                               \r
+                                               if (wantDecrypt)\r
+                                                       mfTraceInit(uid, uid_len, atqa, sak, wantSaveToEmlFile);\r
+                                       } else {\r
+                                               PrintAndLog("%03d| %s |%s", num, isTag ? "TAG" : "RDR", sprint_hex(bufPtr, len));\r
+                                               if (wantLogToFile) \r
+                                                       AddLogHex(logHexFileName, isTag ? "TAG| ":"RDR| ", bufPtr, len);\r
+                                               if (wantDecrypt) \r
+                                                       mfTraceDecode(bufPtr, len, wantSaveToEmlFile);\r
+                                               num++;  \r
+                                       }\r
+                                       bufPtr += len;\r
+                                       bufPtr += ((len-1)/8+1);        // ignore parity\r
+                               }\r
+                               pckNum = 0;\r
+                       }\r
+               } // resp not NULL\r
+       } // while (true)\r
+\r
+       free(buf);\r
+       return 0;\r
+}\r
+\r
 int CmdHF14AMfDbg(const char *Cmd) {\r
-       int dbgMode = param_get32ex(Cmd, 0, 0, 10);\r
-       if (dbgMode > 4)\r
-               PrintAndLog("Max debug mode parameter is 4 \n");\r
-\r
-       if (strlen(Cmd) < 1 || !param_getchar(Cmd, 0) || dbgMode > 4) {\r
-               PrintAndLog("Usage:  hf mf dbg  <debug level>");\r
-               PrintAndLog(" 0 - no debug messages");\r
-               PrintAndLog(" 1 - error messages");\r
-               PrintAndLog(" 2 - plus information messages");\r
-               PrintAndLog(" 3 - plus debug messages");\r
-               PrintAndLog(" 4 - print even debug messages in timing critical functions");\r
-               PrintAndLog("     Note: this option therefore may cause malfunction itself");\r
-               return 0;\r
-       }       \r
+\r
+       char ctmp = param_getchar(Cmd, 0);\r
+       if (strlen(Cmd) < 1  || ctmp == 'h'|| ctmp == 'H') return usage_hf14_dbg();\r
+       \r
+       uint8_t dbgMode = param_get8ex(Cmd, 0, 0, 10);\r
+       if (dbgMode > 4) return usage_hf14_dbg();\r
 \r
        UsbCommand c = {CMD_MIFARE_SET_DBGMODE, {dbgMode, 0, 0}};\r
        SendCommand(&c);\r
@@ -2066,172 +2241,9 @@ int CmdHF14AMfCSave(const char *Cmd) {
        }\r
 }\r
 \r
-\r
-\r
-int CmdHF14AMfSniff(const char *Cmd){\r
-\r
-       bool wantLogToFile = 0;\r
-       bool wantDecrypt = 0;\r
-       //bool wantSaveToEml = 0; TODO\r
-       bool wantSaveToEmlFile = 0;\r
-\r
-       //var \r
-       int tmpchar;\r
-       int res = 0;\r
-       int len = 0;\r
-       int blockLen = 0;\r
-       int pckNum = 0;\r
-       int num = 0;\r
-       uint8_t uid[10];\r
-       uint8_t uid_len = 0;\r
-       uint8_t atqa[2] = {0x00, 0x00};\r
-       uint8_t sak = 0;\r
-       bool isTag;\r
-       uint8_t *buf = NULL;\r
-       uint16_t bufsize = 0;\r
-       uint8_t *bufPtr = NULL;\r
-       \r
-       memset(uid, 0x00, sizeof(uid));\r
-       \r
-       char ctmp = param_getchar(Cmd, 0);\r
-       if ( ctmp == 'h' || ctmp == 'H' ) {\r
-               PrintAndLog("It continuously gets data from the field and saves it to: log, emulator, emulator file.");\r
-               PrintAndLog("You can specify:");\r
-               PrintAndLog("    l - save encrypted sequence to logfile `uid.log`");\r
-               PrintAndLog("    d - decrypt sequence and put it to log file `uid.log`");\r
-               PrintAndLog(" n/a   e - decrypt sequence, collect read and write commands and save the result of the sequence to emulator memory");\r
-               PrintAndLog("    f - decrypt sequence, collect read and write commands and save the result of the sequence to emulator dump file `uid.eml`");\r
-               PrintAndLog("Usage:  hf mf sniff [l][d][e][f]");\r
-               PrintAndLog("  sample: hf mf sniff l d e");\r
-               return 0;\r
-       }       \r
-       \r
-       for (int i = 0; i < 4; i++) {\r
-               ctmp = param_getchar(Cmd, i);\r
-               if (ctmp == 'l' || ctmp == 'L') wantLogToFile = true;\r
-               if (ctmp == 'd' || ctmp == 'D') wantDecrypt = true;\r
-               //if (ctmp == 'e' || ctmp == 'E') wantSaveToEml = true; TODO\r
-               if (ctmp == 'f' || ctmp == 'F') wantSaveToEmlFile = true;\r
-       }\r
-       \r
-       printf("-------------------------------------------------------------------------\n");\r
-       printf("Executing command. \n");\r
-       printf("Press the key on the proxmark3 device to abort both proxmark3 and client.\n");\r
-       printf("Press the key on pc keyboard to abort the client.\n");\r
-       printf("-------------------------------------------------------------------------\n");\r
-\r
-       UsbCommand c = {CMD_MIFARE_SNIFFER, {0, 0, 0}};\r
-       clearCommandBuffer();\r
-       SendCommand(&c);\r
-\r
-       // wait cycle\r
-       while (true) {\r
-               printf(".");\r
-               fflush(stdout);\r
-               if (ukbhit()) {\r
-                       tmpchar = getchar();\r
-                       (void)tmpchar;\r
-                       printf("\naborted via keyboard!\n");\r
-                       break;\r
-               }\r
-               \r
-               UsbCommand resp;\r
-               if (WaitForResponseTimeout(CMD_ACK,&resp,2000)) {\r
-                       res = resp.arg[0] & 0xff;\r
-                       uint16_t traceLen = resp.arg[1];\r
-                       len = resp.arg[2];\r
-\r
-                       // we are done?\r
-                       if (res == 0) {\r
-                               free(buf);\r
-                               return 0;\r
-                       }\r
-\r
-                       if (res == 1) {                                                         // there is (more) data to be transferred\r
-                               if (pckNum == 0) {                                              // first packet, (re)allocate necessary buffer\r
-                                       if (traceLen > bufsize) {\r
-                                               uint8_t *p;\r
-                                               if (buf == NULL) {                              // not yet allocated\r
-                                                       p = malloc(traceLen);\r
-                                               } else {                                                // need more memory\r
-                                                       p = realloc(buf, traceLen);\r
-                                               }\r
-                                               if (p == NULL) {\r
-                                                       PrintAndLog("Cannot allocate memory for trace");\r
-                                                       free(buf);\r
-                                                       return 2;\r
-                                               }\r
-                                               buf = p;\r
-                                       }\r
-                                       bufPtr = buf;\r
-                                       bufsize = traceLen;\r
-                                       memset(buf, 0x00, traceLen);\r
-                               }\r
-                               if (bufPtr == NULL) {\r
-                                       PrintAndLog("Cannot allocate memory for trace");\r
-                                       free(buf);\r
-                                       return 2;\r
-                               }\r
-                               memcpy(bufPtr, resp.d.asBytes, len);\r
-                               bufPtr += len;\r
-                               pckNum++;\r
-                       }\r
-\r
-                       if (res == 2) {                                                         // received all data, start displaying\r
-                               blockLen = bufPtr - buf;\r
-                               bufPtr = buf;\r
-                               printf(">\n");\r
-                               PrintAndLog("received trace len: %d packages: %d", blockLen, pckNum);\r
-                               while (bufPtr - buf < blockLen) {\r
-                                       bufPtr += 6;                                            // skip (void) timing information\r
-                                       len = *((uint16_t *)bufPtr);\r
-                                       if(len & 0x8000) {\r
-                                               isTag = true;\r
-                                               len &= 0x7fff;\r
-                                       } else {\r
-                                               isTag = false;\r
-                                       }\r
-                                       bufPtr += 2;\r
-                                       if ((len == 14) && (bufPtr[0] == 0xff) && (bufPtr[1] == 0xff) && (bufPtr[12] == 0xff) && (bufPtr[13] == 0xff)) {\r
-                                               memcpy(uid, bufPtr + 2, 7);\r
-                                               memcpy(atqa, bufPtr + 2 + 7, 2);\r
-                                               uid_len = (atqa[0] & 0xC0) == 0x40 ? 7 : 4;\r
-                                               sak = bufPtr[11];\r
-                                               PrintAndLog("tag select uid| %s atqa:0x%02x%02x sak:0x%02x", \r
-                                                       sprint_hex(uid + (7 - uid_len), uid_len),\r
-                                                       atqa[1], \r
-                                                       atqa[0], \r
-                                                       sak);\r
-                                               if (wantLogToFile || wantDecrypt) {\r
-                                                       FillFileNameByUID(logHexFileName, uid + (10 - uid_len), ".log", uid_len);\r
-                                                       AddLogCurrentDT(logHexFileName);\r
-                                               }                                               \r
-                                               if (wantDecrypt) \r
-                                                       mfTraceInit(uid, atqa, sak, wantSaveToEmlFile);\r
-                                       } else {\r
-                                               PrintAndLog("%03d| %s |%s", num, isTag ? "TAG" : "RDR", sprint_hex(bufPtr, len));\r
-                                               if (wantLogToFile) \r
-                                                       AddLogHex(logHexFileName, isTag ? "TAG| ":"RDR| ", bufPtr, len);\r
-                                               if (wantDecrypt) \r
-                                                       mfTraceDecode(bufPtr, len, wantSaveToEmlFile);\r
-                                               num++;  \r
-                                       }\r
-                                       bufPtr += len;\r
-                                       bufPtr += ((len-1)/8+1);        // ignore parity\r
-                               }\r
-                               pckNum = 0;\r
-                       }\r
-               } // resp not NULL\r
-       } // while (true)\r
-\r
-       free(buf);\r
-       return 0;\r
-}\r
-\r
 //needs nt, ar, at, Data to decrypt\r
 int CmdHf14MfDecryptBytes(const char *Cmd){\r
        uint8_t data[50];\r
-       \r
        uint32_t nt     = param_get32ex(Cmd,0,0,16);\r
        uint32_t ar_enc = param_get32ex(Cmd,1,0,16);\r
        uint32_t at_enc = param_get32ex(Cmd,2,0,16);\r
@@ -2280,9 +2292,7 @@ static command_t CommandTable[] = {
 };\r
 \r
 int CmdHFMF(const char *Cmd) {\r
-       // flush\r
        clearCommandBuffer();\r
-       //WaitForResponseTimeout(CMD_ACK,NULL,100);\r
        CmdsParse(CommandTable, Cmd);\r
        return 0;\r
 }\r
Impressum, Datenschutz