Add 'hf mfdes getversion' command
This commit is contained in:
1 parent
1a4fdbeffb
commit
73d0388141
8 files changed
+123
No files matched your search
@@ -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]
|
||||
- Added `hf mfdes getversion` command (@kormax)
|
||||
- Changed `doc/magic_cards_notes.md` - updated the ID82xx / Hitag µ clone section with current Proxmark3 support, chip variations, default passwords and detection notes (@mishamyte)
|
||||
- Added two Mifare Classic keys into extensive dictionary which are hardcoded into Mifare Plus SE (@team-orangeBlue)
|
||||
- Fixed `hf mfp rdbl` when using "read multiple" blocks by decrypting the entire buffer instead of one block only (@team-orangeBlue)
|
||||
|
||||
@@ -1133,6 +1133,97 @@ static int CmdHF14ADesInfo(const char *Cmd) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static int CmdHF14ADesGetVersion(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mfdes getversion",
|
||||
"Request and print DESFire GetVersion data. Optionally select an ISO DF name first.",
|
||||
"hf mfdes getversion -> request and print card version/type information\n"
|
||||
"hf mfdes getversion --dfname D2760000850100 -> select DF by name, then request and print version/type information");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("a", "apdu", "Show APDU requests and responses"),
|
||||
arg_lit0("v", "verbose", "Verbose output"),
|
||||
arg_str0(NULL, "dfname", "<hex>", "Application ISO DF Name (1-16 hex bytes, big endian)"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
bool APDULogging = arg_get_lit(ctx, 1);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
|
||||
uint8_t dfname[64] = {0};
|
||||
int dfnamelen = 0;
|
||||
if (CLIParamHexToBuf(arg_get_str(ctx, 3), dfname, sizeof(dfname), &dfnamelen)) {
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
if (dfnamelen > 16) {
|
||||
PrintAndLogEx(ERR, "DF name must be 1-16 bytes, got %d", dfnamelen);
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
SetAPDULogging(APDULogging);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
DesfireContext_t dctx = {0};
|
||||
dctx.commMode = DCMPlain;
|
||||
dctx.cmdSet = DCCNativeISO;
|
||||
|
||||
DropField();
|
||||
|
||||
int res = PM3_SUCCESS;
|
||||
if (dfnamelen > 0) {
|
||||
uint8_t select_resp[250] = {0};
|
||||
size_t select_resplen = 0;
|
||||
res = DesfireISOSelect(&dctx, ISSDFName, dfname, (uint8_t)dfnamelen, select_resp, &select_resplen);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
PrintAndLogEx(ERR, "Select DF name %s " _RED_("failed") ". Result: %d", sprint_hex_inrow(dfname, dfnamelen), res);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (verbose) {
|
||||
PrintAndLogEx(SUCCESS, "DF name %s selected " _GREEN_("ok"), sprint_hex_inrow(dfname, dfnamelen));
|
||||
}
|
||||
} else {
|
||||
res = DesfireAnticollision(verbose);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
mfdes_info_res_t info = {0};
|
||||
uint8_t version[sizeof(info.versionHW) + sizeof(info.versionSW) + sizeof(info.details)] = {0};
|
||||
size_t version_len = 0;
|
||||
res = DesfireGetVersion(&dctx, version, &version_len);
|
||||
if (res != PM3_SUCCESS) {
|
||||
DropField();
|
||||
PrintAndLogEx(ERR, "Desfire GetVersion command " _RED_("error") ". Result: %d", res);
|
||||
return res;
|
||||
}
|
||||
|
||||
if (version_len != sizeof(version)) {
|
||||
DropField();
|
||||
PrintAndLogEx(ERR, "Desfire GetVersion returned wrong length: %zu bytes, expected %zu", version_len, sizeof(version));
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
info.isOK = 1;
|
||||
memcpy(info.versionHW, version, sizeof(info.versionHW));
|
||||
memcpy(info.versionSW, version + sizeof(info.versionHW), sizeof(info.versionSW));
|
||||
memcpy(info.details, version + sizeof(info.versionHW) + sizeof(info.versionSW), sizeof(info.details));
|
||||
memcpy(info.uid, info.details, sizeof(info.uid));
|
||||
info.uidlen = sizeof(info.uid);
|
||||
|
||||
DesfirePrintVersionInfo(&info, NULL);
|
||||
|
||||
DropField();
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
static void DesFill2bPattern(
|
||||
uint8_t deskeyList[MAX_KEYS_LIST_LEN][8], uint32_t *deskeyListLen,
|
||||
uint8_t aeskeyList[MAX_KEYS_LIST_LEN][16], uint32_t *aeskeyListLen,
|
||||
@@ -9608,6 +9699,7 @@ static command_t CommandTable[] = {
|
||||
{"detect", CmdHF14aDesDetect, IfPm3Iso14443a, "Detect key type and tries to find one from the list"},
|
||||
{"formatpicc", CmdHF14ADesFormatPICC, IfPm3Iso14443a, "Format PICC"},
|
||||
{"freemem", CmdHF14ADesGetFreeMem, IfPm3Iso14443a, "Get free memory size"},
|
||||
{"getversion", CmdHF14ADesGetVersion, IfPm3Iso14443a, "Get version/type information"},
|
||||
{"getuid", CmdHF14ADesGetUID, IfPm3Iso14443a, "Get uid from card"},
|
||||
{"pc", CmdHF14ADesPC, IfPm3Iso14443a, "Run proximity check"},
|
||||
{"info", CmdHF14ADesInfo, IfPm3Iso14443a, "Tag information"},
|
||||
|
||||
@@ -2192,6 +2192,10 @@ int DesfireFormatPICC(DesfireContext_t *dctx) {
|
||||
return DesfireCommandNoData(dctx, MFDES_FORMAT_PICC);
|
||||
}
|
||||
|
||||
int DesfireGetVersion(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen) {
|
||||
return DesfireCommandRxData(dctx, MFDES_GET_VERSION, resp, resplen, 28);
|
||||
}
|
||||
|
||||
int DesfireGetFreeMem(DesfireContext_t *dctx, uint32_t *freemem) {
|
||||
*freemem = 0;
|
||||
|
||||
|
||||
@@ -199,6 +199,7 @@ void DesfireCheckAuthCommands(DesfireISOSelectWay way, uint32_t appID, char *dfn
|
||||
void DesfireCheckAuthCommandsPrint(AuthCommandsChk_t *authCmdCheck);
|
||||
|
||||
int DesfireFormatPICC(DesfireContext_t *dctx);
|
||||
int DesfireGetVersion(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetFreeMem(DesfireContext_t *dctx, uint32_t *freemem);
|
||||
int DesfireGetUID(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||
int DesfireGetAIDList(DesfireContext_t *dctx, uint8_t *resp, size_t *resplen);
|
||||
|
||||
@@ -495,6 +495,7 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 0, "hf mfdes detect" },
|
||||
{ 0, "hf mfdes formatpicc" },
|
||||
{ 0, "hf mfdes freemem" },
|
||||
{ 0, "hf mfdes getversion" },
|
||||
{ 0, "hf mfdes getuid" },
|
||||
{ 0, "hf mfdes pc" },
|
||||
{ 0, "hf mfdes info" },
|
||||
|
||||
@@ -7053,6 +7053,22 @@
|
||||
],
|
||||
"usage": "hf mfdes getuid [-hav] [-n <dec>] [-t <DES|2TDEA|3TDEA|AES>] [-k <hex>] [--kdf <none|AN10922|gallagher>] [-i <hex>] [-m <plain|mac|encrypt>] [-c <native|niso|iso>] [--schann <d40|ev1|ev2|lrp>] [--aid <hex>] [--isoid <hex>] [--dfname <hex>]"
|
||||
},
|
||||
"hf mfdes getversion": {
|
||||
"command": "hf mfdes getversion",
|
||||
"description": "Request and print DESFire GetVersion data. Optionally select an ISO DF name first.",
|
||||
"notes": [
|
||||
"hf mfdes getversion -> request and print card version/type information",
|
||||
"hf mfdes getversion --dfname D2760000850100 -> select DF by name, then request and print version/type information"
|
||||
],
|
||||
"offline": false,
|
||||
"options": [
|
||||
"-h, --help This help",
|
||||
"-a, --apdu Show APDU requests and responses",
|
||||
"-v, --verbose Verbose output",
|
||||
"--dfname <hex> Application ISO DF Name (1-16 hex bytes, big endian)"
|
||||
],
|
||||
"usage": "hf mfdes getversion [-hav] [--dfname <hex>]"
|
||||
},
|
||||
"hf mfdes help": {
|
||||
"command": "hf mfdes help",
|
||||
"description": "help This help list List DESFire (ISO 14443A) history makemfclicense Generate a Mifare Classic license for DESFire EV3C test Regression crypto tests --------------------------------------------------------------------------------------- hf mfdes list available offline: yes Alias of `trace list -t des -c` with selected protocol data to annotate trace buffer You can load a trace from file (see `trace load -h`) or it be downloaded from device by default It accepts all other arguments of `trace list`. Note that some might not be relevant for this specific protocol",
|
||||
|
||||
@@ -723,6 +723,7 @@ Check column "offline" for their availability.
|
||||
|`hf mfdes detect `|N |`Detect key type and tries to find one from the list`
|
||||
|`hf mfdes formatpicc `|N |`Format PICC`
|
||||
|`hf mfdes freemem `|N |`Get free memory size`
|
||||
|`hf mfdes getversion `|N |`Get version/type information`
|
||||
|`hf mfdes getuid `|N |`Get uid from card`
|
||||
|`hf mfdes pc `|N |`Run proximity check`
|
||||
|`hf mfdes info `|N |`Tag information`
|
||||
|
||||
@@ -177,6 +177,13 @@ The card can return UID in encrypted communication mode. Needs to authenticate w
|
||||
|
||||
`hf mfdes getuid -s ev2 -t aes -k 11223344556677889900112233445566` - via ev2 secure channel with specified aes key
|
||||
|
||||
### How to get version/type information
|
||||
^[Top](#top)
|
||||
|
||||
`hf mfdes getversion` - request and print card version/type information
|
||||
|
||||
`hf mfdes getversion --dfname D2760000850100` - select an application by ISO DF name before requesting version/type information
|
||||
|
||||
### How to get/set default communication channel settings
|
||||
^[Top](#top)
|
||||
|
||||
|
||||
Reference in new issue
Block a user