Merge branch 'master' into master
Signed-off-by: Angel <jeremy_1996@hotmail.com>
This commit is contained in:
36 files changed
+724
-269
No files matched your search
@@ -531,7 +531,7 @@ static int CmdFlashMemSpiFFSView(const char *Cmd) {
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1("f", "file", "<fn>", "SPIFFS file to view"),
|
||||
arg_int0("c", "cols", "<dec>", "column breaks (def 32)"),
|
||||
arg_int0("c", "cols", "<dec>", "column breaks (def 16)"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
@@ -540,7 +540,7 @@ static int CmdFlashMemSpiFFSView(const char *Cmd) {
|
||||
char fn[32] = {0};
|
||||
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)fn, 32, &fnlen);
|
||||
|
||||
int breaks = arg_get_int_def(ctx, 2, 32);
|
||||
int breaks = arg_get_int_def(ctx, 2, 16);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
uint8_t *dump = NULL;
|
||||
|
||||
+186
-150
@@ -308,7 +308,6 @@ static int mf_print_keys(uint16_t n, uint8_t *d) {
|
||||
}
|
||||
|
||||
for (uint16_t i = 0; i < n; i++) {
|
||||
|
||||
if (mfIsSectorTrailer(i)) {
|
||||
e_sector[mfSectorNum(i)].foundKey[0] = 1;
|
||||
e_sector[mfSectorNum(i)].Key[0] = bytes_to_num(d + (i * MFBLOCK_SIZE), MIFARE_KEY_SIZE);
|
||||
@@ -321,6 +320,52 @@ static int mf_print_keys(uint16_t n, uint8_t *d) {
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
// MFC dump , extract and save the keys to key file
|
||||
static int mf_save_keys_from_arr(uint16_t n, uint8_t *d) {
|
||||
uint8_t sectors = 0;
|
||||
switch (n) {
|
||||
case MIFARE_MINI_MAXBLOCK:
|
||||
sectors = MIFARE_MINI_MAXSECTOR;
|
||||
break;
|
||||
case MIFARE_2K_MAXBLOCK:
|
||||
sectors = MIFARE_2K_MAXSECTOR;
|
||||
break;
|
||||
case MIFARE_4K_MAXBLOCK:
|
||||
sectors = MIFARE_4K_MAXSECTOR;
|
||||
break;
|
||||
case MIFARE_1K_MAXBLOCK:
|
||||
default:
|
||||
sectors = MIFARE_1K_MAXSECTOR;
|
||||
break;
|
||||
}
|
||||
|
||||
uint16_t keysize = 2 * MIFARE_KEY_SIZE * sectors;
|
||||
|
||||
uint8_t *keys = calloc(keysize, sizeof(uint8_t));
|
||||
if (keys == NULL) {
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
uint8_t sector = 0;
|
||||
for (uint16_t i = 0; i < n; i++) {
|
||||
if (mfIsSectorTrailer(i)) {
|
||||
// key A offset in ST block
|
||||
memcpy(keys + (MIFARE_KEY_SIZE * sector), d + (i * MFBLOCK_SIZE), MIFARE_KEY_SIZE);
|
||||
|
||||
// key B offset in ST block
|
||||
memcpy(keys + (MIFARE_KEY_SIZE * sectors) + (MIFARE_KEY_SIZE * sector), d + (i * MFBLOCK_SIZE) + 10, MIFARE_KEY_SIZE);
|
||||
|
||||
sector++;
|
||||
}
|
||||
}
|
||||
|
||||
char fn[FILE_PATH_SIZE] = {0};
|
||||
snprintf(fn, sizeof(fn), "hf-mf-%s-keys", sprint_hex_inrow(d, 4));
|
||||
saveFile(fn, ".bin", keys, keysize);
|
||||
free(keys);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
/*
|
||||
static void mf_print_values(uint16_t n, uint8_t *d) {
|
||||
|
||||
@@ -1211,52 +1256,41 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||
free(fptr);
|
||||
}
|
||||
|
||||
FILE *f;
|
||||
if ((f = fopen(keyfilename, "rb")) == NULL) {
|
||||
PrintAndLogEx(WARNING, "Could not find file " _YELLOW_("%s"), keyfilename);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
|
||||
// key arrays
|
||||
uint8_t keyA[40][6];
|
||||
uint8_t keyB[40][6];
|
||||
|
||||
// read key file
|
||||
size_t bytes_read;
|
||||
for (uint8_t s = 0; s < sectors; s++) {
|
||||
bytes_read = fread(keyA[s], 1, 6, f);
|
||||
if (bytes_read != 6) {
|
||||
PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), keyfilename);
|
||||
fclose(f);
|
||||
return PM3_EFILE;
|
||||
//
|
||||
size_t alen = 0, blen = 0;
|
||||
uint8_t *keyA, *keyB;
|
||||
if (loadFileBinaryKey(keyfilename, "", (void **)&keyA, (void **)&keyB, &alen, &blen) != PM3_SUCCESS) {
|
||||
if (keyA) {
|
||||
free(keyA);
|
||||
}
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
for (uint8_t s = 0; s < sectors; s++) {
|
||||
bytes_read = fread(keyB[s], 1, 6, f);
|
||||
if (bytes_read != 6) {
|
||||
PrintAndLogEx(ERR, "File reading error " _YELLOW_("%s"), keyfilename);
|
||||
fclose(f);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
}
|
||||
fclose(f);
|
||||
PrintAndLogEx(INFO, "Using `" _YELLOW_("%s") "`", keyfilename);
|
||||
|
||||
// try reading card uid and create filename
|
||||
if (datafnlen == 0) {
|
||||
char *fptr = GenerateFilename("hf-mf-", "-dump.bin");
|
||||
if (fptr == NULL)
|
||||
if (fptr == NULL) {
|
||||
if (keyA) {
|
||||
free(keyA);
|
||||
}
|
||||
if (keyB) {
|
||||
free(keyB);
|
||||
}
|
||||
return PM3_ESOFT;
|
||||
|
||||
}
|
||||
strcpy(datafilename, fptr);
|
||||
free(fptr);
|
||||
}
|
||||
|
||||
// read dump file
|
||||
uint8_t *dump = NULL;
|
||||
bytes_read = 0;
|
||||
size_t bytes_read = 0;
|
||||
int res = pm3_load_dump(datafilename, (void **)&dump, &bytes_read, (MFBLOCK_SIZE * MIFARE_4K_MAXBLOCK));
|
||||
if (res != PM3_SUCCESS) {
|
||||
free(keyA);
|
||||
free(keyB);
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -1281,19 +1315,10 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||
if (mfNumBlocksPerSector(s) - 1 == b) {
|
||||
if (use_keyfile_for_auth == false) {
|
||||
// replace KEY A
|
||||
bldata[0] = (keyA[s][0]);
|
||||
bldata[1] = (keyA[s][1]);
|
||||
bldata[2] = (keyA[s][2]);
|
||||
bldata[3] = (keyA[s][3]);
|
||||
bldata[4] = (keyA[s][4]);
|
||||
bldata[5] = (keyA[s][5]);
|
||||
memcpy(bldata, keyA + (s * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
|
||||
// replace KEY B
|
||||
bldata[10] = (keyB[s][0]);
|
||||
bldata[11] = (keyB[s][1]);
|
||||
bldata[12] = (keyB[s][2]);
|
||||
bldata[13] = (keyB[s][3]);
|
||||
bldata[14] = (keyB[s][4]);
|
||||
bldata[15] = (keyB[s][5]);
|
||||
memcpy(bldata + 10, keyB + (s * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
}
|
||||
|
||||
// ensure access right isn't messed up.
|
||||
@@ -1327,12 +1352,12 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||
for (int8_t kt = MF_KEY_B; kt > -1; kt--) {
|
||||
if (use_keyfile_for_auth) {
|
||||
if (kt == MF_KEY_A)
|
||||
memcpy(wdata, keyA[s], 6);
|
||||
memcpy(wdata, keyA + (s * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
else
|
||||
memcpy(wdata, keyB[s], 6);
|
||||
memcpy(wdata, keyB + (s * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
} else {
|
||||
// use default key to authenticate for the write command
|
||||
memcpy(wdata, default_key, 6);
|
||||
memcpy(wdata, default_key, MIFARE_KEY_SIZE);
|
||||
}
|
||||
PrintAndLogEx(INFO, "block %3d: %s", mfFirstBlockOfSector(s) + b, sprint_hex(bldata, sizeof(bldata)));
|
||||
|
||||
@@ -1359,6 +1384,8 @@ static int CmdHF14AMfRestore(const char *Cmd) {
|
||||
} // end loop S
|
||||
|
||||
free(ref_dump);
|
||||
free(keyA);
|
||||
free(keyB);
|
||||
PrintAndLogEx(INFO, "Done!");
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
@@ -2155,26 +2182,27 @@ static int CmdHF14AMfNestedHard(const char *Cmd) {
|
||||
|
||||
uint64_t foundkey = 0;
|
||||
int16_t isOK = mfnestedhard(blockno, keytype, key, trg_blockno, trg_keytype, known_target_key ? trg_key : NULL, nonce_file_read, nonce_file_write, slow, tests, &foundkey, filename);
|
||||
switch (isOK) {
|
||||
case PM3_ETIMEOUT :
|
||||
PrintAndLogEx(ERR, "Error: No response from Proxmark3\n");
|
||||
break;
|
||||
case PM3_EOPABORTED:
|
||||
PrintAndLogEx(WARNING, "Button pressed. Aborted\n");
|
||||
break;
|
||||
case PM3_ESTATIC_NONCE:
|
||||
PrintAndLogEx(ERR, "Error: Static encrypted nonce detected. Aborted\n");
|
||||
break;
|
||||
case PM3_EFAILED: {
|
||||
PrintAndLogEx(FAILED, "\nFailed to recover a key...");
|
||||
break;
|
||||
}
|
||||
default :
|
||||
break;
|
||||
}
|
||||
|
||||
if ((tests == 0) && IfPm3Iso14443a()) {
|
||||
DropField();
|
||||
}
|
||||
|
||||
if (isOK) {
|
||||
switch (isOK) {
|
||||
case PM3_ETIMEOUT :
|
||||
PrintAndLogEx(ERR, "Error: No response from Proxmark3\n");
|
||||
break;
|
||||
case PM3_EOPABORTED:
|
||||
PrintAndLogEx(WARNING, "Button pressed. Aborted\n");
|
||||
break;
|
||||
case PM3_ESTATIC_NONCE:
|
||||
PrintAndLogEx(ERR, "Error: Static encrypted nonce detected. Aborted\n");
|
||||
break;
|
||||
default :
|
||||
break;
|
||||
}
|
||||
}
|
||||
return isOK;
|
||||
}
|
||||
|
||||
@@ -2389,14 +2417,6 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
|
||||
if (is_ev1) {
|
||||
PrintAndLogEx(INFO, "MIFARE Classic EV1 card detected");
|
||||
// Store the keys
|
||||
e_sector[16].Key[MF_KEY_A] = bytes_to_num((uint8_t *)g_mifare_signature_key_a, sizeof(g_mifare_signature_key_a));
|
||||
e_sector[16].foundKey[MF_KEY_A] = 'D';
|
||||
|
||||
e_sector[17].Key[MF_KEY_A] = bytes_to_num((uint8_t *)g_mifare_signature_key_a, sizeof(g_mifare_signature_key_a));
|
||||
e_sector[17].foundKey[MF_KEY_A] = 'D';
|
||||
e_sector[17].Key[MF_KEY_B] = bytes_to_num((uint8_t *)g_mifare_signature_key_b, sizeof(g_mifare_signature_key_b));
|
||||
e_sector[17].foundKey[MF_KEY_B] = 'D';
|
||||
|
||||
// use found key if not supplied
|
||||
if (known_key == false) {
|
||||
@@ -2431,7 +2451,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, " key supplied .. " _YELLOW_("%s"), known_key ? "True" : "False");
|
||||
PrintAndLogEx(INFO, " known sector .. " _YELLOW_("%d"), sectorno);
|
||||
PrintAndLogEx(INFO, " keytype ....... " _YELLOW_("%c"), (keytype == MF_KEY_B) ? 'B' : 'A');
|
||||
PrintAndLogEx(INFO, " known key ..... " _YELLOW_("%s"), sprint_hex(key, sizeof(key)));
|
||||
PrintAndLogEx(INFO, " known key ..... " _YELLOW_("%s"), sprint_hex_inrow(key, sizeof(key)));
|
||||
|
||||
if (has_staticnonce == NONCE_STATIC)
|
||||
PrintAndLogEx(INFO, " card PRNG ..... " _YELLOW_("STATIC"));
|
||||
@@ -2458,10 +2478,10 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
}
|
||||
|
||||
if (mfCheckKeys(mfFirstBlockOfSector(sectorno), keytype, true, 1, key, &key64) == PM3_SUCCESS) {
|
||||
PrintAndLogEx(INFO, "target sector %3u key type %c -- using valid key [ " _GREEN_("%s") "] (used for nested / hardnested attack)",
|
||||
PrintAndLogEx(INFO, "target sector %3u key type %c -- using valid key [ " _GREEN_("%s") " ] (used for nested / hardnested attack)",
|
||||
sectorno,
|
||||
(keytype == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex(key, sizeof(key))
|
||||
sprint_hex_inrow(key, sizeof(key))
|
||||
);
|
||||
|
||||
// Store the key for the nested / hardnested attack (if supplied by the user)
|
||||
@@ -2474,7 +2494,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
PrintAndLogEx(FAILED, "Key is wrong. Can't authenticate to sector"_RED_("%3d") " key type "_RED_("%c") " key " _RED_("%s"),
|
||||
sectorno,
|
||||
(keytype == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex(key, sizeof(key))
|
||||
sprint_hex_inrow(key, sizeof(key))
|
||||
);
|
||||
PrintAndLogEx(WARNING, "falling back to dictionary");
|
||||
}
|
||||
@@ -2482,31 +2502,34 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
// Check if the user supplied key is used by other sectors
|
||||
for (int i = 0; i < sector_cnt; i++) {
|
||||
for (int j = MF_KEY_A; j <= MF_KEY_B; j++) {
|
||||
if (e_sector[i].foundKey[j] == 0) {
|
||||
if (mfCheckKeys(mfFirstBlockOfSector(i), j, true, 1, key, &key64) == PM3_SUCCESS) {
|
||||
e_sector[i].Key[j] = bytes_to_num(key, 6);
|
||||
e_sector[i].foundKey[j] = 'U';
|
||||
|
||||
// If the user supplied secctor / keytype was wrong --> just be nice and correct it ;)
|
||||
if (known_key == false) {
|
||||
num_to_bytes(e_sector[i].Key[j], 6, key);
|
||||
known_key = true;
|
||||
sectorno = i;
|
||||
keytype = j;
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ] (used for nested / hardnested attack)",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(key, sizeof(key))
|
||||
);
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ]",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(key, sizeof(key))
|
||||
);
|
||||
}
|
||||
++num_found_keys;
|
||||
if (e_sector[i].foundKey[j]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (mfCheckKeys(mfFirstBlockOfSector(i), j, true, 1, key, &key64) == PM3_SUCCESS) {
|
||||
e_sector[i].Key[j] = bytes_to_num(key, 6);
|
||||
e_sector[i].foundKey[j] = 'U';
|
||||
|
||||
// If the user supplied secctor / keytype was wrong --> just be nice and correct it ;)
|
||||
if (known_key == false) {
|
||||
num_to_bytes(e_sector[i].Key[j], 6, key);
|
||||
known_key = true;
|
||||
sectorno = i;
|
||||
keytype = j;
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ] (used for nested / hardnested attack)",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(key, sizeof(key))
|
||||
);
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ]",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(key, sizeof(key))
|
||||
);
|
||||
}
|
||||
++num_found_keys;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2551,7 +2574,7 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "." NOLF);
|
||||
// Check all the sectors
|
||||
for (int i = 0; i < sector_cnt; i++) {
|
||||
for (int j = 0; j < 2; j++) {
|
||||
for (int j = MF_KEY_A; j <= MF_KEY_B; j++) {
|
||||
// Check if the key is known
|
||||
if (e_sector[i].foundKey[j] == 0) {
|
||||
for (uint32_t k = 0; k < key_cnt; k++) {
|
||||
@@ -2608,28 +2631,30 @@ static int CmdHF14AMfAutoPWN(const char *Cmd) {
|
||||
// Analyse the dictionary attack
|
||||
for (int i = 0; i < sector_cnt; i++) {
|
||||
for (int j = MF_KEY_A; j <= MF_KEY_B; j++) {
|
||||
if (e_sector[i].foundKey[j] == 1) {
|
||||
e_sector[i].foundKey[j] = 'D';
|
||||
num_to_bytes(e_sector[i].Key[j], 6, tmp_key);
|
||||
if (e_sector[i].foundKey[j] != 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Store valid credentials for the nested / hardnested attack if none exist
|
||||
if (known_key == false) {
|
||||
num_to_bytes(e_sector[i].Key[j], 6, key);
|
||||
known_key = true;
|
||||
sectorno = i;
|
||||
keytype = j;
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ] (used for nested / hardnested attack)",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(tmp_key, sizeof(tmp_key))
|
||||
);
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ]",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(tmp_key, sizeof(tmp_key))
|
||||
);
|
||||
}
|
||||
e_sector[i].foundKey[j] = 'D';
|
||||
num_to_bytes(e_sector[i].Key[j], 6, tmp_key);
|
||||
|
||||
// Store valid credentials for the nested / hardnested attack if none exist
|
||||
if (known_key == false) {
|
||||
num_to_bytes(e_sector[i].Key[j], 6, key);
|
||||
known_key = true;
|
||||
sectorno = i;
|
||||
keytype = j;
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ] (used for nested / hardnested attack)",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(tmp_key, sizeof(tmp_key))
|
||||
);
|
||||
} else {
|
||||
PrintAndLogEx(SUCCESS, "target sector %3u key type %c -- found valid key [ " _GREEN_("%s") " ]",
|
||||
i,
|
||||
(j == MF_KEY_B) ? 'B' : 'A',
|
||||
sprint_hex_inrow(tmp_key, sizeof(tmp_key))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2690,7 +2715,8 @@ noValidKeyFound:
|
||||
|
||||
// Iterate over each sector and key(A/B)
|
||||
for (current_sector_i = 0; current_sector_i < sector_cnt; current_sector_i++) {
|
||||
for (current_key_type_i = 0; current_key_type_i < 2; current_key_type_i++) {
|
||||
|
||||
for (current_key_type_i = MF_KEY_A; current_key_type_i <= MF_KEY_B; current_key_type_i++) {
|
||||
|
||||
// If the key is already known, just skip it
|
||||
if (e_sector[current_sector_i].foundKey[current_key_type_i] == 0) {
|
||||
@@ -2863,7 +2889,7 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack
|
||||
foundkey = 0;
|
||||
isOK = mfnestedhard(mfFirstBlockOfSector(sectorno), keytype, key, mfFirstBlockOfSector(current_sector_i), current_key_type_i, NULL, false, false, slow, 0, &foundkey, NULL);
|
||||
DropField();
|
||||
if (isOK) {
|
||||
if (isOK != PM3_SUCCESS) {
|
||||
switch (isOK) {
|
||||
case PM3_ETIMEOUT: {
|
||||
PrintAndLogEx(ERR, "\nError: No response from Proxmark3");
|
||||
@@ -2886,6 +2912,10 @@ tryHardnested: // If the nested attack fails then we try the hardnested attack
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
break;
|
||||
}
|
||||
case PM3_EFAILED: {
|
||||
PrintAndLogEx(FAILED, "\nFailed to recover a key...");
|
||||
continue;
|
||||
}
|
||||
default: {
|
||||
break;
|
||||
}
|
||||
@@ -4394,6 +4424,7 @@ static int CmdHF14AMfEView(const char *Cmd) {
|
||||
arg_lit0(NULL, "2k", "MIFARE Classic/Plus 2k"),
|
||||
arg_lit0(NULL, "4k", "MIFARE Classic 4k / S70"),
|
||||
arg_lit0("v", "verbose", "verbose output"),
|
||||
arg_lit0(NULL, "sk", "Save extracted keys to file"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
@@ -4402,6 +4433,7 @@ static int CmdHF14AMfEView(const char *Cmd) {
|
||||
bool m2 = arg_get_lit(ctx, 3);
|
||||
bool m4 = arg_get_lit(ctx, 4);
|
||||
bool verbose = arg_get_lit(ctx, 5);
|
||||
bool save_keys = arg_get_lit(ctx, 6);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// validations
|
||||
@@ -4447,6 +4479,11 @@ static int CmdHF14AMfEView(const char *Cmd) {
|
||||
if (verbose) {
|
||||
mf_print_keys(block_cnt, dump);
|
||||
}
|
||||
|
||||
if (save_keys) {
|
||||
mf_save_keys_from_arr(block_cnt, dump);
|
||||
}
|
||||
|
||||
free(dump);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
@@ -5864,8 +5901,9 @@ int CmdHFMFNDEFRead(const char *Cmd) {
|
||||
CLIParserFree(ctx);
|
||||
|
||||
uint16_t ndef_aid = NDEF_MFC_AID;
|
||||
if (aidlen == 2)
|
||||
if (aidlen == 2) {
|
||||
ndef_aid = (aid[0] << 8) + aid[1];
|
||||
}
|
||||
|
||||
uint8_t ndefkey[6] = {0};
|
||||
memcpy(ndefkey, g_mifare_ndef_key, 6);
|
||||
@@ -6079,39 +6117,27 @@ int CmdHFMFNDEFFormat(const char *Cmd) {
|
||||
DropField();
|
||||
}
|
||||
|
||||
|
||||
// load key file if exist
|
||||
if (strlen(keyFilename)) {
|
||||
|
||||
FILE *f;
|
||||
if ((f = fopen(keyFilename, "rb")) == NULL) {
|
||||
// PrintAndLogEx(WARNING, "Could not find file " _YELLOW_("%s"), keyFilename);
|
||||
//
|
||||
size_t alen = 0, blen = 0;
|
||||
uint8_t *tmpA, *tmpB;
|
||||
if (loadFileBinaryKey(keyFilename, "", (void **)&tmpA, (void **)&tmpB, &alen, &blen) != PM3_SUCCESS) {
|
||||
if (tmpA) {
|
||||
free(tmpA);
|
||||
}
|
||||
goto skipfile;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Using `" _YELLOW_("%s") "`", keyFilename);
|
||||
|
||||
// Read keys A from file
|
||||
size_t bytes_read;
|
||||
for (uint8_t i = 0; i < numSectors; i++) {
|
||||
bytes_read = fread(keyA[i], 1, MFKEY_SIZE, f);
|
||||
if (bytes_read != MFKEY_SIZE) {
|
||||
PrintAndLogEx(ERR, "File reading error.");
|
||||
fclose(f);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
for (int i = 0; i < numSectors; i++) {
|
||||
memcpy(keyA[i], tmpA + (i * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
memcpy(keyB[i], tmpB + (i * MIFARE_KEY_SIZE), MIFARE_KEY_SIZE);
|
||||
}
|
||||
|
||||
// Read keys B from file
|
||||
for (uint8_t i = 0; i < numSectors; i++) {
|
||||
bytes_read = fread(keyB[i], 1, MFKEY_SIZE, f);
|
||||
if (bytes_read != MFKEY_SIZE) {
|
||||
PrintAndLogEx(ERR, "File reading error.");
|
||||
fclose(f);
|
||||
return PM3_EFILE;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(f);
|
||||
free(tmpA);
|
||||
free(tmpB);
|
||||
}
|
||||
|
||||
skipfile:
|
||||
@@ -6154,7 +6180,6 @@ skipfile:
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// write to card, try B key first
|
||||
@@ -6169,7 +6194,6 @@ skipfile:
|
||||
}
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -6952,6 +6976,7 @@ static int CmdHF14AMfWipe(const char *Cmd) {
|
||||
PrintAndLogEx(INFO, "Forcing overwrite of sector 0 / block 0 ");
|
||||
else
|
||||
PrintAndLogEx(INFO, "Skipping sector 0 / block 0");
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
uint8_t zeros[MFBLOCK_SIZE] = {0};
|
||||
@@ -6963,7 +6988,12 @@ static int CmdHF14AMfWipe(const char *Cmd) {
|
||||
|
||||
for (uint8_t b = 0; b < mfNumBlocksPerSector(s); b++) {
|
||||
|
||||
// Skipp write to manufacture block if not enforced
|
||||
if (kbd_enter_pressed()) {
|
||||
PrintAndLogEx(WARNING, "\naborted via keyboard!\n");
|
||||
goto out;
|
||||
}
|
||||
|
||||
// Skip write to manufacture block if not enforced
|
||||
if (s == 0 && b == 0 && gen2 == false) {
|
||||
continue;
|
||||
}
|
||||
@@ -7026,6 +7056,7 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
arg_param_begin,
|
||||
arg_str1("f", "file", "<fn>", "filename of dump"),
|
||||
arg_lit0("v", "verbose", "verbose output"),
|
||||
arg_lit0(NULL, "sk", "Save extracted keys to file"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, false);
|
||||
@@ -7033,6 +7064,7 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
char filename[FILE_PATH_SIZE];
|
||||
CLIParamStrToBuf(arg_get_str(ctx, 1), (uint8_t *)filename, FILE_PATH_SIZE, &fnlen);
|
||||
bool verbose = arg_get_lit(ctx, 2);
|
||||
bool save_keys = arg_get_lit(ctx, 3);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// read dump file
|
||||
@@ -7063,6 +7095,10 @@ static int CmdHF14AMfView(const char *Cmd) {
|
||||
mf_analyse_acl(block_cnt, dump);
|
||||
}
|
||||
|
||||
if (save_keys) {
|
||||
mf_save_keys_from_arr(block_cnt, dump);
|
||||
}
|
||||
|
||||
int sector = DetectHID(dump, 0x4910);
|
||||
if (sector > -1) {
|
||||
// decode it
|
||||
|
||||
@@ -34,7 +34,6 @@
|
||||
|
||||
#include "commonutil.h" // ARRAYLEN
|
||||
#include "comms.h"
|
||||
|
||||
#include "proxmark3.h"
|
||||
#include "ui.h"
|
||||
#include "util_posix.h"
|
||||
@@ -48,7 +47,8 @@
|
||||
#define NUM_CHECK_BITFLIPS_THREADS (num_CPUs())
|
||||
#define NUM_REDUCTION_WORKING_THREADS (num_CPUs())
|
||||
|
||||
#define IGNORE_BITFLIP_THRESHOLD 0.99 // ignore bitflip arrays which have nearly only valid states
|
||||
// ignore bitflip arrays which have nearly only valid states
|
||||
#define IGNORE_BITFLIP_THRESHOLD 0.9901
|
||||
|
||||
#define STATE_FILES_DIRECTORY "hardnested_tables/"
|
||||
#define STATE_FILE_TEMPLATE "bitflip_%d_%03" PRIx16 "_states.bin.bz2"
|
||||
@@ -57,7 +57,11 @@
|
||||
// #define DEBUG_REDUCTION
|
||||
|
||||
// possible sum property values
|
||||
static uint16_t sums[NUM_SUMS] = {0, 32, 56, 64, 80, 96, 104, 112, 120, 128, 136, 144, 152, 160, 176, 192, 200, 224, 256};
|
||||
static uint16_t sums[NUM_SUMS] = {
|
||||
0, 32, 56, 64, 80, 96, 104, 112,
|
||||
120, 128, 136, 144, 152, 160, 176, 192,
|
||||
200, 224, 256
|
||||
};
|
||||
|
||||
// number of possible partial sum property values
|
||||
#define NUM_PART_SUMS 9
|
||||
@@ -505,8 +509,11 @@ static void free_sum_bitarrays(void) {
|
||||
static char failstr[250] = "";
|
||||
#endif
|
||||
|
||||
static const float p_K0[NUM_SUMS] = { // the probability that a random nonce has a Sum Property K
|
||||
0.0290, 0.0083, 0.0006, 0.0339, 0.0048, 0.0934, 0.0119, 0.0489, 0.0602, 0.4180, 0.0602, 0.0489, 0.0119, 0.0934, 0.0048, 0.0339, 0.0006, 0.0083, 0.0290
|
||||
// the probability that a random nonce has a Sum Property K
|
||||
static const float p_K0[NUM_SUMS] = {
|
||||
0.0290, 0.0083, 0.0006, 0.0339, 0.0048, 0.0934, 0.0119, 0.0489,
|
||||
0.0602, 0.4180, 0.0602, 0.0489, 0.0119, 0.0934, 0.0048, 0.0339,
|
||||
0.0006, 0.0083, 0.0290
|
||||
};
|
||||
static float my_p_K[NUM_SUMS];
|
||||
static const float *p_K;
|
||||
@@ -1275,6 +1282,7 @@ static void apply_sum_a0(void) {
|
||||
}
|
||||
|
||||
static void simulate_MFplus_RNG(uint32_t test_cuid, uint64_t test_key, uint32_t *nt_enc, uint8_t *par_enc) {
|
||||
|
||||
struct Crypto1State sim_cs = {0, 0};
|
||||
|
||||
// init cryptostate with key:
|
||||
@@ -1285,12 +1293,20 @@ static void simulate_MFplus_RNG(uint32_t test_cuid, uint64_t test_key, uint32_t
|
||||
|
||||
*par_enc = 0;
|
||||
uint32_t nt = (rand() & 0xff) << 24 | (rand() & 0xff) << 16 | (rand() & 0xff) << 8 | (rand() & 0xff);
|
||||
|
||||
for (int8_t byte_pos = 3; byte_pos >= 0; byte_pos--) {
|
||||
|
||||
uint8_t nt_byte_dec = (nt >> (8 * byte_pos)) & 0xff;
|
||||
uint8_t nt_byte_enc = crypto1_byte(&sim_cs, nt_byte_dec ^ (test_cuid >> (8 * byte_pos)), false) ^ nt_byte_dec; // encode the nonce byte
|
||||
|
||||
// encode the nonce byte
|
||||
uint8_t nt_byte_enc = crypto1_byte(&sim_cs, nt_byte_dec ^ (test_cuid >> (8 * byte_pos)), false) ^ nt_byte_dec;
|
||||
*nt_enc = (*nt_enc << 8) | nt_byte_enc;
|
||||
uint8_t ks_par = filter(sim_cs.odd); // the keystream bit to encode/decode the parity bit
|
||||
uint8_t nt_byte_par_enc = ks_par ^ oddparity8(nt_byte_dec); // determine the nt byte's parity and encode it
|
||||
|
||||
// the keystream bit to encode/decode the parity bit
|
||||
uint8_t ks_par = filter(sim_cs.odd);
|
||||
|
||||
// determine the nt byte's parity and encode it
|
||||
uint8_t nt_byte_par_enc = ks_par ^ oddparity8(nt_byte_dec);
|
||||
*par_enc = (*par_enc << 1) | nt_byte_par_enc;
|
||||
}
|
||||
}
|
||||
@@ -2460,6 +2476,9 @@ int mfnestedhard(uint8_t blockNo, uint8_t keyType, uint8_t *key, uint8_t trgBloc
|
||||
free_bitarray(all_bitflips_bitarray[EVEN_STATE]);
|
||||
free_sum_bitarrays();
|
||||
free_part_sum_bitarrays();
|
||||
|
||||
return (key_found) ? PM3_SUCCESS : PM3_EFAILED;
|
||||
}
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
+94
-29
@@ -19,6 +19,7 @@
|
||||
#include "cliparser.h"
|
||||
#include "cmdlfem4x50.h"
|
||||
#include <ctype.h>
|
||||
#include <math.h>
|
||||
#include "cmdparser.h" // command_t
|
||||
#include "util_posix.h" // msclock
|
||||
#include "fileutils.h"
|
||||
@@ -349,54 +350,118 @@ int CmdEM4x50Brute(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "lf em 4x50 brute",
|
||||
"Tries to bruteforce the password of a EM4x50 card.\n"
|
||||
"Function can be stopped by pressing pm3 button.",
|
||||
"lf em 4x50 brute --first 12330000 --last 12340000 -> tries pwds from 0x12330000 to 0x1234000000\n"
|
||||
"Function can be stopped by pressing pm3 button.\n",
|
||||
|
||||
"lf em 4x50 brute --mode range --begin 12330000 --end 12340000 -> tries pwds from 0x12330000 to 0x12340000\n"
|
||||
"lf em 4x50 brute --mode charset --digits --uppercase -> tries all combinations of ASCII codes for digits and uppercase letters\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_str1(NULL, "first", "<hex>", "first password (start), 4 bytes, lsb"),
|
||||
arg_str1(NULL, "last", "<hex>", "last password (stop), 4 bytes, lsb"),
|
||||
arg_str1(NULL, "mode", "<str>", "Bruteforce mode (range|charset)"),
|
||||
arg_str0(NULL, "begin", "<hex>", "Range mode - start of the key range"),
|
||||
arg_str0(NULL, "end", "<hex>", "Range mode - end of the key range"),
|
||||
arg_lit0(NULL, "digits", "Charset mode - include ASCII codes for digits"),
|
||||
arg_lit0(NULL, "uppercase", "Charset mode - include ASCII codes for uppercase letters"),
|
||||
arg_param_end
|
||||
};
|
||||
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
int first_len = 0;
|
||||
uint8_t first[4] = {0, 0, 0, 0};
|
||||
CLIGetHexWithReturn(ctx, 1, first, &first_len);
|
||||
int last_len = 0;
|
||||
uint8_t last[4] = {0, 0, 0, 0};
|
||||
CLIGetHexWithReturn(ctx, 2, last, &last_len);
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (first_len != 4) {
|
||||
PrintAndLogEx(FAILED, "password length must be 4 bytes");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
if (last_len != 4) {
|
||||
PrintAndLogEx(FAILED, "password length must be 4 bytes");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
em4x50_data_t etd;
|
||||
etd.password1 = BYTES2UINT32_BE(first);
|
||||
etd.password2 = BYTES2UINT32_BE(last);
|
||||
memset(&etd, 0, sizeof(etd));
|
||||
|
||||
int mode_len = 64;
|
||||
char mode[64];
|
||||
CLIGetStrWithReturn(ctx, 1, (uint8_t *) mode, &mode_len);
|
||||
PrintAndLogEx(INFO, "Chosen mode: %s", mode);
|
||||
|
||||
if (strcmp(mode, "range") == 0) {
|
||||
etd.bruteforce_mode = BRUTEFORCE_MODE_RANGE;
|
||||
} else if (strcmp(mode, "charset") == 0) {
|
||||
etd.bruteforce_mode = BRUTEFORCE_MODE_CHARSET;
|
||||
} else {
|
||||
PrintAndLogEx(FAILED, "Unknown bruteforce mode: %s", mode);
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (etd.bruteforce_mode == BRUTEFORCE_MODE_RANGE) {
|
||||
int begin_len = 0;
|
||||
uint8_t begin[4] = {0x0};
|
||||
CLIGetHexWithReturn(ctx, 2, begin, &begin_len);
|
||||
|
||||
int end_len = 0;
|
||||
uint8_t end[4] = {0x0};
|
||||
CLIGetHexWithReturn(ctx, 3, end, &end_len);
|
||||
|
||||
if (begin_len != 4) {
|
||||
PrintAndLogEx(FAILED, "'begin' parameter must be 4 bytes");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
if (end_len != 4) {
|
||||
PrintAndLogEx(FAILED, "'end' parameter must be 4 bytes");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
etd.password1 = BYTES2UINT32_BE(begin);
|
||||
etd.password2 = BYTES2UINT32_BE(end);
|
||||
} else if (etd.bruteforce_mode == BRUTEFORCE_MODE_CHARSET) {
|
||||
bool enable_digits = arg_get_lit(ctx, 4);
|
||||
bool enable_uppercase = arg_get_lit(ctx, 5);
|
||||
|
||||
if (enable_digits)
|
||||
etd.bruteforce_charset |= CHARSET_DIGITS;
|
||||
if (enable_uppercase)
|
||||
etd.bruteforce_charset |= CHARSET_UPPERCASE;
|
||||
|
||||
if (etd.bruteforce_charset == 0) {
|
||||
PrintAndLogEx(FAILED, "Please enable at least one charset when using charset bruteforce mode.");
|
||||
CLIParserFree(ctx);
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
|
||||
PrintAndLogEx(INFO, "Enabled charsets: %s%s",
|
||||
enable_digits ? "digits " : "",
|
||||
enable_uppercase ? "uppercase " : "");
|
||||
|
||||
}
|
||||
|
||||
CLIParserFree(ctx);
|
||||
|
||||
// 27 passwords/second (empirical value)
|
||||
const int speed = 27;
|
||||
int no_iter = 0;
|
||||
|
||||
if (etd.bruteforce_mode == BRUTEFORCE_MODE_RANGE) {
|
||||
no_iter = etd.password2 - etd.password1 + 1;
|
||||
PrintAndLogEx(INFO, "Trying " _YELLOW_("%i") " passwords in range [0x%08x, 0x%08x]"
|
||||
, no_iter
|
||||
, etd.password1
|
||||
, etd.password2
|
||||
);
|
||||
} else if (etd.bruteforce_mode == BRUTEFORCE_MODE_CHARSET) {
|
||||
unsigned int digits = 0;
|
||||
|
||||
if (etd.bruteforce_charset & CHARSET_DIGITS)
|
||||
digits += CHARSET_DIGITS_SIZE;
|
||||
|
||||
if (etd.bruteforce_charset & CHARSET_UPPERCASE)
|
||||
digits += CHARSET_UPPERCASE_SIZE;
|
||||
|
||||
no_iter = pow(digits, 4);
|
||||
}
|
||||
|
||||
// print some information
|
||||
int no_iter = etd.password2 - etd.password1 + 1;
|
||||
int dur_s = no_iter / speed;
|
||||
int dur_h = dur_s / 3600;
|
||||
int dur_m = (dur_s - dur_h * 3600) / 60;
|
||||
|
||||
dur_s -= dur_h * 3600 + dur_m * 60;
|
||||
PrintAndLogEx(INFO, "Trying " _YELLOW_("%i") " passwords in range [0x%08x, 0x%08x]"
|
||||
, no_iter
|
||||
, etd.password1
|
||||
, etd.password2
|
||||
);
|
||||
|
||||
PrintAndLogEx(INFO, "Estimated duration: %ih %im %is", dur_h, dur_m, dur_s);
|
||||
|
||||
// start
|
||||
@@ -1190,7 +1255,7 @@ int CmdEM4x50Sim(const char *Cmd) {
|
||||
static command_t CommandTable[] = {
|
||||
{"help", CmdHelp, AlwaysAvailable, "This help"},
|
||||
{"-----------", CmdHelp, AlwaysAvailable, "--------------------- " _CYAN_("operations") " ---------------------"},
|
||||
{"brute", CmdEM4x50Brute, IfPm3EM4x50, "Simple bruteforce attack to find password"},
|
||||
{"brute", CmdEM4x50Brute, IfPm3EM4x50, "Bruteforce attack to find password"},
|
||||
{"chk", CmdEM4x50Chk, IfPm3EM4x50, "Check passwords from dictionary"},
|
||||
{"dump", CmdEM4x50Dump, IfPm3EM4x50, "Dump EM4x50 tag"},
|
||||
{"info", CmdEM4x50Info, IfPm3EM4x50, "Tag information"},
|
||||
|
||||
+10
-4
@@ -68,15 +68,20 @@ static int usart_txrx(uint8_t *srcdata, size_t srclen, uint8_t *dstdata, size_t
|
||||
struct payload_header header;
|
||||
uint8_t data[PM3_CMD_DATA_SIZE - sizeof(uint32_t)];
|
||||
} PACKED payload;
|
||||
|
||||
payload.header.waittime = waittime;
|
||||
if (srclen >= sizeof(payload.data))
|
||||
|
||||
if (srclen >= sizeof(payload.data)) {
|
||||
return PM3_EOVFLOW;
|
||||
}
|
||||
|
||||
memcpy(payload.data, srcdata, srclen);
|
||||
SendCommandNG(CMD_USART_TXRX, (uint8_t *)&payload, srclen + sizeof(payload.header));
|
||||
PacketResponseNG resp;
|
||||
if (!WaitForResponseTimeout(CMD_USART_TXRX, &resp, waittime + 500)) {
|
||||
if (WaitForResponseTimeout(CMD_USART_TXRX, &resp, waittime + 500) == false) {
|
||||
return PM3_ETIMEOUT;
|
||||
}
|
||||
|
||||
if (resp.status == PM3_SUCCESS) {
|
||||
*dstlen = resp.length;
|
||||
memcpy(dstdata, resp.data.asBytes, resp.length);
|
||||
@@ -154,10 +159,11 @@ static int usart_bt_testcomm(uint32_t baudrate, uint8_t parity) {
|
||||
|
||||
PrintAndLogEx(SUCCESS, "TX (%3zu):%.*s at %u 8%c1", strlen(string), (int)strlen(string), string, baudrate, parity);
|
||||
|
||||
ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000); // such large timeout needed
|
||||
// 1000, such large timeout needed
|
||||
ret = usart_txrx((uint8_t *)string, strlen(string), data, &len, 1000);
|
||||
if (ret == PM3_SUCCESS) {
|
||||
PrintAndLogEx(SUCCESS, "RX (%3zu):%.*s", len, (int)len, data);
|
||||
if (strcmp((char *)data, "hc01.comV2.0") == 0) {
|
||||
if (str_startswith((char *)data, "hc01.comV2.0") || str_startswith((char *)data, "BT SPP V3.0")) {
|
||||
PrintAndLogEx(SUCCESS, "Add-on " _GREEN_("found!"));
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
+6
-3
@@ -30,8 +30,8 @@
|
||||
#include "util_posix.h" // msclock
|
||||
#include "util_darwin.h" // en/dis-ableNapp();
|
||||
|
||||
//#define COMMS_DEBUG
|
||||
//#define COMMS_DEBUG_RAW
|
||||
// #define COMMS_DEBUG
|
||||
// #define COMMS_DEBUG_RAW
|
||||
|
||||
// Serial port that we are communicating with the PM3 on.
|
||||
static serial_port sp = NULL;
|
||||
@@ -369,6 +369,7 @@ __attribute__((force_align_arg_pointer))
|
||||
}
|
||||
|
||||
res = uart_receive(sp, (uint8_t *)&rx_raw.pre, sizeof(PacketResponseNGPreamble), &rxlen);
|
||||
|
||||
if ((res == PM3_SUCCESS) && (rxlen == sizeof(PacketResponseNGPreamble))) {
|
||||
rx.magic = rx_raw.pre.magic;
|
||||
uint16_t length = rx_raw.pre.length;
|
||||
@@ -380,6 +381,7 @@ __attribute__((force_align_arg_pointer))
|
||||
PrintAndLogEx(WARNING, "Received packet frame with incompatible length: 0x%04x", length);
|
||||
error = true;
|
||||
}
|
||||
|
||||
if ((!error) && (length > 0)) { // Get the variable length payload
|
||||
|
||||
res = uart_receive(sp, (uint8_t *)&rx_raw.data, length, &rxlen);
|
||||
@@ -418,10 +420,10 @@ __attribute__((force_align_arg_pointer))
|
||||
rx.length = 0; // set received length to 0
|
||||
else { // old frames can't be empty
|
||||
PrintAndLogEx(WARNING, "Received empty MIX packet frame (length: 0x00)");
|
||||
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!error) { // Get the postamble
|
||||
res = uart_receive(sp, (uint8_t *)&rx_raw.foopost, sizeof(PacketResponseNGPostamble), &rxlen);
|
||||
if ((res != PM3_SUCCESS) || (rxlen != sizeof(PacketResponseNGPostamble))) {
|
||||
@@ -429,6 +431,7 @@ __attribute__((force_align_arg_pointer))
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!error) { // Check CRC, accept MAGIC as placeholder
|
||||
rx.crc = rx_raw.foopost.crc;
|
||||
if (rx.crc != RESPONSENG_POSTAMBLE_MAGIC) {
|
||||
|
||||
@@ -805,7 +805,7 @@ int createMfcKeyDump(const char *preferredName, uint8_t sectorsCnt, sector_t *e_
|
||||
fflush(f);
|
||||
fclose(f);
|
||||
PrintAndLogEx(SUCCESS, "Found keys have been dumped to " _YELLOW_("%s"), fileName);
|
||||
PrintAndLogEx(INFO, "FYI! --> " _YELLOW_("0xFFFFFFFFFFFF") " <-- has been inserted for unknown keys where " _YELLOW_("res") " is " _YELLOW_("0"));
|
||||
PrintAndLogEx(INFO, "FYI! --> " _YELLOW_("0xFFFFFFFFFFFF") " <-- has been inserted for unknown keys where " _YELLOW_("res") " is " _RED_("0"));
|
||||
free(fileName);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -530,7 +530,7 @@ uint8_t mfSectorTrailerOfSector(uint8_t sectorNo) {
|
||||
}
|
||||
|
||||
// assumes blockno is 0-255..
|
||||
uint8_t mfSectorTrailer(uint8_t blockNo) {
|
||||
uint8_t mfSectorTrailer(uint16_t blockNo) {
|
||||
if (blockNo < 32 * 4) {
|
||||
return (blockNo | 0x03);
|
||||
} else {
|
||||
@@ -539,15 +539,15 @@ uint8_t mfSectorTrailer(uint8_t blockNo) {
|
||||
}
|
||||
|
||||
// assumes blockno is 0-255..
|
||||
bool mfIsSectorTrailer(uint8_t blockNo) {
|
||||
bool mfIsSectorTrailer(uint16_t blockNo) {
|
||||
return (blockNo == mfSectorTrailer(blockNo));
|
||||
}
|
||||
|
||||
// assumes blockno is 0-255..
|
||||
uint8_t mfSectorNum(uint8_t blockNo) {
|
||||
uint8_t mfSectorNum(uint16_t blockNo) {
|
||||
if (blockNo < 32 * 4)
|
||||
return blockNo / 4;
|
||||
return (blockNo / 4);
|
||||
else
|
||||
return 32 + (blockNo - 32 * 4) / 16;
|
||||
return (32 + (blockNo - 32 * 4) / 16);
|
||||
|
||||
}
|
||||
@@ -77,9 +77,9 @@ const char *mfGetAccessConditionsDesc(uint8_t blockn, const uint8_t *data);
|
||||
uint8_t mfNumBlocksPerSector(uint8_t sectorNo);
|
||||
uint8_t mfFirstBlockOfSector(uint8_t sectorNo);
|
||||
uint8_t mfSectorTrailerOfSector(uint8_t sectorNo);
|
||||
uint8_t mfSectorTrailer(uint8_t blockNo);
|
||||
bool mfIsSectorTrailer(uint8_t blockNo);
|
||||
uint8_t mfSectorNum(uint8_t blockNo);
|
||||
uint8_t mfSectorTrailer(uint16_t blockNo);
|
||||
bool mfIsSectorTrailer(uint16_t blockNo);
|
||||
uint8_t mfSectorNum(uint16_t blockNo);
|
||||
|
||||
|
||||
#endif // mifare4.h
|
||||
@@ -45,7 +45,10 @@ static const uint64_t g_mifare_default_keys[] = {
|
||||
0xffffffffffff, // Default key (first key used by program if no user defined key)
|
||||
0xa0a1a2a3a4a5, // NFCForum MAD key
|
||||
0xd3f7d3f7d3f7, // NDEF public key
|
||||
0x4b791bea7bcc, // MFC EV1 Signature B
|
||||
0x4b791bea7bcc, // MFC EV1 Signature 17 B
|
||||
0x5C8FF9990DA2, // MFC EV1 Signature 16 A
|
||||
0xD01AFEEB890A, // MFC EV1 Signature 16 B
|
||||
0x75CCB59C9BED, // MFC EV1 Signature 17 A
|
||||
0xfc00018778f7, // Public Transport
|
||||
0x6471a5ef2d1a, // SimonsVoss
|
||||
0x4E3552426B32, // ID06
|
||||
@@ -72,6 +75,11 @@ static const uint64_t g_mifare_default_keys[] = {
|
||||
0x199404281998, // NSP B
|
||||
0x6A1987C40A21, // SALTO
|
||||
0x7F33625BC129, // SALTO
|
||||
0x484944204953, // HID
|
||||
0x204752454154, // HID
|
||||
0x3B7E4FD575AD, // HID
|
||||
0x11496F97752A, // HID
|
||||
0x3E65E4FB65B3, // Gym
|
||||
0x000000000000, // Blank key
|
||||
0xb0b1b2b3b4b5,
|
||||
0xaabbccddeeff,
|
||||
|
||||
@@ -285,6 +285,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
|
||||
// Try to retrieve the old (current) terminal info struct
|
||||
if (tcgetattr(sp->fd, &sp->tiOld) == -1) {
|
||||
PrintAndLogEx(ERR, "error: UART get terminal info attribute");
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
@@ -305,6 +306,8 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
|
||||
// Try to set the new terminal info struct
|
||||
if (tcsetattr(sp->fd, TCSANOW, &sp->tiNew) == -1) {
|
||||
PrintAndLogEx(ERR, "error: UART set terminal info attribute");
|
||||
perror("tcsetattr() error");
|
||||
uart_close(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
@@ -98,6 +98,7 @@ serial_port uart_open(const char *pcPortName, uint32_t speed) {
|
||||
free(prefix);
|
||||
|
||||
if (strlen(pcPortName) <= 4) {
|
||||
PrintAndLogEx(ERR, "error: tcp port name length too short");
|
||||
free(sp);
|
||||
return INVALID_SERIAL_PORT;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user