X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/proxmark3-svn/blobdiff_plain/6a1687cc3ed60e13432763e18736defd43168cab..c24364a8a4932f51a9b9e255d2ed0c67b9e37c74:/client/cmdhfemv.c diff --git a/client/cmdhfemv.c b/client/cmdhfemv.c index 664c00c4..17811d74 100644 --- a/client/cmdhfemv.c +++ b/client/cmdhfemv.c @@ -12,8 +12,41 @@ static int CmdHelp(const char *Cmd); -int usage_hf_emv_trans(void){ - PrintAndLog("perform an EMV transaction"); +int usage_hf_emv_test(void){ + PrintAndLog("EMV test "); + PrintAndLog("Usage: hf emv test [h]"); + PrintAndLog("Options:"); + PrintAndLog(" h : this help"); + PrintAndLog(""); + PrintAndLog("Samples:"); + PrintAndLog(" hf emv test"); + return 0; +} +int usage_hf_emv_readrecord(void){ + PrintAndLog("Read a EMV record "); + PrintAndLog("Usage: hf emv readrecord [h] "); + PrintAndLog("Options:"); + PrintAndLog(" h : this help"); + PrintAndLog(" : number of records"); + PrintAndLog(" : number of SFI records"); + PrintAndLog(""); + PrintAndLog("Samples:"); + PrintAndLog(" hf emv readrecord 1 1"); + return 0; +} +int usage_hf_emv_clone(void){ + PrintAndLog("Usage: hf emv clone [h] "); + PrintAndLog("Options:"); + PrintAndLog(" h : this help"); + PrintAndLog(" : number of records"); + PrintAndLog(" : number of SFI records"); + PrintAndLog(""); + PrintAndLog("Samples:"); + PrintAndLog(" hf emv clone 10 10"); + return 0; +} +int usage_hf_emv_transaction(void){ + PrintAndLog("Performs EMV reader transaction"); PrintAndLog("Usage: hf emv trans [h]"); PrintAndLog("Options:"); PrintAndLog(" h : this help"); @@ -43,16 +76,6 @@ int usage_hf_emv_eload(void){ PrintAndLog(" hf emv eload o myfile"); return 0; } -int usage_hf_emv_sim(void){ - PrintAndLog("Simulates a EMV contactless card"); - PrintAndLog("Usage: hf emv sim [h]"); - PrintAndLog("Options:"); - PrintAndLog(" h : this help"); - PrintAndLog(""); - PrintAndLog("Samples:"); - PrintAndLog(" hf emv sim"); - return 0; -} int usage_hf_emv_dump(void){ PrintAndLog("Gets EMV contactless tag values."); PrintAndLog("and saves binary dump into the file `filename.bin` or `cardUID.bin`"); @@ -66,27 +89,109 @@ int usage_hf_emv_dump(void){ PrintAndLog(" hf emv dump o myfile"); return 0; } +int usage_hf_emv_sim(void){ + PrintAndLog("Simulates a EMV contactless card"); + PrintAndLog("Usage: hf emv sim [h]"); + PrintAndLog("Options:"); + PrintAndLog(" h : this help"); + PrintAndLog(""); + PrintAndLog("Samples:"); + PrintAndLog(" hf emv sim"); + return 0; +} + +int CmdHfEmvTest(const char *Cmd) { + char cmdp = param_getchar(Cmd, 0); + if ( cmdp == 'h' || cmdp == 'H') return usage_hf_emv_test(); + + UsbCommand c = {CMD_EMV_TEST, {0, 0, 0}}; + clearCommandBuffer(); + SendCommand(&c); + UsbCommand resp; + if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + PrintAndLog("Command execute time-out"); + return 1; + } + uint8_t isOK = resp.arg[0] & 0xff; + PrintAndLog("isOk: %02x", isOK); + return 0; +} + +int CmdHfEmvReadRecord(const char *Cmd) { + char cmdp = param_getchar(Cmd, 0); + if ((strlen(Cmd)<3) || cmdp == 'h' || cmdp == 'H') return usage_hf_emv_readrecord(); + + uint8_t record = param_get8(Cmd, 0); + uint8_t sfi = param_getchar(Cmd, 1); + if(record > 32){ + PrintAndLog("Record must be less than 32"); + return 1; + } + PrintAndLog("--record no:%02x SFI:%02x ", record, sfi); + + UsbCommand c = {CMD_EMV_READ_RECORD, {record, sfi, 0}}; + clearCommandBuffer(); + SendCommand(&c); + UsbCommand resp; + if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + PrintAndLog("Command execute timeout"); + return 1; + } + uint8_t isOK = resp.arg[0] & 0xff; + PrintAndLog("isOk:%02x", isOK); + return 0; +} + +int CmdHfEmvClone(const char *Cmd) { + char cmdp = param_getchar(Cmd, 0); + if ((strlen(Cmd)<3) || cmdp == 'h' || cmdp == 'H') return usage_hf_emv_clone(); + + uint8_t record = param_get8(Cmd, 0); + uint8_t sfi = param_get8(Cmd, 1); + if(record > 32){ + PrintAndLog("Record must be less than 32"); + return 1; + } + UsbCommand c = {CMD_EMV_CLONE, {sfi, record, 0}}; + clearCommandBuffer(); + SendCommand(&c); + UsbCommand resp; + if (!WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + PrintAndLog("Command execute timeout"); + return 1; + } + uint8_t isOK = resp.arg[0] & 0xff; + PrintAndLog("isOk:%02x", isOK); + return 0; +} -//perform an EMV transaction int CmdHfEmvTrans(const char *Cmd) { - char cmdp = param_getchar(Cmd, 0); - if ( cmdp == 'h' || cmdp == 'H') return usage_hf_emv_trans(); - UsbCommand c = {CMD_EMV_TRANSACTION, {0, 0, 0}}; + char cmdp = param_getchar(Cmd, 0); + if ( cmdp == 'h' || cmdp == 'H') return usage_hf_emv_transaction(); + + UsbCommand c = {CMD_EMV_TRANSACTION, {0, 0, 0}}; clearCommandBuffer(); - SendCommand(&c); - return 0; + SendCommand(&c); + UsbCommand resp; + if (WaitForResponseTimeout(CMD_ACK, &resp, 5000)) { + PrintAndLog("Command execute time-out"); + return 1; + } + uint8_t isOK = resp.arg[0] & 0xff; + PrintAndLog("isOk: %02x", isOK); + print_hex_break(resp.d.asBytes, 512, 32); + return 0; } //retrieve the UN number from a terminal int CmdHfEmvGetrng(const char *Cmd) { - char cmdp = param_getchar(Cmd, 0); + char cmdp = param_getchar(Cmd, 0); if ( cmdp == 'h' || cmdp == 'H') return usage_hf_emv_getrnd(); UsbCommand c = {CMD_EMV_GET_RANDOM_NUM, {0, 0, 0}}; clearCommandBuffer(); SendCommand(&c); return 0; } - -//set EMV tags in the device to use in a transaction +//Load a dumped EMV tag on to emulator memory int CmdHfEmvELoad(const char *Cmd) { FILE * f; char filename[FILE_PATH_SIZE]; @@ -162,7 +267,6 @@ int CmdHfEmvDump(const char *Cmd){ bool errors = false; uint8_t cmdp = 0; - while(param_getchar(Cmd, cmdp) != 0x00) { switch(param_getchar(Cmd, cmdp)) { case 'h': @@ -190,13 +294,10 @@ int CmdHfEmvDump(const char *Cmd){ return 0; } - -/* int CmdHfEmvSim(const char *Cmd) { bool errors = false; uint8_t cmdp = 0; - while(param_getchar(Cmd, cmdp) != 0x00) { switch(param_getchar(Cmd, cmdp)) { case 'h': @@ -213,27 +314,34 @@ int CmdHfEmvSim(const char *Cmd) { //Validations if(errors) return usage_hf_emv_sim(); - UsbCommand c = {CMD_SIMULATE_TAG_LEGIC_RF, {6,3,0}}; - sscanf(Cmd, " %"lli" %"lli" %"lli, &c.arg[0], &c.arg[1], &c.arg[2]); + UsbCommand c = {CMD_EMV_SIM, {0,0,0}}; clearCommandBuffer(); - SendCommand(&c); + SendCommand(&c); + UsbCommand resp; + if (WaitForResponseTimeout(CMD_ACK, &resp, 2000)) { + PrintAndLog("Command execute time-out"); + return 1; + } + uint8_t isOK = resp.arg[0] & 0xff; + PrintAndLog("isOk:%02x", isOK); return 0; } -*/ int CmdHfEmvList(const char *Cmd) { - CmdHFList("7816"); - return 0; + return CmdHFList("7816"); } static command_t CommandTable[] = { - {"help", CmdHelp, 1, "This help"}, - {"trans", CmdHfEmvTrans, 0, "Perform EMV Reader Transaction"}, - {"getrng", CmdHfEmvGetrng, 0, "get random number from terminal"}, - {"eload", CmdHfEmvELoad, 0, "load EMV tag into device"}, - {"dump", CmdHfEmvDump, 0, "Dump EMV tag values"}, -// {"sim", CmdHfEmvSim, 0, "Start tag simulator"}, - {"list", CmdHfEmvList, 1, "[Deprecated] List ISO7816 history"}, + {"help", CmdHelp, 1, "This help"}, + {"readrecord", CmdHfEmvReadRecord, 0, "EMV Read Record"}, + {"transaction", CmdHfEmvTrans, 0, "Perform EMV Transaction"}, + {"getrng", CmdHfEmvGetrng, 0, "get random number from terminal"}, + {"eload", CmdHfEmvELoad, 0, "load EMV tag into device"}, + {"dump", CmdHfEmvDump, 0, "dump EMV tag values"}, + {"sim", CmdHfEmvSim, 0, "simulate EMV tag"}, + {"clone", CmdHfEmvClone, 0, "clone an EMV tag"}, + {"list", CmdHfEmvList, 0, "[Deprecated] List ISO7816 history"}, + {"test", CmdHfEmvTest, 0, "Test Function"}, {NULL, NULL, 0, NULL} };