Merge branch 'RfidResearchGroup:master' into 20260917-15magic-fix
This commit is contained in:
31 files changed
+501
-62
No files matched your search
@@ -81,7 +81,7 @@ static int CmdHFEPACollectPACENonces(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
const epa_result_t *r = (const epa_result_t *)resp.data.asBytes;
|
||||
const epa_result_t *r = (const epa_result_t *)(const void *)resp.data.asBytes;
|
||||
|
||||
if (r->step != 0) {
|
||||
PrintAndLogEx(FAILED, "Error in step %u, Return code: %d", r->step, r->func_return);
|
||||
@@ -211,7 +211,7 @@ static int CmdHFEPAPACEReplay(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
const epa_result_t *rr = (const epa_result_t *)resp.data.asBytes;
|
||||
const epa_result_t *rr = (const epa_result_t *)(const void *)resp.data.asBytes;
|
||||
|
||||
if (rr->step != 0) {
|
||||
PrintAndLogEx(SUCCESS, "\nPACE replay failed in step %u!", rr->step);
|
||||
@@ -273,7 +273,7 @@ static int CmdHFEPAPACESimulate(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
const epa_result_t *sr = (const epa_result_t *)resp.data.asBytes;
|
||||
const epa_result_t *sr = (const epa_result_t *)(const void *)resp.data.asBytes;
|
||||
const uint32_t *data = sr->timings;
|
||||
|
||||
if (sr->step != 0) {
|
||||
|
||||
+44
-10
@@ -65,6 +65,14 @@
|
||||
#define MAX_ST25TN512 0x3F
|
||||
#define MAX_ST25TN01K 0x3F
|
||||
|
||||
// UL-AES fixed memory map, MF0AES(H)20
|
||||
#define MFU_AES_USER_FIRST 0x04
|
||||
#define MFU_AES_USER_LAST 0x27
|
||||
#define MFU_AES_LOCK_PAGE 0x28
|
||||
#define MFU_AES_CFG0_PAGE 0x29
|
||||
#define MFU_AES_CFG1_PAGE 0x2A
|
||||
#define MFU_AES_KEY0_PAGE 0x30
|
||||
|
||||
#define MIFAREU3P_KEY_SIZE 16
|
||||
#define MIFAREULC_KEY_INDEX 3
|
||||
#define MFU_DEFAULT_KEY_DIC "mfulc_default_keys.dic"
|
||||
@@ -4043,6 +4051,7 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||
"hf mfu restore -f myfile -s -> special write\n"
|
||||
"hf mfu restore -f myfile -k AABBCCDD -s -> special write, use key\n"
|
||||
"hf mfu restore -f myfile -k AABBCCDD -ser -> special write, use key, write dump pwd, ...\n"
|
||||
"hf mfu restore -f myfile -k 00112233445566778899AABBCCDDEEFF -> UL-C / UL-AES, use key\n"
|
||||
"\n"
|
||||
"Note: Restoring a NTAG/UL dump to a UMC will likely result in incorrect PWD and PACK\n"
|
||||
);
|
||||
@@ -4050,7 +4059,7 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("f", "file", "<fn>", "Specify a filename for dump file"),
|
||||
arg_str0("k", "key", "<hex>", "key for authentication (UL-C 16 bytes, EV1/NTAG 4 bytes)"),
|
||||
arg_str0("k", "key", "<hex>", "key for authentication (UL-C/UL-AES 16 bytes, EV1/NTAG 4 bytes)"),
|
||||
arg_lit0("l", NULL, "swap entered key's endianness"),
|
||||
arg_lit0("s", NULL, "enable special write UID -MAGIC TAG ONLY-"),
|
||||
arg_lit0("e", NULL, "enable special write version/signature -MAGIC NTAG 21* ONLY-"),
|
||||
@@ -4142,6 +4151,8 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
bool is_ulaes = ((tagtype & MFU_TT_UL_AES) == MFU_TT_UL_AES);
|
||||
|
||||
if ((tagtype & MFU_TT_UL_C) == MFU_TT_UL_C) {
|
||||
if ((has_key == true) && (ak_len != 16)) {
|
||||
PrintAndLogEx(ERR, "UL-C key must be 16 bytes");
|
||||
@@ -4172,12 +4183,6 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||
}
|
||||
}
|
||||
|
||||
if ((tagtype & MFU_TT_UL_AES) == MFU_TT_UL_AES) {
|
||||
PrintAndLogEx(ERR, "Sorry, UL-AES not yet supported. Feel free to implement!");
|
||||
free(dump);
|
||||
return PM3_ENOTIMPL;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Restoring " _YELLOW_("%s")" to card", filename);
|
||||
|
||||
mfu_print_dump(mem, pages, 0, dense_output);
|
||||
@@ -4279,7 +4284,19 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||
// write all other data
|
||||
// Skip block 0,1,2,3 (only magic tags can write to them)
|
||||
// Skip last 5 blocks usually is configuration
|
||||
for (uint8_t b = 4; b < pages - 5; b++) {
|
||||
uint8_t first_page = 4;
|
||||
uint8_t last_page = pages - 5;
|
||||
|
||||
if (is_ulaes) {
|
||||
// UL-AES user memory stops before the lock, config and key pages
|
||||
first_page = MFU_AES_USER_FIRST;
|
||||
last_page = MFU_AES_USER_LAST + 1;
|
||||
if (pages < last_page) {
|
||||
last_page = pages;
|
||||
}
|
||||
}
|
||||
|
||||
for (uint8_t b = first_page; b < last_page; b++) {
|
||||
|
||||
//Send write Block
|
||||
memcpy(packetw.data, mem->data + (b * 4), 4);
|
||||
@@ -4306,8 +4323,19 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||
// otp, uid, lock, dynlockbits, cfg0, cfg1
|
||||
uint8_t blocks[] = {3, 0, 1, 2, pages - 5, pages - 4, pages - 3};
|
||||
#endif
|
||||
for (uint8_t i = 0; i < ARRAYLEN(blocks); i++) {
|
||||
uint8_t b = blocks[i];
|
||||
// otp, uid, lock, cfg0, cfg1.
|
||||
// RFU pages (0x2B, 0x2C) and the key lock bits (0x2D) are left alone, they are one way
|
||||
uint8_t ulaes_blocks[] = {3, 0, 1, 2, MFU_AES_LOCK_PAGE, MFU_AES_CFG0_PAGE, MFU_AES_CFG1_PAGE};
|
||||
|
||||
uint8_t *pblocks = blocks;
|
||||
uint8_t blockcnt = ARRAYLEN(blocks);
|
||||
if (is_ulaes) {
|
||||
pblocks = ulaes_blocks;
|
||||
blockcnt = ARRAYLEN(ulaes_blocks);
|
||||
}
|
||||
|
||||
for (uint8_t i = 0; i < blockcnt; i++) {
|
||||
uint8_t b = pblocks[i];
|
||||
memcpy(packetw.data, mem->data + (b * 4), 4);
|
||||
packetw.block_no = b;
|
||||
clearCommandBuffer();
|
||||
@@ -4319,6 +4347,12 @@ static int CmdHF14AMfURestore(const char *Cmd) {
|
||||
|
||||
DropField();
|
||||
free(dump);
|
||||
|
||||
if (is_ulaes) {
|
||||
PrintAndLogEx(INFO, "Key pages 0x%02X..0x%02X not restored", MFU_AES_KEY0_PAGE, MAX_UL_AES);
|
||||
PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu setkey -k <16 hex bytes>") "` to restore the AES keys");
|
||||
}
|
||||
|
||||
PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf mfu dump --ns") "` to verify");
|
||||
PrintAndLogEx(INFO, "Done!");
|
||||
return PM3_SUCCESS;
|
||||
|
||||
+194
-1
@@ -48,6 +48,8 @@
|
||||
#define NTAG424_CMD_MORE_DATA 0xAF
|
||||
#define NTAG424_CMD_GET_VERSION 0x60
|
||||
#define NTAG424_CMD_GET_SIGNATURE 0x3C
|
||||
#define NTAG424_CMD_GET_TT_STATUS 0xF7
|
||||
#define NTAG424_CMD_SET_CONFIGURATION 0x5C
|
||||
|
||||
//
|
||||
// Original from https://github.com/rfidhacking/node-sdm/
|
||||
@@ -148,6 +150,11 @@ typedef struct {
|
||||
ntag424_production_information_t production;
|
||||
} ntag424_full_version_information_t;
|
||||
|
||||
typedef struct {
|
||||
uint8_t perm;
|
||||
uint8_t curr;
|
||||
} ntag424_tag_tamper_status_t;
|
||||
|
||||
|
||||
static void ntag424_print_version_information(ntag424_version_information_t *version, bool is_hw) {
|
||||
PrintAndLogEx(INFO, " vendor id: " _GREEN_("%02X"), version->vendor_id);
|
||||
@@ -856,6 +863,35 @@ static int ntag424_read_data(uint8_t fileno, uint16_t offset, uint16_t num_bytes
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static const char *tt_status_str(uint8_t status) {
|
||||
switch (status) {
|
||||
case 'C': return "Close";
|
||||
case 'O': return "Open";
|
||||
case 'I': return "Invalid";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
static int ntag424_get_tt_status(ntag424_tag_tamper_status_t *status, ntag424_communication_mode_t comm_mode, ntag424_session_keys_t *session_keys) {
|
||||
APDU_t apdu = {
|
||||
.cla = 0x90,
|
||||
.ins = NTAG424_CMD_GET_TT_STATUS,
|
||||
.lc = 0
|
||||
};
|
||||
|
||||
// align_up(sizeof(ntag424_tag_tamper_status_t) + 1, 16) + sizeof(mac) + sizeof(status_word)
|
||||
int response_length = 16 + 8 + 2;
|
||||
uint8_t response[response_length];
|
||||
|
||||
int res = ntag424_exchange_apdu(apdu, 0, response, &response_length, comm_mode, session_keys, 0x91, 0x00);
|
||||
if (res != PM3_SUCCESS) {
|
||||
return res;
|
||||
}
|
||||
|
||||
memcpy(status, response, sizeof(*status));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int ntag424_get_version(ntag424_full_version_information_t *version) {
|
||||
APDU_t apdu = {
|
||||
.cla = 0x90,
|
||||
@@ -913,6 +949,25 @@ static int ntag424_get_signature(uint8_t *signature_out) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int ntag424_set_configuration(uint8_t option, const uint8_t *data, int data_len, ntag424_session_keys_t *session_keys) {
|
||||
uint8_t cmd_buffer[64];
|
||||
cmd_buffer[0] = option;
|
||||
memcpy(&cmd_buffer[1], data, data_len);
|
||||
|
||||
APDU_t apdu = {
|
||||
.cla = 0x90,
|
||||
.ins = NTAG424_CMD_SET_CONFIGURATION,
|
||||
.lc = 1 + data_len,
|
||||
.data = cmd_buffer
|
||||
};
|
||||
|
||||
// No response data, only MAC and status word
|
||||
int response_length = 8 + 2;
|
||||
uint8_t response[response_length];
|
||||
|
||||
return ntag424_exchange_apdu(apdu, 1, response, &response_length, COMM_FULL, session_keys, 0x91, 0x00);
|
||||
}
|
||||
|
||||
static int ntag424_change_key(uint8_t keyno, const uint8_t *new_key, const uint8_t *old_key, uint8_t version, ntag424_session_keys_t *session_keys) {
|
||||
// -------- Calculate xor and crc
|
||||
uint8_t key[16] = {0};
|
||||
@@ -1513,7 +1568,13 @@ static int CmdHF_ntag424_changekey(const char *Cmd) {
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
uint8_t version = arg_get_int(ctx, 6);
|
||||
int kv = arg_get_int(ctx, 5);
|
||||
if (kv < 0 || kv > 0xFF) {
|
||||
PrintAndLogEx(ERR, "Key version must be 0..255, got ( %d )", kv);
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
uint8_t version = (uint8_t)kv;
|
||||
int keyno = arg_get_int(ctx, 1);
|
||||
|
||||
uint8_t oldkey[16] = {0};
|
||||
@@ -1573,6 +1634,136 @@ static int CmdHF_ntag424_changekey(const char *Cmd) {
|
||||
return res;
|
||||
}
|
||||
|
||||
static int CmdHF_ntag424_getttstatus(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf ntag424 gettt",
|
||||
"Read and print Tag Tamper status. Will authenticate if key information is provided.",
|
||||
"hf ntag424 gettt --keyno 0 -k 00000000000000000000000000000000");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_int0(NULL, "keyno", "<dec>", "Key number"),
|
||||
arg_str0("k", "key", "<hex>", "Key for authentication (HEX 16 bytes)"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
int keyno = 0;
|
||||
uint8_t key[16] = {0};
|
||||
bool auth = arg_get_str(ctx, 2)->count > 0;
|
||||
if (auth && ntag424_cli_get_auth_information(ctx, 1, 2, &keyno, key) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Could not get key settings");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (SelectCard14443A_4(false, true, NULL) != PM3_SUCCESS) {
|
||||
DropField();
|
||||
PrintAndLogEx(ERR, "Failed to select card");
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
|
||||
if (ntag424_select_application() != PM3_SUCCESS) {
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
int res = PM3_SUCCESS;
|
||||
ntag424_session_keys_t session_keys = {0};
|
||||
if (auth) {
|
||||
res = ntag424_authenticate_ev2_first(keyno, key, &session_keys);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Auth key %d ( " _RED_("fail") " )", keyno);
|
||||
DropField();
|
||||
return res;
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "Auth key %d ( " _GREEN_("ok") " )", keyno);
|
||||
}
|
||||
}
|
||||
|
||||
ntag424_tag_tamper_status_t tt_status = {0};
|
||||
res = ntag424_get_tt_status(&tt_status, auth ? COMM_FULL : COMM_PLAIN, &session_keys);
|
||||
DropField();
|
||||
if (res == PM3_SUCCESS) {
|
||||
PrintAndLogEx(SUCCESS, "--- " _CYAN_("Tag Tamper status:"));
|
||||
PrintAndLogEx(SUCCESS, " TTPermStatus: " _GREEN_("%02X (%s)"), tt_status.perm, tt_status_str(tt_status.perm));
|
||||
PrintAndLogEx(SUCCESS, " TTCurrStatus: " _GREEN_("%02X (%s)"), tt_status.curr, tt_status_str(tt_status.curr));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static int CmdHF_ntag424_setconfig(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf ntag424 setconfig",
|
||||
"Change a PICC configuration option.\n"
|
||||
"Several options are one-way, see the datasheet before using this.",
|
||||
"hf ntag424 setconfig -k 00000000000000000000000000000000 --option 07 -d 0100");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("k", "key0", "<hex>", "Authentication key (must be key 0, HEX 16 bytes)"),
|
||||
arg_str1(NULL, "option", "<hex>", "Configuration option (HEX 1 byte)"),
|
||||
arg_strx1("d", "data", "<hex>", "Option data (HEX, 1..47 bytes)"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
|
||||
uint8_t key[16] = {0};
|
||||
if (ntag424_cli_get_auth_information(ctx, 0, 1, NULL, key) != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Could not get key settings");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint8_t option[1] = {0};
|
||||
int optionlen = sizeof(option);
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 2), option, sizeof(option), &optionlen) || (optionlen != sizeof(option))) {
|
||||
PrintAndLogEx(ERR, "Option must be 1 byte");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
uint8_t data[47] = {0};
|
||||
int datalen = sizeof(data);
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 3), data, sizeof(data), &datalen) || (datalen < 1)) {
|
||||
PrintAndLogEx(ERR, "Data must be 1..%zu bytes", sizeof(data));
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (SelectCard14443A_4(false, true, NULL) != PM3_SUCCESS) {
|
||||
DropField();
|
||||
PrintAndLogEx(ERR, "Failed to select card");
|
||||
return PM3_ERFTRANS;
|
||||
}
|
||||
|
||||
if (ntag424_select_application() != PM3_SUCCESS) {
|
||||
DropField();
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
ntag424_session_keys_t session = {0};
|
||||
int res = ntag424_authenticate_ev2_first(0, key, &session);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(ERR, "Auth key 0 ( " _RED_("fail") " )");
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
PrintAndLogEx(SUCCESS, "Auth key 0 ( " _GREEN_("ok") " )");
|
||||
|
||||
res = ntag424_set_configuration(option[0], data, datalen, &session);
|
||||
DropField();
|
||||
if (res == PM3_SUCCESS) {
|
||||
PrintAndLogEx(SUCCESS, "Set configuration option %02X ( " _GREEN_("ok") " )", option[0]);
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Set configuration option %02X ( " _RED_("fail") " )", option[0]);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("operations") " -----------------------"},
|
||||
@@ -1584,6 +1775,8 @@ static command_t CommandTable[] = {
|
||||
{"getfs", CmdHF_ntag424_getfilesettings, IfPm3Iso14443a, "Get file settings"},
|
||||
{"changefs", CmdHF_ntag424_changefilesettings, IfPm3Iso14443a, "Change file settings"},
|
||||
{"changekey", CmdHF_ntag424_changekey, IfPm3Iso14443a, "Change key"},
|
||||
{"gettt", CmdHF_ntag424_getttstatus, IfPm3Iso14443a, "Get Tag Tamper status"},
|
||||
{"setconfig", CmdHF_ntag424_setconfig, IfPm3Iso14443a, "Set PICC configuration option"},
|
||||
{NULL, NULL, NULL, NULL}
|
||||
};
|
||||
|
||||
|
||||
@@ -1940,7 +1940,7 @@ static int CmdLFHitagEload(const char *Cmd) {
|
||||
arg_lit0("1", "ht1", "Card type Hitag 1"),
|
||||
arg_lit0("2", "ht2", "Card type Hitag 2"),
|
||||
arg_lit0("s", "hts", "Card type Hitag S"),
|
||||
arg_lit0("m", "htm", "Card type Hitag \xce\xbc"), // μ
|
||||
arg_lit0("m", "htm", "Card type Hitag µ"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
@@ -1990,7 +1990,7 @@ static int CmdLFHitagEload(const char *Cmd) {
|
||||
} else if (use_htm) {
|
||||
// a u dump is sized by the tag's ICR, so accept anything that fits
|
||||
expected = 0;
|
||||
tname = "Hitag \xce\xbc";
|
||||
tname = "Hitag µ";
|
||||
}
|
||||
|
||||
if (use_htm) {
|
||||
@@ -2053,7 +2053,7 @@ static int CmdLFHitagEview(const char *Cmd) {
|
||||
arg_lit0("1", "ht1", "Card type Hitag 1"),
|
||||
arg_lit0("2", "ht2", "Card type Hitag 2 (default)"),
|
||||
arg_lit0("s", "hts", "Card type Hitag S"),
|
||||
arg_lit0("m", "htm", "Card type Hitag \xce\xbc"),
|
||||
arg_lit0("m", "htm", "Card type Hitag µ"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
@@ -2933,4 +2933,3 @@ int CmdLFHitag(const char *Cmd) {
|
||||
return CmdsParse(CommandTable, Cmd);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user