Added support for collecting all fm11rf08s nT/{nT}/par_err at once
This commit is contained in:
1 parent
df1c24c42a
commit
c73e2ea623
7 files changed
+192
-37
No files matched your search
@@ -18,6 +18,7 @@ import sys
|
||||
import time
|
||||
import subprocess
|
||||
import argparse
|
||||
import json
|
||||
import pm3
|
||||
# optional color support
|
||||
try:
|
||||
@@ -101,44 +102,14 @@ if args.init_check:
|
||||
found_keys[sec][1] = res[4]
|
||||
print_key(sec, 1, found_keys[sec][1])
|
||||
|
||||
nt = [["", ""] for _ in range(NUM_SECTORS)]
|
||||
nt_enc = [["", ""] for _ in range(NUM_SECTORS)]
|
||||
par_err = [["", ""] for _ in range(NUM_SECTORS)]
|
||||
print("Getting nonces...")
|
||||
for sec in range(NUM_SECTORS):
|
||||
blk = sec * 4
|
||||
if found_keys[sec][0] == "" or found_keys[sec][1] == "":
|
||||
# Even if one key already found, we'll need both nt
|
||||
for key_type in [0, 1]:
|
||||
cmd = f"hf mf isen -n1 --blk {blk} -c {key_type+4} --key {BACKDOOR_RF08S}"
|
||||
p.console(cmd)
|
||||
cmd += f" --c2 {key_type}"
|
||||
p.console(cmd)
|
||||
print("Processing traces...")
|
||||
for line in p.grabbed_output.split('\n'):
|
||||
if "nested cmd: 64" in line or "nested cmd: 65" in line:
|
||||
sec = int(line[24:26], 16)//4
|
||||
key_type = int(line[21:23], 16) - 0x64
|
||||
data = line[65:73]
|
||||
nt[sec][key_type] = data
|
||||
if "nested cmd: 60" in line or "nested cmd: 61" in line:
|
||||
sec = int(line[24:26], 16)//4
|
||||
key_type = int(line[21:23], 16) - 0x60
|
||||
data = line[108:116]
|
||||
nt_enc[sec][key_type] = data
|
||||
data = line[128:136]
|
||||
par_err[sec][key_type] = data
|
||||
|
||||
# Check if we got all nonces, else abort.
|
||||
# TODO: retry instead...
|
||||
for sec in range(NUM_SECTORS):
|
||||
if found_keys[sec][0] == "" or found_keys[sec][1] == "":
|
||||
for key_type in [0, 1]:
|
||||
if (nt[sec][key_type] == "" or
|
||||
nt_enc[sec][key_type] == "" or
|
||||
par_err[sec][key_type] == ""):
|
||||
print("Error, could not collect all nonces, try again.")
|
||||
exit()
|
||||
cmd = f"hf mf isen --collect_fm11rf08s --key {BACKDOOR_RF08S}"
|
||||
p.console(cmd)
|
||||
try:
|
||||
nt, nt_enc, par_err = json.loads(p.grabbed_output)
|
||||
except json.decoder.JSONDecodeError:
|
||||
print("Error getting nonces, abort.")
|
||||
exit()
|
||||
|
||||
if os.path.isfile(DICT_DEF_PATH):
|
||||
print(f"Loading {DICT_DEF}")
|
||||
|
||||
@@ -9727,6 +9727,7 @@ static int CmdHF14AMfISEN(const char *Cmd) {
|
||||
arg_lit0(NULL, "incblk2", "auth(blk)-auth(blk2)-auth(blk2+4)-..."),
|
||||
arg_lit0(NULL, "corruptnrar", "corrupt {nR}{aR}, but with correct parity"),
|
||||
arg_lit0(NULL, "corruptnrarparity", "correct {nR}{aR}, but with corrupted parity"),
|
||||
arg_lit0(NULL, "collect_fm11rf08s", "correct all nT/{nT}/par_err of FM11RF08S in JSON. Option to be used only with -k."),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
@@ -9792,6 +9793,7 @@ static int CmdHF14AMfISEN(const char *Cmd) {
|
||||
bool incblk2 = arg_get_lit(ctx, 16);
|
||||
bool corruptnrar = arg_get_lit(ctx, 17);
|
||||
bool corruptnrarparity = arg_get_lit(ctx, 18);
|
||||
bool collect_fm11rf08s = arg_get_lit(ctx, 19);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
uint8_t dbg_curr = DBG_NONE;
|
||||
@@ -9837,6 +9839,47 @@ static int CmdHF14AMfISEN(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "Card doesn't support standard iso14443-3 anticollision");
|
||||
}
|
||||
|
||||
if (collect_fm11rf08s) {
|
||||
SendCommandNG(CMD_HF_MIFARE_ACQ_STATIC_ENCRYPTED_NONCES, key, sizeof(key));
|
||||
if (WaitForResponseTimeout(CMD_HF_MIFARE_STATIC_ENCRYPTED_NONCE, &resp, 1000)) {
|
||||
if (resp.status == PM3_ESOFT) {
|
||||
return NONCE_FAIL;
|
||||
}
|
||||
}
|
||||
uint8_t num_sectors = 16;
|
||||
// TODO: get nonces and display
|
||||
PrintAndLogEx(NORMAL, "[\n [");
|
||||
for (uint8_t sec = 0; sec < num_sectors; sec++) {
|
||||
PrintAndLogEx(NORMAL, " [\"%08x\", \"%08x\"]%s",
|
||||
bytes_to_num(resp.data.asBytes + ((sec * 2) * 9), 4),
|
||||
bytes_to_num(resp.data.asBytes + (((sec * 2) + 1) * 9), 4),
|
||||
sec < num_sectors - 1 ? "," : "");
|
||||
}
|
||||
PrintAndLogEx(NORMAL, " ],\n [");
|
||||
for (uint8_t sec = 0; sec < num_sectors; sec++) {
|
||||
PrintAndLogEx(NORMAL, " [\"%08x\", \"%08x\"]%s",
|
||||
bytes_to_num(resp.data.asBytes + ((sec * 2) * 9) + 4, 4),
|
||||
bytes_to_num(resp.data.asBytes + (((sec * 2) + 1) * 9) + 4, 4),
|
||||
sec < num_sectors - 1 ? "," : "");
|
||||
}
|
||||
PrintAndLogEx(NORMAL, " ],\n [");
|
||||
for (uint8_t sec = 0; sec < num_sectors; sec++) {
|
||||
uint8_t p0 = resp.data.asBytes[((sec * 2) * 9) + 8];
|
||||
uint8_t p1 = resp.data.asBytes[(((sec * 2) + 1) * 9) + 8];
|
||||
PrintAndLogEx(NORMAL, " [\"%i%i%i%i\", \"%i%i%i%i\"]%s",
|
||||
(p0 >> 3) & 1, (p0 >> 2) & 1, (p0 >> 1) & 1, p0 & 1,
|
||||
(p1 >> 3) & 1, (p1 >> 2) & 1, (p1 >> 1) & 1, p1 & 1,
|
||||
sec < num_sectors - 1 ? "," : "");
|
||||
}
|
||||
PrintAndLogEx(NORMAL, " ]\n]");
|
||||
|
||||
// PrintAndLogEx(SUCCESS, " nT: " _GREEN_("%s"), sprint_hex(resp.data.asBytes + (((sec * 2) + keyType) * 9), 4));
|
||||
// PrintAndLogEx(SUCCESS, " {nT}: " _GREEN_("%s"), sprint_hex(resp.data.asBytes + (((sec * 2) + keyType) * 9) + 4, 4));
|
||||
// // TODO: wrong par:
|
||||
// PrintAndLogEx(SUCCESS, " par: " _GREEN_("%02x"), resp.data.asBytes[(((sec * 2) + keyType) * 9) + 8]);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("ISO14443-a Information") " ---------------------");
|
||||
PrintAndLogEx(SUCCESS, " UID: " _GREEN_("%s"), sprint_hex(card.uid, card.uidlen));
|
||||
|
||||
Reference in new issue
Block a user