mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 05:13:46 -07:00
CHG: minor fixes to some tnp luascripts
ADD: a script to make a barebone clone for tnp3 on a chinese magic s50 generation 1 tag.
This commit is contained in:
parent
0ec548dc21
commit
4076250660
4 changed files with 167 additions and 51 deletions
|
@ -116,42 +116,42 @@ local _names = {
|
||||||
--[[
|
--[[
|
||||||
TRAPTEAM
|
TRAPTEAM
|
||||||
--]]
|
--]]
|
||||||
["01C2"]="TRAPTEAM GUSTO",
|
["C201"]="TRAPTEAM GUSTO",
|
||||||
["01C3"]="TRAPTEAM THUNDERBOLT",
|
["C301"]="TRAPTEAM THUNDERBOLT",
|
||||||
["01C4"]="TRAPTEAM FLING KONG",
|
["C401"]="TRAPTEAM FLING KONG",
|
||||||
["01C5"]="TRAPTEAM BLADES",
|
["C501"]="TRAPTEAM BLADES",
|
||||||
["01C6"]="TRAPTEAM WALLOP",
|
["C601"]="TRAPTEAM WALLOP",
|
||||||
["01C7"]="TRAPTEAM HEAD RUSH",
|
["C701"]="TRAPTEAM HEAD RUSH",
|
||||||
["01C8"]="TRAPTEAM FIST BUMP",
|
["C801"]="TRAPTEAM FIST BUMP",
|
||||||
["01C9"]="TRAPTEAM ROCKY ROLL",
|
["C901"]="TRAPTEAM ROCKY ROLL",
|
||||||
["01CA"]="TRAPTEAM WILDFIRE",
|
["CA01"]="TRAPTEAM WILDFIRE",
|
||||||
["01CB"]="TRAPTEAM KA BOOM",
|
["CB01"]="TRAPTEAM KA BOOM",
|
||||||
["01CC"]="TRAPTEAM TRAIL BLAZER",
|
["CC01"]="TRAPTEAM TRAIL BLAZER",
|
||||||
["01CD"]="TRAPTEAM TORCH",
|
["CD01"]="TRAPTEAM TORCH",
|
||||||
["01CE"]="TRAPTEAM SNAP SHOT",
|
["CE01"]="TRAPTEAM SNAP SHOT",
|
||||||
["01CF"]="TRAPTEAM LOB STAR",
|
["CF01"]="TRAPTEAM LOB STAR",
|
||||||
["01D0"]="TRAPTEAM FLIP WRECK",
|
["D001"]="TRAPTEAM FLIP WRECK",
|
||||||
["01D1"]="TRAPTEAM ECHO",
|
["D101"]="TRAPTEAM ECHO",
|
||||||
["01D2"]="TRAPTEAM BLASTERMIND",
|
["D201"]="TRAPTEAM BLASTERMIND",
|
||||||
["01D3"]="TRAPTEAM ENIGMA",
|
["D301"]="TRAPTEAM ENIGMA",
|
||||||
["01D4"]="TRAPTEAM DEJA VU",
|
["D401"]="TRAPTEAM DEJA VU",
|
||||||
["01D5"]="TRAPTEAM COBRA CADABRA",
|
["D501"]="TRAPTEAM COBRA CADABRA",
|
||||||
["01D6"]="TRAPTEAM JAWBREAKER",
|
["D601"]="TRAPTEAM JAWBREAKER",
|
||||||
["01D7"]="TRAPTEAM GEARSHIFT",
|
["D701"]="TRAPTEAM GEARSHIFT",
|
||||||
["01D8"]="TRAPTEAM CHOPPER",
|
["D801"]="TRAPTEAM CHOPPER",
|
||||||
["01D9"]="TRAPTEAM TREAD HEAD",
|
["D901"]="TRAPTEAM TREAD HEAD",
|
||||||
["01DA"]="TRAPTEAM BUSHWHACK",
|
["DA01"]="TRAPTEAM BUSHWHACK",
|
||||||
["01DB"]="TRAPTEAM TUFF LUCK",
|
["DB01"]="TRAPTEAM TUFF LUCK",
|
||||||
["01DC"]="TRAPTEAM FOOD FIGHT",
|
["DC01"]="TRAPTEAM FOOD FIGHT",
|
||||||
["01DD"]="TRAPTEAM HIGH FIVE",
|
["DD01"]="TRAPTEAM HIGH FIVE",
|
||||||
["01DE"]="TRAPTEAM NITRO KRYPT KING",
|
["DE01"]="TRAPTEAM NITRO KRYPT KING",
|
||||||
["01DF"]="TRAPTEAM SHORT CUT",
|
["DF01"]="TRAPTEAM SHORT CUT",
|
||||||
["01E0"]="TRAPTEAM BAT SPIN",
|
["E001"]="TRAPTEAM BAT SPIN",
|
||||||
["01E1"]="TRAPTEAM FUNNY BONE",
|
["E101"]="TRAPTEAM FUNNY BONE",
|
||||||
["01E2"]="TRAPTEAM KNIGHT LIGHT",
|
["E201"]="TRAPTEAM KNIGHT LIGHT",
|
||||||
["01E3"]="TRAPTEAM SPOTLIGHT",
|
["E301"]="TRAPTEAM SPOTLIGHT",
|
||||||
["01E4"]="TRAPTEAM KNIGHT MARE",
|
["E401"]="TRAPTEAM KNIGHT MARE",
|
||||||
["01E5"]="TRAPTEAM BLACKOUT",
|
["E501"]="TRAPTEAM BLACKOUT",
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
PET
|
PET
|
||||||
|
|
113
client/scripts/tnp3clone.lua
Normal file
113
client/scripts/tnp3clone.lua
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
local cmds = require('commands')
|
||||||
|
local getopt = require('getopt')
|
||||||
|
local lib14a = require('read14a')
|
||||||
|
local utils = require('utils')
|
||||||
|
local pre = require('precalc')
|
||||||
|
|
||||||
|
local lsh = bit32.lshift
|
||||||
|
local rsh = bit32.rshift
|
||||||
|
local bor = bit32.bor
|
||||||
|
local band = bit32.band
|
||||||
|
|
||||||
|
example =[[
|
||||||
|
script run tnp3dump
|
||||||
|
script run tnp3dump -h
|
||||||
|
script run tnp3dump -t aa00
|
||||||
|
|
||||||
|
]]
|
||||||
|
author = "Iceman"
|
||||||
|
usage = "script run tnp3clone -t <toytype>"
|
||||||
|
desc =[[
|
||||||
|
This script will try making a barebone clone of a tnp3 tag on to a magic generation1 card.
|
||||||
|
|
||||||
|
Arguments:
|
||||||
|
-h : this help
|
||||||
|
-k <key> : toytype id, 4 hex symbols.
|
||||||
|
]]
|
||||||
|
|
||||||
|
|
||||||
|
-- This is only meant to be used when errors occur
|
||||||
|
function oops(err)
|
||||||
|
print("ERROR: ",err)
|
||||||
|
end
|
||||||
|
-- Usage help
|
||||||
|
function help()
|
||||||
|
print(desc)
|
||||||
|
print("Example usage")
|
||||||
|
print(example)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function waitCmd()
|
||||||
|
local response = core.WaitForResponseTimeout(cmds.CMD_ACK,2000)
|
||||||
|
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 readblock( keyA )
|
||||||
|
-- Read block 0
|
||||||
|
cmd = Command:new{cmd = cmds.CMD_MIFARE_READBL, arg1 = 0,arg2 = 0,arg3 = 0, data = keyA}
|
||||||
|
err = core.SendCommand(cmd:getBytes())
|
||||||
|
if err then return oops(err) end
|
||||||
|
local block0, err = waitCmd()
|
||||||
|
if err then return oops(err) end
|
||||||
|
return block0
|
||||||
|
end
|
||||||
|
|
||||||
|
local function main(args)
|
||||||
|
|
||||||
|
local numBlocks = 64
|
||||||
|
local cset = 'hf mf csetbl'
|
||||||
|
local empty = '00000000000000000000000000000000'
|
||||||
|
local AccAndKeyB = '7F078869000000000000'
|
||||||
|
-- Defaults to Gusto
|
||||||
|
local toytype = 'C201'
|
||||||
|
|
||||||
|
-- Arguments for the script
|
||||||
|
for o, a in getopt.getopt(args, 'ht:') do
|
||||||
|
if o == "h" then return help() end
|
||||||
|
if o == "t" then toytype = a end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #toytype ~= 4 then return oops('Wrong size in toytype. (4hex symbols)') end
|
||||||
|
|
||||||
|
-- find tag
|
||||||
|
result, err = lib14a.read1443a(false)
|
||||||
|
if not result then return oops(err) end
|
||||||
|
|
||||||
|
-- Show tag info
|
||||||
|
print((' Found tag %s'):format(result.name))
|
||||||
|
|
||||||
|
-- load keys
|
||||||
|
local akeys = pre.GetAll(result.uid)
|
||||||
|
local keyA = akeys:sub(1, 12 )
|
||||||
|
|
||||||
|
local b0 = readblock(keyA)
|
||||||
|
local b1 = toytype..'000000000000000000000000'
|
||||||
|
|
||||||
|
local calc = utils.Crc16(b0..b1)
|
||||||
|
local calcEndian = bor(rsh(calc,8), lsh(band(calc, 0xff), 8))
|
||||||
|
|
||||||
|
local cmd = ('hf mf csetbl 1 %s%04x'):format( b1, calcEndian)
|
||||||
|
core.console( cmd)
|
||||||
|
|
||||||
|
local pos, key
|
||||||
|
for blockNo = 2, numBlocks-1, 1 do
|
||||||
|
pos = (math.floor( blockNo / 4 ) * 12)+1
|
||||||
|
key = akeys:sub(pos, pos + 11 )
|
||||||
|
if blockNo%4 ~= 3 then
|
||||||
|
cmd = ('%s %d %s'):format(cset,blockNo,empty)
|
||||||
|
else
|
||||||
|
cmd = ('%s %d %s%s'):format(cset,blockNo,key,AccAndKeyB)
|
||||||
|
end
|
||||||
|
core.console(cmd)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
main(args)
|
|
@ -148,7 +148,7 @@ local function main(args)
|
||||||
core.clearCommandBuffer()
|
core.clearCommandBuffer()
|
||||||
|
|
||||||
if 0x01 ~= result.sak then -- NXP MIFARE TNP3xxx
|
if 0x01 ~= result.sak then -- NXP MIFARE TNP3xxx
|
||||||
return oops('This is not a TNP3xxx tag. aborting.')
|
-- return oops('This is not a TNP3xxx tag. aborting.')
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Show tag info
|
-- Show tag info
|
||||||
|
@ -215,7 +215,9 @@ local function main(args)
|
||||||
local blockdata, err = waitCmd()
|
local blockdata, err = waitCmd()
|
||||||
if err then return oops(err) end
|
if err then return oops(err) end
|
||||||
|
|
||||||
|
|
||||||
if blockNo%4 ~= 3 then
|
if blockNo%4 ~= 3 then
|
||||||
|
|
||||||
if blockNo < 8 then
|
if blockNo < 8 then
|
||||||
-- Block 0-7 not encrypted
|
-- Block 0-7 not encrypted
|
||||||
blocks[blockNo+1] = ('%02d :: %s'):format(blockNo,blockdata)
|
blocks[blockNo+1] = ('%02d :: %s'):format(blockNo,blockdata)
|
||||||
|
|
|
@ -26,7 +26,7 @@ Arguments:
|
||||||
]]
|
]]
|
||||||
|
|
||||||
local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
|
local TIMEOUT = 2000 -- Shouldn't take longer than 2 seconds
|
||||||
local DEBUG = false -- the debug flag
|
local DEBUG = true -- the debug flag
|
||||||
|
|
||||||
|
|
||||||
local band = bit32.band
|
local band = bit32.band
|
||||||
|
@ -302,25 +302,25 @@ function DivideByK(msw, lsw)
|
||||||
remainder = num % RADIX
|
remainder = num % RADIX
|
||||||
return remainder, highLSW, lowLSW
|
return remainder, highLSW, lowLSW
|
||||||
|
|
||||||
uint num = 0 | (msw >> 16) & 0xffff;
|
-- uint num = 0 | (msw >> 16) & 0xffff;
|
||||||
|
|
||||||
highLSW = 0 | (num / RADIX) << 16;
|
-- highLSW = 0 | (num / RADIX) << 16;
|
||||||
remainder = num % RADIX;
|
-- remainder = num % RADIX;
|
||||||
|
|
||||||
num = (remainder << 16) | (msw & 0xffff);
|
-- num = (remainder << 16) | (msw & 0xffff);
|
||||||
|
|
||||||
highLSW |= num / RADIX;
|
-- highLSW |= num / RADIX;
|
||||||
remainder = num % RADIX;
|
-- remainder = num % RADIX;
|
||||||
|
|
||||||
num = (remainder << 16) | ((lsw >> 16) & 0xffff);
|
-- num = (remainder << 16) | ((lsw >> 16) & 0xffff);
|
||||||
|
|
||||||
lowLSW = 0 | (num / RADIX) << 16;
|
-- lowLSW = 0 | (num / RADIX) << 16;
|
||||||
remainder = num % RADIX;
|
-- remainder = num % RADIX;
|
||||||
|
|
||||||
num = (remainder << 16) | (lsw & 0xffff);
|
-- num = (remainder << 16) | (lsw & 0xffff);
|
||||||
|
|
||||||
lowLSW |= num / RADIX;
|
-- lowLSW |= num / RADIX;
|
||||||
remainder = num % RADIX;
|
-- remainder = num % RADIX;
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -397,7 +397,8 @@ local function main(args)
|
||||||
print( (' UID : 0x%s'):format(uid) )
|
print( (' UID : 0x%s'):format(uid) )
|
||||||
print( (' CARDID : 0x%s %s [%s]'):format(
|
print( (' CARDID : 0x%s %s [%s]'):format(
|
||||||
cardidMsw,cardidLsw,
|
cardidMsw,cardidLsw,
|
||||||
Num2Card(cardidMsw, cardidLsw))
|
--Num2Card(cardidMsw, cardidLsw))
|
||||||
|
'')
|
||||||
)
|
)
|
||||||
print( string.rep('--',20) )
|
print( string.rep('--',20) )
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue