diff --git a/armsrc/mifarecmd.c b/armsrc/mifarecmd.c index 36fb7455c..7faa0c268 100644 --- a/armsrc/mifarecmd.c +++ b/armsrc/mifarecmd.c @@ -2082,9 +2082,10 @@ void MifareCSetBlock(uint32_t arg0, uint32_t arg1, uint8_t *datain) { if (!iso14443a_select_card(uid, NULL, &cuid, true, 0, true)) { if (DBGLEVEL >= DBG_ERROR) Dbprintf("Can't select card"); errormsg = MAGIC_UID; + mifare_classic_halt_ex(NULL); + break; } mifare_classic_halt_ex(NULL); - break; } // wipe tag, fill it with zeros diff --git a/client/dictionaries/mfc_default_keys.dic b/client/dictionaries/mfc_default_keys.dic index 8c9611c56..b3bf93312 100644 --- a/client/dictionaries/mfc_default_keys.dic +++ b/client/dictionaries/mfc_default_keys.dic @@ -1132,8 +1132,6 @@ e2a9e88bfe16 aade86b1f9c1 5ea088c824c9 c67beb41ffbf -5ea088c824c9 -c67beb41ffbf b84d52971107 52b0d3f6116e # @@ -1209,3 +1207,72 @@ FEE2A3FBC5B6 0602721E8F06 FC0B50AF8700 F7BA51A9434E +# +# eskart +# eskisehir transport card +E902395C1744 +4051A85E7F2D +7357EBD483CC +D8BA1AA9ABA0 +76939DDD9E97 +3BF391815A8D +# +# muzekart +# museum card for turkey +7C87013A648A +E8794FB14C63 +9F97C182585B +EC070A52E539 +C229CE5123D5 +E495D6E69D9C +26BF1A68B00F +B1D3BC5A7CCA +734EBE504CE8 +974A36E2B1BA +C197AE6D6990 +4D80A10649DF +037F64F470AD +C9CD8D7C65E5 +B70B1957FE71 +CE7712C5071D +C0AD1B72921A +45FEE09C1D06 +E592ED478E59 +F3C1F1DB1D83 +704A81DDACED +89E00BC444EF +AFAAFCC40DEC +ECC58C5D34CA +57D83754711D +D0DDDF2933EC +240F0BB84681 +9E7168064993 +2F8A867B06B4 +# +# bursakart +# bursa transport card +# +A0A1A2A3A4A5 +755D49191A78 +DAC7E0CBA8FD +68D3263A8CD6 +865B6472B1C0 +0860318A3A89 +1927A45A83D3 +B2FE3B2875A6 +# +# playland +# maltepe park +# +ABCC1276FCB0 +AABAFFCC7612 +# +# lunasan +# kocaeli fair +# +26107E7006A0 +# +# gamefactory +# ozdilek +# +17D071403C20 \ No newline at end of file diff --git a/client/src/cmdhflto.c b/client/src/cmdhflto.c index ab79423a4..69dab2108 100644 --- a/client/src/cmdhflto.c +++ b/client/src/cmdhflto.c @@ -28,6 +28,7 @@ If you have access to datasheet, le me know! LTO w Type info 00 01 has 101 blocks. + LTO w Type info 00 02 has 95 blocks. LTO w Type info 00 03 has 255 blocks. LTO w Type info 00 xx has NN blocks. */ @@ -242,18 +243,18 @@ static int CmdHfLTOList(const char *Cmd) { return CmdTraceList(args); } -static int lto_rdbl(uint8_t blk, uint8_t *block_responce, uint8_t *block_cnt_responce, bool verbose) { +static int lto_rdbl(uint8_t blk, uint8_t *block_response, uint8_t *block_cnt_response, bool verbose) { uint16_t resp_len = 18; uint8_t rdbl_cmd[] = {0x30, blk}; uint8_t rdbl_cnt_cmd[] = {0x80}; - int status = lto_send_cmd_raw(rdbl_cmd, sizeof(rdbl_cmd), block_responce, &resp_len, true, false, verbose); + int status = lto_send_cmd_raw(rdbl_cmd, sizeof(rdbl_cmd), block_response, &resp_len, true, false, verbose); if (status == PM3_ETIMEOUT || status == PM3_ESOFT) { return PM3_EWRONGANSWER; // READ BLOCK failed } - status = lto_send_cmd_raw(rdbl_cnt_cmd, sizeof(rdbl_cnt_cmd), block_cnt_responce, &resp_len, false, false, verbose); + status = lto_send_cmd_raw(rdbl_cnt_cmd, sizeof(rdbl_cnt_cmd), block_cnt_response, &resp_len, false, false, verbose); if (status == PM3_ETIMEOUT || status == PM3_ESOFT) { return PM3_EWRONGANSWER; // READ BLOCK CONTINUE failed } diff --git a/client/src/cmdhfmfdes.c b/client/src/cmdhfmfdes.c index 3c5de933a..4c4f713f7 100644 --- a/client/src/cmdhfmfdes.c +++ b/client/src/cmdhfmfdes.c @@ -42,6 +42,15 @@ #define status(x) ( ((uint16_t)(0x91<<8)) + (uint16_t)x ) +#ifndef DropFieldDesfire +#define DropFieldDesfire() { \ + clearCommandBuffer(); \ + SendCommandNG(CMD_HF_DROPFIELD, NULL, 0); \ + tag->rf_field_on = false; \ + PrintAndLogEx(DEBUG, "field dropped"); \ + } +#endif + struct desfire_key default_key = {0}; uint8_t desdefaultkeys[3][8] = {{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, //Official @@ -86,7 +95,7 @@ typedef struct mfdes_data { uint8_t *data; } PACKED mfdes_data_t; -typedef struct { +typedef struct mfdes_info_res { uint8_t isOK; uint8_t uid[7]; uint8_t uidlen; @@ -443,7 +452,7 @@ static int DESFIRESendApdu(bool activate_field, bool leavefield_on, sAPDU apdu, int res = 0; if (activate_field) { - DropField(); + DropFieldDesfire(); msleep(50); } @@ -466,6 +475,11 @@ static int DESFIRESendApdu(bool activate_field, bool leavefield_on, sAPDU apdu, return res; } + if (activate_field) { + PrintAndLogEx(DEBUG, "field up"); + tag->rf_field_on = true; + } + if (GetAPDULogging() || (g_debugMode > 1)) PrintAndLogEx(SUCCESS, "<<<< %s", sprint_hex(result, *result_len)); @@ -633,7 +647,7 @@ static int send_desfire_cmd(sAPDU *apdu, bool select, uint8_t *dest, uint32_t *r int res = DESFIRESendApdu(select, true, *apdu, data, sizeof(data), &resplen, sw); if (res != PM3_SUCCESS) { PrintAndLogEx(DEBUG, "%s", GetErrorString(res, sw)); - DropField(); + DropFieldDesfire(); return res; } if (dest != NULL) { @@ -658,7 +672,7 @@ static int send_desfire_cmd(sAPDU *apdu, bool select, uint8_t *dest, uint32_t *r res = DESFIRESendApdu(false, true, *apdu, data, sizeof(data), &resplen, sw); if (res != PM3_SUCCESS) { PrintAndLogEx(DEBUG, "%s", GetErrorString(res, sw)); - DropField(); + DropFieldDesfire(); return res; } @@ -704,7 +718,7 @@ static int mfdes_get_info(mfdes_info_res_t *info) { if (WaitForResponseTimeout(CMD_HF_DESFIRE_INFO, &resp, 1500) == false) { PrintAndLogEx(WARNING, "Command execute timeout"); - DropField(); + DropFieldDesfire(); return PM3_ETIMEOUT; } @@ -1058,7 +1072,7 @@ static int test_desfire_authenticate(void) { int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false); if (res == PM3_SUCCESS) if (sw == status(MFDES_ADDITIONAL_FRAME)) { - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1073,7 +1087,7 @@ static int test_desfire_authenticate_iso(void) { int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false); if (res == PM3_SUCCESS) if (sw == status(MFDES_ADDITIONAL_FRAME)) { - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1088,7 +1102,7 @@ static int test_desfire_authenticate_aes(void) { int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, 0, false); if (res == PM3_SUCCESS) if (sw == status(MFDES_ADDITIONAL_FRAME)) { - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1161,27 +1175,40 @@ static int mifare_desfire_change_key(uint8_t key_no, uint8_t *new_key, uint8_t n break; } } + /* + keyno 1b + key 8b + cpy 8b + crc 2b + padding + */ - // Variable length ciphered key data 26-42 bytes plus padding.. + // Variable length ciphered key data 24-42 bytes plus padding.. uint8_t data[64] = {key_no}; sAPDU apdu = {0x90, MFDES_CHANGE_KEY, 0x00, 0x00, 0x01, data}; // 0xC4 + size_t cmdcnt = 0; + uint8_t new_key_length = 16; switch (new_algo) { case MFDES_ALGO_DES: - new_key_length = 8; + // double + memcpy(data + cmdcnt + 1, new_key, new_key_length); + memcpy(data + cmdcnt + 1 + new_key_length, new_key, new_key_length); break; case MFDES_ALGO_3DES: case MFDES_ALGO_AES: new_key_length = 16; + memcpy(data + cmdcnt + 1, new_key, new_key_length); break; case MFDES_ALGO_3K3DES: new_key_length = 24; + memcpy(data + cmdcnt + 1, new_key, new_key_length); break; } - size_t cmdcnt = 0; - memcpy(data + cmdcnt + 1, new_key, new_key_length); + + if ((tag->authenticated_key_no & 0x0f) != (key_no & 0x0f)) { if (old_key) { @@ -1237,7 +1264,7 @@ static int mifare_desfire_change_key(uint8_t key_no, uint8_t *new_key, uint8_t n if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't change key -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } @@ -1350,7 +1377,7 @@ static int handler_desfire_signature(uint8_t *signature, size_t *signature_len) *signature_len = recv_len; } } - DropField(); + DropFieldDesfire(); return res; } @@ -1558,10 +1585,15 @@ static int handler_desfire_select_application(uint8_t *aid) { sAPDU apdu = {0x90, MFDES_SELECT_APPLICATION, 0x00, 0x00, 0x03, aid}; //0x5a uint32_t recv_len = 0; uint16_t sw = 0; - int res = send_desfire_cmd(&apdu, true, NULL, &recv_len, &sw, sizeof(dfname_t), true); + + int res = send_desfire_cmd(&apdu, !tag->rf_field_on, NULL, &recv_len, &sw, sizeof(dfname_t), true); if (res != PM3_SUCCESS) { - PrintAndLogEx(WARNING, _RED_(" Can't select AID 0x%X -> %s"), (aid[2] << 16) + (aid[1] << 8) + aid[0], GetErrorString(res, &sw)); - DropField(); + PrintAndLogEx(WARNING, + _RED_(" Can't select AID 0x%X -> %s"), + (aid[2] << 16) + (aid[1] << 8) + aid[0], + GetErrorString(res, &sw) + ); + DropFieldDesfire(); return res; } memcpy(&tag->selected_application, aid, 3); @@ -1603,7 +1635,7 @@ static int handler_desfire_fileids(uint8_t *dest, uint32_t *file_ids_len) { int res = send_desfire_cmd(&apdu, false, dest, &recv_len, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't get file ids -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } *file_ids_len = recv_len; @@ -1622,7 +1654,7 @@ static int handler_desfire_filesettings(uint8_t file_id, uint8_t *dest, uint32_t int res = send_desfire_cmd(&apdu, false, dest, destlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't get file settings -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1662,7 +1694,7 @@ static int handler_desfire_createapp(aidhdr_t *aidhdr, bool usename, bool usefid } if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't create aid -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); } return res; } @@ -1677,7 +1709,7 @@ static int handler_desfire_deleteapp(const uint8_t *aid) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't delete aid -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); } return res; } @@ -1695,7 +1727,7 @@ static int handler_desfire_credit(mfdes_value_t *value, uint8_t cs) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't credit value -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1714,7 +1746,7 @@ static int handler_desfire_limitedcredit(mfdes_value_t *value, uint8_t cs) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't credit limited value -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1733,7 +1765,7 @@ static int handler_desfire_debit(mfdes_value_t *value, uint8_t cs) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't debit value -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1755,7 +1787,7 @@ static int handler_desfire_readdata(mfdes_data_t *data, MFDES_FILE_TYPE_T type, int res = send_desfire_cmd(&apdu, false, data->data, &resplen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't read data -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } @@ -1785,7 +1817,7 @@ static int handler_desfire_getvalue(mfdes_value_t *value, uint32_t *resplen, uin int res = send_desfire_cmd(&apdu, false, value->value, resplen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't read data -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } size_t dlen = (size_t)resplen; @@ -1840,7 +1872,7 @@ static int handler_desfire_writedata(mfdes_data_t *data, MFDES_FILE_TYPE_T type, res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't write data -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } offset += datasize; @@ -1850,7 +1882,7 @@ static int handler_desfire_writedata(mfdes_data_t *data, MFDES_FILE_TYPE_T type, if (type == MFDES_RECORD_FILE) { if (handler_desfire_commit_transaction() != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't commit transaction -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } } @@ -1865,7 +1897,7 @@ static int handler_desfire_deletefile(uint8_t fileno) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't delete file -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1879,13 +1911,13 @@ static int handler_desfire_clearrecordfile(uint8_t fileno) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't clear record file -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } else { res = handler_desfire_commit_transaction(); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't commit transaction -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } } @@ -1902,7 +1934,7 @@ static int handler_desfire_create_value_file(mfdes_value_file_t *value) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't create value -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1917,7 +1949,7 @@ static int handler_desfire_create_std_file(mfdes_file_t *file) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't create file -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1933,7 +1965,7 @@ static int handler_desfire_create_linearrecordfile(mfdes_linear_t *file) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't create linear record file -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1949,7 +1981,7 @@ static int handler_desfire_create_cyclicrecordfile(mfdes_linear_t *file) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't create cyclic record file -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -1965,7 +1997,7 @@ static int handler_desfire_create_backup_file(mfdes_file_t *file) { int res = send_desfire_cmd(&apdu, false, NULL, &recvlen, &sw, 0, true); if (res != PM3_SUCCESS) { PrintAndLogEx(WARNING, _RED_(" Can't create backup file -> %s"), GetErrorString(res, &sw)); - DropField(); + DropFieldDesfire(); return res; } return res; @@ -2066,7 +2098,7 @@ static int getKeySettings(uint8_t *aid) { } } - DropField(); + DropFieldDesfire(); return PM3_SUCCESS; } @@ -2204,7 +2236,7 @@ static int CmdHF14ADesGetUID(const char *Cmd) { uint8_t uid[16] = {0}; int res = handler_desfire_getuid(uid); if (res != PM3_SUCCESS) { - DropField(); + DropFieldDesfire(); PrintAndLogEx(ERR, "Error on getting uid."); return res; } @@ -2238,9 +2270,9 @@ static int CmdHF14ADesSelectApp(const char *Cmd) { } int res = handler_desfire_select_application(aid); - DropField(); if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "Error on selecting aid."); + DropFieldDesfire(); } else { PrintAndLogEx(SUCCESS, "Successfully selected aid."); } @@ -2373,15 +2405,17 @@ static int CmdHF14ADesCreateApp(const char *Cmd) { if (usename) PrintAndLogEx(INFO, "DF Name %s", aidhdr.name); +/* uint8_t rootaid[3] = {0x00, 0x00, 0x00}; int res = handler_desfire_select_application(rootaid); if (res != PM3_SUCCESS) { - DropField(); + DropFieldDesfire(); return res; } +*/ - res = handler_desfire_createapp(&aidhdr, usename, usefid); - DropField(); + int res = handler_desfire_createapp(&aidhdr, usename, usefid); + DropFieldDesfire(); if (res == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "Successfully created aid."); } @@ -2392,7 +2426,6 @@ static int CmdHF14ADesDeleteApp(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfdes deleteaid", "Delete Application ID", -// "Usage:\n\t-a aid (3 hex bytes, big endian)\n\n" "hf mfdes deleteaid -a 123456" ); @@ -2417,14 +2450,9 @@ static int CmdHF14ADesDeleteApp(const char *Cmd) { return PM3_ESOFT; } - uint8_t rootaid[3] = {0x00, 0x00, 0x00}; - int res = handler_desfire_select_application(rootaid); - if (res != PM3_SUCCESS) { - DropField(); - return res; - } - res = handler_desfire_deleteapp(aid); - DropField(); + int res = handler_desfire_deleteapp(aid); + DropFieldDesfire(); + if (res == PM3_SUCCESS) { PrintAndLogEx(SUCCESS, "Successfully deleted aid."); } @@ -2514,7 +2542,7 @@ static int CmdHF14ADesClearRecordFile(const char *Cmd) { } else { PrintAndLogEx(ERR, "Error on deleting file : %d", res); } - DropField(); + DropFieldDesfire(); return res; } @@ -2574,7 +2602,7 @@ static int CmdHF14ADesDeleteFile(const char *Cmd) { } else { PrintAndLogEx(ERR, "Error on deleting file : %d", res); } - DropField(); + DropFieldDesfire(); return res; } @@ -2664,12 +2692,12 @@ static int CmdHF14ADesCreateFile(const char *Cmd) { if (aidlength != 3 && aidlength != 0) { PrintAndLogEx(ERR, _RED_(" The given aid must have 3 bytes (big endian).")); - DropField(); + DropFieldDesfire(); return PM3_ESOFT; } else if (aidlength == 0) { if (memcmp(&tag->selected_application, aid, 3) == 0) { PrintAndLogEx(ERR, _RED_(" You need to select an aid first.")); - DropField(); + DropFieldDesfire(); return PM3_ESOFT; } memcpy(aid, (uint8_t *)&tag->selected_application, 3); @@ -2678,7 +2706,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) { int res = handler_desfire_select_application(aid); if (res != PM3_SUCCESS) { PrintAndLogEx(ERR, "Couldn't select aid. Error %d", res); - DropField(); + DropFieldDesfire(); return res; } @@ -2692,7 +2720,7 @@ static int CmdHF14ADesCreateFile(const char *Cmd) { else PrintAndLogEx(ERR, "Couldn't create standard/backup file. Error %d", res); - DropField(); + DropFieldDesfire(); return res; } @@ -2763,7 +2791,7 @@ static int CmdHF14ADesGetValueData(const char *Cmd) { } else { PrintAndLogEx(ERR, "Couldn't read value. Error %d", res); } - DropField(); + DropFieldDesfire(); return res; } @@ -2879,12 +2907,12 @@ static int CmdHF14ADesReadData(const char *Cmd) { } } else { PrintAndLogEx(ERR, "Couldn't read data. Error %d", res); - DropField(); + DropFieldDesfire(); return res; } free(data); } - DropField(); + DropFieldDesfire(); return res; } @@ -2980,7 +3008,7 @@ static int CmdHF14ADesChangeValue(const char *Cmd) { } else { PrintAndLogEx(ERR, "Couldn't change value in value file. Error %d", res); } - DropField(); + DropFieldDesfire(); return res; } @@ -3074,7 +3102,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) { uint8_t cs = 0; if (selectfile(aid, _fileno[0], &cs) != PM3_SUCCESS) { PrintAndLogEx(ERR, _RED_(" Error on selecting file.")); - DropField(); + DropFieldDesfire(); return PM3_ESOFT; } @@ -3086,7 +3114,7 @@ static int CmdHF14ADesWriteData(const char *Cmd) { } else { PrintAndLogEx(ERR, "Couldn't read data. Error %d", res); } - DropField(); + DropFieldDesfire(); return res; } @@ -3222,7 +3250,7 @@ static int CmdHF14ADesCreateRecordFile(const char *Cmd) { } else { PrintAndLogEx(ERR, "Couldn't create linear/cyclic record file. Error %d", res); } - DropField(); + DropFieldDesfire(); return res; } @@ -3354,7 +3382,7 @@ static int CmdHF14ADesCreateValueFile(const char *Cmd) { } else { PrintAndLogEx(ERR, "Couldn't create value file. Error %d", res); } - DropField(); + DropFieldDesfire(); return res; } @@ -3380,13 +3408,13 @@ static int CmdHF14ADesFormatPICC(const char *Cmd) { } else { PrintAndLogEx(INFO, "Card successfully reset"); } - DropField(); + DropFieldDesfire(); return res; } static int CmdHF14ADesInfo(const char *Cmd) { (void)Cmd; // Cmd is not used so far - DropField(); + DropFieldDesfire(); mfdes_info_res_t info; int res = mfdes_get_info(&info); @@ -3493,7 +3521,7 @@ static int CmdHF14ADesInfo(const char *Cmd) { */ - DropField(); + DropFieldDesfire(); return PM3_SUCCESS; } @@ -3644,7 +3672,7 @@ static int CmdHF14ADesDump(const char *Cmd) { CLIParserFree(ctx); (void)Cmd; // Cmd is not used so far - DropField(); + DropFieldDesfire(); uint8_t aid[3] = {0}; uint8_t app_ids[78] = {0}; @@ -3660,7 +3688,7 @@ static int CmdHF14ADesDump(const char *Cmd) { if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Can't get list of applications on tag"); - DropField(); + DropFieldDesfire(); return PM3_ESOFT; } @@ -3724,7 +3752,7 @@ static int CmdHF14ADesDump(const char *Cmd) { uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t)); if (data == NULL) { - DropField(); + DropFieldDesfire(); return PM3_EMALLOC; } @@ -3771,7 +3799,7 @@ static int CmdHF14ADesDump(const char *Cmd) { memset(fdata.length, 0, 3); uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t)); if (data == NULL) { - DropField(); + DropFieldDesfire(); return PM3_EMALLOC; } @@ -3801,14 +3829,14 @@ static int CmdHF14ADesDump(const char *Cmd) { } PrintAndLogEx(INFO, "-------------------------------------------------------------"); - DropField(); + DropFieldDesfire(); return PM3_SUCCESS; } static int CmdHF14ADesEnumApplications(const char *Cmd) { (void)Cmd; // Cmd is not used so far - DropField(); + DropFieldDesfire(); uint8_t aid[3] = {0}; uint8_t app_ids[78] = {0}; @@ -3822,7 +3850,7 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) { if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Can't get list of applications on tag"); - DropField(); + DropFieldDesfire(); return PM3_ESOFT; } @@ -3892,12 +3920,12 @@ static int CmdHF14ADesEnumApplications(const char *Cmd) { } PrintAndLogEx(INFO, "-------------------------------------------------------------"); - DropField(); + DropFieldDesfire(); return PM3_SUCCESS; } static int CmdHF14ADesChangeKey(const char *Cmd) { - //DropField(); + //DropFieldDesfire(); // NR DESC KEYLENGHT // ------------------------ // 1 = DES 8 @@ -3998,7 +4026,7 @@ static int CmdHF14ADesChangeKey(const char *Cmd) { // #define BUFSIZE 256 static int CmdHF14ADesAuth(const char *Cmd) { - //DropField(); + //DropFieldDesfire(); // NR DESC KEYLENGHT // ------------------------ // 1 = DES 8 @@ -4261,7 +4289,7 @@ static int AuthCheckDesfire(uint8_t *aid, break; } else if (error < 7) { badlen = true; - DropField(); + DropFieldDesfire(); res = handler_desfire_select_application(aid); if (res != PM3_SUCCESS) { return res; @@ -4293,7 +4321,7 @@ static int AuthCheckDesfire(uint8_t *aid, break; } else if (error < 7) { badlen = true; - DropField(); + DropFieldDesfire(); res = handler_desfire_select_application(aid); if (res != PM3_SUCCESS) { return res; @@ -4325,7 +4353,7 @@ static int AuthCheckDesfire(uint8_t *aid, break; } else if (error < 7) { badlen = true; - DropField(); + DropFieldDesfire(); res = handler_desfire_select_application(aid); if (res != PM3_SUCCESS) { return res; @@ -4357,7 +4385,7 @@ static int AuthCheckDesfire(uint8_t *aid, break; } else if (error < 7) { badlen = true; - DropField(); + DropFieldDesfire(); res = handler_desfire_select_application(aid); if (res != PM3_SUCCESS) { return res; @@ -4372,7 +4400,7 @@ static int AuthCheckDesfire(uint8_t *aid, } } } - DropField(); + DropFieldDesfire(); return PM3_SUCCESS; } @@ -4570,7 +4598,7 @@ static int CmdHF14aDesChk(const char *Cmd) { if (handler_desfire_appids(app_ids, &app_ids_len) != PM3_SUCCESS) { PrintAndLogEx(ERR, "Can't get list of applications on tag"); - DropField(); + DropFieldDesfire(); return PM3_ESOFT; } @@ -4670,7 +4698,7 @@ static int CmdHF14ADesList(const char *Cmd) { /* static int CmdHF14aDesNDEF(const char *Cmd) { - DropField(); + DropFieldDesfire(); CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfdes ndef", @@ -4735,7 +4763,7 @@ static int CmdHF14aDesNDEF(const char *Cmd) { uint8_t *data = (uint8_t *)calloc(filesize, sizeof(uint8_t)); if (data == NULL) { - DropField(); + DropFieldDesfire(); return PM3_EMALLOC; } @@ -4774,7 +4802,7 @@ static int CmdHF14aDesNDEF(const char *Cmd) { */ /* static int CmdHF14aDesMAD(const char *Cmd) { - DropField(); + DropFieldDesfire(); CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfdes mad", diff --git a/client/src/cmdlffdxb.c b/client/src/cmdlffdxb.c index efd567128..92e466358 100644 --- a/client/src/cmdlffdxb.c +++ b/client/src/cmdlffdxb.c @@ -50,7 +50,7 @@ static int CmdHelp(const char *Cmd); static int usage_lf_fdxb_clone(void) { PrintAndLogEx(NORMAL, "Clone a FDX-B animal tag to a T55x7 or Q5/T5555 tag."); - PrintAndLogEx(NORMAL, "Usage: lf fdxb clone [h] [c ] [a ] [e ] "); + PrintAndLogEx(NORMAL, "Usage: lf fdxb clone [h] [c ] [n ] [e ] "); PrintAndLogEx(NORMAL, "Options:"); PrintAndLogEx(NORMAL, " h : This help"); PrintAndLogEx(NORMAL, " c : (dec) Country code"); diff --git a/client/src/cmdlfhid.c b/client/src/cmdlfhid.c index 9bfbbaf3f..178a75449 100644 --- a/client/src/cmdlfhid.c +++ b/client/src/cmdlfhid.c @@ -138,9 +138,9 @@ int demodHID(bool verbose) { wiegand_message_t packed = initialize_message_object(hi2, hi, lo); if (HIDTryUnpack(&packed, false) == false) { - PrintAndLogEx(INFO, "raw: " _GREEN_("%08x%08x%08x"), hi2, hi, lo); printDemodBuff(0, false, false, true); } + PrintAndLogEx(INFO, "raw: " _GREEN_("%08x%08x%08x"), hi2, hi, lo); PrintAndLogEx(DEBUG, "DEBUG: HID idx: %d, Len: %zu, Printing Demod Buffer: ", idx, size); if (g_debugMode) { diff --git a/client/src/cmdmain.c b/client/src/cmdmain.c index 1cf3a6776..551f5ccf6 100644 --- a/client/src/cmdmain.c +++ b/client/src/cmdmain.c @@ -38,47 +38,10 @@ #include "util_posix.h" #include "commonutil.h" // ARRAYLEN #include "preferences.h" +#include "cliparser.h" static int CmdHelp(const char *Cmd); -static int usage_hints(void) { - PrintAndLogEx(NORMAL, "Turn on/off hints"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: hints [h] <0|1>"); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h This help"); - PrintAndLogEx(NORMAL, " <0|1> off or on"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" hints 1")); - return PM3_SUCCESS; -} - -static int usage_msleep(void) { - PrintAndLogEx(NORMAL, "Sleep for given amount of milliseconds"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: msleep "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h This help"); - PrintAndLogEx(NORMAL, " time in milliseconds"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" msleep 100")); - return PM3_SUCCESS; -} - -static int usage_auto(void) { - PrintAndLogEx(NORMAL, "Run LF SEARCH / HF SEARCH / DATA PLOT / DATA SAVE "); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Usage: auto "); - PrintAndLogEx(NORMAL, "Options:"); - PrintAndLogEx(NORMAL, " h This help"); - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(NORMAL, "Examples:"); - PrintAndLogEx(NORMAL, _YELLOW_(" auto")); - return PM3_SUCCESS; -} - static void AppendDate(char *s, size_t slen, const char *fmt) { struct tm *ct, tm_buf; time_t now = time(NULL); @@ -157,18 +120,31 @@ static int lf_search_plus(const char *Cmd) { return retval; } -static int CmdAuto(const char *Cmd) { - char ctmp = tolower(param_getchar(Cmd, 0)); - if (ctmp == 'h') return usage_auto(); +static int CmdAuto(const char *Cmd) { + CLIParserContext *ctx; + CLIParserInit(&ctx, "auto", + "Run LF SEARCH / HF SEARCH / DATA PLOT / DATA SAVE", + "auto" + ); + void *argtable[] = { + arg_param_begin, + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + CLIParserFree(ctx); + + PrintAndLogEx(INFO, "lf search"); int ret = CmdLFfind(""); - if (ret == PM3_SUCCESS) + if (ret == PM3_SUCCESS) return ret; + PrintAndLogEx(INFO, "hf search"); ret = CmdHFSearch(""); if (ret == PM3_SUCCESS) return ret; + PrintAndLogEx(INFO, "lf search - unknown"); ret = lf_search_plus(""); if (ret == PM3_SUCCESS) return ret; @@ -193,26 +169,35 @@ int CmdRem(const char *Cmd) { } static int CmdHints(const char *Cmd) { - uint32_t ms = 0; - char ctmp = tolower(param_getchar(Cmd, 0)); - if (ctmp == 'h') return usage_hints(); - if (strlen(Cmd) > 1) { - str_lower((char *)Cmd); - if (str_startswith(Cmd, "of")) { - session.show_hints = false; - } else { - session.show_hints = true; - } - } else if (strlen(Cmd) == 1) { - if (param_getchar(Cmd, 0) != 0x00) { - ms = param_get32ex(Cmd, 0, 0, 10); - if (ms == 0) { - session.show_hints = false; - } else { - session.show_hints = true; - } - } + CLIParserContext *ctx; + CLIParserInit(&ctx, "hints", + "Turn on/off hints", + "hints --on\n" + "hints -1\n" + ); + + void *argtable[] = { + arg_param_begin, + arg_lit0("1", "on", "turn on hints"), + arg_lit0("0", "off", "turn off hints"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, true); + + bool turn_on = arg_get_lit(ctx, 1); + bool turn_off = arg_get_lit(ctx, 2); + CLIParserFree(ctx); + + if (turn_on && turn_off) { + PrintAndLogEx(ERR, "you can't turn off and on at the same time"); + return PM3_EINVARG; + } + + if (turn_off) { + session.show_hints = false; + } else if (turn_on) { + session.show_hints = true; } PrintAndLogEx(INFO, "Hints are %s", (session.show_hints) ? "ON" : "OFF"); @@ -220,14 +205,26 @@ static int CmdHints(const char *Cmd) { } static int CmdMsleep(const char *Cmd) { - uint32_t ms = 0; - char ctmp = tolower(param_getchar(Cmd, 0)); - if (strlen(Cmd) < 1 || ctmp == 'h') return usage_msleep(); - if (param_getchar(Cmd, 0) != 0x00) { - ms = param_get32ex(Cmd, 0, 0, 10); - if (ms == 0) - return usage_msleep(); + CLIParserContext *ctx; + CLIParserInit(&ctx, "msleep", + "Sleep for given amount of milliseconds", + "msleep 100" + ); + + void *argtable[] = { + arg_param_begin, + arg_int0("t", "ms", "", "time in milliseconds"), + arg_param_end + }; + CLIExecWithReturn(ctx, Cmd, argtable, false); + uint32_t ms = arg_get_u32_def(ctx, 1, 0); + CLIParserFree(ctx); + + if (ms == 0) { + PrintAndLogEx(ERR, "Specified invalid input. Can't be zero"); + return PM3_EINVARG; } + msleep(ms); return PM3_SUCCESS; } diff --git a/client/src/mifare/desfire_crypto.h b/client/src/mifare/desfire_crypto.h index a1d514507..e7219eaf0 100644 --- a/client/src/mifare/desfire_crypto.h +++ b/client/src/mifare/desfire_crypto.h @@ -93,6 +93,7 @@ struct desfire_tag { uint8_t *crypto_buffer; size_t crypto_buffer_size; uint32_t selected_application; + bool rf_field_on; }; typedef struct desfire_tag *desfiretag_t; diff --git a/client/src/mifare/mifarehost.c b/client/src/mifare/mifarehost.c index f48a696ed..3df2e295c 100644 --- a/client/src/mifare/mifarehost.c +++ b/client/src/mifare/mifarehost.c @@ -859,7 +859,7 @@ int mfCSetUID(uint8_t *uid, uint8_t *atqa, uint8_t *sak, uint8_t *oldUID, uint8_ PrintAndLogEx(SUCCESS, "new block 0: %s", sprint_hex(block0, 16)); if (wipecard) params |= MAGIC_WIPE; - if (oldUID == NULL) params |= MAGIC_UID; + if (oldUID != NULL) params |= MAGIC_UID; return mfCSetBlock(0, block0, oldUID, params); }