]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhficlass.c
MFU - Icemans further improvements
[proxmark3-svn] / client / cmdhficlass.c
index 7bc23e9bb522d32db4e3db637dfc60aa7b3eea9b..b83371960d007958e6ae5c1a7d6f1d861693a9de 100644 (file)
@@ -29,6 +29,8 @@
 #include "loclass/ikeys.h"
 #include "loclass/elite_crack.h"
 #include "loclass/fileutils.h"
+#include "protocols.h"
+#include "usb_cmd.h"
 
 static int CmdHelp(const char *Cmd);
 
@@ -75,10 +77,9 @@ int CmdHFiClassSim(const char *Cmd)
        uint8_t CSN[8] = {0, 0, 0, 0, 0, 0, 0, 0};
 
        if (strlen(Cmd)<1) {
-               usage_hf_iclass_sim();
+               return usage_hf_iclass_sim();
        }
-
-       simType = param_get8(Cmd, 0);
+       simType = param_get8ex(Cmd, 0, 0, 10);
 
        if(simType == 0)
        {
@@ -166,29 +167,25 @@ int CmdHFiClassSim(const char *Cmd)
 
 int CmdHFiClassReader(const char *Cmd)
 {
-       UsbCommand c = {CMD_READER_ICLASS, {0}};
+       UsbCommand c = {CMD_READER_ICLASS, {FLAG_ICLASS_READER_CSN|
+                                       FLAG_ICLASS_READER_CONF|FLAG_ICLASS_READER_AA}};
        SendCommand(&c);
        UsbCommand resp;
        while(!ukbhit()){
                if (WaitForResponseTimeout(CMD_ACK,&resp,4500)) {
-                       uint8_t isOK    = resp.arg[0] & 0xff;
+                       uint8_t readStatus    = resp.arg[0] & 0xff;
                        uint8_t * data  = resp.d.asBytes;
 
-                       PrintAndLog("isOk:%02x", isOK);
-                       if( isOK == 0){
+                       PrintAndLog("Readstatus:%02x", readStatus);
+                       if( readStatus == 0){
                                //Aborted
                                PrintAndLog("Quitting...");
                                return 0;
                        }
-                       if(isOK > 0)
-                       {
-                               PrintAndLog("CSN: %s",sprint_hex(data,8));
-                       }
-                       if(isOK >= 1)
-                       {
-                               PrintAndLog("CC: %s",sprint_hex(data+8,8));
-                       }else{
-                               PrintAndLog("No CC obtained");
+                       if( readStatus & FLAG_ICLASS_READER_CSN) PrintAndLog("CSN: %s",sprint_hex(data,8));
+                       if( readStatus & FLAG_ICLASS_READER_CC)  PrintAndLog("CC: %s",sprint_hex(data+16,8));
+                       if( readStatus & FLAG_ICLASS_READER_CONF){
+                               printIclassDumpInfo(data);
                        }
                } else {
                        PrintAndLog("Command execute timeout");
@@ -269,7 +266,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
        uint8_t key_sel_p[8] = { 0 };
 
        UsbCommand c = {CMD_READER_ICLASS, {0}};
-       c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE| FLAG_ICLASS_READER_GET_CC;
+       c.arg[0] = FLAG_ICLASS_READER_ONLY_ONCE| FLAG_ICLASS_READER_CC;
        SendCommand(&c);
 
 
@@ -284,7 +281,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
        uint8_t * data  = resp.d.asBytes;
 
        memcpy(CSN,data,8);
-       memcpy(CCNR,data+8,8);
+       memcpy(CCNR,data+16,8);
 
        PrintAndLog("isOk:%02x", isOK);
 
@@ -322,7 +319,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
        PrintAndLog("Hash0, a.k.a diversified key, that is computed using Ksel and stored in the card (Block 3):");
        printvar("Div key", div_key, 8);
        printvar("CC_NR:",CCNR,12);
-       doMAC(CCNR,12,div_key, MAC);
+       doMAC(CCNR,div_key, MAC);
        printvar("MAC", MAC, 4);
 
        uint8_t iclass_data[32000] = {0};
@@ -348,7 +345,7 @@ int CmdHFiClassReader_Dump(const char *Cmd)
                        if(dataLength > 0)
                        {
                                PrintAndLog("Got %d bytes data (total so far %d)" ,dataLength,iclass_datalen);
-                               memcpy(iclass_data, resp.d.asBytes,dataLength);
+                               memcpy(iclass_data+iclass_datalen, resp.d.asBytes,dataLength);
                                iclass_datalen += dataLength;
                        }else
                        {//Last transfer, datalength 0 means the dump is finished
@@ -421,9 +418,12 @@ int CmdHFiClassELoad(const char *Cmd)
        fseek(f, 0, SEEK_SET);
 
        uint8_t *dump = malloc(fsize);
+
+
        size_t bytes_read = fread(dump, 1, fsize, f);
        fclose(f);
 
+       printIclassDumpInfo(dump);
        //Validate
 
        if (bytes_read < fsize)
@@ -456,7 +456,7 @@ int usage_hf_iclass_decrypt()
        PrintAndLog("OBS! In order to use this function, the file 'iclass_decryptionkey.bin' must reside");
        PrintAndLog("in the working directory. The file should be 16 bytes binary data");
        PrintAndLog("");
-       PrintAndLog("example: hf iclass decrypt tagdump_12312342343.bin");
+       PrintAndLog("example: hf iclass decrypt tagdump_12312342343.bin");
        PrintAndLog("");
        PrintAndLog("OBS! This is pretty stupid implementation, it tries to decrypt every block after block 6. ");
        PrintAndLog("Correct behaviour would be to decrypt only the application areas where the key is valid,");
@@ -604,7 +604,7 @@ int CmdHFiClass_iso14443A_write(const char *Cmd)
        diversifyKey(CSN,KEY, div_key);
 
        PrintAndLog("Div Key: %s",sprint_hex(div_key,8));
-       doMAC(CCNR, 12,div_key, MAC);
+       doMAC(CCNR, div_key, MAC);
 
        UsbCommand c2 = {CMD_ICLASS_ISO14443A_WRITE, {readerType,blockNo}};
        memcpy(c2.d.asBytes, bldata, 8);
Impressum, Datenschutz