mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 12:42:30 +04:00
Merge branch 'fz-dev' into dev
This commit is contained in:
@@ -115,7 +115,8 @@ bool nfc_scene_mf_classic_dict_attack_on_event(void* context, SceneManagerEvent
|
|||||||
consumed = true;
|
consumed = true;
|
||||||
}
|
}
|
||||||
} else if(event.event == NfcWorkerEventAborted) {
|
} 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);
|
nfc_scene_mf_classic_dict_attack_prepare_view(nfc, state);
|
||||||
consumed = true;
|
consumed = true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ struct DictAttack {
|
|||||||
View* view;
|
View* view;
|
||||||
DictAttackCallback callback;
|
DictAttackCallback callback;
|
||||||
void* context;
|
void* context;
|
||||||
|
bool card_present;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct {
|
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) {
|
void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type) {
|
||||||
furi_assert(dict_attack);
|
furi_assert(dict_attack);
|
||||||
|
dict_attack->card_present = true;
|
||||||
with_view_model(
|
with_view_model(
|
||||||
dict_attack->view,
|
dict_attack->view,
|
||||||
DictAttackViewModel * model,
|
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) {
|
void dict_attack_set_card_removed(DictAttack* dict_attack) {
|
||||||
furi_assert(dict_attack);
|
furi_assert(dict_attack);
|
||||||
|
dict_attack->card_present = false;
|
||||||
with_view_model(
|
with_view_model(
|
||||||
dict_attack->view,
|
dict_attack->view,
|
||||||
DictAttackViewModel * model,
|
DictAttackViewModel * model,
|
||||||
@@ -182,6 +185,11 @@ void dict_attack_set_card_removed(DictAttack* dict_attack) {
|
|||||||
true);
|
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) {
|
void dict_attack_set_sector_read(DictAttack* dict_attack, uint8_t sec_read) {
|
||||||
furi_assert(dict_attack);
|
furi_assert(dict_attack);
|
||||||
with_view_model(
|
with_view_model(
|
||||||
|
|||||||
@@ -25,6 +25,8 @@ void dict_attack_set_card_detected(DictAttack* dict_attack, MfClassicType type);
|
|||||||
|
|
||||||
void dict_attack_set_card_removed(DictAttack* dict_attack);
|
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_sector_read(DictAttack* dict_attack, uint8_t sec_read);
|
||||||
|
|
||||||
void dict_attack_set_keys_found(DictAttack* dict_attack, uint8_t keys_found);
|
void dict_attack_set_keys_found(DictAttack* dict_attack, uint8_t keys_found);
|
||||||
|
|||||||
@@ -33,12 +33,22 @@ static StorageType storage_get_type_by_path(FuriString* path) {
|
|||||||
StorageType type = ST_ERROR;
|
StorageType type = ST_ERROR;
|
||||||
const char* path_cstr = furi_string_get_cstr(path);
|
const char* path_cstr = furi_string_get_cstr(path);
|
||||||
|
|
||||||
if(memcmp(path_cstr, STORAGE_EXT_PATH_PREFIX, strlen(STORAGE_EXT_PATH_PREFIX)) == 0) {
|
if(furi_string_size(path) == 4) {
|
||||||
type = ST_EXT;
|
if(memcmp(path_cstr, STORAGE_EXT_PATH_PREFIX, strlen(STORAGE_EXT_PATH_PREFIX)) == 0) {
|
||||||
} else if(memcmp(path_cstr, STORAGE_INT_PATH_PREFIX, strlen(STORAGE_INT_PATH_PREFIX)) == 0) {
|
type = ST_EXT;
|
||||||
type = ST_INT;
|
} else if(memcmp(path_cstr, STORAGE_INT_PATH_PREFIX, strlen(STORAGE_INT_PATH_PREFIX)) == 0) {
|
||||||
} else if(memcmp(path_cstr, STORAGE_ANY_PATH_PREFIX, strlen(STORAGE_ANY_PATH_PREFIX)) == 0) {
|
type = ST_INT;
|
||||||
type = ST_ANY;
|
} 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;
|
return type;
|
||||||
|
|||||||
@@ -739,7 +739,7 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) {
|
|||||||
if(mf_classic_authenticate_skip_activate(
|
if(mf_classic_authenticate_skip_activate(
|
||||||
&tx_rx, block_num, key, MfClassicKeyA, !deactivated, cuid)) {
|
&tx_rx, block_num, key, MfClassicKeyA, !deactivated, cuid)) {
|
||||||
mf_classic_set_key_found(data, i, MfClassicKeyA, key);
|
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);
|
nfc_worker->callback(NfcWorkerEventFoundKeyA, nfc_worker->context);
|
||||||
|
|
||||||
uint64_t found_key;
|
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);
|
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);
|
nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1);
|
||||||
}
|
}
|
||||||
furi_hal_nfc_sleep();
|
furi_hal_nfc_sleep();
|
||||||
deactivated = true;
|
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) {
|
if(!is_key_b_found) {
|
||||||
is_key_b_found = mf_classic_is_key_found(data, i, MfClassicKeyB);
|
is_key_b_found = mf_classic_is_key_found(data, i, MfClassicKeyB);
|
||||||
if(mf_classic_authenticate_skip_activate(
|
if(mf_classic_authenticate_skip_activate(
|
||||||
&tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) {
|
&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);
|
mf_classic_set_key_found(data, i, MfClassicKeyB, key);
|
||||||
nfc_worker->callback(NfcWorkerEventFoundKeyB, nfc_worker->context);
|
nfc_worker->callback(NfcWorkerEventFoundKeyB, nfc_worker->context);
|
||||||
nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1);
|
nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1);
|
||||||
}
|
}
|
||||||
deactivated = true;
|
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(is_key_a_found && is_key_b_found) break;
|
||||||
if(nfc_worker->state != NfcWorkerStateMfClassicDictAttack) break;
|
if(nfc_worker->state != NfcWorkerStateMfClassicDictAttack) break;
|
||||||
|
|||||||
@@ -651,7 +651,12 @@ void mf_classic_read_sector(FuriHalNfcTxRxContext* tx_rx, MfClassicData* data, u
|
|||||||
if(!key_a_found) break;
|
if(!key_a_found) break;
|
||||||
FURI_LOG_D(TAG, "Try to read blocks with key A");
|
FURI_LOG_D(TAG, "Try to read blocks with key A");
|
||||||
key = nfc_util_bytes2num(sec_tr->key_a, sizeof(sec_tr->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++) {
|
for(size_t i = start_block; i < start_block + total_blocks; i++) {
|
||||||
if(!mf_classic_is_block_read(data, i)) {
|
if(!mf_classic_is_block_read(data, i)) {
|
||||||
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
|
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) {
|
} else if(i > start_block) {
|
||||||
// Try to re-auth to read block in case prevous block was protected from read
|
// Try to re-auth to read block in case prevous block was protected from read
|
||||||
furi_hal_nfc_sleep();
|
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)) {
|
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
|
||||||
mf_classic_set_block_read(data, i, &block_tmp);
|
mf_classic_set_block_read(data, i, &block_tmp);
|
||||||
blocks_read++;
|
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");
|
FURI_LOG_D(TAG, "Try to read blocks with key B");
|
||||||
key = nfc_util_bytes2num(sec_tr->key_b, sizeof(sec_tr->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++) {
|
for(size_t i = start_block; i < start_block + total_blocks; i++) {
|
||||||
if(!mf_classic_is_block_read(data, i)) {
|
if(!mf_classic_is_block_read(data, i)) {
|
||||||
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
|
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) {
|
} else if(i > start_block) {
|
||||||
// Try to re-auth to read block in case prevous block was protected from read
|
// Try to re-auth to read block in case prevous block was protected from read
|
||||||
furi_hal_nfc_sleep();
|
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)) {
|
if(mf_classic_read_block(tx_rx, &crypto, i, &block_tmp)) {
|
||||||
mf_classic_set_block_read(data, i, &block_tmp);
|
mf_classic_set_block_read(data, i, &block_tmp);
|
||||||
blocks_read++;
|
blocks_read++;
|
||||||
|
|||||||
Reference in New Issue
Block a user