make hf 14a antifuzz actually reach a reader

Every answer was modulated after the reader's frame arrived, landing
~1812 carrier periods late against the 1172 the FDT allows, so readers
timed out before any of it mattered. All answers are now precomputed the
way hf 14a sim does it, and a phone answers at 1172 exactly.

Cascade mode sent a cascade tag at every level, which a conforming reader
rejects in the last level its ATQA announced - it dropped the card before
ever sending a SELECT. The cascade tag now appears only below that level;
it is the SAK that lies about the UID being incomplete, and that is what
walks a reader up to cascade level 7.

A bit oriented ANTICOLLISION was answered with the whole UID instead of
the bits the reader still lacked, handing it a frame of the wrong length.
One encoder now builds any tail, with or without collisions in it.

--coll leaves the first UID byte clean and collides every bit after it, so
a reader resolves 24 bits one round trip at a time, is then given a BCC
that checks out, and is cascaded into the same again - 183 answers per
poll against the 3 a real card needs. Colliding byte 0 as well only
produced a UID of all ones, which readers drop before asking for the BCC.

Reader frames that go unanswered are traced instead of silently dropped,
LED B marks an attempt in progress and LED C flips on each step deeper,
and the closing line reports rounds run and how far a reader got.

trace list -t 14a decodes SEL 0x99..0x9F, shows how many UID bits a bit
oriented ANTICOLL claims, and no longer flags those CRC-less frames as
bad CRC.

Co-Authored-By: Claude Opus 5 (1M context)
This commit is contained in:
iceman1001andClaude Opus 5 (1M context) committed 2026-09-12 21:18:26 +02:00
1 parent 25b3c88acf
commit 255576fa43
7 files changed
+558 -94

No files matched your search

