hf mfdes dump: keep the session across the ISO file id probe
DesfireFillFileList() ends with GetISOFileIDs (0x61). An application created
without ISO file ids answers 0x91F0, and the PICC ends the authentication on a
command error. The client never noticed: dctx->secureChannel still said ev1, so
every later command was framed as MACed against a dead session.
For hf mfdes dump that meant the first file was read as if its response carried
a CMAC. An 8 byte plain free access file came back as exactly 8 bytes of data,
which were consumed as the MAC, so the file content was thrown away and reported
as
Received MAC is not match with calculated
received MAC: A0 A1 A2 A3 A4 A5 A6 A7
Read operation returned no data from file 0
The next key protected file then failed with 0x91AE, and only that failure
triggered the loop's blind re-authentication, after which the rest of the dump
was correct. Dumping an application that does have ISO file ids was never
affected, because 0x61 succeeds there.
Drop our side of the session when the probe fails so the context tells the
truth, and re-authenticate in CmdHF14ADesDump before the read loop. The two
warnings the probe printed are demoted to DEBUG: an application without ISO
file ids is the normal case, not something to warn about.
Key settings 2 bit 0x20 is not usable to predict this. On a DESFire EV2 both an
application with working ISO file ids and one without report key settings 0F 83,
so the bit reads back as 0 either way.
Co-Authored-By: Claude Opus 5 (1M context)
This commit is contained in:
1 parent
2449bb2472
commit
3853540d31
3 files changed
+21
-2
No files matched your search
@@ -8322,6 +8322,18 @@ static int CmdHF14ADesDump(const char *Cmd) {
|
||||
return res;
|
||||
}
|
||||
|
||||
// the ISO file id probe in DesfireFillFileList makes the PICC end the session on
|
||||
// applications without ISO file ids, so get it back before reading the files
|
||||
if (noauth == false && DesfireIsAuthenticated(&dctx) == false) {
|
||||
DesfireSetCommMode(&dctx, DCMPlain);
|
||||
res = DesfireSelectAndAuthenticateAppW(&dctx, securechann, selectway, id, noauth, verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
PrintAndLogEx(FAILED, "Select or authentication %s " _RED_("failed") ". Result [%d] %s", DesfireWayIDStr(selectway, id), res, DesfireAuthErrorToStr(res));
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, "Application " _CYAN_("%s") " have " _GREEN_("%zu") " files", DesfireWayIDStr(selectway, id), filescount);
|
||||
|
||||
|
||||
@@ -2358,7 +2358,12 @@ int DesfireFillFileList(DesfireContext_t *dctx, FileList_t FileList, size_t *fil
|
||||
buflen = 0;
|
||||
res = DesfireGetFileISOIDList(dctx, buf, &buflen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
PrintAndLogEx(WARNING, "Desfire GetFileISOIDList command, res " _RED_("%d"), res);
|
||||
// An application created without ISO file IDs answers 0x91F0 here, and the PICC
|
||||
// ends the authentication on a command error. Drop our side of the session too,
|
||||
// otherwise the next command is still framed as MACed and the plain response to
|
||||
// it gets parsed as a CMAC. Callers that keep using the card re-authenticate.
|
||||
dctx->secureChannel = DACNone;
|
||||
PrintAndLogEx(DEBUG, "Desfire GetFileISOIDList command, res " _RED_("%d") ". Session dropped by the PICC", res);
|
||||
}
|
||||
|
||||
size_t isoindx = 0;
|
||||
@@ -2373,7 +2378,7 @@ int DesfireFillFileList(DesfireContext_t *dctx, FileList_t FileList, size_t *fil
|
||||
if (isoindx * 2 != buflen)
|
||||
PrintAndLogEx(WARNING, "Wrong ISO ID list length. must be %zu but %zu", buflen, isoindx * 2);
|
||||
} else {
|
||||
PrintAndLogEx(WARNING, "ISO ID list returned no data");
|
||||
PrintAndLogEx(DEBUG, "ISO ID list returned no data");
|
||||
}
|
||||
|
||||
*isopresent = (isoindx > 0);
|
||||
|
||||
Reference in new issue
Block a user