mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-03-20 12:07:05 +08:00
chg: script run didump - use MIX
This commit is contained in:
parent
c180c8df20
commit
df555be792
1 changed files with 68 additions and 50 deletions
|
@ -7,29 +7,36 @@ local lib14a = require('read14a')
|
||||||
local json = require('dkjson')
|
local json = require('dkjson')
|
||||||
local toys = require('default_toys_di')
|
local toys = require('default_toys_di')
|
||||||
|
|
||||||
example =[[
|
copyright = ''
|
||||||
|
author = 'Iceman'
|
||||||
|
version = 'v1.0.1'
|
||||||
|
desc = [[
|
||||||
|
This is a script to dump and decrypt the data of a specific type of Mifare Mini token.
|
||||||
|
The dump is decrypted. If a raw dump is wanted, use the -r parameter
|
||||||
|
]]
|
||||||
|
example = [[
|
||||||
script run didump
|
script run didump
|
||||||
script run didump -t
|
script run didump -t
|
||||||
script run didump -r
|
script run didump -r
|
||||||
]]
|
]]
|
||||||
author = "Iceman"
|
usage = [[
|
||||||
usage = "script run didump -h -t"
|
script run didump -h -t -r
|
||||||
desc = [[
|
|
||||||
This is a script to dump and decrypt the data of a specific type of Mifare Mini token.
|
|
||||||
The dump is decrypted. If a raw dump is wanted, use the -r parameter
|
|
||||||
Arguments:
|
Arguments:
|
||||||
-h : this help
|
h this helptext
|
||||||
-r : raw
|
r raw
|
||||||
-t : selftest
|
t selftest
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local band=bit32.band
|
-- Some shortcuts
|
||||||
local bor=bit32.bor
|
local band = bit32.band
|
||||||
local bnot=bit32.bnot
|
local bor = bit32.bor
|
||||||
local bxor=bit32.bxor
|
local bnot = bit32.bnot
|
||||||
local lsh=bit32.lshift
|
local bxor = bit32.bxor
|
||||||
local rsh=bit32.rshift
|
local lsh = bit32.lshift
|
||||||
|
local rsh = bit32.rshift
|
||||||
|
|
||||||
|
-- Some globals
|
||||||
local FOO = 'AF62D2EC0491968CC52A1A7165F865FE'
|
local FOO = 'AF62D2EC0491968CC52A1A7165F865FE'
|
||||||
local BAR = '286329204469736E65792032303133'
|
local BAR = '286329204469736E65792032303133'
|
||||||
local MIS = '0A14FD0507FF4BCD026BA83F0A3B89A9'
|
local MIS = '0A14FD0507FF4BCD026BA83F0A3B89A9'
|
||||||
|
@ -44,29 +51,33 @@ local CHECKSUM_OFFSET = 12; -- +1???
|
||||||
-- A debug printout-function
|
-- A debug printout-function
|
||||||
local function dbg(args)
|
local function dbg(args)
|
||||||
if not DEBUG then return end
|
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
|
||||||
print("###", args[i])
|
print('###', args[i])
|
||||||
i = i+1
|
i = i+1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
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
|
||||||
local function oops(err)
|
local function oops(err)
|
||||||
print("ERROR: ",err)
|
print('ERROR: ', err)
|
||||||
core.clearCommandBuffer()
|
core.clearCommandBuffer()
|
||||||
return false
|
return nil, err
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- Usage help
|
-- Usage help
|
||||||
local function help()
|
local function help()
|
||||||
|
print(copyright)
|
||||||
|
print(author)
|
||||||
|
print(version)
|
||||||
print(desc)
|
print(desc)
|
||||||
print("Example usage")
|
print('Example usage')
|
||||||
print(example)
|
print(example)
|
||||||
|
print(usage)
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
--
|
--
|
||||||
|
@ -370,21 +381,7 @@ local function updateChecksum(data)
|
||||||
return string.format("%s%X", part, chksum)
|
return string.format("%s%X", part, chksum)
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- receives the answer from deviceside, used with a readblock command
|
--
|
||||||
local function waitCmd()
|
|
||||||
local response = core.WaitForResponseTimeout(cmds.CMD_ACK,TIMEOUT)
|
|
||||||
if response then
|
|
||||||
local count,cmd,arg0 = bin.unpack('LL',response)
|
|
||||||
if(arg0==1) then
|
|
||||||
local count,arg1,arg2,data = bin.unpack('LLH511',response,count)
|
|
||||||
return data:sub(1,32)
|
|
||||||
else
|
|
||||||
return nil, "Couldn't read block.."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return nil, "No response from device"
|
|
||||||
end
|
|
||||||
|
|
||||||
local function keygen(uid)
|
local function keygen(uid)
|
||||||
local data = MIS..uid..BAR
|
local data = MIS..uid..BAR
|
||||||
local hash = utils.ConvertAsciiToBytes(utils.Sha1Hex(data))
|
local hash = utils.ConvertAsciiToBytes(utils.Sha1Hex(data))
|
||||||
|
@ -397,7 +394,6 @@ local function keygen(uid)
|
||||||
hash[6+1]
|
hash[6+1]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
--- encode 'table' into a json formatted string
|
--- encode 'table' into a json formatted string
|
||||||
--
|
--
|
||||||
local function convert_to_json( obj )
|
local function convert_to_json( obj )
|
||||||
|
@ -449,6 +445,29 @@ local function create_key(uid)
|
||||||
key = key..utils.SwapEndiannessStr( sha:sub(25,32), 32 )
|
key = key..utils.SwapEndiannessStr( sha:sub(25,32), 32 )
|
||||||
return key
|
return key
|
||||||
end
|
end
|
||||||
|
---
|
||||||
|
-- decode response and get the blockdata from a normal mifare read command
|
||||||
|
local function getblockdata(response)
|
||||||
|
if not response then
|
||||||
|
return nil, 'No response from device'
|
||||||
|
end
|
||||||
|
|
||||||
|
local count, cmd, arg0 = bin.unpack('LL', response)
|
||||||
|
if arg0 == 1 then
|
||||||
|
local count, arg1, arg2, data = bin.unpack('LLH511', response, count)
|
||||||
|
return data:sub(1, 32)
|
||||||
|
else
|
||||||
|
return nil, "Couldn't read block.. ["..arg0.."]"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function readblock( blocknum, key )
|
||||||
|
-- Read block N
|
||||||
|
local c = Command:newMIX{cmd = cmds.CMD_MIFARE_READBL, arg1 = blocknum, data = key}
|
||||||
|
local b, err = getblockdata(c:sendMIX())
|
||||||
|
if not b then return oops(err) end
|
||||||
|
return b
|
||||||
|
end
|
||||||
--- reads all blocks from tag
|
--- reads all blocks from tag
|
||||||
--
|
--
|
||||||
local function readtag(mfkey, aeskey )
|
local function readtag(mfkey, aeskey )
|
||||||
|
@ -463,11 +482,8 @@ local function readtag(mfkey, aeskey )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- read block from tag.
|
-- read block from tag.
|
||||||
cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = blockNo ,arg2 = 0,arg3 = 0, data = mfkey}
|
local blockdata = readblock(blockNo, mfkey)
|
||||||
local err = core.SendCommand(cmd:getBytes())
|
if not blockdata then return oops('[!] failed reading block') end
|
||||||
if err then return oops(err) end
|
|
||||||
local blockdata, err = waitCmd()
|
|
||||||
if err then return oops(err) end
|
|
||||||
|
|
||||||
-- rules:
|
-- rules:
|
||||||
-- the following blocks is NOT encrypted
|
-- the following blocks is NOT encrypted
|
||||||
|
@ -488,7 +504,6 @@ local function readtag(mfkey, aeskey )
|
||||||
else
|
else
|
||||||
-- Sectorblocks, not encrypted, but we add our known key to it since it is normally zeros.
|
-- Sectorblocks, not encrypted, but we add our known key to it since it is normally zeros.
|
||||||
blockdata = mfkey..blockdata:sub(13,20)..mfkey
|
blockdata = mfkey..blockdata:sub(13,20)..mfkey
|
||||||
--dbg(blockdata:sub(13,20))
|
|
||||||
end
|
end
|
||||||
table.insert(tagdata, blockdata)
|
table.insert(tagdata, blockdata)
|
||||||
end
|
end
|
||||||
|
@ -549,12 +564,12 @@ function main(args)
|
||||||
|
|
||||||
-- Read the parameters
|
-- Read the parameters
|
||||||
for o, a in getopt.getopt(args, 'htdevi:') do
|
for o, a in getopt.getopt(args, 'htdevi:') do
|
||||||
if o == "h" then help() return end
|
if o == 'h' then help() return end
|
||||||
if o == "t" then return selftest() end
|
if o == 't' then return selftest() end
|
||||||
if o == "d" then shall_dec = true end
|
if o == 'd' then shall_dec = true end
|
||||||
if o == "e" then shall_enc = true end
|
if o == 'e' then shall_enc = true end
|
||||||
if o == "v" then shall_validate = true end
|
if o == 'v' then shall_validate = true end
|
||||||
if o == "i" then input = load_json(a) end
|
if o == 'i' then input = load_json(a) end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Turn off Debug
|
-- Turn off Debug
|
||||||
|
@ -562,7 +577,10 @@ function main(args)
|
||||||
|
|
||||||
-- GET TAG UID
|
-- GET TAG UID
|
||||||
tag, err = lib14a.read(false, true)
|
tag, err = lib14a.read(false, true)
|
||||||
if not tag then return oops(err) end
|
if err then
|
||||||
|
lib14a.disconnect()
|
||||||
|
return oops(err)
|
||||||
|
end
|
||||||
core.clearCommandBuffer()
|
core.clearCommandBuffer()
|
||||||
|
|
||||||
-- simple tag check
|
-- simple tag check
|
||||||
|
|
Loading…
Add table
Reference in a new issue