Merge branch 'fz-dev' into dev

This commit is contained in:
MX 2023-03-16 13:49:24 +03:00
commit 49378f0893
No known key found for this signature in database
GPG Key ID: 7CCC66B7DBDD1C83
6 changed files with 61 additions and 13 deletions

View File

@ -115,7 +115,8 @@ bool nfc_scene_mf_classic_dict_attack_on_event(void* context, SceneManagerEvent
consumed = true;
}
} else if(event.event == NfcWorkerEventAborted) {
if(state == DictAttackStateUserDictInProgress) {
if(state == DictAttackStateUserDictInProgress &&
dict_attack_get_card_state(nfc->dict_attack)) {
nfc_scene_mf_classic_dict_attack_prepare_view(nfc, state);
consumed = true;
} else {

View File

@ -11,6 +11,7 @@ struct DictAttack {
View* view;
DictAttackCallback callback;
void* context;
bool card_present;
};
typedef struct {
@ -162,6 +163,7 @@ void dict_attack_set_header(DictAttack* dict_attack, const char* header) {
void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type) {
furi_assert(dict_attack);
dict_attack->card_present = true;
with_view_model(
dict_attack->view,
DictAttackViewModel * model,
@ -175,6 +177,7 @@ void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type)
void dict_attack_set_card_removed(DictAttack* dict_attack) {
furi_assert(dict_attack);
dict_attack->card_present = false;
with_view_model(
dict_attack->view,
DictAttackViewModel * model,
@ -182,6 +185,11 @@ void dict_attack_set_card_removed(DictAttack* dict_attack) {
true);
}
bool dict_attack_get_card_state(DictAttack* dict_attack) {
furi_assert(dict_attack);
return dict_attack->card_present;
}
void dict_attack_set_sector_read(DictAttack* dict_attack, uint8_t sec_read) {
furi_assert(dict_attack);
with_view_model(

View File

@ -25,6 +25,8 @@ void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type);
void dict_attack_set_card_removed(DictAttack* dict_attack);
bool dict_attack_get_card_state(DictAttack* dict_attack);
void dict_attack_set_sector_read(DictAttack* dict_attack, uint8_t sec_read);
void dict_attack_set_keys_found(DictAttack* dict_attack, uint8_t keys_found);

View File

@ -33,12 +33,22 @@ static StorageType storage_get_type_by_path(FuriString* path) {
StorageType type = ST_ERROR;
const char* path_cstr = furi_string_get_cstr(path);
if(memcmp(path_cstr, STORAGE_EXT_PATH_PREFIX, strlen(STORAGE_EXT_PATH_PREFIX)) == 0) {
type = ST_EXT;
} else if(memcmp(path_cstr, STORAGE_INT_PATH_PREFIX, strlen(STORAGE_INT_PATH_PREFIX)) == 0) {
type = ST_INT;
} else if(memcmp(path_cstr, STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) == 0) {
type = ST_ANY;
if(furi_string_size(path) == 4) {
if(memcmp(path_cstr, STORAGE_EXT_PATH_PREFIX, strlen(STORAGE_EXT_PATH_PREFIX)) == 0) {
type = ST_EXT;
} else if(memcmp(path_cstr, STORAGE_INT_PATH_PREFIX, strlen(STORAGE_INT_PATH_PREFIX)) == 0) {
type = ST_INT;
} else if(memcmp(path_cstr, STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) == 0) {
type = ST_ANY;
}
} else if(furi_string_size(path) > 4) {
if(memcmp(path_cstr, EXT_PATH(""), strlen(EXT_PATH(""))) == 0) {
type = ST_EXT;
} else if(memcmp(path_cstr, INT_PATH(""), strlen(INT_PATH(""))) == 0) {
type = ST_INT;
} else if(memcmp(path_cstr, ANY_PATH(""), strlen(ANY_PATH(""))) == 0) {
type = ST_ANY;
}
}
return type;

View File

@ -739,7 +739,7 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) {
if(mf_classic_authenticate_skip_activate(
&tx_rx, block_num, key, MfClassicKeyA, !deactivated, cuid)) {
mf_classic_set_key_found(data, i, MfClassicKeyA, key);
FURI_LOG_D(TAG, "Key found");
FURI_LOG_D(TAG, "Key A found");
nfc_worker->callback(NfcWorkerEventFoundKeyA, nfc_worker->context);
uint64_t found_key;
@ -753,22 +753,31 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) {
}
nfc_worker_mf_classic_key_attack(nfc_worker, found_key, &tx_rx, i + 1);
break;
}
nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1);
}
furi_hal_nfc_sleep();
deactivated = true;
} else {
mf_classic_set_key_not_found(data, i, MfClassicKeyA);
is_key_a_found = false;
FURI_LOG_D(TAG, "Key %dA not found in attack", i);
}
if(!is_key_b_found) {
is_key_b_found = mf_classic_is_key_found(data, i, MfClassicKeyB);
if(mf_classic_authenticate_skip_activate(
&tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) {
FURI_LOG_D(TAG, "Key found");
FURI_LOG_D(TAG, "Key B found");
mf_classic_set_key_found(data, i, MfClassicKeyB, key);
nfc_worker->callback(NfcWorkerEventFoundKeyB, nfc_worker->context);
nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1);
}
deactivated = true;
} else {
mf_classic_set_key_not_found(data, i, MfClassicKeyB);
is_key_b_found = false;
FURI_LOG_D(TAG, "Key %dB not found in attack", i);
}
if(is_key_a_found && is_key_b_found) break;
if(nfc_worker->state != NfcWorkerStateMfClassicDictAttack) break;

View File

@ -651,7 +651,12 @@ void mf_classic_read_sector(FuriHalNfcTxRxContext* tx_rx, MfClassicData* data, u
if(!key_a_found) break;
FURI_LOG_D(TAG, "Try to read blocks with key A");
key = nfc_util_bytes2num(sec_tr->key_a, sizeof(sec_tr->key_a));
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyA, &crypto, false, 0)) break;
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyA, &crypto, false, 0)) {
mf_classic_set_key_not_found(data, sec_num, MfClassicKeyA);
FURI_LOG_D(TAG, "Key %dA not found in read", sec_num);
break;
}
for(size_t i = start_block; i < start_block + total_blocks; i++) {
if(!mf_classic_is_block_read(data, i)) {
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
@ -660,7 +665,11 @@ void mf_classic_read_sector(FuriHalNfcTxRxContext* tx_rx, MfClassicData* data, u
} else if(i > start_block) {
// Try to re-auth to read block in case prevous block was protected from read
furi_hal_nfc_sleep();
if(!mf_classic_auth(tx_rx, i, key, MfClassicKeyA, &crypto, false, 0)) break;
if(!mf_classic_auth(tx_rx, i, key, MfClassicKeyA, &crypto, false, 0)) {
mf_classic_set_key_not_found(data, sec_num, MfClassicKeyA);
FURI_LOG_D(TAG, "Key %dA not found in read", sec_num);
break;
}
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
mf_classic_set_block_read(data, i, &block_tmp);
blocks_read++;
@ -680,7 +689,12 @@ void mf_classic_read_sector(FuriHalNfcTxRxContext* tx_rx, MfClassicData* data, u
}
FURI_LOG_D(TAG, "Try to read blocks with key B");
key = nfc_util_bytes2num(sec_tr->key_b, sizeof(sec_tr->key_b));
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyB, &crypto, false, 0)) break;
if(!mf_classic_auth(tx_rx, start_block, key, MfClassicKeyB, &crypto, false, 0)) {
mf_classic_set_key_not_found(data, sec_num, MfClassicKeyB);
FURI_LOG_D(TAG, "Key %dB not found in read", sec_num);
break;
}
for(size_t i = start_block; i < start_block + total_blocks; i++) {
if(!mf_classic_is_block_read(data, i)) {
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
@ -689,7 +703,11 @@ void mf_classic_read_sector(FuriHalNfcTxRxContext* tx_rx, MfClassicData* data, u
} else if(i > start_block) {
// Try to re-auth to read block in case prevous block was protected from read
furi_hal_nfc_sleep();
if(!mf_classic_auth(tx_rx, i, key, MfClassicKeyB, &crypto, false, 0)) break;
if(!mf_classic_auth(tx_rx, i, key, MfClassicKeyB, &crypto, false, 0)) {
mf_classic_set_key_not_found(data, sec_num, MfClassicKeyB);
FURI_LOG_D(TAG, "Key %dB not found in read", sec_num);
break;
}
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
mf_classic_set_block_read(data, i, &block_tmp);
blocks_read++;