hf mf staticnested - now use cliparser

This commit is contained in:
tcprst 2021-02-07 17:49:45 -05:00
commit b7b0830194
No known key found for this signature in database
GPG key ID: 9145EAF5121AED25
2 changed files with 58 additions and 56 deletions

View file

@ -57,21 +57,6 @@ static int CmdHelp(const char *Cmd);
return PM3_SUCCESS; return PM3_SUCCESS;
} }
*/ */
static int usage_hf14_staticnested(void) {
PrintAndLogEx(NORMAL, "Usage:");
PrintAndLogEx(NORMAL, " all sectors: hf mf staticnested <card memory> <block> <key A/B> <key (12 hex symbols)> [t,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, " t transfer keys into emulator memory");
PrintAndLogEx(NORMAL, " d write keys to binary file `hf-mf-<UID>-key.bin`");
PrintAndLogEx(NORMAL, "");
PrintAndLogEx(NORMAL, "Examples:");
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf staticnested 1 0 A FFFFFFFFFFFF")" -- key recovery against 1K, block 0, Key A using key FFFFFFFFFFFF");
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf staticnested 1 0 A FFFFFFFFFFFF t")" -- and transfer keys into emulator memory");
PrintAndLogEx(NORMAL, _YELLOW_(" hf mf staticnested 1 0 A FFFFFFFFFFFF d")" -- or write keys to binary file ");
return PM3_SUCCESS;
}
static int usage_hf14_hardnested(void) { static int usage_hf14_hardnested(void) {
PrintAndLogEx(NORMAL, "Usage:"); PrintAndLogEx(NORMAL, "Usage:");
PrintAndLogEx(NORMAL, " hf mf hardnested <block number> <key A|B> <key (12 hex symbols)>"); PrintAndLogEx(NORMAL, " hf mf hardnested <block number> <key A|B> <key (12 hex symbols)>");
@ -1309,8 +1294,7 @@ static int CmdHF14AMfNested(const char *Cmd) {
uint8_t key[6] = {0}; uint8_t key[6] = {0};
CLIGetHexWithReturn(ctx, 1, key, &keylen); CLIGetHexWithReturn(ctx, 1, key, &keylen);
uint8_t SectorsCnt = 0; uint8_t SectorsCnt = NewNumOfSectors(arg_get_u32_def(ctx, 2, 1));
SectorsCnt = NewNumOfSectors(arg_get_u32_def(ctx, 2, 1));
uint8_t blockNo = arg_get_u32_def(ctx, 3, 0); uint8_t blockNo = arg_get_u32_def(ctx, 3, 0);
@ -1568,48 +1552,67 @@ jumptoend:
} }
static int CmdHF14AMfNestedStatic(const char *Cmd) { static int CmdHF14AMfNestedStatic(const char *Cmd) {
sector_t *e_sector = NULL; CLIParserContext *ctx;
CLIParserInit(&ctx, "hf mf staticnested",
"Execute Nested attack against MIFARE Classic card with static nonce for key recovery",
"hf mf staticnested -t 0 -b 0 --keya -k FFFFFFFFFFFF -> Key recovery against MIFARE Mini\n"
"hf mf staticnested -t 1 -b 0 --keya -k FFFFFFFFFFFF -> Key recovery against MIFARE Classic 1k\n"
"hf mf staticnested -t 2 -b 0 --keya -k FFFFFFFFFFFF -> Key recovery against MIFARE 2k\n"
"hf mf staticnested -t 4 -b 0 --keya -k FFFFFFFFFFFF -> Key recovery against MIFARE 4k\n");
void *argtable[] = {
arg_param_begin,
arg_str0("k", "key", "<hex>", "Key specified as 12 hex symbols"),
arg_int0("t", "type", "<0-4>", "MIFARE Classic type"),
arg_int0("b", "block", "<dec>", "Input block number"),
arg_lit0(NULL, "keya", "Input key specified is A key (default)"),
arg_lit0(NULL, "keyb", "Input key specified is B key"),
arg_lit0("e", "emukeys", "Fill simulator keys from found keys"),
arg_lit0(NULL, "dumpkeys", "Dump found keys to file"),
arg_param_end
};
CLIExecWithReturn(ctx, Cmd, argtable, false);
int keylen = 0;
uint8_t key[6] = {0};
CLIGetHexWithReturn(ctx, 1, key, &keylen);
uint8_t SectorsCnt = NewNumOfSectors(arg_get_u32_def(ctx, 2, 1));
uint8_t blockNo = arg_get_u32_def(ctx, 3, 0);
uint8_t keyType = 0; uint8_t keyType = 0;
if (arg_get_lit(ctx, 4) && arg_get_lit(ctx, 5)) {
CLIParserFree(ctx);
PrintAndLogEx(WARNING, "Input key type must be A or B");
return PM3_EINVARG;
} else if (arg_get_lit(ctx, 5)) {
keyType = 1;
}
bool transferToEml = arg_get_lit(ctx, 6);
bool createDumpFile = arg_get_lit(ctx, 7);
CLIParserFree(ctx);
//validations
if (SectorsCnt == 0) {
PrintAndLogEx(WARNING, "Invalid MIFARE Type");
return PM3_EINVARG;
}
if (keylen != 6) {
PrintAndLogEx(WARNING, "Input key must include 12 HEX symbols");
return PM3_EINVARG;
}
sector_t *e_sector = NULL;
uint8_t trgKeyType = 0; uint8_t trgKeyType = 0;
uint8_t SectorsCnt = 0;
uint8_t key[6] = {0, 0, 0, 0, 0, 0};
uint8_t keyBlock[(ARRAYLEN(g_mifare_default_keys) + 1) * 6]; uint8_t keyBlock[(ARRAYLEN(g_mifare_default_keys) + 1) * 6];
uint64_t key64 = 0; uint64_t key64 = 0;
bool transferToEml = false;
bool createDumpFile = false;
if (strlen(Cmd) < 3) return usage_hf14_staticnested();
char cmdp, ctmp;
cmdp = tolower(param_getchar(Cmd, 0));
uint8_t blockNo = param_get8(Cmd, 1);
ctmp = tolower(param_getchar(Cmd, 2));
if (ctmp != 'a' && ctmp != 'b') {
PrintAndLogEx(WARNING, "key type must be A or B");
return PM3_EINVARG;
}
if (ctmp != 'a')
keyType = 1;
if (param_gethex(Cmd, 3, key, 12)) {
PrintAndLogEx(WARNING, "key must include 12 HEX symbols");
return PM3_EINVARG;
}
SectorsCnt = NumOfSectors(cmdp);
if (SectorsCnt == 0) return usage_hf14_staticnested();
uint8_t j = 4;
while (ctmp != 0x00) {
ctmp = tolower(param_getchar(Cmd, j));
transferToEml |= (ctmp == 't');
createDumpFile |= (ctmp == 'd');
j++;
}
// check if tag have static nonce // check if tag have static nonce
if (detect_classic_static_nonce() != NONCE_STATIC) { if (detect_classic_static_nonce() != NONCE_STATIC) {

View file

@ -58,7 +58,6 @@ hf felica resetmode
hf felica litesim hf felica litesim
hf felica litedump hf felica litedump
hf mf hardnested hf mf hardnested
hf mf staticnested
hf mf autopwn hf mf autopwn
hf mf nack hf mf nack
hf mf chk hf mf chk