Added nested auto mode. it checks known keys and thel launches nested

This commit is contained in:
merlokk 2017-07-27 18:30:27 +03:00
commit 2709391d3b

View file

@ -530,6 +530,8 @@ int CmdHF14AMfNested(const char *Cmd)
uint8_t keyBlock[NESTED_KEY_COUNT * 6]; uint8_t keyBlock[NESTED_KEY_COUNT * 6];
uint64_t key64 = 0; uint64_t key64 = 0;
bool autosearchKey = false;
bool transferToEml = false; bool transferToEml = false;
bool createDumpFile = false; bool createDumpFile = false;
FILE *fkeys; FILE *fkeys;
@ -543,7 +545,7 @@ int CmdHF14AMfNested(const char *Cmd)
PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]"); PrintAndLog(" all sectors: hf mf nested <card memory> <block number> <key A/B> <key (12 hex symbols)> [t,d]");
PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>"); PrintAndLog(" one sector: hf mf nested o <block number> <key A/B> <key (12 hex symbols)>");
PrintAndLog(" <target block number> <target key A/B> [t]"); PrintAndLog(" <target block number> <target key A/B> [t]");
// PrintAndLog(" all sectors autosearch key: hf mf nested s <card memory> [t,d]"); PrintAndLog(" all sectors autosearch key: hf mf nested <card memory> * [t,d]");
PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K"); PrintAndLog("card memory - 0 - MINI(320 bytes), 1 - 1K, 2 - 2K, 4 - 4K, <other> - 1K");
PrintAndLog("t - transfer keys into emulator memory"); PrintAndLog("t - transfer keys into emulator memory");
PrintAndLog("d - write keys to binary file"); PrintAndLog("d - write keys to binary file");
@ -556,22 +558,6 @@ int CmdHF14AMfNested(const char *Cmd)
} }
cmdp = param_getchar(Cmd, 0); cmdp = param_getchar(Cmd, 0);
blockNo = param_get8(Cmd, 1);
ctmp = param_getchar(Cmd, 2);
if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {
PrintAndLog("Key type must be A or B");
return 1;
}
if (ctmp != 'A' && ctmp != 'a')
keyType = 1;
if (param_gethex(Cmd, 3, key, 12)) {
PrintAndLog("Key must include 12 HEX symbols");
return 1;
}
switch (cmdp) { switch (cmdp) {
case 'o': case 'o':
case 'O': case 'O':
@ -593,6 +579,29 @@ int CmdHF14AMfNested(const char *Cmd)
default: SectorsCnt = 16; default: SectorsCnt = 16;
} }
if (param_getchar(Cmd, 1) == '*') {
autosearchKey = true;
ctmp = param_getchar(Cmd, 2);
transferToEml |= (ctmp == 't' || ctmp == 'T');
createDumpFile |= (ctmp == 'd' || ctmp == 'D');
} else {
blockNo = param_get8(Cmd, 1);
ctmp = param_getchar(Cmd, 2);
if (ctmp != 'a' && ctmp != 'A' && ctmp != 'b' && ctmp != 'B') {
PrintAndLog("Key type must be A or B");
return 1;
}
if (ctmp != 'A' && ctmp != 'a')
keyType = 1;
if (param_gethex(Cmd, 3, key, 12)) {
PrintAndLog("Key must include 12 HEX symbols");
return 1;
}
ctmp = param_getchar(Cmd, 4); ctmp = param_getchar(Cmd, 4);
transferToEml |= (ctmp == 't' || ctmp == 'T'); transferToEml |= (ctmp == 't' || ctmp == 'T');
createDumpFile |= (ctmp == 'd' || ctmp == 'D'); createDumpFile |= (ctmp == 'd' || ctmp == 'D');
@ -607,6 +616,7 @@ int CmdHF14AMfNested(const char *Cmd)
PrintAndLog("Can't authenticate to block:%3d key type:%c key:%s", blockNo, keyType?'B':'A', sprint_hex(key, 6)); PrintAndLog("Can't authenticate to block:%3d key type:%c key:%s", blockNo, keyType?'B':'A', sprint_hex(key, 6));
return 3; return 3;
} }
}
// one-sector nested // one-sector nested
if (cmdp == 'o') { if (cmdp == 'o') {
@ -675,7 +685,7 @@ int CmdHF14AMfNested(const char *Cmd)
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
if (e_sector[i].foundKey[j]) continue; if (e_sector[i].foundKey[j]) continue;
res = mfCheckKeys(FirstBlockOfSector(i), j, true, NESTED_KEY_COUNT, keyBlock, &key64); // bbbuuuuggg!!!!!!!! res = mfCheckKeys(FirstBlockOfSector(i), j, true, NESTED_KEY_COUNT, keyBlock, &key64);
if (!res) { if (!res) {
e_sector[i].Key[j] = key64; e_sector[i].Key[j] = key64;
@ -685,34 +695,48 @@ int CmdHF14AMfNested(const char *Cmd)
} }
// PrintAndLog("---- known key:");
// PrintAndLog("|sec|key A |res|key B |res|");
// for (i = 0; i < SectorsCnt; i++) {
// PrintAndLog("|%03d| %012" PRIx64 " | %d | %012" PRIx64 " | %d |", i,
// e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[1], e_sector[i].foundKey[1]);
// }
// PrintAndLog("|---|----------------|---|----------------|---|");
// return 0;
// get known key
if (false) {
key64 = bytes_to_num(keyBlock, 6);
PrintAndLog("---- known key:");
PrintAndLog("|sec|key A |res|key B |res|");
for (i = 0; i < SectorsCnt; i++) {
PrintAndLog("|%03d| %012" PRIx64 " | %d | %012" PRIx64 " | %d |", i,
e_sector[i].Key[0], e_sector[i].foundKey[0], e_sector[i].Key[1], e_sector[i].foundKey[1]);
}
PrintAndLog("|---|----------------|---|----------------|---|");
// get known key from array
bool keyFound = false;
if (autosearchKey) {
for (i = 0; i < SectorsCnt; i++) { for (i = 0; i < SectorsCnt; i++) {
for (j = 0; j < 2; j++) { for (j = 0; j < 2; j++) {
if (e_sector[i].foundKey[j] && e_sector[i].Key[j] == key64) { if (e_sector[i].foundKey[j]) {
// get here // get known key
blockNo = i * 4;
keyType = j;
num_to_bytes(e_sector[i].Key[j], 6, key);
keyFound = true;
break; break;
} }
} }
if (keyFound) break;
}
// Can't found a key.... // Can't found a key....
if (i == SectorsCnt - 1) { if (!keyFound) {
PrintAndLog("Can't found any of the known keys.");
return 4;
}
PrintAndLog("--auto key. block no:%3d, key type:%c key:%s", blockNo, keyType?'B':'A', sprint_hex(key, 6));
}
} // return 0;
}
}
// nested sectors // nested sectors
iterations = 0; iterations = 0;