Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nfc: Fix sector overrun in MFC nested dictionary attack #4048

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions lib/nfc/protocols/mf_classic/mf_classic_poller.c
Original file line number Diff line number Diff line change
Expand Up @@ -1900,6 +1900,19 @@ NfcCommand mf_classic_poller_handler_nested_controller(MfClassicPoller* instance
if((dict_attack_ctx->nested_phase == MfClassicNestedPhaseDictAttack ||
dict_attack_ctx->nested_phase == MfClassicNestedPhaseDictAttackResume) &&
(dict_attack_ctx->nested_target_key < dict_target_key_max)) {
if(dict_attack_ctx->reuse_key_sector == instance->sectors_total) {
// Reset target sector to first sector whose key has not been found
for(dict_attack_ctx->reuse_key_sector = 0;
dict_attack_ctx->reuse_key_sector < instance->sectors_total &&
mf_classic_nested_is_target_key_found(instance, true);
dict_attack_ctx->reuse_key_sector++)
;
// Reset to sane value just in case we happen to have all of the keys
if(dict_attack_ctx->reuse_key_sector == instance->sectors_total) {
dict_attack_ctx->reuse_key_sector = 0;
}
}

bool is_last_iter_for_hard_key =
((!is_weak) && ((dict_attack_ctx->nested_target_key % 8) == 7));
if(initial_dict_attack_iter) {
Expand Down