Flipper-XFW / Xtreme-Firmware

The Dom amongst the Flipper Zero Firmware. Give your Flipper the power and freedom it is really craving. Let it show you its true form. Dont delay, switch to the one and only true Master today!
https://flipper-xtre.me
GNU General Public License v3.0
9.29k stars 668 forks source link

Reader attack reports incorrect keys #241

Closed DidierA closed 1 year ago

DidierA commented 1 year ago

Describe the bug.

Using latest Xtreme firmware, NFC Reader attack reports incorrect keys. This is due to a wrong cuid being written in nfc/.mfkey32.log I could pinpoint the issue by emulating a reader with a proxmark3, using the flipper in Reader attack mode and looking at the trace. The UID sent by the flipper is not the one it dumps in the log file.

Reproduction

Target

No response

Logs

No response

Anything else?

lua script to use on the proxmark:

local getopt = require('getopt')
local lib14a = require('read14a')
local cmds = require('commands')
local utils = require('utils')
local ansicolors  = require('ansicolors')

copyright = ''
author = "Didier"
version = 'v1.0.4'
desc = [[
This is a script which simulates a mifare classic reader. It sets itself into
'listening'-mode, after which it continuously tries to read a specific sector
on any mifare classic card that you place by the device.

based on hf_mf_autopwn.lua
]]
example = [[
    1. script run hf_mf_reader
]]
usage = [[
script run hf_mf_reader [-h] [-d] [-a <key>] [-b <key>]
]]
arguments = [[
    -h         this help
    -d         debug logging on
    -a         key to use, keytype A
    -b         key to use, keytype B

]]

-------------------------------
-- Some utilities
-------------------------------
local DEBUG = false
---
-- A debug printout-function
local function dbg(args)
    if not DEBUG then return end
    if type(args) == 'table' then
        local i = 1
        while result[i] do
            dbg(result[i])
            i = i+1
        end
    else
        print('###', args)
    end
end
---
-- This is only meant to be used when errors occur
local function oops(err)
    print('ERROR:', err)
    core.clearCommandBuffer()
    return nil, err
end
---
-- Usage help
local function help()
    print(copyright)
    print(author)
    print(version)
    print(desc)
    print(ansicolors.cyan..'Usage'..ansicolors.reset)
    print(usage)
    print(ansicolors.cyan..'Arguments'..ansicolors.reset)
    print(arguments)
    print(ansicolors.cyan..'Example usage'..ansicolors.reset)
    print(example)
end
---
-- Waits for a mifare card to be placed within the vicinity of the reader.
-- @return if successful: an table containing card info
-- @return if unsuccessful : nil, error
local function wait_for_mifare()
    while not core.kbd_enter_pressed() do
        res, err = lib14a.read()
        if res then return res end
        -- err means that there was no response from card
    end
    return nil, 'Aborted by user'
end

---
-- The main entry point
local function main(args)

    local res, uid, err, _, sak
    local seen_uids = {}
    local keyA = 'A0A1A2A3A4A5'
    local keyB = 'FFFFFFFFFFFF'
    local cmd_template = 'hf mf rdbl --blk 0 %s -k %s'

    -- Read the parameters
    for o, a in getopt.getopt(args, 'hda:b:') do
        if o == 'h' then help() return end
        if o == 'd' then DEBUG = true end
        if o == 'a' then keyA = a end
        if o == 'b' then keyB = a end
    end

    print('Waiting for card or press Enter to stop')
    res, err = wait_for_mifare()
    if err then return oops(err) end

    uid = res.uid
    sak = res.sak

    print(string.format('Card found. UID: %s', res.uid))

    print (string.format('Reading continuously with keyA: %s and keyB: %s. Press Enter to stop', keyA, keyB))
    local steps=6
    while steps > 0 do
        steps = steps -1 
        local cmd = string.format(cmd_template,'-a', keyA)
        core.console(cmd)
        core.console('trace list -t mf')
        cmd = string.format(cmd_template, '-b',  keyB)
        core.console(cmd)
        core.console('trace list -t mf')
    end

end

-- Call the main
main(args)
ClaraCrazy commented 1 year ago

Yea, we know. Someone else already mentioned it like two days ago. Not sure where it comes from tho unfortunately (yet)

ClaraCrazy commented 1 year ago

fixed in next release

ClaraCrazy commented 1 year ago

fixed in release

DidierA commented 1 year ago

Thank you, tested this morning, I can confirm it is now working as expected.