Skip to content

Commit

Permalink
fixed the magic detection , and improved the hints reporting MF Class…
Browse files Browse the repository at this point in the history
…ic tags
  • Loading branch information
iceman1001 committed Feb 21, 2024
1 parent 26fda45 commit 490111e
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 31 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ All notable changes to this project will be documented in this file.
This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log...

## [unreleased][unreleased]
- Fixed `hf 14a info` - magic detection works again and better hint detection (@iceman1001)
- Added `hf 14b restore` - new command to restore dump files to a SR512/4k card (@Sonic803)
- Changed led show / leds detection for PM3 Easy devices (@francesco-scar)

## [DEFCON is Cancelled.4.18218][2024-02-18]
- Changed `hf fudan dump --ns` - now supports nosave flag (@iceman1001)
Expand Down
56 changes: 26 additions & 30 deletions client/src/cmdhf14a.c
Original file line number Diff line number Diff line change
Expand Up @@ -2030,7 +2030,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
isSEOS = ((nxptype & HID_SEOS) == HID_SEOS);

// generic catch, we assume MIFARE Classic for all unknown ISO14443a tags
isMifareClassic = ((nxptype & MTOTHER) == MTOTHER);
isMifareClassic |= ((nxptype & MTOTHER) == MTOTHER);

} else {

Expand Down Expand Up @@ -2272,10 +2272,11 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {

} else if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x00\x35\xC7", 7) == 0) {

if ((card.atqa[0] & 0x02) == 0x02)
if ((card.atqa[0] & 0x02) == 0x02) {
snprintf(tip + strlen(tip), sizeof(tip) - strlen(tip), _GREEN_("%s"), "MIFARE Plus S 2K (SL3)");
else if ((card.atqa[0] & 0x04) == 0x04)
} else if ((card.atqa[0] & 0x04) == 0x04) {
snprintf(tip + strlen(tip), sizeof(tip) - strlen(tip), _GREEN_("%s"), "MIFARE Plus S 4K (SL3)");
}

} else if (memcmp(card.ats + pos, "\xC1\x05\x21\x30\x00\xF6\xD1", 7) == 0) {
snprintf(tip + strlen(tip), sizeof(tip) - strlen(tip), _GREEN_("%s"), "MIFARE Plus SE 1K (17pF)");
Expand All @@ -2288,7 +2289,6 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {

if ((card.sak & 0x20) == 0x20) { // and no GetVersion()..


if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x01\xBC\xD6", 7) == 0) {
snprintf(tip + strlen(tip), sizeof(tip) - strlen(tip), _GREEN_("%s"), "MIFARE Plus X 2K (SL1)");
} else if (memcmp(card.ats + pos, "\xC1\x05\x2F\x2F\x00\x35\xC7", 7) == 0) {
Expand Down Expand Up @@ -2480,15 +2480,18 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
PrintAndLogEx(INFO, "--> SAK incorrectly claims that card supports RATS <--");
}
}
if (select_status == 1)

if (select_status == 1) {
select_status = 2;
}
}

if (setDeviceDebugLevel(verbose ? DBG_INFO : DBG_NONE, false) != PM3_SUCCESS) {
return PM3_EFAILED;
}

uint16_t isMagic = 0;

if (isMifareClassic) {
isMagic = detect_mf_magic(true, MF_KEY_B, 0xFFFFFFFFFFFF);
}
Expand Down Expand Up @@ -2529,7 +2532,6 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
if (res == PM3_SUCCESS) {
mfc_ev1_print_signature(card.uid, card.uidlen, signature, sizeof(signature));
}
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mf`") " commands");
}

if (setDeviceDebugLevel(dbg_curr, false) != PM3_SUCCESS) {
Expand Down Expand Up @@ -2580,34 +2582,28 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
PrintAndLogEx(HINT, "Hint: try `" _YELLOW_("hf ntag424 info") "`");
}

if (isMifareClassic &&
(((isMagic & MAGIC_FLAG_GEN_1A) == MAGIC_FLAG_GEN_1A) || ((isMagic & MAGIC_FLAG_GEN_1B) == MAGIC_FLAG_GEN_1B))
) {
PrintAndLogEx(HINT, "Hint: use `" _YELLOW_("hf mf c*") "` commands when interacting");
}
if (isMifareClassic) {
if (((isMagic & MAGIC_FLAG_GEN_1A) == MAGIC_FLAG_GEN_1A) || ((isMagic & MAGIC_FLAG_GEN_1B) == MAGIC_FLAG_GEN_1B)) {
PrintAndLogEx(HINT, "Hint: use `" _YELLOW_("hf mf c*") "` commands when interacting");
}

if (isMifareClassic &&
((isMagic & MAGIC_FLAG_GEN_2) == MAGIC_FLAG_GEN_2)
) {
PrintAndLogEx(HINT, "Hint: Use normal `" _YELLOW_("hf mf") "` commands when interacting");
}
if ((isMagic & MAGIC_FLAG_GEN_3) == MAGIC_FLAG_GEN_3) {
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("hf mf gen3*") "` commands when interacting");
}

if (isMifareClassic &&
((isMagic & MAGIC_FLAG_GEN_3) == MAGIC_FLAG_GEN_3)
) {
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("hf mf gen3*") "` commands when interacting");
}
if ((isMagic & MAGIC_FLAG_GEN_4GTU) == MAGIC_FLAG_GEN_4GTU) {
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("hf mf g*") "` commands when interacting");
}

if (isMifareClassic &&
((isMagic & MAGIC_FLAG_GEN_4GTU) == MAGIC_FLAG_GEN_4GTU)
) {
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("hf mf g*") "` commands when interacting");
}
if ((isMagic & MAGIC_FLAG_GDM_AUTH) == MAGIC_FLAG_GDM_AUTH) {
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("hf mf gdm*") "` commands when interacting");
}

if (isMifareClassic &&
((isMagic & MAGIC_FLAG_GDM_AUTH) == MAGIC_FLAG_GDM_AUTH)
) {
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("hf mf gdm*") "` commands when interacting");
if ((isMagic & MAGIC_FLAG_GEN_2) == MAGIC_FLAG_GEN_2) {
PrintAndLogEx(HINT, "Hint: Use `" _YELLOW_("hf mf") "` commands when interacting");
} else {
PrintAndLogEx(HINT, "Hint: try " _YELLOW_("`hf mf`") " commands");
}
}

PrintAndLogEx(NORMAL, "");
Expand Down
2 changes: 1 addition & 1 deletion client/src/mifare/mifarehost.c
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,7 @@ uint16_t detect_mf_magic(bool is_mfc, uint8_t key_type, uint64_t key) {

uint16_t isMagic = MAGIC_FLAG_NONE;
if ((resp.status == PM3_SUCCESS) && resp.length == sizeof(uint16_t)) {
isMagic = resp.data.asDwords[0] & 0xFFFF;
isMagic = MemLeToUint2byte(resp.data.asBytes);
}

if ((isMagic & MAGIC_FLAG_GEN_1A) == MAGIC_FLAG_GEN_1A) {
Expand Down

0 comments on commit 490111e

Please sign in to comment.