Merge branch 'master' of https://github.com/klks/proxmark3
This commit is contained in:
commit
cec95558df
59 files changed
+5852
-2261
No files matched your search
@@ -467,7 +467,7 @@ static int CmdFlashMemSpiFFSWipe(const char *Cmd) {
|
||||
CLIParserInit(&ctx, "mem spiffs wipe",
|
||||
_RED_("* * * Warning * * *") " \n"
|
||||
_CYAN_("This command wipes all files on the device SPIFFS file system"),
|
||||
"mem spiffs wipe");
|
||||
"mem spiffs wipe");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
|
||||
@@ -3025,7 +3025,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
int16_t fsci = card.ats[1] & 0x0f;
|
||||
|
||||
PrintAndLogEx(INFO, " ..." _YELLOW_("%02X") "............ T0 TA1 is%s present, TB1 is%s present, "
|
||||
"TC1 is%s present, FSCI is %d (FSC = %d)",
|
||||
"TC1 is%s present, FSCI is %d (FSC = %d)",
|
||||
card.ats[1],
|
||||
(ta1 ? "" : _RED_(" NOT")),
|
||||
(tb1 ? "" : _RED_(" NOT")),
|
||||
@@ -3047,7 +3047,7 @@ int infoHF14A(bool verbose, bool do_nack_test, bool do_aid_search) {
|
||||
if (strlen(ds) != 0) ds[strlen(ds) - 2] = '\0';
|
||||
if (strlen(dr) != 0) dr[strlen(dr) - 2] = '\0';
|
||||
PrintAndLogEx(INFO, " ......" _YELLOW_("%02X") "......... TA1 different divisors are%s supported, "
|
||||
"DR: [%s], DS: [%s]",
|
||||
"DR: [%s], DS: [%s]",
|
||||
card.ats[pos],
|
||||
((card.ats[pos] & 0x80) ? _RED_(" NOT") : ""),
|
||||
dr,
|
||||
|
||||
+2316
-1010
File diff suppressed because it is too large.
Load diff
+20
-20
@@ -70,8 +70,8 @@
|
||||
#define FELICA_SYSTEM_CODE_FELICA_LITE 0x88B4U
|
||||
#define FELICA_POLL_REQUEST_NO_DATA 0x00U
|
||||
#define FELICA_POLL_REQUEST_SYSTEM_CODE 0x01U
|
||||
#define FELICA_SYSTEM_LIST_JSON "felica_system_code_list"
|
||||
#define FELICA_IC_CODE_LIST_JSON "felica_ic_code_list"
|
||||
#define FELICA_SYSTEM_LIST_JSON "felica/felica_system_code_list"
|
||||
#define FELICA_IC_CODE_LIST_JSON "felica/felica_ic_code_list"
|
||||
|
||||
#define FELICA_SERVICE_ATTRIBUTE_UNAUTH_READ (0b000001)
|
||||
#define FELICA_SERVICE_ATTRIBUTE_READ_ONLY (0b000010)
|
||||
@@ -350,10 +350,10 @@ static void print_status_flag1_interpretation(void) {
|
||||
PrintAndLogEx(INFO, "----+--------------------------------------------------------------------------------------------------------------------");
|
||||
PrintAndLogEx(INFO, " 00 | Indicates the successful completion of a command.");
|
||||
PrintAndLogEx(INFO, " FF | If an error occurs during the processing of a command that includes no list in the command packet, \n"
|
||||
" | or if an error occurs independently of any list, the card returns a response by setting FFh to Status Flag1.");
|
||||
" | or if an error occurs independently of any list, the card returns a response by setting FFh to Status Flag1.");
|
||||
PrintAndLogEx(INFO, " XX | If an error occurs while processing a command that includes Service Code List or Block List \n"
|
||||
" | in the command packet, the card returns a response by setting a number in the list to Status Flag1,\n"
|
||||
" | indicating the location of the error.");
|
||||
" | in the command packet, the card returns a response by setting a number in the list to Status Flag1,\n"
|
||||
" | indicating the location of the error.");
|
||||
PrintAndLogEx(INFO, "----+--------------------------------------------------------------------------------------------------------------------");
|
||||
}
|
||||
|
||||
@@ -362,28 +362,28 @@ static void print_status_flag2_interpration(void) {
|
||||
PrintAndLogEx(INFO, "----+--------------------------------------------------------------------------------------------------------------------");
|
||||
PrintAndLogEx(INFO, " 00 | Indicates the successful completion of a command.");
|
||||
PrintAndLogEx(INFO, " 01 | The calculated result is either less than zero when the purse data is decremented, or exceeds 4\n"
|
||||
" | Bytes when the purse data is incremented.");
|
||||
" | Bytes when the purse data is incremented.");
|
||||
PrintAndLogEx(INFO, " 02 | The specified data exceeds the value of cashback data at cashback of purse.");
|
||||
PrintAndLogEx(INFO, " 70 | Memory error (fatal error).");
|
||||
PrintAndLogEx(INFO, " 71 | The number of memory rewrites exceeds the upper limit (this is only a warning; data writing is performed as normal).\n"
|
||||
" | The maximum number of rewrites can differ, depending on the product being used.\n"
|
||||
" | In addition, Status Flag1 is either 00h or FFh depending on the product being used.");
|
||||
" | The maximum number of rewrites can differ, depending on the product being used.\n"
|
||||
" | In addition, Status Flag1 is either 00h or FFh depending on the product being used.");
|
||||
|
||||
PrintAndLogEx(INFO, " A1 | Illegal Number of Service| Number of Service or Number of Node specified by the command \n"
|
||||
" | falls outside the range of the prescribed value.");
|
||||
" | falls outside the range of the prescribed value.");
|
||||
PrintAndLogEx(INFO, " A2 | Illegal command packet (specified Number of Block) : Number of Block specified by the \n"
|
||||
" | command falls outside the range of the prescribed values for the product.");
|
||||
" | command falls outside the range of the prescribed values for the product.");
|
||||
PrintAndLogEx(INFO, " A3 | Illegal Block List (specified order of Service) : Service Code List Order specified by \n"
|
||||
" | Block List Element falls outside the Number of Service specified by the command \n"
|
||||
" | (or the Number of Service specified at the times of mutual authentication).");
|
||||
" | Block List Element falls outside the Number of Service specified by the command \n"
|
||||
" | (or the Number of Service specified at the times of mutual authentication).");
|
||||
PrintAndLogEx(INFO, " A4 | Illegal Service type : Area Attribute specified by the command or Service Attribute of Service Code is incorrect.");
|
||||
PrintAndLogEx(INFO, " A5 | Access is not allowed : Area or Service specified by the command cannot be accessed.\n"
|
||||
" | The parameter specified by the command does not satisfy the conditions for success.");
|
||||
" | The parameter specified by the command does not satisfy the conditions for success.");
|
||||
PrintAndLogEx(INFO, " A6 | Illegal Service Code List : Target to be accessed, identified by Service Code List Order, specified by Block\n"
|
||||
" | List Element does not exist. Or, Node specified by Node Code List does not exist.");
|
||||
" | List Element does not exist. Or, Node specified by Node Code List does not exist.");
|
||||
PrintAndLogEx(INFO, " A7 | Illegal Block List (Access Mode) : Access Mode specified by Block List Element is incorrect.");
|
||||
PrintAndLogEx(INFO, " A8 | Illegal Block Number Block Number (access to the specified data is inhibited) :\n"
|
||||
" | specified by Block List Element exceeds the number of Blocks assigned to Service.");
|
||||
" | specified by Block List Element exceeds the number of Blocks assigned to Service.");
|
||||
PrintAndLogEx(INFO, " A9 | Data write failure : This is the error that occurs in issuance commands.");
|
||||
PrintAndLogEx(INFO, " AA | Key-change failure : Key change failed.");
|
||||
PrintAndLogEx(INFO, " AB | Illegal Package Parity or illegal Package MAC : This is the error that occurs in issuance commands.");
|
||||
@@ -391,7 +391,7 @@ static void print_status_flag2_interpration(void) {
|
||||
PrintAndLogEx(INFO, " AD | Service exists already : This is the error that occurs in issuance commands.");
|
||||
PrintAndLogEx(INFO, " AE | Illegal System Code : This is the error that occurs in issuance commands.");
|
||||
PrintAndLogEx(INFO, " AF | Too many simultaneous cyclic write operations : Number of simultaneous write Blocks\n"
|
||||
" | specified by the command to Cyclic Service exceeds the number of Blocks assigned to Service.");
|
||||
" | specified by the command to Cyclic Service exceeds the number of Blocks assigned to Service.");
|
||||
PrintAndLogEx(INFO, " C0 | Illegal Package Identifier : This is the error that occurs in issuance commands.");
|
||||
PrintAndLogEx(INFO, " C1 | Discrepancy of parameters inside and outside Package : This is the error that occurs in issuance commands.");
|
||||
PrintAndLogEx(INFO, " C2 | Command is disabled already : This is the error that occurs in issuance commands.");
|
||||
@@ -415,16 +415,16 @@ static void print_number_of_service_constraints(void) {
|
||||
|
||||
static void print_number_of_block_constraints(void) {
|
||||
PrintAndLogEx(INFO, " - Number of Block: shall be less than or equal to the maximum number of Blocks that can be read simultaneously.\n"
|
||||
" The maximum number of Blocks that can be read simultaneously can differ, depending on the product being used.\n"
|
||||
" Use as default 01");
|
||||
" The maximum number of Blocks that can be read simultaneously can differ, depending on the product being used.\n"
|
||||
" Use as default 01");
|
||||
}
|
||||
|
||||
static void print_service_code_list_constraints(void) {
|
||||
PrintAndLogEx(INFO, " - Service Code List: For Service Code List, only Service Code existing in the product shall be specified:");
|
||||
PrintAndLogEx(INFO, " - Even when Service Code exists in the product, Service Code not referenced from Block List shall not \n"
|
||||
" be specified to Service Code List.");
|
||||
" be specified to Service Code List.");
|
||||
PrintAndLogEx(INFO, " - For existence or nonexistence of Service in a product, please check using the Request Service \n"
|
||||
" (or Request Service v2) command.");
|
||||
" (or Request Service v2) command.");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -381,7 +381,7 @@ static int hfgal_create_creds_app(DesfireContext_t *ctx, uint8_t *site_key, uint
|
||||
// UID is required for key diversification
|
||||
if (ctx->uidlen == 0) {
|
||||
PM3_RET_ERR(PM3_EINVARG, "UID is required for key diversification. "
|
||||
"Please fetch it before calling `hfgal_create_creds_app`");
|
||||
"Please fetch it before calling `hfgal_create_creds_app`");
|
||||
}
|
||||
|
||||
// Create application
|
||||
@@ -871,11 +871,11 @@ static int hfgal_read_desfire_card(uint32_t aid, uint8_t *site_key, bool verbose
|
||||
PM3_RET_IF_ERR_MAYBE_MSG(res, !quiet, "Failed reading card application credentials");
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Gallagher (AID %06X) - region: " _GREEN_("%c") " ( " _GREEN_("%u") " )"
|
||||
", facility: " _GREEN_("%u")
|
||||
", card number: " _GREEN_("%u")
|
||||
", issue level: " _GREEN_("%u"),
|
||||
", facility: " _GREEN_("%u")
|
||||
", card number: " _GREEN_("%u")
|
||||
", issue level: " _GREEN_("%u"),
|
||||
current_aid,
|
||||
'A' + creds.region_code,
|
||||
'A' + creds.region_code,
|
||||
creds.region_code,
|
||||
creds.facility_code,
|
||||
creds.card_number,
|
||||
@@ -1696,10 +1696,10 @@ static int CmdGallagherDecode(const char *cmd) {
|
||||
gallagher_decode_creds(data_buf, &creds);
|
||||
|
||||
PrintAndLogEx(SUCCESS, "Gallagher - region: " _GREEN_("%c") " ( " _GREEN_("%u") " )"
|
||||
", facility: " _GREEN_("%u")
|
||||
", card number: " _GREEN_("%u")
|
||||
", issue level: " _GREEN_("%u"),
|
||||
'A' + creds.region_code,
|
||||
", facility: " _GREEN_("%u")
|
||||
", card number: " _GREEN_("%u")
|
||||
", issue level: " _GREEN_("%u"),
|
||||
'A' + creds.region_code,
|
||||
creds.region_code,
|
||||
creds.facility_code,
|
||||
creds.card_number,
|
||||
|
||||
@@ -352,7 +352,7 @@ static int decode_and_print_memory(uint16_t card_size, const uint8_t *input_buff
|
||||
// for printing the complete segment we need at least wrc + wrp_len + remain_seg_payload_len bytes
|
||||
if ((i + wrc + wrp_len + remain_seg_payload_len) > card_size) {
|
||||
PrintAndLogEx(FAILED, "Cannot read segment body, because the input buffer is too small. "
|
||||
"Please check that the data is correct and properly aligned. ");
|
||||
"Please check that the data is correct and properly aligned. ");
|
||||
return_value = PM3_EOUTOFBOUND;
|
||||
goto out;
|
||||
}
|
||||
@@ -436,7 +436,7 @@ static int decode_and_print_memory(uint16_t card_size, const uint8_t *input_buff
|
||||
// for printing the complete segment we need at least wrc + wrp_len + remain_seg_payload_len bytes
|
||||
if ((i + wrc + wrp_len + remain_seg_payload_len) > card_size) {
|
||||
PrintAndLogEx(FAILED, "Cannot read segment body, because the input buffer is too small. "
|
||||
"Please check that the data is correct and properly aligned. ");
|
||||
"Please check that the data is correct and properly aligned. ");
|
||||
return_value = PM3_EOUTOFBOUND;
|
||||
goto out;
|
||||
}
|
||||
@@ -607,7 +607,7 @@ static int CmdLegicSim(const char *Cmd) {
|
||||
"If a file is supplied, it is loaded into emulator memory first.",
|
||||
"hf legic sim --22\n"
|
||||
"hf legic sim -f myfile.bin --1024\n"
|
||||
);
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
|
||||
+38
-13
@@ -33,6 +33,7 @@
|
||||
#include "cmdhfcalypso.h"
|
||||
#include "mifare/mifaredefault.h" // mifare consts
|
||||
#include "cmdhfseos.h"
|
||||
#include "iso7816/apduinfo.h"
|
||||
|
||||
enum MifareAuthSeq {
|
||||
masNone,
|
||||
@@ -1034,24 +1035,48 @@ static bool annotateCalypsoApdu(char *exp, size_t size, const uint8_t *apdu, siz
|
||||
return false;
|
||||
}
|
||||
|
||||
uint8_t ins = apdu[1];
|
||||
uint8_t p1 = apdu[2];
|
||||
uint8_t p2 = apdu[3];
|
||||
uint8_t decoded_data[1024] = {0};
|
||||
APDU_t decoded = {0};
|
||||
bool decoded_ok = false;
|
||||
if (apdu_len <= sizeof(decoded_data)) {
|
||||
memcpy(decoded_data, apdu, apdu_len);
|
||||
decoded_ok = APDUDecode(decoded_data, (int)apdu_len, &decoded) == 0;
|
||||
if (decoded_ok == false && apdu_len > 2) {
|
||||
decoded_ok = APDUDecode(decoded_data, (int)(apdu_len - 2), &decoded) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t ins = decoded_ok ? decoded.ins : apdu[1];
|
||||
uint8_t p1 = decoded_ok ? decoded.p1 : apdu[2];
|
||||
uint8_t p2 = decoded_ok ? decoded.p2 : apdu[3];
|
||||
|
||||
switch (ins) {
|
||||
case CALYPSO_SELECT: {
|
||||
if (p1 == 0x04) {
|
||||
if (decoded_ok && (p1 == 0x00 || p1 == 0x08 || p1 == 0x09)) {
|
||||
char ref[64] = "current DF"; // Select for empty LID implies current DF
|
||||
if (decoded.lc == 2) {
|
||||
uint16_t fid = (decoded.data[0] << 8) | decoded.data[1];
|
||||
if (fid == 0x3F00) {
|
||||
snprintf(ref, sizeof(ref), "MF");
|
||||
} else if (fid != 0x0000) {
|
||||
snprintf(ref, sizeof(ref), p1 == 0x08 ? "path=%04X" : "lid=%04X", fid);
|
||||
}
|
||||
} else if (decoded.lc > 0) {
|
||||
snprintf(ref, sizeof(ref), p1 == 0x08 ? "path=%s" : "data=%s", sprint_hex_inrow(decoded.data, decoded.lc));
|
||||
}
|
||||
snprintf(exp, size, "SELECT FILE (%s)", ref);
|
||||
} else if (p1 == 0x04) {
|
||||
const char *mode = (p2 == 0x02 || p2 == 0x0E) ? "next" : "first";
|
||||
const char *fci = (p2 == 0x0C || p2 == 0x0E) ? "none" : "return";
|
||||
snprintf(exp, size, "SELECT APPLICATION (mode=%s, fci=%s)", mode, fci);
|
||||
const char *fci = (p2 == 0x0C || p2 == 0x0E) ? "N" : "Y";
|
||||
if (decoded_ok && decoded.lc > 0) {
|
||||
snprintf(exp, size, "SELECT APP (aid=%s, mode=%s, fci=%s)", sprint_hex_inrow(decoded.data, decoded.lc), mode, fci);
|
||||
} else {
|
||||
snprintf(exp, size, "SELECT APP (mode=%s, fci=%s)", mode, fci);
|
||||
}
|
||||
} else if (p1 == 0x02 && (p2 == 0x00 || p2 == 0x02)) {
|
||||
snprintf(exp, size, "SELECT FILE");
|
||||
} else if (p1 == 0x09 && p2 == 0x00) {
|
||||
snprintf(exp, size, "SELECT FILE (current DF)");
|
||||
} else if (p1 == 0x00) {
|
||||
snprintf(exp, size, "SELECT FILE (by file id)");
|
||||
} else if (p1 == 0x08) {
|
||||
snprintf(exp, size, "SELECT FILE (by path)");
|
||||
snprintf(exp, size, p2 == 0x02 ? "SELECT FILE (next EF)" : "SELECT FILE (first EF)");
|
||||
} else if (p1 == 0x03) {
|
||||
snprintf(exp, size, "SELECT FILE (parent DF)");
|
||||
} else {
|
||||
snprintf(exp, size, "SELECT");
|
||||
}
|
||||
|
||||
@@ -5050,7 +5050,7 @@ void printKeyTableEx(size_t sectorscnt, sector_t *e_sector, uint8_t start_sector
|
||||
_YELLOW_("H") ":Hardnested / "
|
||||
_YELLOW_("C") ":statiCnested / "
|
||||
_YELLOW_("A") ":keyA "
|
||||
" )"
|
||||
" )"
|
||||
);
|
||||
if (sectorscnt == 18) {
|
||||
PrintAndLogEx(INFO, "( " _MAGENTA_("*") " ) These sectors used for signature. Lays outside of user memory");
|
||||
|
||||
@@ -9234,7 +9234,7 @@ static int CmdHF14ADesVerifyCert(const char *Cmd) {
|
||||
arg_str0(NULL, "fid", "<hex>", "Certificate file ID (1 byte)"), // 15
|
||||
arg_lit0(NULL, "no-auth", "Read certificate file without authentication"), // 16
|
||||
arg_strn(NULL, "ca", "<name|cert|pubkey|path|skip>", 0, MFDES_VERIFYCERT_MAX_CAS,
|
||||
"CA input, or `skip` to skip certificate signature validation. Repeat --ca for multiple entries"), // 17
|
||||
"CA input, or `skip` to skip certificate signature validation. Repeat --ca for multiple entries"), // 17
|
||||
arg_str0(NULL, "keyaid", "<hex>", "Key application ID (default: cert app)"), // 18
|
||||
arg_str0(NULL, "keyisoid", "<hex>", "Key application ISO DF ID (2 bytes)"), // 19
|
||||
arg_str0(NULL, "keydfname", "<hex>", "Key application DF name (default: cert app)"), // 20
|
||||
|
||||
+26
-18
@@ -1236,7 +1236,7 @@ static uint32_t fm11_count_candidate_seed_matches_vec(const fm11_keylist_t *list
|
||||
uint32_t i = 0;
|
||||
for (; i + 4 <= list->count; i += 4) {
|
||||
const union vec probe = VEC_U(list->data[i].seed, list->data[i + 1].seed,
|
||||
list->data[i + 2].seed, list->data[i + 3].seed);
|
||||
list->data[i + 2].seed, list->data[i + 3].seed);
|
||||
const union vec eq = vec_ueq(probe, target);
|
||||
matches += eq.elem.u[0] != 0;
|
||||
matches += eq.elem.u[1] != 0;
|
||||
@@ -1289,7 +1289,7 @@ static int fm11_filter_candidates_by_seed(fm11_keylist_t *list, uint32_t nt, uin
|
||||
uint32_t i = 0;
|
||||
for (; i + 4 <= list->count; i += 4) {
|
||||
const union vec probe = VEC_U(list->data[i].seed, list->data[i + 1].seed,
|
||||
list->data[i + 2].seed, list->data[i + 3].seed);
|
||||
list->data[i + 2].seed, list->data[i + 3].seed);
|
||||
const union vec eq = vec_ueq(probe, target);
|
||||
if (eq.elem.u[0] != 0) {
|
||||
filtered.data[filtered.count++] = list->data[i];
|
||||
@@ -1401,30 +1401,38 @@ static int fm11_intersect_pair(uint32_t nt_a, fm11_keylist_t *a, uint32_t nt_b,
|
||||
fm11_keylist_t fb = {0};
|
||||
for (uint32_t i = 0; i < a->count; i++) {
|
||||
if (((i & 0x3FF) == 0) && kbd_enter_pressed()) {
|
||||
free(bset_a); free(bset_b);
|
||||
fm11_keylist_free(&fa); fm11_keylist_free(&fb);
|
||||
free(bset_a);
|
||||
free(bset_b);
|
||||
fm11_keylist_free(&fa);
|
||||
fm11_keylist_free(&fb);
|
||||
return PM3_EOPABORTED;
|
||||
}
|
||||
if (BSET_TEST(bset_b, a->data[i].seed)) {
|
||||
int res = fm11_keylist_push_seeded(&fa, a->data[i].key, a->data[i].seed);
|
||||
if (res != PM3_SUCCESS) {
|
||||
free(bset_a); free(bset_b);
|
||||
fm11_keylist_free(&fa); fm11_keylist_free(&fb);
|
||||
free(bset_a);
|
||||
free(bset_b);
|
||||
fm11_keylist_free(&fa);
|
||||
fm11_keylist_free(&fb);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint32_t i = 0; i < b->count; i++) {
|
||||
if (((i & 0x3FF) == 0) && kbd_enter_pressed()) {
|
||||
free(bset_a); free(bset_b);
|
||||
fm11_keylist_free(&fa); fm11_keylist_free(&fb);
|
||||
free(bset_a);
|
||||
free(bset_b);
|
||||
fm11_keylist_free(&fa);
|
||||
fm11_keylist_free(&fb);
|
||||
return PM3_EOPABORTED;
|
||||
}
|
||||
if (BSET_TEST(bset_a, b->data[i].seed)) {
|
||||
int res = fm11_keylist_push_seeded(&fb, b->data[i].key, b->data[i].seed);
|
||||
if (res != PM3_SUCCESS) {
|
||||
free(bset_a); free(bset_b);
|
||||
fm11_keylist_free(&fa); fm11_keylist_free(&fb);
|
||||
free(bset_a);
|
||||
free(bset_b);
|
||||
fm11_keylist_free(&fa);
|
||||
fm11_keylist_free(&fb);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
@@ -1462,8 +1470,8 @@ typedef struct {
|
||||
} fm11_seed_bucket_t;
|
||||
|
||||
static int fm11_build_seed_buckets(fm11_keylist_t *a, fm11_keylist_t *b,
|
||||
fm11_seed_bucket_t **buckets_out,
|
||||
uint32_t *bucket_count_out) {
|
||||
fm11_seed_bucket_t **buckets_out,
|
||||
uint32_t *bucket_count_out) {
|
||||
uint32_t *count_a = calloc(UINT16_MAX + 1, sizeof(uint32_t));
|
||||
uint32_t *count_b = calloc(UINT16_MAX + 1, sizeof(uint32_t));
|
||||
if (count_a == NULL || count_b == NULL) {
|
||||
@@ -1763,7 +1771,7 @@ static void fm11_probe_queue_push(fm11_probe_queue_t *q, uint8_t sec, uint8_t kt
|
||||
return;
|
||||
}
|
||||
}
|
||||
q->entries[q->count++] = (fm11_probe_entry_t){.sec = sec, .key_type = kt, .key = key};
|
||||
q->entries[q->count++] = (fm11_probe_entry_t) {.sec = sec, .key_type = kt, .key = key};
|
||||
}
|
||||
|
||||
static uint32_t fm11_accept_found_key_global(
|
||||
@@ -1891,9 +1899,9 @@ static uint32_t fm11_promote_singletons(const iso14a_fm11rf08s_nonces_with_data_
|
||||
}
|
||||
|
||||
static uint32_t fm11_propagate_exact_reused_keys(fm11_keylist_t candidates[FM11RF08S_SECTORS][2],
|
||||
uint64_t keys_found[FM11RF08S_SECTORS][2],
|
||||
bool found_key[FM11RF08S_SECTORS][2],
|
||||
bool promote_inferred) {
|
||||
uint64_t keys_found[FM11RF08S_SECTORS][2],
|
||||
bool found_key[FM11RF08S_SECTORS][2],
|
||||
bool promote_inferred) {
|
||||
uint32_t propagated = 0;
|
||||
if (promote_inferred == false) {
|
||||
return 0;
|
||||
@@ -3121,7 +3129,7 @@ int CmdHF14AMfSEN(const char *Cmd) {
|
||||
fm11_keylist_free(&priority);
|
||||
}
|
||||
|
||||
priority = (fm11_keylist_t){0};
|
||||
priority = (fm11_keylist_t) {0};
|
||||
retval = fm11_build_global_priority_keys(candidates, duplicate_prefix, &priority);
|
||||
if (retval != PM3_SUCCESS) {
|
||||
fm11_keylist_free(&priority);
|
||||
@@ -3256,7 +3264,7 @@ int CmdHF14AMfSEN(const char *Cmd) {
|
||||
snprintf(activity, sizeof(activity), "sec %03u key %c - checking %u candidates", real_sec, kt ? 'B' : 'A', candidates[sec][kt].count);
|
||||
|
||||
fm11_sen_progress(nonce_count, activity, candidates[sec][kt].count,
|
||||
(candidates[sec][kt].count / 2 / FM11RF08S_FCHK_KEYS_PER_SECOND) + 1);
|
||||
(candidates[sec][kt].count / 2 / FM11RF08S_FCHK_KEYS_PER_SECOND) + 1);
|
||||
uint64_t key = 0;
|
||||
int res = fm11_verify_candidates(real_sec, kt, &candidates[sec][kt], &key);
|
||||
if (res == PM3_SUCCESS) {
|
||||
|
||||
+633
-4
@@ -38,6 +38,9 @@
|
||||
#include "preferences.h" // setDeviceDebugLevel
|
||||
#include "crc16.h"
|
||||
#include "crypto/originality.h"
|
||||
#include "util.h"
|
||||
#include <pthread.h>
|
||||
#include <vec/vec.h>
|
||||
|
||||
#define MAX_UL_BLOCKS 0x0F
|
||||
#define MAX_ULC_BLOCKS 0x2F
|
||||
@@ -4882,6 +4885,631 @@ out:
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
//DESBRUTE Translation: C2Pwn
|
||||
|
||||
typedef enum {
|
||||
MFULC_DESBRUTE_LFSR_UNDEF = 0,
|
||||
MFULC_DESBRUTE_LFSR_ULCG = 1,
|
||||
MFULC_DESBRUTE_LFSR_MFC = 2,
|
||||
} mfulc_desbrute_lfsr_t;
|
||||
|
||||
typedef struct {
|
||||
uint32_t start;
|
||||
uint32_t end;
|
||||
int key_mode;
|
||||
bool candidate_in_k1;
|
||||
int var_offset;
|
||||
uint8_t init_ciphertext[8];
|
||||
uint8_t prev_ciphertext[8];
|
||||
uint8_t ciphertext[8];
|
||||
uint64_t init_ip_block;
|
||||
uint64_t prev_ciphertext_be;
|
||||
uint64_t ciphertext_ip_block;
|
||||
uint8_t base_key[16];
|
||||
uint64_t fixed_sk[16];
|
||||
uint64_t cand_sk_base[16];
|
||||
uint64_t cand_sk_contrib[28 * 16];
|
||||
mfulc_desbrute_lfsr_t lfsr_type;
|
||||
bool is_reader_mode;
|
||||
int thread_id;
|
||||
} mfulc_desbrute_thread_args_t;
|
||||
|
||||
typedef struct {
|
||||
volatile bool found;
|
||||
volatile bool aborted;
|
||||
uint32_t found_idx;
|
||||
uint8_t found_key[16];
|
||||
} mfulc_desbrute_shared_t;
|
||||
|
||||
typedef struct {
|
||||
mfulc_desbrute_thread_args_t args;
|
||||
mfulc_desbrute_shared_t *shared;
|
||||
volatile uint32_t progress;
|
||||
volatile bool done;
|
||||
} mfulc_desbrute_worker_args_t;
|
||||
|
||||
static uint64_t mfulc_desbrute_be64(const uint8_t *b) {
|
||||
return ((uint64_t)b[0] << 56) | ((uint64_t)b[1] << 48) |
|
||||
((uint64_t)b[2] << 40) | ((uint64_t)b[3] << 32) |
|
||||
((uint64_t)b[4] << 24) | ((uint64_t)b[5] << 16) |
|
||||
((uint64_t)b[6] << 8) | (uint64_t)b[7];
|
||||
}
|
||||
|
||||
static const uint8_t MFULC_DES_PC1[56] = {
|
||||
57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
|
||||
10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
|
||||
63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
|
||||
14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
|
||||
};
|
||||
|
||||
static const uint8_t MFULC_DES_PC2[48] = {
|
||||
14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
|
||||
23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
|
||||
41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
|
||||
44, 49, 39, 56, 34, 53, 46, 42, 50, 36, 29, 32
|
||||
};
|
||||
|
||||
static const uint8_t MFULC_DES_SHIFTS[16] = {
|
||||
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
|
||||
};
|
||||
|
||||
static const uint8_t MFULC_DES_IP[64] = {
|
||||
58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
|
||||
62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
|
||||
57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
|
||||
61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
|
||||
};
|
||||
|
||||
static const uint8_t MFULC_DES_FP[64] = {
|
||||
40, 8, 48, 16, 56, 24, 64, 32, 39, 7, 47, 15, 55, 23, 63, 31,
|
||||
38, 6, 46, 14, 54, 22, 62, 30, 37, 5, 45, 13, 53, 21, 61, 29,
|
||||
36, 4, 44, 12, 52, 20, 60, 28, 35, 3, 43, 11, 51, 19, 59, 27,
|
||||
34, 2, 42, 10, 50, 18, 58, 26, 33, 1, 41, 9, 49, 17, 57, 25
|
||||
};
|
||||
|
||||
static const uint32_t MFULC_DES_SP[512] = {
|
||||
0x00808200, 0x00000000, 0x00008000, 0x00808202, 0x00808002, 0x00008202, 0x00000002, 0x00008000, 0x00000200, 0x00808200, 0x00808202, 0x00000200, 0x00800202, 0x00808002, 0x00800000, 0x00000002, 0x00000202, 0x00800200, 0x00800200, 0x00008200, 0x00008200, 0x00808000, 0x00808000, 0x00800202, 0x00008002, 0x00800002, 0x00800002, 0x00008002, 0x00000000, 0x00000202, 0x00008202, 0x00800000, 0x00008000, 0x00808202, 0x00000002, 0x00808000, 0x00808200, 0x00800000, 0x00800000, 0x00000200, 0x00808002, 0x00008000, 0x00008200, 0x00800002, 0x00000200, 0x00000002, 0x00800202, 0x00008202, 0x00808202, 0x00008002, 0x00808000, 0x00800202, 0x00800002, 0x00000202, 0x00008202, 0x00808200, 0x00000202, 0x00800200, 0x00800200, 0x00000000, 0x00008002, 0x00008200, 0x00000000, 0x00808002,
|
||||
0x40084010, 0x40004000, 0x00004000, 0x00084010, 0x00080000, 0x00000010, 0x40080010, 0x40004010, 0x40000010, 0x40084010, 0x40084000, 0x40000000, 0x40004000, 0x00080000, 0x00000010, 0x40080010, 0x00084000, 0x00080010, 0x40004010, 0x00000000, 0x40000000, 0x00004000, 0x00084010, 0x40080000, 0x00080010, 0x40000010, 0x00000000, 0x00084000, 0x00004010, 0x40084000, 0x40080000, 0x00004010, 0x00000000, 0x00084010, 0x40080010, 0x00080000, 0x40004010, 0x40080000, 0x40084000, 0x00004000, 0x40080000, 0x40004000, 0x00000010, 0x40084010, 0x00084010, 0x00000010, 0x00004000, 0x40000000, 0x00004010, 0x40084000, 0x00080000, 0x40000010, 0x00080010, 0x40004010, 0x40000010, 0x00080010, 0x00084000, 0x00000000, 0x40004000, 0x00004010, 0x40000000, 0x40080010, 0x40084010, 0x00084000,
|
||||
0x00000104, 0x04010100, 0x00000000, 0x04010004, 0x04000100, 0x00000000, 0x00010104, 0x04000100, 0x00010004, 0x04000004, 0x04000004, 0x00010000, 0x04010104, 0x00010004, 0x04010000, 0x00000104, 0x04000000, 0x00000004, 0x04010100, 0x00000100, 0x00010100, 0x04010000, 0x04010004, 0x00010104, 0x04000104, 0x00010100, 0x00010000, 0x04000104, 0x00000004, 0x04010104, 0x00000100, 0x04000000, 0x04010100, 0x04000000, 0x00010004, 0x00000104, 0x00010000, 0x04010100, 0x04000100, 0x00000000, 0x00000100, 0x00010004, 0x04010104, 0x04000100, 0x04000004, 0x00000100, 0x00000000, 0x04010004, 0x04000104, 0x00010000, 0x04000000, 0x04010104, 0x00000004, 0x00010104, 0x00010100, 0x04000004, 0x04010000, 0x04000104, 0x00000104, 0x04010000, 0x00010104, 0x00000004, 0x04010004, 0x00010100,
|
||||
0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x00401040, 0x80400040, 0x80400000, 0x80001000, 0x00000000, 0x00401000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00400040, 0x80400000, 0x80000000, 0x00001000, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x80001000, 0x00001040, 0x80400040, 0x80000000, 0x00001040, 0x00400040, 0x00001000, 0x00401040, 0x80401040, 0x80000040, 0x00400040, 0x80400000, 0x00401000, 0x80401040, 0x80000040, 0x00000000, 0x00000000, 0x00401000, 0x00001040, 0x00400040, 0x80400040, 0x80000000, 0x80401000, 0x80001040, 0x80001040, 0x00000040, 0x80401040, 0x80000040, 0x80000000, 0x00001000, 0x80400000, 0x80001000, 0x00401040, 0x80400040, 0x80001000, 0x00001040, 0x00400000, 0x80401000, 0x00000040, 0x00400000, 0x00001000, 0x00401040,
|
||||
0x00000080, 0x01040080, 0x01040000, 0x21000080, 0x00040000, 0x00000080, 0x20000000, 0x01040000, 0x20040080, 0x00040000, 0x01000080, 0x20040080, 0x21000080, 0x21040000, 0x00040080, 0x20000000, 0x01000000, 0x20040000, 0x20040000, 0x00000000, 0x20000080, 0x21040080, 0x21040080, 0x01000080, 0x21040000, 0x20000080, 0x00000000, 0x21000000, 0x01040080, 0x01000000, 0x21000000, 0x00040080, 0x00040000, 0x21000080, 0x00000080, 0x01000000, 0x20000000, 0x01040000, 0x21000080, 0x20040080, 0x01000080, 0x20000000, 0x21040000, 0x01040080, 0x20040080, 0x00000080, 0x01000000, 0x21040000, 0x21040080, 0x00040080, 0x21000000, 0x21040080, 0x01040000, 0x00000000, 0x20040000, 0x21000000, 0x00040080, 0x01000080, 0x20000080, 0x00040000, 0x00000000, 0x20040000, 0x01040080, 0x20000080,
|
||||
0x10000008, 0x10200000, 0x00002000, 0x10202008, 0x10200000, 0x00000008, 0x10202008, 0x00200000, 0x10002000, 0x00202008, 0x00200000, 0x10000008, 0x00200008, 0x10002000, 0x10000000, 0x00002008, 0x00000000, 0x00200008, 0x10002008, 0x00002000, 0x00202000, 0x10002008, 0x00000008, 0x10200008, 0x10200008, 0x00000000, 0x00202008, 0x10202000, 0x00002008, 0x00202000, 0x10202000, 0x10000000, 0x10002000, 0x00000008, 0x10200008, 0x00202000, 0x10202008, 0x00200000, 0x00002008, 0x10000008, 0x00200000, 0x10002000, 0x10000000, 0x00002008, 0x10000008, 0x10202008, 0x00202000, 0x10200000, 0x00202008, 0x10202000, 0x00000000, 0x10200008, 0x00000008, 0x00002000, 0x10200000, 0x00202008, 0x00002000, 0x00200008, 0x10002008, 0x00000000, 0x10202000, 0x10000000, 0x00200008, 0x10002008,
|
||||
0x00100000, 0x02100001, 0x02000401, 0x00000000, 0x00000400, 0x02000401, 0x00100401, 0x02100400, 0x02100401, 0x00100000, 0x00000000, 0x02000001, 0x00000001, 0x02000000, 0x02100001, 0x00000401, 0x02000400, 0x00100401, 0x00100001, 0x02000400, 0x02000001, 0x02100000, 0x02100400, 0x00100001, 0x02100000, 0x00000400, 0x00000401, 0x02100401, 0x00100400, 0x00000001, 0x02000000, 0x00100400, 0x02000000, 0x00100400, 0x00100000, 0x02000401, 0x02000401, 0x02100001, 0x02100001, 0x00000001, 0x00100001, 0x02000000, 0x02000400, 0x00100000, 0x02100400, 0x00000401, 0x00100401, 0x02100400, 0x00000401, 0x02000001, 0x02100401, 0x02100000, 0x00100400, 0x00000000, 0x00000001, 0x02100401, 0x00000000, 0x00100401, 0x02100000, 0x00000400, 0x02000001, 0x02000400, 0x00000400, 0x00100001,
|
||||
0x08000820, 0x00000800, 0x00020000, 0x08020820, 0x08000000, 0x08000820, 0x00000020, 0x08000000, 0x00020020, 0x08020000, 0x08020820, 0x00020800, 0x08020800, 0x00020820, 0x00000800, 0x00000020, 0x08020000, 0x08000020, 0x08000800, 0x00000820, 0x00020800, 0x00020020, 0x08020020, 0x08020800, 0x00000820, 0x00000000, 0x00000000, 0x08020020, 0x08000020, 0x08000800, 0x00020820, 0x00020000, 0x00020820, 0x00020000, 0x08020800, 0x00000800, 0x00000020, 0x08020020, 0x00000800, 0x00020820, 0x08000800, 0x00000020, 0x08000020, 0x08020000, 0x08020020, 0x08000000, 0x00020000, 0x08000820, 0x00000000, 0x08020820, 0x00020020, 0x08000020, 0x08020000, 0x08000800, 0x08000820, 0x00000000, 0x08020820, 0x00020800, 0x00020800, 0x00000820, 0x00000820, 0x00020020, 0x08000000, 0x08020800
|
||||
};
|
||||
|
||||
static uint64_t mfulc_desbrute_perm(uint64_t src, int src_bits, const uint8_t *tbl, int n) {
|
||||
uint64_t dst = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
int sb = tbl[i] - 1;
|
||||
dst |= ((src >> (src_bits - 1 - sb)) & 1ULL) << (n - 1 - i);
|
||||
}
|
||||
return dst;
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_keyschedule(uint64_t key64, uint64_t sk[16]) {
|
||||
uint64_t key56 = mfulc_desbrute_perm(key64, 64, MFULC_DES_PC1, 56);
|
||||
uint32_t c = (uint32_t)(key56 >> 28) & 0x0FFFFFFF;
|
||||
uint32_t d = (uint32_t)key56 & 0x0FFFFFFF;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
int s = MFULC_DES_SHIFTS[i];
|
||||
c = ((c << s) | (c >> (28 - s))) & 0x0FFFFFFF;
|
||||
d = ((d << s) | (d >> (28 - s))) & 0x0FFFFFFF;
|
||||
sk[i] = mfulc_desbrute_perm(((uint64_t)c << 28) | d, 56, MFULC_DES_PC2, 48);
|
||||
}
|
||||
}
|
||||
|
||||
static uint32_t mfulc_desbrute_f(uint32_t r, uint64_t k) {
|
||||
uint32_t r0 = ((r & 1u) << 5) | ((r >> 27) & 0x1Fu);
|
||||
uint32_t r1 = (r >> 23) & 0x3Fu;
|
||||
uint32_t r2 = (r >> 19) & 0x3Fu;
|
||||
uint32_t r3 = (r >> 15) & 0x3Fu;
|
||||
uint32_t r4 = (r >> 11) & 0x3Fu;
|
||||
uint32_t r5 = (r >> 7) & 0x3Fu;
|
||||
uint32_t r6 = (r >> 3) & 0x3Fu;
|
||||
uint32_t r7 = ((r & 0x1Fu) << 1) | ((r >> 31) & 1u);
|
||||
|
||||
r0 ^= (uint32_t)((k >> 42) & 0x3Fu);
|
||||
r1 ^= (uint32_t)((k >> 36) & 0x3Fu);
|
||||
r2 ^= (uint32_t)((k >> 30) & 0x3Fu);
|
||||
r3 ^= (uint32_t)((k >> 24) & 0x3Fu);
|
||||
r4 ^= (uint32_t)((k >> 18) & 0x3Fu);
|
||||
r5 ^= (uint32_t)((k >> 12) & 0x3Fu);
|
||||
r6 ^= (uint32_t)((k >> 6) & 0x3Fu);
|
||||
r7 ^= (uint32_t)(k & 0x3Fu);
|
||||
|
||||
return MFULC_DES_SP[r0] ^ MFULC_DES_SP[64 + r1] ^ MFULC_DES_SP[128 + r2] ^ MFULC_DES_SP[192 + r3] ^
|
||||
MFULC_DES_SP[256 + r4] ^ MFULC_DES_SP[320 + r5] ^ MFULC_DES_SP[384 + r6] ^ MFULC_DES_SP[448 + r7];
|
||||
}
|
||||
|
||||
static uint64_t mfulc_desbrute_des_rounds(uint64_t ip_block, const uint64_t sk[16], bool decrypt) {
|
||||
uint32_t l = (uint32_t)(ip_block >> 32);
|
||||
uint32_t r = (uint32_t)ip_block;
|
||||
|
||||
for (int i = 0; i < 16; i++) {
|
||||
uint64_t k = decrypt ? sk[15 - i] : sk[i];
|
||||
uint32_t nr = l ^ mfulc_desbrute_f(r, k);
|
||||
l = r;
|
||||
r = nr;
|
||||
}
|
||||
return ((uint64_t)r << 32) | l;
|
||||
}
|
||||
|
||||
static uint64_t mfulc_desbrute_des(uint64_t block, const uint64_t sk[16], bool decrypt) {
|
||||
uint64_t t = mfulc_desbrute_perm(block, 64, MFULC_DES_IP, 64);
|
||||
t = mfulc_desbrute_des_rounds(t, sk, decrypt);
|
||||
return mfulc_desbrute_perm(t, 64, MFULC_DES_FP, 64);
|
||||
}
|
||||
|
||||
static uint64_t mfulc_desbrute_tdea2_dec_ip(uint64_t ip_block, const uint64_t k1_sk[16], const uint64_t k2_sk[16]) {
|
||||
uint64_t t = mfulc_desbrute_des_rounds(ip_block, k1_sk, true);
|
||||
t = mfulc_desbrute_des_rounds(t, k2_sk, false);
|
||||
t = mfulc_desbrute_des_rounds(t, k1_sk, true);
|
||||
return mfulc_desbrute_perm(t, 64, MFULC_DES_FP, 64);
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_format_duration(uint64_t seconds, char *buf, size_t buflen) {
|
||||
unsigned int h = (unsigned int)(seconds / 3600);
|
||||
unsigned int m = (unsigned int)((seconds / 60) % 60);
|
||||
unsigned int s = (unsigned int)(seconds % 60);
|
||||
|
||||
if (h > 99) {
|
||||
snprintf(buf, buflen, ">99h");
|
||||
} else if (h > 0) {
|
||||
snprintf(buf, buflen, "%02u:%02u:%02u", h, m, s);
|
||||
} else {
|
||||
snprintf(buf, buflen, "%02u:%02u", m, s);
|
||||
}
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_progress_bar(double pct, char *buf, size_t buflen) {
|
||||
const int width = 28;
|
||||
int filled = (int)((pct / 100.0) * width);
|
||||
|
||||
if (filled < 0) filled = 0;
|
||||
if (filled > width) filled = width;
|
||||
if (buflen < (size_t)width + 3) {
|
||||
if (buflen > 0) buf[0] = '\0';
|
||||
return;
|
||||
}
|
||||
|
||||
buf[0] = '[';
|
||||
for (int i = 0; i < width; i++) {
|
||||
buf[i + 1] = i < filled ? '#' : '.';
|
||||
}
|
||||
buf[width + 1] = ']';
|
||||
buf[width + 2] = '\0';
|
||||
}
|
||||
|
||||
static const char *mfulc_desbrute_progress_color(double pct) {
|
||||
if (pct >= 90.0) {
|
||||
return "\x1b[32m";
|
||||
}
|
||||
if (pct >= 50.0) {
|
||||
return "\x1b[33m";
|
||||
}
|
||||
return "\x1b[36m";
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_compute_sk_tables(const uint8_t base_half[8], int var_offset, uint64_t sk_base[16], uint64_t sk_contrib[28 * 16]) {
|
||||
uint8_t half[8] = {0};
|
||||
|
||||
memcpy(half, base_half, sizeof(half));
|
||||
half[var_offset] = 0;
|
||||
half[var_offset + 1] = 0;
|
||||
half[var_offset + 2] = 0;
|
||||
half[var_offset + 3] = 0;
|
||||
mfulc_desbrute_keyschedule(mfulc_desbrute_be64(half), sk_base);
|
||||
|
||||
for (int bit = 0; bit < 28; bit++) {
|
||||
uint8_t tmp[8] = {0};
|
||||
int byte_in_half = bit / 7;
|
||||
int bit_in_byte = bit % 7;
|
||||
uint64_t bit_sk[16] = {0};
|
||||
|
||||
tmp[var_offset + byte_in_half] = (uint8_t)(1u << (bit_in_byte + 1));
|
||||
mfulc_desbrute_keyschedule(mfulc_desbrute_be64(tmp), bit_sk);
|
||||
|
||||
for (int round = 0; round < 16; round++) {
|
||||
sk_contrib[(bit * 16) + round] = bit_sk[round];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_make_candidate_sk(const mfulc_desbrute_thread_args_t *args, uint32_t idx, uint64_t cand_sk[16]) {
|
||||
memcpy(cand_sk, args->cand_sk_base, sizeof(args->cand_sk_base));
|
||||
|
||||
for (int bit = 0; bit < 28; bit++) {
|
||||
if ((idx >> bit) & 1u) {
|
||||
const uint64_t *contrib = &args->cand_sk_contrib[bit * 16];
|
||||
for (int round = 0; round < 16; round++) {
|
||||
cand_sk[round] ^= contrib[round];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_update_candidate_sk(const mfulc_desbrute_thread_args_t *args, uint32_t old_idx, uint32_t new_idx, uint64_t cand_sk[16]) {
|
||||
uint32_t changed = old_idx ^ new_idx;
|
||||
|
||||
while (changed != 0) {
|
||||
int bit = __builtin_ctz(changed);
|
||||
const uint64_t *contrib = &args->cand_sk_contrib[bit * 16];
|
||||
|
||||
for (int round = 0; round < 16; round++) {
|
||||
cand_sk[round] ^= contrib[round];
|
||||
}
|
||||
changed &= changed - 1;
|
||||
}
|
||||
}
|
||||
|
||||
static bool mfulc_desbrute_valid_lfsr_ulcg(uint64_t x64) {
|
||||
x64 = BSWAP_64(x64);
|
||||
uint16_t x16 = x64 >> 48;
|
||||
x16 = (uint16_t)(x16 << 15 | ((x16 >> 1) ^ ((x16 >> 3 ^ x16 >> 4 ^ x16 >> 6) & 1)));
|
||||
if (x16 != ((x64 >> 32) & 0xFFFF)) return false;
|
||||
x16 = (uint16_t)(x16 << 15 | ((x16 >> 1) ^ ((x16 >> 3 ^ x16 >> 4 ^ x16 >> 6) & 1)));
|
||||
if (x16 != ((x64 >> 16) & 0xFFFF)) return false;
|
||||
x16 = (uint16_t)(x16 << 15 | ((x16 >> 1) ^ ((x16 >> 3 ^ x16 >> 4 ^ x16 >> 6) & 1)));
|
||||
return x16 == (x64 & 0xFFFF);
|
||||
}
|
||||
|
||||
static bool mfulc_desbrute_valid_lfsr_mfc(uint64_t x64) {
|
||||
x64 = BSWAP_64(x64);
|
||||
uint16_t x16 = x64 & 0xFFFF;
|
||||
for (int i = 0; i < 16; i++) x16 = (uint16_t)(x16 >> 1 | (x16 ^ x16 >> 2 ^ x16 >> 3 ^ x16 >> 5) << 15);
|
||||
if (x16 != ((x64 >> 16) & 0xFFFF)) return false;
|
||||
for (int i = 0; i < 16; i++) x16 = (uint16_t)(x16 >> 1 | (x16 ^ x16 >> 2 ^ x16 >> 3 ^ x16 >> 5) << 15);
|
||||
if (x16 != ((x64 >> 32) & 0xFFFF)) return false;
|
||||
for (int i = 0; i < 16; i++) x16 = (uint16_t)(x16 >> 1 | (x16 ^ x16 >> 2 ^ x16 >> 3 ^ x16 >> 5) << 15);
|
||||
return x16 == ((x64 >> 48) & 0xFFFF);
|
||||
}
|
||||
|
||||
static bool mfulc_desbrute_valid_lfsr(uint64_t x64, mfulc_desbrute_lfsr_t lfsr_type) {
|
||||
switch (lfsr_type) {
|
||||
case MFULC_DESBRUTE_LFSR_ULCG:
|
||||
return mfulc_desbrute_valid_lfsr_ulcg(x64);
|
||||
case MFULC_DESBRUTE_LFSR_MFC:
|
||||
return mfulc_desbrute_valid_lfsr_mfc(x64);
|
||||
case MFULC_DESBRUTE_LFSR_UNDEF:
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
static mfulc_desbrute_lfsr_t mfulc_desbrute_detect_lfsr_type(const uint8_t init_ciphertext[8]) {
|
||||
uint64_t zero_sk[16] = {0};
|
||||
uint64_t x_be;
|
||||
|
||||
mfulc_desbrute_keyschedule(0, zero_sk);
|
||||
x_be = mfulc_desbrute_des(mfulc_desbrute_be64(init_ciphertext), zero_sk, true);
|
||||
uint64_t x = BSWAP_64(x_be);
|
||||
if (mfulc_desbrute_valid_lfsr_ulcg(x)) {
|
||||
return MFULC_DESBRUTE_LFSR_ULCG;
|
||||
}
|
||||
if (mfulc_desbrute_valid_lfsr_mfc(x)) {
|
||||
return MFULC_DESBRUTE_LFSR_MFC;
|
||||
}
|
||||
return MFULC_DESBRUTE_LFSR_UNDEF;
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_fill_candidate(uint8_t key[16], const uint8_t base_key[16], int key_mode, uint32_t idx) {
|
||||
memcpy(key, base_key, 16);
|
||||
int seg_offset = key_mode * 4;
|
||||
key[seg_offset] = (uint8_t)(((idx) & 0x7F) << 1);
|
||||
key[seg_offset + 1] = (uint8_t)(((idx >> 7) & 0x7F) << 1);
|
||||
key[seg_offset + 2] = (uint8_t)(((idx >> 14) & 0x7F) << 1);
|
||||
key[seg_offset + 3] = (uint8_t)(((idx >> 21) & 0x7F) << 1);
|
||||
}
|
||||
|
||||
static void mfulc_desbrute_candidate_batch(uint32_t start, uint32_t idx[4]) {
|
||||
union vec lanes = vec_uadd(vec_u1(start), vec_u(0, 1, 2, 3));
|
||||
for (int i = 0; i < 4; i++) {
|
||||
idx[i] = lanes.elem.u[i];
|
||||
}
|
||||
}
|
||||
|
||||
static bool mfulc_desbrute_test_candidate_sk(const mfulc_desbrute_thread_args_t *args, const uint64_t cand_sk[16]) {
|
||||
uint64_t out_be;
|
||||
const uint64_t *k1_sk;
|
||||
const uint64_t *k2_sk;
|
||||
|
||||
k1_sk = args->candidate_in_k1 ? cand_sk : args->fixed_sk;
|
||||
k2_sk = args->candidate_in_k1 ? args->fixed_sk : cand_sk;
|
||||
out_be = mfulc_desbrute_tdea2_dec_ip(args->ciphertext_ip_block, k1_sk, k2_sk);
|
||||
|
||||
bool match = false;
|
||||
if (args->is_reader_mode) {
|
||||
uint64_t init_be = mfulc_desbrute_tdea2_dec_ip(args->init_ip_block, k1_sk, k2_sk);
|
||||
uint64_t rotated_init_be = (init_be << 8) | (init_be >> 56);
|
||||
|
||||
match = (out_be ^ args->prev_ciphertext_be) == rotated_init_be;
|
||||
} else {
|
||||
match = mfulc_desbrute_valid_lfsr(BSWAP_64(out_be), args->lfsr_type);
|
||||
}
|
||||
return match;
|
||||
}
|
||||
|
||||
static void *mfulc_desbrute_worker(void *arg) {
|
||||
mfulc_desbrute_worker_args_t *ctx = arg;
|
||||
|
||||
uint32_t candidate[4] = {0};
|
||||
uint32_t last_candidate = 0;
|
||||
uint64_t cand_sk[16] = {0};
|
||||
bool have_candidate_sk = false;
|
||||
|
||||
ctx->progress = ctx->args.start;
|
||||
for (uint32_t idx = ctx->args.start; idx < ctx->args.end; idx += 4) {
|
||||
if (ctx->shared->found || ctx->shared->aborted) {
|
||||
break;
|
||||
}
|
||||
if ((idx & 0x3FF) == 0) {
|
||||
ctx->progress = idx;
|
||||
}
|
||||
if (ctx->args.thread_id == 0 && ((idx & 0x3FFFF) == 0) && kbd_enter_pressed()) {
|
||||
ctx->shared->aborted = true;
|
||||
break;
|
||||
}
|
||||
|
||||
mfulc_desbrute_candidate_batch(idx, candidate);
|
||||
for (int lane = 0; lane < 4; lane++) {
|
||||
if (candidate[lane] >= ctx->args.end) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (have_candidate_sk) {
|
||||
mfulc_desbrute_update_candidate_sk(&ctx->args, last_candidate, candidate[lane], cand_sk);
|
||||
} else {
|
||||
mfulc_desbrute_make_candidate_sk(&ctx->args, candidate[lane], cand_sk);
|
||||
have_candidate_sk = true;
|
||||
}
|
||||
last_candidate = candidate[lane];
|
||||
|
||||
if (mfulc_desbrute_test_candidate_sk(&ctx->args, cand_sk)) {
|
||||
ctx->shared->found_idx = candidate[lane];
|
||||
mfulc_desbrute_fill_candidate(ctx->shared->found_key, ctx->args.base_key, ctx->args.key_mode, candidate[lane]);
|
||||
ctx->progress = candidate[lane] + 1;
|
||||
ctx->shared->found = true;
|
||||
ctx->done = true;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
ctx->progress = ctx->shared->found || ctx->shared->aborted ? ctx->progress : ctx->args.end;
|
||||
ctx->done = true;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int CmdHF14AMfUCDesBrute(const char *Cmd) {
|
||||
CLIParserContext *ctx;
|
||||
CLIParserInit(&ctx, "hf mfu desbrute",
|
||||
"Recover one 4-byte segment of a MIFARE Ultralight-C 2TDEA key from known authentication ciphertexts.",
|
||||
"hf mfu desbrute --counterfeit --null F35C740106ECED87 --target E9E0DC67B35919FC --key 00000000000000000000000000000000 --segment 2\n"
|
||||
"hf mfu desbrute --counterfeit --null 49C1603621CCAA72 --target 8122262EF5FA8DEB --key 48444C4A4044524200000000544E5846 --segment 3\n"
|
||||
"hf mfu desbrute --reader --erndb EC9C5CF763244367 --cryptogram 2283BFE8DEBE1780922327794D0706EF --key 48444C4A4044524200000000544E5846 --segment 3");
|
||||
|
||||
void *argtable[] = {
|
||||
arg_param_begin,
|
||||
arg_lit0("c", "counterfeit", "Counterfeit nonce mode: --null and --target are ERndB blocks"),
|
||||
arg_lit0("r", "reader", "Reader nonce mode: --erndb and --cryptogram are sniffed authentication blocks"),
|
||||
arg_str0(NULL, "null", "<hex>", "Null-key ERndB, 8 hex bytes"),
|
||||
arg_str0(NULL, "target", "<hex>", "Target-key ERndB, 8 hex bytes"),
|
||||
arg_str0(NULL, "erndb", "<hex>", "Reader mode ERndB, 8 hex bytes"),
|
||||
arg_str0(NULL, "cryptogram", "<hex>", "Reader mode ERndA|ERndB', 16 hex bytes"),
|
||||
arg_str1("k", "key", "<hex>", "Base 3DES key, 16 hex bytes"),
|
||||
arg_int1("s", "segment", "<1..4>", "4-byte key segment to brute force"),
|
||||
arg_int0("t", "threads", "<n>", "Worker threads (default: all logical CPUs)"),
|
||||
arg_param_end
|
||||
};
|
||||
CLIExecWithReturn(ctx, Cmd, argtable, true);
|
||||
|
||||
bool counterfeit_mode = arg_get_lit(ctx, 1);
|
||||
bool reader_mode = arg_get_lit(ctx, 2);
|
||||
uint8_t init_ciphertext[8] = {0};
|
||||
uint8_t ciphertext[8] = {0};
|
||||
uint8_t prev_ciphertext[8] = {0};
|
||||
uint8_t tmp_blocks[16] = {0};
|
||||
uint8_t base_key[16] = {0};
|
||||
int init_len = 0;
|
||||
int ciphertext_len = 0;
|
||||
int tmp_len = 0;
|
||||
int key_len = 0;
|
||||
|
||||
if (counterfeit_mode) {
|
||||
CLIGetHexWithReturn(ctx, 3, init_ciphertext, &init_len);
|
||||
CLIGetHexWithReturn(ctx, 4, ciphertext, &ciphertext_len);
|
||||
}
|
||||
if (reader_mode) {
|
||||
CLIGetHexWithReturn(ctx, 5, init_ciphertext, &init_len);
|
||||
CLIGetHexWithReturn(ctx, 6, tmp_blocks, &tmp_len);
|
||||
memcpy(prev_ciphertext, tmp_blocks, 8);
|
||||
memcpy(ciphertext, tmp_blocks + 8, 8);
|
||||
}
|
||||
CLIGetHexWithReturn(ctx, 7, base_key, &key_len);
|
||||
int segment = arg_get_int_def(ctx, 8, 0);
|
||||
int threads = arg_get_int_def(ctx, 9, num_CPUs());
|
||||
CLIParserFree(ctx);
|
||||
|
||||
if (counterfeit_mode == reader_mode) {
|
||||
PrintAndLogEx(WARNING, "Select exactly one mode: --counterfeit or --reader");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
if (init_len != 8 || key_len != 16 || (counterfeit_mode && ciphertext_len != 8) || (reader_mode && tmp_len != 16)) {
|
||||
PrintAndLogEx(WARNING, "Invalid input length. Blocks are 8 bytes, reader cryptogram is 16 bytes, key is 16 bytes");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
if (segment < 1 || segment > 4) {
|
||||
PrintAndLogEx(WARNING, "Segment must be 1..4");
|
||||
return PM3_EINVARG;
|
||||
}
|
||||
if (threads < 1) {
|
||||
threads = 1;
|
||||
}
|
||||
int max_threads = num_CPUs();
|
||||
if (threads > max_threads) {
|
||||
PrintAndLogEx(INFO, "Capping threads at available CPU count (%d)", max_threads);
|
||||
threads = max_threads;
|
||||
}
|
||||
|
||||
mfulc_desbrute_lfsr_t lfsr_type = MFULC_DESBRUTE_LFSR_UNDEF;
|
||||
if (counterfeit_mode) {
|
||||
lfsr_type = mfulc_desbrute_detect_lfsr_type(init_ciphertext);
|
||||
if (lfsr_type == MFULC_DESBRUTE_LFSR_UNDEF) {
|
||||
PrintAndLogEx(WARNING, "LFSR detection failed");
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
PrintAndLogEx(INFO, "LFSR detection: %s", lfsr_type == MFULC_DESBRUTE_LFSR_ULCG ? "ULCG" : "MFC (USCUID-UL/FJ8010)");
|
||||
}
|
||||
|
||||
pthread_t *tids = calloc(threads, sizeof(pthread_t));
|
||||
mfulc_desbrute_worker_args_t *worker_args = calloc(threads, sizeof(*worker_args));
|
||||
if (tids == NULL || worker_args == NULL) {
|
||||
free(tids);
|
||||
free(worker_args);
|
||||
return PM3_EMALLOC;
|
||||
}
|
||||
|
||||
mfulc_desbrute_shared_t shared = {0};
|
||||
uint64_t start_ms = msclock();
|
||||
uint32_t total = 1UL << 28;
|
||||
uint32_t chunk = total / (uint32_t)threads;
|
||||
uint32_t remainder = total % (uint32_t)threads;
|
||||
uint32_t current = 0;
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(INFO, "--- " _CYAN_("MFU DESBRUTE"));
|
||||
PrintAndLogEx(INFO, "Mode....... " _YELLOW_("%s"), counterfeit_mode ? "counterfeit nonce" : "reader nonce");
|
||||
PrintAndLogEx(INFO, "Segment.... " _YELLOW_("%d") " (key bytes " _YELLOW_("%d..%d") ")", segment, (segment - 1) * 4, ((segment - 1) * 4) + 3);
|
||||
PrintAndLogEx(INFO, "Keyspace... " _YELLOW_("2^28") " = " _YELLOW_("%" PRIu32) " candidates", total);
|
||||
PrintAndLogEx(INFO, "Threads.... " _YELLOW_("%d") " / " _YELLOW_("%d") " logical CPUs", threads, max_threads);
|
||||
PrintAndLogEx(INFO, "Base key... " _GREEN_("%s"), sprint_hex_inrow(base_key, sizeof(base_key)));
|
||||
if (counterfeit_mode) {
|
||||
PrintAndLogEx(INFO, "Null ERndB. " _GREEN_("%s"), sprint_hex_inrow(init_ciphertext, sizeof(init_ciphertext)));
|
||||
PrintAndLogEx(INFO, "Target..... " _GREEN_("%s"), sprint_hex_inrow(ciphertext, sizeof(ciphertext)));
|
||||
PrintAndLogEx(INFO, "LFSR....... " _YELLOW_("%s"), lfsr_type == MFULC_DESBRUTE_LFSR_ULCG ? "ULCG" : "MFC (USCUID-UL/FJ8010)");
|
||||
} else {
|
||||
PrintAndLogEx(INFO, "ERndB...... " _GREEN_("%s"), sprint_hex_inrow(init_ciphertext, sizeof(init_ciphertext)));
|
||||
PrintAndLogEx(INFO, "ERndA|B'... " _GREEN_("%s"), sprint_hex_inrow(tmp_blocks, sizeof(tmp_blocks)));
|
||||
}
|
||||
PrintAndLogEx(INFO, "Engine..... " _CYAN_("DES SP table + subkey contribution tables + vec candidate lanes"));
|
||||
PrintAndLogEx(INFO, "Abort...... " _YELLOW_("press Enter"));
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
for (int i = 0; i < threads; i++) {
|
||||
mfulc_desbrute_worker_args_t *wa = &worker_args[i];
|
||||
|
||||
wa->args.start = current;
|
||||
wa->args.end = current + chunk + (i == threads - 1 ? remainder : 0);
|
||||
wa->progress = wa->args.start;
|
||||
wa->done = false;
|
||||
wa->args.key_mode = segment - 1;
|
||||
wa->args.candidate_in_k1 = wa->args.key_mode < 2;
|
||||
wa->args.var_offset = wa->args.candidate_in_k1 ? ((wa->args.key_mode % 2) * 4) : (((wa->args.key_mode - 2) % 2) * 4);
|
||||
wa->args.lfsr_type = lfsr_type;
|
||||
wa->args.is_reader_mode = reader_mode;
|
||||
wa->args.thread_id = i;
|
||||
memcpy(wa->args.init_ciphertext, init_ciphertext, sizeof(init_ciphertext));
|
||||
memcpy(wa->args.prev_ciphertext, prev_ciphertext, sizeof(prev_ciphertext));
|
||||
memcpy(wa->args.ciphertext, ciphertext, sizeof(ciphertext));
|
||||
memcpy(wa->args.base_key, base_key, sizeof(base_key));
|
||||
wa->args.init_ip_block = mfulc_desbrute_perm(mfulc_desbrute_be64(init_ciphertext), 64, MFULC_DES_IP, 64);
|
||||
wa->args.prev_ciphertext_be = mfulc_desbrute_be64(prev_ciphertext);
|
||||
wa->args.ciphertext_ip_block = mfulc_desbrute_perm(mfulc_desbrute_be64(ciphertext), 64, MFULC_DES_IP, 64);
|
||||
mfulc_desbrute_keyschedule(
|
||||
mfulc_desbrute_be64(wa->args.candidate_in_k1 ? base_key + 8 : base_key),
|
||||
wa->args.fixed_sk
|
||||
);
|
||||
mfulc_desbrute_compute_sk_tables(
|
||||
wa->args.candidate_in_k1 ? base_key : base_key + 8,
|
||||
wa->args.var_offset,
|
||||
wa->args.cand_sk_base,
|
||||
wa->args.cand_sk_contrib
|
||||
);
|
||||
wa->shared = &shared;
|
||||
current = wa->args.end;
|
||||
|
||||
if (pthread_create(&tids[i], NULL, mfulc_desbrute_worker, wa) != 0) {
|
||||
shared.aborted = true;
|
||||
threads = i;
|
||||
PrintAndLogEx(WARNING, "Failed creating worker thread");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
uint64_t checked = 0;
|
||||
bool all_done = true;
|
||||
|
||||
for (int i = 0; i < threads; i++) {
|
||||
uint32_t p = worker_args[i].progress;
|
||||
if (p < worker_args[i].args.start) {
|
||||
p = worker_args[i].args.start;
|
||||
}
|
||||
if (p > worker_args[i].args.end) {
|
||||
p = worker_args[i].args.end;
|
||||
}
|
||||
checked += (uint64_t)(p - worker_args[i].args.start);
|
||||
if (worker_args[i].done == false) {
|
||||
all_done = false;
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t elapsed_now_ms = msclock() - start_ms;
|
||||
double elapsed_s = elapsed_now_ms > 0 ? elapsed_now_ms / 1000.0 : 0.001;
|
||||
double speed = checked / elapsed_s;
|
||||
double pct = ((double)checked * 100.0) / (double)total;
|
||||
uint64_t eta_s = 0;
|
||||
char eta[16] = {0};
|
||||
char elapsed[16] = {0};
|
||||
char bar[32] = {0};
|
||||
|
||||
if (pct > 100.0) pct = 100.0;
|
||||
if (speed > 0.0 && checked < total) {
|
||||
eta_s = (uint64_t)(((double)total - (double)checked) / speed);
|
||||
}
|
||||
mfulc_desbrute_format_duration(eta_s, eta, sizeof(eta));
|
||||
mfulc_desbrute_format_duration(elapsed_now_ms / 1000, elapsed, sizeof(elapsed));
|
||||
mfulc_desbrute_progress_bar(pct, bar, sizeof(bar));
|
||||
|
||||
PrintAndLogEx(INPLACE, "%s%s" AEND " " _YELLOW_("%6.2f%%") " checked " _CYAN_("%" PRIu64) "/" _CYAN_("%" PRIu32) " " _GREEN_("%.0f keys/s") " elapsed " _YELLOW_("%s") " ETA " _YELLOW_("%s"),
|
||||
mfulc_desbrute_progress_color(pct), bar, pct, checked, total, speed, elapsed, eta);
|
||||
|
||||
if (all_done || shared.found || shared.aborted) {
|
||||
break;
|
||||
}
|
||||
if (kbd_enter_pressed()) {
|
||||
shared.aborted = true;
|
||||
break;
|
||||
}
|
||||
msleep(250);
|
||||
}
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
|
||||
for (int i = 0; i < threads; i++) {
|
||||
pthread_join(tids[i], NULL);
|
||||
}
|
||||
|
||||
uint64_t elapsed_ms = msclock() - start_ms;
|
||||
free(tids);
|
||||
free(worker_args);
|
||||
|
||||
if (shared.aborted) {
|
||||
PrintAndLogEx(WARNING, "Aborted");
|
||||
return PM3_EOPABORTED;
|
||||
}
|
||||
if (shared.found) {
|
||||
PrintAndLogEx(SUCCESS, "Found key index: " _YELLOW_("%" PRIu32), shared.found_idx);
|
||||
PrintAndLogEx(SUCCESS, "Full key: " _GREEN_("%s"), sprint_hex_inrow(shared.found_key, sizeof(shared.found_key)));
|
||||
PrintAndLogEx(INFO, "Time spent " _YELLOW_("%.1fs"), elapsed_ms / 1000.0);
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
PrintAndLogEx(WARNING, "Key segment not found");
|
||||
PrintAndLogEx(INFO, "Time spent " _YELLOW_("%.1fs"), elapsed_ms / 1000.0);
|
||||
return PM3_ESOFT;
|
||||
}
|
||||
|
||||
/**
|
||||
A test function to validate that the polarssl-function works the same
|
||||
was as the openssl-implementation.
|
||||
@@ -5935,7 +6563,7 @@ static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) {
|
||||
|
||||
clearCommandBuffer();
|
||||
PacketResponseNG resp;
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t *)&payload, sizeof(payload));
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t*)&payload, sizeof(payload));
|
||||
if (WaitForResponseTimeout(CMD_HF_MFU_COUNTER_TEAROFF, &resp, 2000) == false) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(WARNING, "\nTear off command failed");
|
||||
@@ -6057,7 +6685,7 @@ static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) {
|
||||
|
||||
clearCommandBuffer();
|
||||
PacketResponseNG resp;
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t *)&payload, sizeof(payload));
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t*)&payload, sizeof(payload));
|
||||
if (WaitForResponseTimeout(CMD_HF_MFU_COUNTER_TEAROFF, &resp, 2000) == false) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(WARNING, "\nTear off command failed");
|
||||
@@ -6146,7 +6774,7 @@ static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) {
|
||||
|
||||
clearCommandBuffer();
|
||||
PacketResponseNG resp;
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t *)&payload, sizeof(payload));
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t*)&payload, sizeof(payload));
|
||||
if (WaitForResponseTimeout(CMD_HF_MFU_COUNTER_TEAROFF, &resp, 2000) == false) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(WARNING, "\nTear off command failed");
|
||||
@@ -6168,7 +6796,7 @@ static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) {
|
||||
memcpy(payload.value, (uint8_t[]) {0x00, 0x00, 0x00}, sizeof(payload.value));
|
||||
|
||||
clearCommandBuffer();
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t *)&payload, sizeof(payload));
|
||||
SendCommandNG(CMD_HF_MFU_COUNTER_TEAROFF, (uint8_t*)&payload, sizeof(payload));
|
||||
if (WaitForResponseTimeout(CMD_HF_MFU_COUNTER_TEAROFF, &resp, 2000) == false) {
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(WARNING, "\nTear off command failed");
|
||||
@@ -7302,6 +7930,7 @@ static command_t CommandTable[] = {
|
||||
{"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("operations") " -----------------------"},
|
||||
{"cauth", CmdHF14AMfUCAuth, IfPm3Iso14443a, "Ultralight-C - Authentication"},
|
||||
{"cchk", CmdHF14AMfUCAuthChk, IfPm3Iso14443a, "Ultralight-C - Authentication dictionary check"},
|
||||
{"desbrute", CmdHF14AMfUCDesBrute, AlwaysAvailable, "Ultralight-C - 3DES key segment brute force"},
|
||||
{"aesauth", CmdHF14AMfUAESAuth, IfPm3Iso14443a, "Ultralight-AES - Authentication"},
|
||||
{"aeschk", CmdHF14AMfUAESAuthChk, IfPm3Iso14443a, "Ultralight-AES - Authentication dictionary check"},
|
||||
{"setkey", CmdHF14AMfUSetKey, IfPm3Iso14443a, "Ultralight C/AES - Set 3DES/AES keys"},
|
||||
|
||||
@@ -723,8 +723,8 @@ static int ntag424_authenticate_ev2_first(uint8_t keyno, uint8_t *key, ntag424_s
|
||||
if (memcmp(response.rnd_a, &rnd_a_clear[1], 15) != 0 ||
|
||||
response.rnd_a[15] != rnd_a_clear[0]) {
|
||||
PrintAndLogEx(ERR, "Incorrect response from card\n"
|
||||
"expected: %s\n"
|
||||
"got: %s"
|
||||
"expected: %s\n"
|
||||
"got: %s"
|
||||
, sprint_hex(rnd_a_clear, 16),
|
||||
sprint_hex(response.rnd_a, 16));
|
||||
return PM3_ESOFT;
|
||||
|
||||
@@ -476,11 +476,11 @@ static int CmdHFHIDConfigSim(const char *Cmd) {
|
||||
strncpy(uid_str, sprint_hex_inrow(uid, uidlen), sizeof(uid_str) - 1);
|
||||
uid_str[sizeof(uid_str) - 1] = '\0';
|
||||
PrintAndLogEx(INFO, "HID Config Card sim:"
|
||||
" UID " _YELLOW_("%s")
|
||||
" AID " _YELLOW_("%s")
|
||||
" ATS len " _YELLOW_("%d")
|
||||
" APDU overrides " _YELLOW_("%u")
|
||||
" default resp " _YELLOW_("%s"),
|
||||
" UID " _YELLOW_("%s")
|
||||
" AID " _YELLOW_("%s")
|
||||
" ATS len " _YELLOW_("%d")
|
||||
" APDU overrides " _YELLOW_("%u")
|
||||
" default resp " _YELLOW_("%s"),
|
||||
uid_str, aid_str, ats_len, apdu_count,
|
||||
has_default_resp ? sprint_hex_inrow(default_resp, default_resp_len_sz) : "9000 (builtin)");
|
||||
PrintAndLogEx(INFO, "Press " _GREEN_("pm3 button") " or " _GREEN_("<Enter>") " to abort simulation");
|
||||
|
||||
+4
-4
@@ -1829,11 +1829,11 @@ int CmdLFRelay(const char *Cmd) {
|
||||
" --rdr : Reading device, act as IP client and reads LF tag and sends data\n"
|
||||
" --tag : Simulation device, act as IP server and simulates relayed data\n",
|
||||
_WHITE_("Device A, reading LF tag, client") "\n"
|
||||
"lf relay --rdr --ip 192.168.1.141 -> Client, connect to IP 192.168.1.141:8000\n"
|
||||
"lf relay --rdr --ip 192.168.1.141 -p 18111 -> Client, connect to IP 192.168.1.141:18111 \n\n"
|
||||
"lf relay --rdr --ip 192.168.1.141 -> Client, connect to IP 192.168.1.141:8000\n"
|
||||
"lf relay --rdr --ip 192.168.1.141 -p 18111 -> Client, connect to IP 192.168.1.141:18111 \n\n"
|
||||
_WHITE_("Device B, simulate LF tag, server") "\n"
|
||||
"lf relay --tag -p 8111 -> Server listening port 8111, recv 40000 samples\n"
|
||||
"lf relay --tag -s 10000 -> Server listening port 8000, recv 10000 samples\n"
|
||||
"lf relay --tag -p 8111 -> Server listening port 8111, recv 40000 samples\n"
|
||||
"lf relay --tag -s 10000 -> Server listening port 8000, recv 10000 samples\n"
|
||||
);
|
||||
|
||||
void *argtable[] = {
|
||||
|
||||
@@ -948,9 +948,9 @@ static int CmdT55xxReadBlock(const char *Cmd) {
|
||||
_CYAN_("Use of read with password on a tag not configured") "\n"
|
||||
_CYAN_("for a password can damage the tag") "\n"
|
||||
_RED_(" * * * * * * * * * *"),
|
||||
"lf t55xx read -b 0 --> read data from block 0\n"
|
||||
"lf t55xx read -b 0 --pwd 01020304 --> read data from block 0, pwd 01020304\n"
|
||||
"lf t55xx read -b 0 --pwd 01020304 -o --> read data from block 0, pwd 01020304, override\n"
|
||||
"lf t55xx read -b 0 --> read data from block 0\n"
|
||||
"lf t55xx read -b 0 --pwd 01020304 --> read data from block 0, pwd 01020304\n"
|
||||
"lf t55xx read -b 0 --pwd 01020304 -o --> read data from block 0, pwd 01020304, override\n"
|
||||
);
|
||||
|
||||
// 1 (help) + 4(four user specified params) + (5 T55XX_DLMODE_SINGLE)
|
||||
|
||||
@@ -1498,7 +1498,7 @@ int CmdTraceList(const char *Cmd) {
|
||||
|
||||
if (protocol == LEGIC)
|
||||
PrintAndLogEx(INFO, _YELLOW_("LEGIC") " - Reader Mode: Timings are in ticks (1us == 1.5ticks)\n"
|
||||
" Tag Mode: Timings are in sub carrier periods (1/212 kHz == 4.7us)");
|
||||
" Tag Mode: Timings are in sub carrier periods (1/212 kHz == 4.7us)");
|
||||
|
||||
if (protocol == ISO_14443B || protocol == PROTO_CRYPTORF) {
|
||||
if (use_us)
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ static int build_segs_from_phdrs(flash_file_t *ctx, uint32_t flash_size) {
|
||||
offset);
|
||||
if (filesz != memsz) {
|
||||
PrintAndLogEx(ERR, "Error: PHDR file size does not equal memory size\n"
|
||||
"(DATA+BSS PHDRs do not make sense on ROM platforms!)");
|
||||
"(DATA+BSS PHDRs do not make sense on ROM platforms!)");
|
||||
return PM3_EFILE;
|
||||
}
|
||||
if (paddr < last_end) {
|
||||
|
||||
@@ -300,10 +300,10 @@ void print_gallagher_creds(GallagherCredentials_t *creds) {
|
||||
return;
|
||||
}
|
||||
PrintAndLogEx(SUCCESS, "Gallagher - region: " _GREEN_("%c") " ( " _GREEN_("%u") " )"
|
||||
", facility: " _GREEN_("%u")
|
||||
", card number: " _GREEN_("%u")
|
||||
", issue level: " _GREEN_("%u"),
|
||||
'A' + creds->region_code,
|
||||
", facility: " _GREEN_("%u")
|
||||
", card number: " _GREEN_("%u")
|
||||
", issue level: " _GREEN_("%u"),
|
||||
'A' + creds->region_code,
|
||||
creds->region_code,
|
||||
creds->facility_code,
|
||||
creds->card_number,
|
||||
|
||||
@@ -319,10 +319,10 @@ int mf_check_keys_fast_ex(uint8_t sectorsCnt, uint8_t firstChunk, uint8_t lastCh
|
||||
|
||||
PrintAndLogEx(NORMAL, "");
|
||||
PrintAndLogEx(SUCCESS, "\nTarget block " _GREEN_("%4u") " key type " _GREEN_("%c") " -- found valid key [ " _GREEN_("%s") " ]",
|
||||
block_no,
|
||||
key_type ? 'B' : 'A',
|
||||
sprint_hex_inrow(resp.data.asBytes, MIFARE_KEY_SIZE)
|
||||
);
|
||||
block_no,
|
||||
key_type ? 'B' : 'A',
|
||||
sprint_hex_inrow(resp.data.asBytes, MIFARE_KEY_SIZE)
|
||||
);
|
||||
|
||||
return PM3_SUCCESS;
|
||||
}
|
||||
|
||||
@@ -2756,9 +2756,9 @@ static int _wrap_new_pm3(lua_State *L) {
|
||||
}
|
||||
|
||||
SWIG_Lua_pusherrstring(L, "Wrong arguments for overloaded function 'new_pm3'\n"
|
||||
" Possible C/C++ prototypes are:\n"
|
||||
" pm3::pm3()\n"
|
||||
" pm3::pm3(char *)\n");
|
||||
" Possible C/C++ prototypes are:\n"
|
||||
" pm3::pm3()\n"
|
||||
" pm3::pm3(char *)\n");
|
||||
lua_error(L);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -356,6 +356,7 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 0, "hf legic rdbl" },
|
||||
{ 0, "hf legic reader" },
|
||||
{ 0, "hf legic restore" },
|
||||
{ 0, "hf legic clone" },
|
||||
{ 0, "hf legic wipe" },
|
||||
{ 0, "hf legic wrbl" },
|
||||
{ 0, "hf legic sim" },
|
||||
@@ -379,6 +380,7 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 0, "hf mf nested" },
|
||||
{ 1, "hf mf hardnested" },
|
||||
{ 0, "hf mf staticnested" },
|
||||
{ 0, "hf mf sen" },
|
||||
{ 0, "hf mf brute" },
|
||||
{ 0, "hf mf autopwn" },
|
||||
{ 0, "hf mf nack" },
|
||||
@@ -465,6 +467,7 @@ const static vocabulary_t vocabulary[] = {
|
||||
{ 0, "hf mfu countertear" },
|
||||
{ 0, "hf mfu cauth" },
|
||||
{ 0, "hf mfu cchk" },
|
||||
{ 1, "hf mfu desbrute" },
|
||||
{ 0, "hf mfu aesauth" },
|
||||
{ 0, "hf mfu aeschk" },
|
||||
{ 0, "hf mfu setkey" },
|
||||
|
||||
@@ -854,7 +854,7 @@ static int dumpmem_pm3(char *serial_port_name, const char *filename, uint32_t ad
|
||||
PrintAndLogEx(INFO, "Device is running the bootloader.");
|
||||
} else {
|
||||
PrintAndLogEx(ERR, "Device is running the bootloader, but the bootloader"
|
||||
" doesn't understand the READ MEM command.");
|
||||
" doesn't understand the READ MEM command.");
|
||||
goto finish2;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user