mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-22 14:23:50 -07:00
Merge pull request #1413 from merlokk/desf_select
Desfire: select MF via iso and select EF by ISO ID via ISO
This commit is contained in:
commit
5046eb22a6
1 changed files with 46 additions and 4 deletions
|
@ -2270,7 +2270,10 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
||||||
CLIParserContext *ctx;
|
CLIParserContext *ctx;
|
||||||
CLIParserInit(&ctx, "hf mfdes selectapp",
|
CLIParserInit(&ctx, "hf mfdes selectapp",
|
||||||
"Select application on the card. It selects app if it is a valid one or returns an error.",
|
"Select application on the card. It selects app if it is a valid one or returns an error.",
|
||||||
"hf mfdes selectapp --aid 123456 -> select application 123456");
|
"hf mfdes selectapp --aid 123456 -> select application 123456\n"
|
||||||
|
"hf mfdes selectapp --mf -> select master file (PICC level)\n"
|
||||||
|
"hf mfdes selectapp --dfname aid123456 -> select application aid123456 by DF name\n"
|
||||||
|
"hf mfdes selectapp --isoid 1111 -> select application 1111 by ISO ID");
|
||||||
|
|
||||||
void *argtable[] = {
|
void *argtable[] = {
|
||||||
arg_param_begin,
|
arg_param_begin,
|
||||||
|
@ -2286,6 +2289,8 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
||||||
arg_str0("s", "schann", "<d40/ev1/ev2>", "Secure channel: d40/ev1/ev2"),
|
arg_str0("s", "schann", "<d40/ev1/ev2>", "Secure channel: d40/ev1/ev2"),
|
||||||
arg_str0(NULL, "aid", "<app id hex>", "Application ID of application for some parameters (3 hex bytes, big endian)"),
|
arg_str0(NULL, "aid", "<app id hex>", "Application ID of application for some parameters (3 hex bytes, big endian)"),
|
||||||
arg_str0(NULL, "dfname", "<df name str>", "Application DF Name (string, max 16 chars). Selects application via ISO SELECT command"),
|
arg_str0(NULL, "dfname", "<df name str>", "Application DF Name (string, max 16 chars). Selects application via ISO SELECT command"),
|
||||||
|
arg_str0(NULL, "isoid", "<isoid hex>", "Application ISO ID (ISO DF ID) (2 hex bytes, big endian)"),
|
||||||
|
arg_lit0(NULL, "mf", "Select MF (master file) via ISO channel"),
|
||||||
arg_param_end
|
arg_param_end
|
||||||
};
|
};
|
||||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||||
|
@ -2306,12 +2311,49 @@ static int CmdHF14ADesSelectApp(const char *Cmd) {
|
||||||
int dfnamelen = 16;
|
int dfnamelen = 16;
|
||||||
CLIGetStrWithReturn(ctx, 12, dfname, &dfnamelen);
|
CLIGetStrWithReturn(ctx, 12, dfname, &dfnamelen);
|
||||||
|
|
||||||
|
uint32_t isoid = 0x0000;
|
||||||
|
res = arg_get_u32_hexstr_def_nlen(ctx, 13, 0x0000, &isoid, 2, true);
|
||||||
|
bool idsoidpresent = (res == 1);
|
||||||
|
if (res == 2) {
|
||||||
|
PrintAndLogEx(ERR, "ISO ID for EF or DF must have 2 bytes length");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool selectmf = arg_get_lit(ctx, 14);
|
||||||
|
|
||||||
SetAPDULogging(APDULogging);
|
SetAPDULogging(APDULogging);
|
||||||
CLIParserFree(ctx);
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
if (dctx.cmdSet == DCCISO || dfnamelen > 0) {
|
|
||||||
uint8_t resp[250] = {0};
|
uint8_t resp[250] = {0};
|
||||||
size_t resplen = 0;
|
size_t resplen = 0;
|
||||||
|
|
||||||
|
if (selectmf) {
|
||||||
|
res = DesfireISOSelect(&dctx, ISSMFDFEF, NULL, 0, resp, &resplen);
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
DropField();
|
||||||
|
PrintAndLogEx(FAILED, "ISO Select MF " _RED_("failed"));
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resplen > 0)
|
||||||
|
PrintAndLogEx(FAILED, "Application " _CYAN_("FCI template") " [%zu]%s", resplen, sprint_hex(resp, resplen));
|
||||||
|
|
||||||
|
PrintAndLogEx(SUCCESS, "PICC MF selected " _GREEN_("succesfully"));
|
||||||
|
} else if (idsoidpresent) {
|
||||||
|
uint8_t data[2] = {0};
|
||||||
|
Uint2byteToMemLe(data, isoid);
|
||||||
|
res = DesfireISOSelect(&dctx, ISSMFDFEF, data, 2, resp, &resplen);
|
||||||
|
if (res != PM3_SUCCESS) {
|
||||||
|
DropField();
|
||||||
|
PrintAndLogEx(FAILED, "ISO Select DF 0x%04x " _RED_("failed"), isoid);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (resplen > 0)
|
||||||
|
PrintAndLogEx(FAILED, "Application " _CYAN_("FCI template") " [%zu]%s", resplen, sprint_hex(resp, resplen));
|
||||||
|
|
||||||
|
PrintAndLogEx(SUCCESS, "PICC DF 0x%04x selected " _GREEN_("succesfully"), isoid);
|
||||||
|
} else if (dctx.cmdSet == DCCISO || dfnamelen > 0) {
|
||||||
if (dfnamelen > 0)
|
if (dfnamelen > 0)
|
||||||
res = DesfireISOSelectDF(&dctx, (char *)dfname, resp, &resplen);
|
res = DesfireISOSelectDF(&dctx, (char *)dfname, resp, &resplen);
|
||||||
else
|
else
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue