mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-21 22:03:42 -07:00
hf mf ekeyprn, eclr, nack - now uses cliparser
This commit is contained in:
parent
49b830266c
commit
e1b856b5fc
1 changed files with 79 additions and 71 deletions
|
@ -188,13 +188,6 @@ static int usage_hf14_decryptbytes(void) {
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int usage_hf14_eclr(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF \n");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf mf eclr");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf eclr"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_hf14_eset(void) {
|
static int usage_hf14_eset(void) {
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf mf eset <block number> <block data (32 hex symbols)>");
|
PrintAndLogEx(NORMAL, "Usage: hf mf eset <block number> <block data (32 hex symbols)>");
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
PrintAndLogEx(NORMAL, "Examples:");
|
||||||
|
@ -243,19 +236,7 @@ static int usage_hf14_ecfill(void) {
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf ecfill A 4"));
|
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf ecfill A 4"));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_hf14_ekeyprn(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Download and print the keys from emulator memory");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf mf ekeyprn [card memory] [d]");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h this help");
|
|
||||||
PrintAndLogEx(NORMAL, " card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
|
|
||||||
PrintAndLogEx(NORMAL, " d write keys to binary file `hf-mf-<UID>-key.bin`");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf ekeyprn 1"));
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf ekeyprn d"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int usage_hf14_csetuid(void) {
|
static int usage_hf14_csetuid(void) {
|
||||||
PrintAndLogEx(NORMAL, "Set UID, ATQA, and SAK for magic Chinese card. Only works with magic cards");
|
PrintAndLogEx(NORMAL, "Set UID, ATQA, and SAK for magic Chinese card. Only works with magic cards");
|
||||||
|
@ -333,17 +314,7 @@ static int usage_hf14_cview(void) {
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf cview 1"));
|
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf cview 1"));
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
}
|
}
|
||||||
static int usage_hf14_nack(void) {
|
|
||||||
PrintAndLogEx(NORMAL, "Test a MIFARE Classic based card for the NACK bug.");
|
|
||||||
PrintAndLogEx(NORMAL, "");
|
|
||||||
PrintAndLogEx(NORMAL, "Usage: hf mf nack [h] [v]");
|
|
||||||
PrintAndLogEx(NORMAL, "Options:");
|
|
||||||
PrintAndLogEx(NORMAL, " h this help");
|
|
||||||
PrintAndLogEx(NORMAL, " v verbose");
|
|
||||||
PrintAndLogEx(NORMAL, "Examples:");
|
|
||||||
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf nack"));
|
|
||||||
return PM3_SUCCESS;
|
|
||||||
}
|
|
||||||
static int usage_hf14_gen3uid(void) {
|
static int usage_hf14_gen3uid(void) {
|
||||||
PrintAndLogEx(NORMAL, "Set UID for magic GEN 3 card without manufacturer block changing");
|
PrintAndLogEx(NORMAL, "Set UID for magic GEN 3 card without manufacturer block changing");
|
||||||
PrintAndLogEx(NORMAL, "");
|
PrintAndLogEx(NORMAL, "");
|
||||||
|
@ -868,7 +839,7 @@ static int CmdHF14AMfDump(const char *Cmd) {
|
||||||
arg_str0("f", "file", "<fn>", "filename of dump"),
|
arg_str0("f", "file", "<fn>", "filename of dump"),
|
||||||
arg_str0("k", "keys", "<fn>", "filename of keys"),
|
arg_str0("k", "keys", "<fn>", "filename of keys"),
|
||||||
arg_lit0(NULL, "mini", "MIFARE Classic Mini / S20"),
|
arg_lit0(NULL, "mini", "MIFARE Classic Mini / S20"),
|
||||||
arg_lit0(NULL, "1k", "MIFARE Classic 1k / S50 (default)"),
|
arg_lit0(NULL, "1k", "MIFARE Classic 1k / S50 (def)"),
|
||||||
arg_lit0(NULL, "2k", "MIFARE Classic/Plus 2k"),
|
arg_lit0(NULL, "2k", "MIFARE Classic/Plus 2k"),
|
||||||
arg_lit0(NULL, "4k", "MIFARE Classic 4k / S70"),
|
arg_lit0(NULL, "4k", "MIFARE Classic 4k / S70"),
|
||||||
arg_param_end
|
arg_param_end
|
||||||
|
@ -909,7 +880,7 @@ static int CmdHF14AMfDump(const char *Cmd) {
|
||||||
m1 = true;
|
m1 = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t numSectors = 1;
|
uint8_t numSectors = MIFARE_1K_MAXSECTOR;
|
||||||
|
|
||||||
if (m0) {
|
if (m0) {
|
||||||
numSectors = MIFARE_MINI_MAXSECTOR;
|
numSectors = MIFARE_MINI_MAXSECTOR;
|
||||||
|
@ -3727,6 +3698,7 @@ void printKeyTable(uint8_t sectorscnt, sector_t *e_sector) {
|
||||||
void printKeyTableEx(uint8_t sectorscnt, sector_t *e_sector, uint8_t start_sector) {
|
void printKeyTableEx(uint8_t sectorscnt, sector_t *e_sector, uint8_t start_sector) {
|
||||||
char strA[12 + 1] = {0};
|
char strA[12 + 1] = {0};
|
||||||
char strB[12 + 1] = {0};
|
char strB[12 + 1] = {0};
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
PrintAndLogEx(SUCCESS, "|-----|----------------|---|----------------|---|");
|
PrintAndLogEx(SUCCESS, "|-----|----------------|---|----------------|---|");
|
||||||
PrintAndLogEx(SUCCESS, "| Sec | key A |res| key B |res|");
|
PrintAndLogEx(SUCCESS, "| Sec | key A |res| key B |res|");
|
||||||
PrintAndLogEx(SUCCESS, "|-----|----------------|---|----------------|---|");
|
PrintAndLogEx(SUCCESS, "|-----|----------------|---|----------------|---|");
|
||||||
|
@ -3778,6 +3750,7 @@ void printKeyTableEx(uint8_t sectorscnt, sector_t *e_sector, uint8_t start_secto
|
||||||
} else {
|
} else {
|
||||||
PrintAndLogEx(SUCCESS, "( " _YELLOW_("0") ":Failed / " _YELLOW_("1") ":Success)");
|
PrintAndLogEx(SUCCESS, "( " _YELLOW_("0") ":Failed / " _YELLOW_("1") ":Success)");
|
||||||
}
|
}
|
||||||
|
PrintAndLogEx(NORMAL, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3872,9 +3845,17 @@ static int CmdHF14AMfEGetSc(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int CmdHF14AMfEClear(const char *Cmd) {
|
static int CmdHF14AMfEClear(const char *Cmd) {
|
||||||
char c = tolower(param_getchar(Cmd, 0));
|
CLIParserContext *ctx;
|
||||||
if (c == 'h') return usage_hf14_eclr();
|
CLIParserInit(&ctx, "hf mf eclr",
|
||||||
|
"It set card emulator memory to empty data blocks and key A/B FFFFFFFFFFFF",
|
||||||
|
"hf mf eclr"
|
||||||
|
);
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
CLIParserFree(ctx);
|
||||||
clearCommandBuffer();
|
clearCommandBuffer();
|
||||||
SendCommandNG(CMD_HF_MIFARE_EML_MEMCLR, NULL, 0);
|
SendCommandNG(CMD_HF_MIFARE_EML_MEMCLR, NULL, 0);
|
||||||
return PM3_SUCCESS;
|
return PM3_SUCCESS;
|
||||||
|
@ -4163,37 +4144,52 @@ static int CmdHF14AMfECFill(const char *Cmd) {
|
||||||
|
|
||||||
static int CmdHF14AMfEKeyPrn(const char *Cmd) {
|
static int CmdHF14AMfEKeyPrn(const char *Cmd) {
|
||||||
|
|
||||||
uint8_t sectors_cnt = MIFARE_1K_MAXSECTOR;
|
CLIParserContext *ctx;
|
||||||
uint8_t data[16];
|
CLIParserInit(&ctx, "hf mf ekeyprn",
|
||||||
uint8_t uid[4];
|
"Download and print the keys from emulator memory",
|
||||||
uint8_t cmdp = 0;
|
"hf mf ekeyprn --1k --> print MFC 1K keyset\n"
|
||||||
bool errors = false, createDumpFile = false;
|
"hf mf ekeyprn -w --> write keys to binary file"
|
||||||
|
);
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_lit0("w", "write", "write keys to binary file `hf-mf-<UID>-key.bin`"),
|
||||||
|
arg_lit0(NULL, "mini", "MIFARE Classic Mini / S20"),
|
||||||
|
arg_lit0(NULL, "1k", "MIFARE Classic 1k / S50 (def)"),
|
||||||
|
arg_lit0(NULL, "2k", "MIFARE Classic/Plus 2k"),
|
||||||
|
arg_lit0(NULL, "4k", "MIFARE Classic 4k / S70"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
|
||||||
|
bool create_dumpfile = arg_get_lit(ctx, 1);
|
||||||
|
bool m0 = arg_get_lit(ctx, 2);
|
||||||
|
bool m1 = arg_get_lit(ctx, 3);
|
||||||
|
bool m2 = arg_get_lit(ctx, 4);
|
||||||
|
bool m4 = arg_get_lit(ctx, 5);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
while (param_getchar(Cmd, cmdp) != 0x00 && !errors) {
|
|
||||||
char ctmp = tolower(param_getchar(Cmd, cmdp));
|
|
||||||
switch (ctmp) {
|
|
||||||
case 'd':
|
|
||||||
createDumpFile = true;
|
|
||||||
cmdp++;
|
|
||||||
break;
|
|
||||||
case 'h':
|
|
||||||
return usage_hf14_ekeyprn();
|
|
||||||
case '0':
|
|
||||||
case '1':
|
|
||||||
case '2':
|
|
||||||
case '4':
|
|
||||||
sectors_cnt = NumOfSectors(ctmp);
|
|
||||||
if (sectors_cnt == 0) return usage_hf14_ekeyprn();
|
|
||||||
cmdp++;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
PrintAndLogEx(WARNING, "Unknown parameter '%c'", param_getchar(Cmd, cmdp));
|
|
||||||
errors = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// validations
|
// validations
|
||||||
if (errors) return usage_hf14_ekeyprn();
|
if ((m0 + m1 + m2 + m4) > 1) {
|
||||||
|
PrintAndLogEx(WARNING, "Only specify one MIFARE Type");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
} else if ((m0 + m1 + m2 + m4) == 0) {
|
||||||
|
m1 = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t sectors_cnt = MIFARE_1K_MAXSECTOR;
|
||||||
|
|
||||||
|
if (m0) {
|
||||||
|
sectors_cnt = MIFARE_MINI_MAXSECTOR;
|
||||||
|
} else if (m1) {
|
||||||
|
sectors_cnt = MIFARE_1K_MAXSECTOR;
|
||||||
|
} else if (m2) {
|
||||||
|
sectors_cnt = MIFARE_2K_MAXSECTOR;
|
||||||
|
} else if (m4) {
|
||||||
|
sectors_cnt = MIFARE_4K_MAXSECTOR;
|
||||||
|
} else {
|
||||||
|
PrintAndLogEx(WARNING, "Please specify a MIFARE Type");
|
||||||
|
return PM3_EINVARG;
|
||||||
|
}
|
||||||
|
|
||||||
sector_t *e_sector = NULL;
|
sector_t *e_sector = NULL;
|
||||||
|
|
||||||
|
@ -4205,12 +4201,15 @@ static int CmdHF14AMfEKeyPrn(const char *Cmd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// read UID from EMUL
|
// read UID from EMUL
|
||||||
|
uint8_t data[16];
|
||||||
if (mfEmlGetMem(data, 0, 1) != PM3_SUCCESS) {
|
if (mfEmlGetMem(data, 0, 1) != PM3_SUCCESS) {
|
||||||
PrintAndLogEx(WARNING, "error get block %d", 0);
|
PrintAndLogEx(WARNING, "error get block 0");
|
||||||
free(e_sector);
|
free(e_sector);
|
||||||
return PM3_ESOFT;
|
return PM3_ESOFT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// assuming 4byte UID.
|
||||||
|
uint8_t uid[4];
|
||||||
memcpy(uid, data, sizeof(uid));
|
memcpy(uid, data, sizeof(uid));
|
||||||
|
|
||||||
// download keys from EMUL
|
// download keys from EMUL
|
||||||
|
@ -4232,7 +4231,7 @@ static int CmdHF14AMfEKeyPrn(const char *Cmd) {
|
||||||
printKeyTable(sectors_cnt, e_sector);
|
printKeyTable(sectors_cnt, e_sector);
|
||||||
|
|
||||||
// dump the keys
|
// dump the keys
|
||||||
if (createDumpFile) {
|
if (create_dumpfile) {
|
||||||
|
|
||||||
char filename[FILE_PATH_SIZE] = {0};
|
char filename[FILE_PATH_SIZE] = {0};
|
||||||
char *fptr = filename;
|
char *fptr = filename;
|
||||||
|
@ -4925,10 +4924,19 @@ static int CmdHf14AMfSetMod(const char *Cmd) {
|
||||||
|
|
||||||
// MIFARE NACK bug detection
|
// MIFARE NACK bug detection
|
||||||
static int CmdHf14AMfNack(const char *Cmd) {
|
static int CmdHf14AMfNack(const char *Cmd) {
|
||||||
|
CLIParserContext *ctx;
|
||||||
char ctmp = tolower(param_getchar(Cmd, 0));
|
CLIParserInit(&ctx, "hf mf nack",
|
||||||
if (ctmp == 'h') return usage_hf14_nack();
|
"Test a MIFARE Classic based card for the NACK bug",
|
||||||
bool verbose = (ctmp == 'v');
|
"hf mf nack"
|
||||||
|
);
|
||||||
|
void *argtable[] = {
|
||||||
|
arg_param_begin,
|
||||||
|
arg_lit0("v", "verbose", "verbose output`"),
|
||||||
|
arg_param_end
|
||||||
|
};
|
||||||
|
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||||
|
bool verbose = arg_get_lit(ctx, 1);
|
||||||
|
CLIParserFree(ctx);
|
||||||
|
|
||||||
if (verbose)
|
if (verbose)
|
||||||
PrintAndLogEx(INFO, "Started testing card for NACK bug. Press Enter to abort");
|
PrintAndLogEx(INFO, "Started testing card for NACK bug. Press Enter to abort");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue