From c77d6455f53290c398092bb9ac96c32dfafbff65 Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Sun, 13 Sep 2026 09:18:08 +0200 Subject: [PATCH] hf mf: identify VIGIK family systems by their static key sets is_valid_vigik_card() only fired when the MAD advertised aid 0x4910. Plenty of VIGIK based deployments ship no MAD at all - a Hexact card has HEXACT as key A on every sector and nothing in sector 0 block 1 - so hf mf view and hf mf dump --ns said nothing whatsoever about them. These systems use the same keys on every card they issue, which makes them identifiable outright. Take the schemas out of armsrc/Standalone/hf_colin.c, where they sit commented out inside the standalone mode, and match a whole dump against them: Infineon / Hexact / COGELEC / Intratone key A HEXACT x16, 15 static key B Noralsy ALARON / BLARON Urmet Captiv 8829da9daf76 throughout VIGIK service badge MAD key, then 1KIGIV on sectors 1-4 Every slot a schema pins down has to match, VIGIK_KEY_ANY marks the ones it does not, so there are 31 exact keys to hit for Hexact and no room for a coincidence. A HID card carrying a MAD, and a card on default keys, both still match nothing. Co-Authored-By: Claude Opus 5 (1M context) --- CHANGELOG.md | 1 + client/src/parsers/parsevigik.c | 139 +++++++++++++++++++++++++++++++- client/src/parsers/parsevigik.h | 12 ++- 3 files changed, 150 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 44ad69a84..fcbc347ff 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ 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] +- Changed `hf mf view` / `hf mf dump --ns` - identify VIGIK family systems (@iceman1001) - Added `parsehid.c` - HID PACS decoding for MIFARE Classic dumps - Added `parsevigik.c` - VIGIK PACS decoding for MIFARE Classic dumps (@iceman1001) - Changed `hf mf view` - now decode a HID PACS credential (@iceman1001) diff --git a/client/src/parsers/parsevigik.c b/client/src/parsers/parsevigik.c index bebff60ec..a32900dd2 100644 --- a/client/src/parsers/parsevigik.c +++ b/client/src/parsers/parsevigik.c @@ -26,6 +26,8 @@ #include "util.h" #include "protocols.h" // MFBLOCK_SIZE #include "mifare/mad.h" +#include "mifare/mifare4.h" // mfFirstBlockOfSector +#include "mifare/mifaredefault.h" // MIFARE_KEY_SIZE #include "mbedtls/bignum.h" static const vigik_pk_t vigik_rsa_pk[] = { @@ -334,11 +336,133 @@ int vigik_annotate(mfc_vigik_t *d) { } +// Key layouts of the VIGIK family building access systems. Every one of these +// ships the same keys on every card, so matching the whole set identifies the +// system outright - no guessing from the payload. Sourced from the schemas in +// armsrc/Standalone/hf_colin.c, with the Hexact sector 15 key B measured on a +// card here; hf_colin.c leaves that slot empty. +typedef struct { + const char *name; + uint64_t key_a[16]; + uint64_t key_b[16]; +} vigik_schema_t; + +static const vigik_schema_t vigik_schemas[] = { + { + "Infineon / Hexact / COGELEC / Intratone", + { + 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, + 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, + 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, + 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL, 0x484558414354ULL + }, + { + 0xa22ae129c013ULL, 0x49fae4e3849fULL, 0x38fcf33072e0ULL, 0x8ad5517b4b18ULL, + 0x509359f131b1ULL, 0x6c78928e1317ULL, 0xaa0720018738ULL, 0xa6cac2886412ULL, + 0x62d0c424ed8eULL, 0xe64a986a5d94ULL, 0x8fa1d601d0a2ULL, 0x89347350bd36ULL, + 0x66d2b7dc39efULL, 0x6bc1e1ae547dULL, 0x22729a9bd40fULL, 0x484558414354ULL + } + }, + { + "Noralsy", + { + 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL, + 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL, + 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL, + 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL, 0x414c41524f4eULL + }, + { + 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL, + 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL, + 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL, + 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL, 0x424c41524f4eULL + } + }, + { + "Urmet Captiv", + { + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL + }, + { + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, + 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL, 0x8829da9daf76ULL + } + }, + { + "VIGIK service badge", + { + 0xa0a1a2a3a4a5ULL, 0x314b49474956ULL, 0x314b49474956ULL, 0x314b49474956ULL, + 0x314b49474956ULL, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, + VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, + VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY + }, + { + 0x010203040506ULL, 0x010203040506ULL, 0x010203040506ULL, 0x010203040506ULL, + 0x010203040506ULL, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, + VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, + VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY, VIGIK_KEY_ANY + } + }, +}; + +// Key A or key B out of a sector trailer, VIGIK_KEY_ANY when the dump is short +static uint64_t vigik_sector_key(const uint8_t *dump, size_t dumplen, uint8_t sector, bool keyb) { + size_t trailer = (mfFirstBlockOfSector(sector) + mfNumBlocksPerSector(sector) - 1) * MFBLOCK_SIZE; + if (trailer + MFBLOCK_SIZE > dumplen) { + return VIGIK_KEY_ANY; + } + const uint8_t *p = dump + trailer + (keyb ? 10 : 0); + uint64_t key = 0; + for (uint8_t i = 0; i < MIFARE_KEY_SIZE; i++) { + key = (key << 8) | p[i]; + } + return key; +} + +const char *vigik_detect_schema(const uint8_t *dump, size_t dumplen) { + + if (dump == NULL) { + return NULL; + } + + for (size_t i = 0; i < ARRAYLEN(vigik_schemas); i++) { + + const vigik_schema_t *schema = &vigik_schemas[i]; + bool match = true; + + for (uint8_t s = 0; s < 16 && match; s++) { + + if (schema->key_a[s] != VIGIK_KEY_ANY && + schema->key_a[s] != vigik_sector_key(dump, dumplen, s, false)) { + match = false; + } + + if (schema->key_b[s] != VIGIK_KEY_ANY && + schema->key_b[s] != vigik_sector_key(dump, dumplen, s, true)) { + match = false; + } + } + + if (match) { + return schema->name; + } + } + return NULL; +} + bool is_valid_vigik_card(const uint8_t *dump, size_t dumplen) { if (dump == NULL || dumplen < sizeof(mad1_sector_t)) { return false; } - return (DetectHID((const mad1_sector_t *)dump, VIGIK_MAD_AID) > -1); + if (DetectHID((const mad1_sector_t *)dump, VIGIK_MAD_AID) > -1) { + return true; + } + return (vigik_detect_schema(dump, dumplen) != NULL); } int vigik_parser_parse(const uint8_t *dump, size_t dumplen) { @@ -352,6 +476,19 @@ int vigik_parser_parse(const uint8_t *dump, size_t dumplen) { PrintAndLogEx(INFO, ""); PrintAndLogEx(INFO, _CYAN_("VIGIK PACS detected")); + const char *schema = vigik_detect_schema(dump, dumplen); + if (schema != NULL) { + PrintAndLogEx(SUCCESS, "System............. " _YELLOW_("%s"), schema); + } + + // Only the deployments that publish a MAD can be taken apart any further. + // The others keep the same structure somewhere else on the card, and where + // that is has not been worked out, so say so instead of printing nonsense. + if (DetectHID(s0, VIGIK_MAD_AID) < 0) { + PrintAndLogEx(INFO, "No MAD on this card, structure " _YELLOW_("not decoded")); + return PM3_SUCCESS; + } + mad_entry_list_t mad_list = {0}; int res = MADDecode(s0, NULL, &mad_list, false, true); if (res != PM3_SUCCESS) { diff --git a/client/src/parsers/parsevigik.h b/client/src/parsers/parsevigik.h index c6d8b38ab..b90208ef0 100644 --- a/client/src/parsers/parsevigik.h +++ b/client/src/parsers/parsevigik.h @@ -26,7 +26,17 @@ #define VIGIK_MAD_AID 0x4910 #define VIGIK_MAD_AID_ALT 0x4916 -// True when the MAD of this dump advertises the VIGIK application +// A key slot the schema does not pin down. Not a valid 48 bit key, so it can +// never collide with one read off a card. +#define VIGIK_KEY_ANY 0xFFFFFFFFFFFFFFFFULL + +// Name of the VIGIK family system whose key layout this dump matches, NULL when +// none does. The key sets below are static across every card of a given system, +// so a full match identifies it outright. +const char *vigik_detect_schema(const uint8_t *dump, size_t dumplen); + +// True when this dump carries the VIGIK application in its MAD, or its keys +// match a known VIGIK family schema bool is_valid_vigik_card(const uint8_t *dump, size_t dumplen); // Collect the VIGIK sectors out of a whole card dump and print them