From c9d5bdd7ea16b5fd0766610b950d23889194c32d Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Mon, 9 Nov 2026 14:28:34 +0700 Subject: [PATCH] trace extract: find the DESFire auth challenge after PCB, CID and NAD The tag challenge of the DES, ISO and AES auth branches was read from frame + 1. In native framing that is the AF status byte, and with a CID it is the CID byte, so the challenge came out shifted by one, eg traces/hf_mfdes_sniff.trace gave 000675359294E7CD instead of 0675359294E7CDA1. Co-Authored-By: Claude Opus 5.5 --- client/src/cmdtrace.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/client/src/cmdtrace.c b/client/src/cmdtrace.c index b90291544..033202224 100644 --- a/client/src/cmdtrace.c +++ b/client/src/cmdtrace.c @@ -164,6 +164,11 @@ static uint8_t calc_pos(const uint8_t *d) { return pos; } +// offset of the challenge in a DESFire auth reply, native puts the AF status before it +static uint8_t mfdes_chall_pos(const uint8_t *d, uint8_t long_jmp) { + return calc_pos(d) + ((long_jmp == 1) ? 1 : 0); +} + // Discard the client side trace buffer void ClearTraceBuffer(void) { free(gs_trace); @@ -432,12 +437,13 @@ static uint16_t extractChallenges(uint16_t tracepos, uint16_t traceLen, uint8_t break; } - if (next_hdr->data_len < 9) { + uint8_t cpos = mfdes_chall_pos(next_hdr->frame, long_jmp); + if (next_hdr->data_len < cpos + 8 + 2) { break; } tracepos += TRACELOG_HDR_LEN + next_hdr->data_len + TRACELOG_PARITY_LEN(next_hdr); - PrintAndLogEx(INFO, "DES 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + 1, 8)); + PrintAndLogEx(INFO, "DES 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + cpos, 8)); next_hdr = get_record(tracepos, traceLen, trace); if (next_hdr != NULL) { @@ -460,16 +466,17 @@ static uint16_t extractChallenges(uint16_t tracepos, uint16_t traceLen, uint8_t } tracepos += TRACELOG_HDR_LEN + next_hdr->data_len + TRACELOG_PARITY_LEN(next_hdr); - if (next_hdr->data_len < 9) { + uint8_t cpos = mfdes_chall_pos(next_hdr->frame, long_jmp); + if (next_hdr->data_len < cpos + 8 + 2) { break; } uint8_t tdea = 8; if (next_hdr->data_len > 20) { tdea = 16; - PrintAndLogEx(INFO, "3TDEA 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + 1, tdea)); + PrintAndLogEx(INFO, "3TDEA 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + cpos, tdea)); } else { - PrintAndLogEx(INFO, "2TDEA 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + 1, tdea)); + PrintAndLogEx(INFO, "2TDEA 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + cpos, tdea)); } next_hdr = get_record(tracepos, traceLen, trace); @@ -493,12 +500,12 @@ static uint16_t extractChallenges(uint16_t tracepos, uint16_t traceLen, uint8_t } tracepos += TRACELOG_HDR_LEN + next_hdr->data_len + TRACELOG_PARITY_LEN(next_hdr); - // PCB + 16 byte RndB + CRC - if (next_hdr->data_len < 19) { + uint8_t cpos = mfdes_chall_pos(next_hdr->frame, long_jmp); + if (next_hdr->data_len < cpos + 16 + 2) { break; } - PrintAndLogEx(INFO, "AES 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + 1, 16)); + PrintAndLogEx(INFO, "AES 1499999999 %s " NOLF, sprint_hex_inrow(next_hdr->frame + cpos, 16)); next_hdr = get_record(tracepos, traceLen, trace); if (next_hdr != NULL) {