Fix state machine behavior and access bits verification in MF1 emulation#274
Fix state machine behavior and access bits verification in MF1 emulation#274unkernet wants to merge 2 commits intoRfidResearchGroup:mainfrom
Conversation
- Ensured state machine reset on CRC/parity errors and invalid operations across command handlers. - Set `NFC_TAG_STATE_14A_PROPRIETARY` upon successful authentication to route subsequent commands only into the MF1 handler.
- Introduced `blockToSector()` and `sectorToBlock()` helpers to map between blocks and sectors. - Added `AuthenticatedSector` to track which sector is currently authenticated. - Fix access control table `abTrailerAccessConditions`: fixed swapped entries for access conditions. - Prevent authentication with Key B if it is readable using Key A. - READ and WRITE commands now verify permissions; unauthorized access are rejected. - On trailer writes, preserved protected fields (Key A, access bits, Key B) based on access conditions if write is not permitted.
|
You are welcome to add an entry to the CHANGELOG.md as well |
Built artifacts for commit 6ceefb3FirmwareClient |
There was a problem hiding this comment.
I can't test in the field, because in my area the public transport is not NFC based, yet. [But Other MF1 functions does not seems to be affected negative and still working.] ... It seems the code does not to compile anymore. I don't know what is different to last weeks test.
Could you check? I see missing dependencies to the nrf52_sdk. For example:
make: *** [../nrf52_sdk/components/toolchain/gcc/Makefile.common:272: ../objects/application/nfc_mf0_ntag.c.o] Fehler 127
./src/rfid/mf1_crapto1.c:142:10: fatal error: cmsis_gcc.h: No such file or directory
142 | #include <cmsis_gcc.h>
| ^~~~~~~~~~~~~
compilation terminated.
I've cloned your branch directly. because there where a lot of changes in the main branch lately.
|
The compilation errors seems to be caused by my environment. In a clean new approach, everything is working fine. Nice LUA script for the PM3. Card details: (UID redacted) |
|
There are two possible issues with this test:
|
|
I know the position of the CU is a little picky. So I compared the latest released FW and Auth worked. I upgraded to the compiled version of your branch, and Auth stopped working. Without moving the CU. My PM3 RDV4 was updated just yesterday. For reference I also checked the original card, to be sure it is not a PM3 error: |
|
I was able to reproduce the issue you describe, but only in one specific case: when attempting authentication with Key B on a sector where Key B is marked as readable. According to the datasheet, if Key B is readable in the Sector Trailer, it cannot be used for authentication. Could this be your case? |
|
Sorry for the late answer. You know, life is always blocking development ;) No, as far as I am aware, I am testing always with A keys... Maybe I switched this time because the key was easier to type. I'll check, when I am home next time (approx. 2 weeks, I forgot my test cards). |
I observed unstable and incorrect behavior when using Chameleon MIFARE emulation with a city transport system.
To investigate, I wrote a Proxmark script to check card responses and determine the state after receiving incorrect or unexpected commands from a reader. I ran this script against both Chameleon and various genuine cards. The differences observed:
This PR addresses all of the above issues.
It is split into two commits for clarity: