chg: 'script run mifare_autopwn' added the prng_test, to make sure it only attacks weak cards.

This commit is contained in:
iceman1001 2017-07-31 15:53:26 +02:00
commit 6df9012de5

View file

@ -26,25 +26,23 @@ Output files from this operation:
-- Some utilities -- Some utilities
------------------------------- -------------------------------
local DEBUG = false local DEBUG = false
local MIFARE_AUTH_KEYA = 0x60
local MIFARE_AUTH_KEYB = 0x61
--- ---
-- A debug printout-function -- A debug printout-function
function dbg(args) local function dbg(args)
if DEBUG then if DEBUG then
print(":: ", args) print(":: ", args)
end end
end end
--- ---
-- This is only meant to be used when errors occur -- This is only meant to be used when errors occur
function oops(err) local function oops(err)
print("ERROR: ",err) print("ERROR: ",err)
return nil,err return nil,err
end end
--- ---
-- Usage help -- Usage help
function help() local function help()
print(desc) print(desc)
print("Example usage") print("Example usage")
print(example) print(example)
@ -54,7 +52,7 @@ end
-- Waits for a mifare card to be placed within the vicinity of the reader. -- Waits for a mifare card to be placed within the vicinity of the reader.
-- @return if successfull: an table containing card info -- @return if successfull: an table containing card info
-- @return if unsuccessfull : nil, error -- @return if unsuccessfull : nil, error
function wait_for_mifare() local function wait_for_mifare()
while not core.ukbhit() do while not core.ukbhit() do
res, err = reader.read1443a() res, err = reader.read1443a()
if res then return res end if res then return res end
@ -63,7 +61,7 @@ function wait_for_mifare()
return nil, "Aborted by user" return nil, "Aborted by user"
end end
function nested(key,sak) local function nested(key,sak)
local typ = 1 local typ = 1
if 0x18 == sak then --NXP MIFARE Classic 4k | Plus 4k | Ev1 4k if 0x18 == sak then --NXP MIFARE Classic 4k | Plus 4k | Ev1 4k
typ = 4 typ = 4
@ -82,7 +80,7 @@ function nested(key,sak)
core.console(cmd) core.console(cmd)
end end
function dump(uid) local function dump(uid)
core.console("hf mf dump") core.console("hf mf dump")
-- Save the global args, those are *our* arguments -- Save the global args, those are *our* arguments
local myargs = args local myargs = args
@ -97,10 +95,22 @@ function dump(uid)
-- Set back args. Not that it's used, just for the karma... -- Set back args. Not that it's used, just for the karma...
args = myargs args = myargs
end end
--
-- performs a test if tag nonce uses weak or hardend prng
local function perform_prng_test()
local isweak = core.detect_prng()
if isweak == 1 then
dbg('PRNG detection : WEAK nonce detected')
return true
end
dbg('PRNG detection : HARDEND nonce detected')
return false
end
--- ---
-- The main entry point -- The main entry point
function main(args) local function main(args)
local verbose, exit, res, uid, err, _, sak local verbose, exit, res, uid, err, _, sak
local seen_uids = {} local seen_uids = {}
@ -121,9 +131,15 @@ function main(args)
-- Seen already? -- Seen already?
uid = res.uid uid = res.uid
sak = res.sak sak = res.sak
if not seen_uids[uid] then if not seen_uids[uid] then
-- Store it -- Store it
seen_uids[uid] = uid seen_uids[uid] = uid
-- check if PRNG is WEAK
if perform_prng_test() then
print("Card found, commencing crack on UID", uid) print("Card found, commencing crack on UID", uid)
-- Crack it -- Crack it
local key, cnt local key, cnt
@ -148,6 +164,7 @@ generating polynomial with 16 effective bits only, but shows unexpected behaviou
nested(key,sak) nested(key,sak)
-- Dump info -- Dump info
dump(uid) dump(uid)
end
print_message = true print_message = true
end end
end end