This commit is contained in:
iceman1001 2023-07-24 13:34:24 +02:00
commit 72057f9b81
3 changed files with 28 additions and 8 deletions

View file

@ -153,26 +153,37 @@ static int initSectorTable(sector_t **src, size_t items) {
static void decode_print_st(uint16_t blockno, uint8_t *data) {
if (mfIsSectorTrailer(blockno)) {
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, "----------------------- " _CYAN_("Sector trailer decoder") " -----------------------");
PrintAndLogEx(INFO, "-------------------------- " _CYAN_("Sector trailer decoder") " --------------------------");
PrintAndLogEx(INFO, "key A........ " _GREEN_("%s"), sprint_hex_inrow(data, 6));
PrintAndLogEx(INFO, "acr.......... " _GREEN_("%s"), sprint_hex_inrow(data + 6, 3));
PrintAndLogEx(INFO, "user / gpb... " _GREEN_("%02x"), data[9]);
PrintAndLogEx(INFO, "key B........ " _GREEN_("%s"), sprint_hex_inrow(data + 10, 6));
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(INFO, " # | Access rights");
PrintAndLogEx(INFO, "----+-----------------------------------------------------------------");
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, " # | access rights");
PrintAndLogEx(INFO, "----+-----------------------------------------------------------------------");
if (mfValidateAccessConditions(&data[6]) == false) {
PrintAndLogEx(WARNING, _RED_("Invalid Access Conditions"));
}
int bln = mfFirstBlockOfSector(mfSectorNum(blockno));
int blinc = (mfNumBlocksPerSector(mfSectorNum(blockno)) > 4) ? 5 : 1;
for (int i = 0; i < 4; i++) {
PrintAndLogEx(INFO, "%3d%c| " _YELLOW_("%s"), bln, ((blinc > 1) && (i < 3) ? '+' : ' '), mfGetAccessConditionsDesc(i, &data[6]));
bln += blinc;
if (i == 3) {
uint8_t cond = mf_get_accesscondition(i, &data[6]);
if (cond == 0 || cond == 1 || cond == 2) {
PrintAndLogEx(INFO, "");
PrintAndLogEx(INFO, "OBS! Key B is readable, it SHALL NOT be able to authenticate on original MFC");
}
}
}
PrintAndLogEx(INFO, "----------------------------------------------------------------------");
PrintAndLogEx(INFO, "----------------------------------------------------------------------------");
PrintAndLogEx(NORMAL, "");
}
}

View file

@ -83,6 +83,7 @@ bool mfValidateAccessConditions(const uint8_t *data) {
return ((nd1 == (d1 ^ 0xF)) && (nd2 == (d2 ^ 0xF)) && (nd3 == (d3 ^ 0xF)));
}
bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data) {
uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn;
@ -98,7 +99,6 @@ bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data) {
return false;
}
const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data) {
uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn;
uint8_t d2 = NIBBLE_LOW(data[2]) >> blockn;
@ -118,9 +118,17 @@ const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data) {
}
};
static char StaticNone[] = "none";
return StaticNone;
static char none[] = "none";
return none;
}
uint8_t mf_get_accesscondition(uint8_t blockn, const uint8_t *data) {
uint8_t d1 = NIBBLE_HIGH(data[1]) >> blockn;
uint8_t d2 = NIBBLE_LOW(data[2]) >> blockn;
uint8_t d3 = NIBBLE_HIGH(data[2]) >> blockn;
return (d1 & 0x01) << 2 | (d2 & 0x01) << 1 | (d3 & 0x01);
}
/*
static int CalculateEncIVCommand(mf4Session_t *mf4session, uint8_t *iv, bool verbose) {
memcpy(&iv[0], &mf4session->TI, 4);

View file

@ -73,6 +73,7 @@ int MFPGetVersion(bool activateField, bool leaveSignalON, uint8_t *dataout, int
bool mfValidateAccessConditions(const uint8_t *data);
bool mfReadOnlyAccessConditions(uint8_t blockn, const uint8_t *data);
const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data);
uint8_t mf_get_accesscondition(uint8_t blockn, const uint8_t *data);
uint8_t mfNumBlocksPerSector(uint8_t sectorNo);
uint8_t mfFirstBlockOfSector(uint8_t sectorNo);