Skip to content

Commit a8f0a83

Browse files
committed
1.2.0 - Hard Nested attack
1 parent 6c1eaa1 commit a8f0a83

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

lib/nested/nested.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,8 @@ NestedCheckKeyResult nested_check_key(
614614
nfc_activate();
615615
if(!furi_hal_nfc_activate_nfca(200, &cuid)) return NestedCheckKeyNoTag;
616616

617-
FURI_LOG_D(TAG, "Checking %c key %06llX for block %u", !keyType ? 'A' : 'B', ui64Key, blockNo);
617+
FURI_LOG_D(
618+
TAG, "Checking %c key %012llX for block %u", !keyType ? 'A' : 'B', ui64Key, blockNo);
618619

619620
bool success =
620621
mifare_classic_authex(crypto, tx_rx, cuid, blockNo, keyType, ui64Key, false, &nt);

mifare_nested_worker.c

+15-17
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ uint32_t mifare_nested_worker_predict_delay(
315315
uint32_t nt1, nt2, i = 0, previous = 0, prng_delay = 0, zero_prng_value = 65565, repeat = 0;
316316

317317
if(tries > 10) {
318-
return 2; // To many tries, fallback to hardnested
318+
return 2; // Too many tries, fallback to hardnested
319319
}
320320

321321
// This part of attack is my attempt to implement it on Flipper.
@@ -618,13 +618,9 @@ bool mifare_nested_worker_check_initial_keys(
618618
}
619619
}
620620
}
621-
622-
if(sector == sector_count - 1 && key_block == 0) {
623-
return false;
624-
}
625621
}
626622

627-
return true;
623+
return *key_block;
628624
}
629625

630626
void mifare_nested_worker_collect_nonces_static(MifareNestedWorker* mifare_nested_worker) {
@@ -686,7 +682,7 @@ void mifare_nested_worker_collect_nonces_static(MifareNestedWorker* mifare_neste
686682
}
687683

688684
FURI_LOG_I(
689-
TAG, "Using %c key for block %lu: %06llX", !found_key_type ? 'A' : 'B', key_block, key);
685+
TAG, "Using %c key for block %lu: %012llX", !found_key_type ? 'A' : 'B', key_block, key);
690686

691687
nonces->tries = 1;
692688

@@ -783,6 +779,8 @@ void mifare_nested_worker_collect_nonces_hard(MifareNestedWorker* mifare_nested_
783779
uint32_t found_key_type = 0;
784780
uint32_t key_block = 0;
785781
uint32_t sector_count = 0;
782+
uint32_t cuid = 0;
783+
furi_hal_nfc_activate_nfca(200, &cuid);
786784

787785
FURI_LOG_I(TAG, "Running hardnested attack");
788786
FuriString* tag_info = furi_string_alloc_printf("Tag UID: ");
@@ -829,7 +827,7 @@ void mifare_nested_worker_collect_nonces_hard(MifareNestedWorker* mifare_nested_
829827
}
830828

831829
FURI_LOG_I(
832-
TAG, "Using %c key for block %lu: %06llX", !found_key_type ? 'A' : 'B', key_block, key);
830+
TAG, "Using %c key for block %lu: %012llX", !found_key_type ? 'A' : 'B', key_block, key);
833831

834832
FuriHalNfcTxRxContext tx_rx = {};
835833
nonces->tries = 1;
@@ -880,17 +878,16 @@ void mifare_nested_worker_collect_nonces_hard(MifareNestedWorker* mifare_nested_
880878
FSAM_READ_WRITE,
881879
FSOM_CREATE_ALWAYS);
882880

883-
FuriString* cuid = furi_string_alloc_printf("CUID: ");
884-
mifare_nested_worker_write_uid_string(&data, cuid);
885881
FuriString* header = furi_string_alloc_printf(
886-
"Filetype: Flipper Nested Nonces File\nVersion: %s\nNote: you will need desktop app to recover keys: %s\n%s\n",
882+
"Filetype: Flipper Nested Nonces File\nVersion: %s\nNote: you will need desktop app to recover keys: %s\nKey %c cuid 0x%08lx sec %u\n",
887883
NESTED_NONCE_FORMAT_VERSION,
888884
NESTED_RECOVER_KEYS_GITHUB_LINK,
889-
furi_string_get_cstr(cuid));
885+
!key_type ? 'A' : 'B',
886+
cuid,
887+
sector);
890888

891889
stream_write_string(file_stream, header);
892890
furi_string_free(header);
893-
furi_string_free(cuid);
894891

895892
while(!info->collected &&
896893
mifare_nested_worker->state == MifareNestedWorkerStateCollecting) {
@@ -1037,7 +1034,7 @@ void mifare_nested_worker_collect_nonces(MifareNestedWorker* mifare_nested_worke
10371034
}
10381035

10391036
FURI_LOG_I(
1040-
TAG, "Using %c key for block %lu: %06llX", !found_key_type ? 'A' : 'B', key_block, key);
1037+
TAG, "Using %c key for block %lu: %012llX", !found_key_type ? 'A' : 'B', key_block, key);
10411038

10421039
while(mifare_nested_worker->state == MifareNestedWorkerStateCollecting) {
10431040
FuriHalNfcTxRxContext tx_rx = {};
@@ -1278,7 +1275,7 @@ bool* mifare_nested_worker_check_keys_exists(
12781275

12791276
for(uint32_t i = 0; i < key_count; i++) {
12801277
old_keys[i] = false;
1281-
key_strings[i] = furi_string_alloc_printf("%06llX\n", keys[i]);
1278+
key_strings[i] = furi_string_alloc_printf("%012llX\n", keys[i]);
12821279
}
12831280

12841281
while(mifare_nested_worker->state == MifareNestedWorkerStateValidating) {
@@ -1467,7 +1464,8 @@ void mifare_nested_worker_check_keys(MifareNestedWorker* mifare_nested_worker) {
14671464
}
14681465

14691466
if(result == NestedCheckKeyValid) {
1470-
FURI_LOG_I(TAG, "Found valid %c key for sector %u: %06llX", key_type, sector, key);
1467+
FURI_LOG_I(
1468+
TAG, "Found valid %c key for sector %u: %012llX", key_type, sector, key);
14711469
bool exists = false;
14721470

14731471
for(uint8_t i = 0; i < keys_count; i++) {
@@ -1525,7 +1523,7 @@ void mifare_nested_worker_check_keys(MifareNestedWorker* mifare_nested_worker) {
15251523
for(uint8_t i = 0; i < keys_count; i++) {
15261524
if(keys[i] == (uint64_t)-1) continue;
15271525

1528-
FuriString* key_string = furi_string_alloc_printf("%06llX\n", keys[i]);
1526+
FuriString* key_string = furi_string_alloc_printf("%012llX\n", keys[i]);
15291527

15301528
mifare_nested_worker_write_key(storage, key_string);
15311529
FURI_LOG_I(TAG, "Added new key: %s", furi_string_get_cstr(key_string));

0 commit comments

Comments
 (0)