mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-19 19:38:52 +08:00
CHG: 'script run calc_di' - added the possibilty to write to binary file :)
CHG: 'script run calc_mizip' - added the possibilty to write to binary file :)
This commit is contained in:
parent
926277507a
commit
fec33d7d74
2 changed files with 105 additions and 33 deletions
|
@ -58,7 +58,7 @@ local function help()
|
||||||
print('Example usage')
|
print('Example usage')
|
||||||
print(example)
|
print(example)
|
||||||
end
|
end
|
||||||
--
|
---
|
||||||
-- Exit message
|
-- Exit message
|
||||||
local function exitMsg(msg)
|
local function exitMsg(msg)
|
||||||
print( string.rep('--',20) )
|
print( string.rep('--',20) )
|
||||||
|
@ -66,7 +66,34 @@ local function exitMsg(msg)
|
||||||
print(msg)
|
print(msg)
|
||||||
print()
|
print()
|
||||||
end
|
end
|
||||||
|
---
|
||||||
|
-- dumps all keys to file
|
||||||
|
local function dumptofile(keys)
|
||||||
|
dbg('dumping keys to file')
|
||||||
|
|
||||||
|
if utils.confirm('Do you wish to save the keys to dumpfile?') then
|
||||||
|
local destination = utils.input('Select a filename to store to', 'dumpkeys.bin')
|
||||||
|
local file = io.open(destination, 'wb')
|
||||||
|
if file == nil then
|
||||||
|
print('Could not write to file ', destination)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Mifare Mini has 5 sectors,
|
||||||
|
local key_a = ''
|
||||||
|
local key_b = ''
|
||||||
|
|
||||||
|
for sector = 0, #keys do
|
||||||
|
local keyA, keyB = unpack(keys[sector])
|
||||||
|
key_a = key_a .. bin.pack('H', keyA);
|
||||||
|
key_b = key_b .. bin.pack('H', keyB);
|
||||||
|
end
|
||||||
|
file:write(key_a)
|
||||||
|
file:write(key_b)
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
---
|
||||||
-- create key
|
-- create key
|
||||||
local function keygen(uid)
|
local function keygen(uid)
|
||||||
local data = MIS..uid..BAR
|
local data = MIS..uid..BAR
|
||||||
|
@ -81,21 +108,26 @@ local function keygen(uid)
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- print one row with keys
|
-- print keys
|
||||||
local function printRow(sector, keyA, keyB)
|
local function printKeys(keys)
|
||||||
print('|'..sector..'| '..keyA..' | '..keyB..' |' )
|
print('|---|----------------|---|----------------|---|')
|
||||||
|
print('|sec|key A |res|key B |res|')
|
||||||
|
print('|---|----------------|---|----------------|---|')
|
||||||
|
for sector = 0, #keys do
|
||||||
|
local keyA, keyB = unpack(keys[sector])
|
||||||
|
print(('|%03d| %s | %s | %s | %s |'):format(sector, keyA, 1, keyB, 1))
|
||||||
|
end
|
||||||
|
print('|---|----------------|---|----------------|---|')
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- print keys
|
-- createfull set of keys
|
||||||
local function printKeys(key)
|
local function createKeys(uid)
|
||||||
print('|---|----------------|----------------|')
|
local key = keygen(uid)
|
||||||
print('|sec|key A |key B |')
|
local k = {}
|
||||||
print('|---|----------------|----------------|')
|
for i = 0,4 do
|
||||||
for i=0,4 do
|
k[i] = { key, key }
|
||||||
local s = ("02X"):format(i)
|
|
||||||
printRow( s, key, key)
|
|
||||||
end
|
end
|
||||||
print('|---|----------------|----------------|')
|
return k
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- main
|
-- main
|
||||||
|
@ -134,8 +166,10 @@ local function main(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
print('|UID|', uid)
|
print('|UID|', uid)
|
||||||
local key = keygen(uid)
|
|
||||||
printKeys(key)
|
local keys, err = createKeys( uid )
|
||||||
|
printKeys( keys )
|
||||||
|
dumptofile( keys )
|
||||||
end
|
end
|
||||||
|
|
||||||
main(args)
|
main(args)
|
|
@ -28,14 +28,15 @@ local bxor = bit32.bxor
|
||||||
local _xortable = {
|
local _xortable = {
|
||||||
--[[ sector key A/B, 6byte xor
|
--[[ sector key A/B, 6byte xor
|
||||||
--]]
|
--]]
|
||||||
{"001","09125a2589e5","F12C8453D821"},
|
{1, "09125a2589e5", "F12C8453D821"},
|
||||||
{"002","AB75C937922F","73E799FE3241"},
|
{2, "AB75C937922F", "73E799FE3241"},
|
||||||
{"003","E27241AF2C09","AA4D137656AE"},
|
{3, "E27241AF2C09", "AA4D137656AE"},
|
||||||
{"004","317AB72F4490","B01327272DFD"},
|
{4, "317AB72F4490", "B01327272DFD"},
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
-- A debug printout-function
|
-- A debug printout-function
|
||||||
local function dbg(args)
|
local function dbg(args)
|
||||||
|
if not DEBUG then return end
|
||||||
if type(args) == "table" then
|
if type(args) == "table" then
|
||||||
local i = 1
|
local i = 1
|
||||||
while args[i] do
|
while args[i] do
|
||||||
|
@ -69,6 +70,33 @@ local function exitMsg(msg)
|
||||||
print(msg)
|
print(msg)
|
||||||
print()
|
print()
|
||||||
end
|
end
|
||||||
|
--
|
||||||
|
-- dumps all keys to file
|
||||||
|
local function dumptofile(keys)
|
||||||
|
dbg('dumping keys to file')
|
||||||
|
|
||||||
|
if utils.confirm('Do you wish to save the keys to dumpfile?') then
|
||||||
|
local destination = utils.input('Select a filename to store to', 'dumpkeys.bin')
|
||||||
|
local file = io.open(destination, 'wb')
|
||||||
|
if file == nil then
|
||||||
|
print('Could not write to file ', destination)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Mifare Mini has 5 sectors,
|
||||||
|
local key_a = ''
|
||||||
|
local key_b = ''
|
||||||
|
|
||||||
|
for sector = 0, #keys do
|
||||||
|
local keyA, keyB = unpack(keys[sector])
|
||||||
|
key_a = key_a .. bin.pack('H', keyA);
|
||||||
|
key_b = key_b .. bin.pack('H', keyB);
|
||||||
|
end
|
||||||
|
file:write(key_a)
|
||||||
|
file:write(key_b)
|
||||||
|
file:close()
|
||||||
|
end
|
||||||
|
end
|
||||||
---
|
---
|
||||||
-- key bytes to string
|
-- key bytes to string
|
||||||
local function keyStr(p1, p2, p3, p4, p5, p6)
|
local function keyStr(p1, p2, p3, p4, p5, p6)
|
||||||
|
@ -96,25 +124,31 @@ local function calckey(uid, xorkey, keytype)
|
||||||
return keyStr(p1,p2,p3,p4,p5,p6)
|
return keyStr(p1,p2,p3,p4,p5,p6)
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- print one row with keys
|
-- print keys
|
||||||
local function printRow(sector, keyA, keyB)
|
local function printKeys(keys)
|
||||||
print('|'..sector..'| '..keyA..' | '..keyB..' |' )
|
print('|---|----------------|---|----------------|---|')
|
||||||
|
print('|sec|key A |res|key B |res|')
|
||||||
|
print('|---|----------------|---|----------------|---|')
|
||||||
|
for sector = 0, #keys do
|
||||||
|
local keyA, keyB = unpack(keys[sector])
|
||||||
|
print(('|%03d| %s | %s | %s | %s |'):format(sector, keyA, 1, keyB, 1))
|
||||||
|
end
|
||||||
|
print('|---|----------------|---|----------------|---|')
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- print keys
|
-- create a full set of keys
|
||||||
local function printKeys(uid)
|
local function createKeys(uid)
|
||||||
print('|---|----------------|----------------|')
|
|
||||||
print('|sec|key A |key B |')
|
|
||||||
print('|---|----------------|----------------|')
|
|
||||||
printRow('000', keyStr(0xA0,0xA1,0xA2,0xA3,0xA4,0xA5), keyStr(0xB4,0xC1,0x32,0x43,0x9e,0xef) )
|
|
||||||
|
|
||||||
local uidbytes = utils.ConvertHexToBytes(uid)
|
local uidbytes = utils.ConvertHexToBytes(uid)
|
||||||
for k, v in pairs(_xortable) do
|
|
||||||
|
local k = {}
|
||||||
|
k[0] = { keyStr(0xA0,0xA1,0xA2,0xA3,0xA4,0xA5), keyStr(0xB4,0xC1,0x32,0x43,0x9e,0xef) }
|
||||||
|
|
||||||
|
for _, v in pairs(_xortable) do
|
||||||
local keyA = calckey(uidbytes, utils.ConvertHexToBytes(v[2]), 'A')
|
local keyA = calckey(uidbytes, utils.ConvertHexToBytes(v[2]), 'A')
|
||||||
local keyB = calckey(uidbytes, utils.ConvertHexToBytes(v[3]), 'B')
|
local keyB = calckey(uidbytes, utils.ConvertHexToBytes(v[3]), 'B')
|
||||||
printRow(v[1], keyA, keyB )
|
k[v[1]] = { keyA, keyB }
|
||||||
end
|
end
|
||||||
print('|---|----------------|----------------|')
|
return k
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- main
|
-- main
|
||||||
|
@ -151,8 +185,12 @@ local function main(args)
|
||||||
end
|
end
|
||||||
uid = tag.uid
|
uid = tag.uid
|
||||||
end
|
end
|
||||||
|
|
||||||
print('|UID|', uid)
|
print('|UID|', uid)
|
||||||
printKeys(uid)
|
|
||||||
|
local keys, err = createKeys( uid )
|
||||||
|
printKeys( keys )
|
||||||
|
dumptofile( keys )
|
||||||
end
|
end
|
||||||
|
|
||||||
main(args)
|
main(args)
|
Loading…
Add table
Reference in a new issue