+35 -5
View File
@@ -2049,20 +2049,28 @@ static int CmdHF14AAntiFuzz(const char *Cmd) {
CLIParserContext *ctx;
CLIParserInit(&ctx, "hf 14a antifuzz",
"Tries to fuzz the ISO14443a anticollision phase",
"hf 14a antifuzz -4\n");
"Tries to fuzz the ISO14443a anticollision phase.\n"
"Default keeps the cascade bit set in every SAK, so the reader asks for\n"
"one more cascade level until its UID buffer gives up. With --coll only\n"
"the first UID byte goes out clean and every bit after it collides, so the\n"
"reader has to resolve 24 bits one round trip at a time; it is then given a\n"
"BCC that checks out, and the SAK sends it round again one level deeper.",
"hf 14a antifuzz -4\n"
"hf 14a antifuzz --10 --coll\n");
void *argtable[] = {
arg_param_begin,
arg_lit0("4", NULL, "4 byte uid"),
arg_lit0("7", NULL, "7 byte uid"),
arg_lit0(NULL, "10", "10 byte uid"),
arg_lit0("4", NULL, "4 byte uid"),
arg_lit0("7", NULL, "7 byte uid"),
arg_lit0(NULL, "10", "10 byte uid"),
arg_lit0(NULL, "coll", "collision storm instead of cascade overflow"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
struct {
uint8_t flag;
uint8_t mode;
} PACKED param;
param.flag = 0;
FLAG_SET_UID_IN_DATA(param.flag, 4);
@@ -2072,10 +2080,32 @@ static int CmdHF14AAntiFuzz(const char *Cmd) {
if (arg_get_lit(ctx, 3)) {
FLAG_SET_UID_IN_DATA(param.flag, 10);
}
param.mode = arg_get_lit(ctx, 4) ? ANTIFUZZ_MODE_COLLISION : ANTIFUZZ_MODE_CASCADE;
CLIParserFree(ctx);
clearCommandBuffer();
SendCommandNG(CMD_HF_ISO14443A_ANTIFUZZ, (uint8_t *)&param, sizeof(param));
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("<Enter>") " to abort");
PacketResponseNG resp;
bool keypress = kbd_enter_pressed();
while (keypress == false) {
keypress = kbd_enter_pressed();
if (WaitForResponseTimeout(CMD_HF_ISO14443A_ANTIFUZZ, &resp, 500)) {
break;
}
}
if (keypress) {
// inform device to break the fuzz loop since the client has exited
SendCommandNG(CMD_BREAK_LOOP, NULL, 0);
WaitForResponse(CMD_HF_ISO14443A_ANTIFUZZ, &resp);
}
PrintAndLogEx(INFO, "Done!");
PrintAndLogEx(HINT, "Hint: Try `" _YELLOW_("hf 14a list") "` to view the fuzzed anticollision");
return PM3_SUCCESS;
}
+67 -39
View File
@@ -49,7 +49,12 @@ enum MifareAuthSeq {
static enum MifareAuthSeq MifareAuthState;
static AuthData_t AuthData;
// Set while the previous reader frame was a bit oriented ANTICOLLISION, whose
// answer completes a split byte and so carries no CRC either.
static bool gs_14a_anticoll_answer = false;
void ClearAuthData(void) {
gs_14a_anticoll_answer = false;
AuthData.uid = 0;
AuthData.nt = 0;
AuthData.first_auth = true;
@@ -74,6 +79,29 @@ static uint8_t *gs_mfuc_key = NULL;
*/
uint8_t iso14443A_CRC_check(bool isResponse, uint8_t *d, uint8_t n) {
// Neither half of a bit oriented ANTICOLLISION exchange carries a CRC: the
// request stops mid byte and the answer completes it. NVB counts SEL and
// NVB themselves, so 0x20..0x67 is the anticollision range and only a
// SELECT, NVB 0x70, ends in a CRC. `hf 14a antifuzz` pushes a reader past
// cascade level 3, hence the whole odd 0x93..0x9F range.
//
// The answer carries nothing that identifies it, so it is recognised by the
// request it follows - frames reach us in order.
if (isResponse == false) {
gs_14a_anticoll_answer = (n >= 2 &&
(d[0] & 1) &&
d[0] >= ISO14443A_CMD_ANTICOLL_OR_SELECT &&
d[0] <= 0x9F &&
d[1] >= 0x20 && d[1] <= 0x67);
if (gs_14a_anticoll_answer) {
return 2;
}
} else if (gs_14a_anticoll_answer) {
gs_14a_anticoll_answer = false;
return 2;
}
if (n < 3) {
return 2;
}
@@ -82,11 +110,6 @@ uint8_t iso14443A_CRC_check(bool isResponse, uint8_t *d, uint8_t n) {
return 2;
}
if (d[1] == 0x50 &&
d[0] >= ISO14443A_CMD_ANTICOLL_OR_SELECT &&
d[0] <= ISO14443A_CMD_ANTICOLL_OR_SELECT_3) {
return 2;
}
return check_crc(CRC_14443_A, d, n);
}
@@ -266,40 +289,45 @@ int applyIso14443a(char *exp, size_t size, uint8_t *cmd, uint8_t cmdsize, bool i
case ISO14443A_CMD_WUPA:
snprintf(exp, size, "WUPA");
break;
case ISO14443A_CMD_ANTICOLL_OR_SELECT: {
// 93 20 = Anticollision (usage: 9320 - answer: 4bytes UID+1byte UID-bytes-xor)
// 93 50 = Bit oriented anti-collision (usage: 9350+ up to 5bytes, 9350 answer - up to 5bytes UID+BCC)
// 93 70 = Select (usage: 9370+5bytes 9370 answer - answer: 1byte SAK)
if (cmd[1] == 0x70)
snprintf(exp, size, "SELECT_UID");
else if (cmd[1] == 0x20 || cmd[1] == 0x50)
snprintf(exp, size, "ANTICOLL");
else
snprintf(exp, size, "SELECT_XXX");
break;
}
case ISO14443A_CMD_ANTICOLL_OR_SELECT_2: {
//95 20 = Anticollision of cascade level2
//95 50 = Bit oriented anti-collision level2
//95 70 = Select of cascade level2
if (cmd[1] == 0x70)
snprintf(exp, size, "SELECT_UID-2");
else if (cmd[1] == 0x20 || cmd[1] == 0x50)
snprintf(exp, size, "ANTICOLL-2");
else
snprintf(exp, size, "SELECT_XXX-2");
break;
}
case ISO14443A_CMD_ANTICOLL_OR_SELECT_3: {
//97 20 = Anticollision of cascade level3
//97 50 = Bit oriented anti-collision level3
//97 70 = Select of cascade level3
if (cmd[1] == 0x70)
snprintf(exp, size, "SELECT_UID-3");
else if (cmd[1] == 0x20 || cmd[1] == 0x50)
snprintf(exp, size, "ANTICOLL-3");
else
snprintf(exp, size, "SELECT_XXX-3");
// 93 20 = Anticollision (usage: 9320 - answer: 4bytes UID+1byte UID-bytes-xor)
// 93 50 = Bit oriented anti-collision (usage: 9350+ up to 5bytes, 9350 answer - up to 5bytes UID+BCC)
// 93 70 = Select (usage: 9370+5bytes 9370 answer - answer: 1byte SAK)
// 95 xx / 97 xx are the same for cascade level 2 and 3. ISO 14443-3
// defines no level above 3, but `hf 14a antifuzz` walks a reader up
// the whole odd 0x93..0x9F range, so decode that range too.
case ISO14443A_CMD_ANTICOLL_OR_SELECT:
case ISO14443A_CMD_ANTICOLL_OR_SELECT_2:
case ISO14443A_CMD_ANTICOLL_OR_SELECT_3:
case 0x99:
case 0x9B:
case 0x9D:
case 0x9F: {
// one suffix for every level past the first, so an ordinary
// trace keeps reading "ANTICOLL" / "SELECT_UID"
char lvl[8] = {0};
uint8_t level = ((cmd[0] - ISO14443A_CMD_ANTICOLL_OR_SELECT) >> 1) + 1;
if (level > 1) {
snprintf(lvl, sizeof(lvl), "-%u", level);
}
if (cmdsize < 2) {
snprintf(exp, size, "SELECT_XXX%s", lvl);
} else if (cmd[1] == 0x70) {
snprintf(exp, size, "SELECT_UID%s", lvl);
} else if (cmd[1] >= 0x20 && cmd[1] <= 0x67 && (cmd[1] & 0x0F) < 8) {
// NVB counts SEL and NVB themselves, so 0x20 is "no UID bits
// known" and 0x67 is "39 known". Anything in between is a
// bit oriented request, and how far the reader has got is
// the whole story of a collision storm.
uint8_t known = (uint8_t)((((cmd[1] >> 4) - 2) * 8) + (cmd[1] & 0x0F));
if (known) {
snprintf(exp, size, "ANTICOLL%s(" _MAGENTA_("%u") " bit%s)", lvl, known, (known == 1) ? "" : "s");
} else {
snprintf(exp, size, "ANTICOLL%s", lvl);
}
} else {
snprintf(exp, size, "SELECT_XXX%s", lvl);
}
break;
}
case ISO14443A_CMD_REQA: