mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-20 13:23:51 -07:00
next
This commit is contained in:
parent
f4f8636b86
commit
cf0d17853e
3 changed files with 128 additions and 128 deletions
|
@ -1,11 +1,13 @@
|
||||||
|
|
||||||
-- Ability to read what card is there
|
|
||||||
local getopt = require('getopt')
|
local getopt = require('getopt')
|
||||||
local cmds = require('commands')
|
local cmds = require('commands')
|
||||||
local taglib = require('taglib')
|
local taglib = require('taglib')
|
||||||
|
local utils = require('utils')
|
||||||
|
|
||||||
local desc =
|
copyright = ''
|
||||||
[[This script will automatically recognize and dump full content of a NFC NDEF Initialized tag; non-initialized tags will be ignored.
|
author = 'Martin Holst Swende & Asper'
|
||||||
|
version = 'v1.0.1'
|
||||||
|
desc = [[
|
||||||
|
This script will automatically recognize and dump full content of a NFC NDEF Initialized tag; non-initialized tags will be ignored.
|
||||||
|
|
||||||
It also write the dump to an eml-file <uid>.eml.
|
It also write the dump to an eml-file <uid>.eml.
|
||||||
|
|
||||||
|
@ -15,72 +17,54 @@ raw data, but when saving into that for, we lose the infromation about how the m
|
||||||
For example: 24 bytes could be 6 blocks of 4 bytes, or vice versa.
|
For example: 24 bytes could be 6 blocks of 4 bytes, or vice versa.
|
||||||
Therefore, the .eml is better to use file when saving dumps.)
|
Therefore, the .eml is better to use file when saving dumps.)
|
||||||
|
|
||||||
|
]]
|
||||||
|
example = [[
|
||||||
|
1. script run ndef_dump
|
||||||
|
]]
|
||||||
|
usage = [[
|
||||||
|
script run ndef_dump
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
-h this help
|
-h this help
|
||||||
-d debug logging on
|
-d debug logging on
|
||||||
|
|
||||||
]]
|
]]
|
||||||
local example = "script run xxx"
|
|
||||||
local author = "Martin Holst Swende & Asper"
|
local DEBUG = true -- the debug flag
|
||||||
|
|
||||||
---
|
---
|
||||||
-- PrintAndLog
|
-- A debug printout-function
|
||||||
local function prlog(...)
|
local function dbg(args)
|
||||||
-- TODO; replace this with a call to the proper PrintAndLog
|
if not DEBUG then return end
|
||||||
print(...)
|
if type(args) == 'table' then
|
||||||
|
local i = 1
|
||||||
|
while result[i] do
|
||||||
|
dbg(result[i])
|
||||||
|
i = i+1
|
||||||
|
end
|
||||||
|
else
|
||||||
|
print('###', args)
|
||||||
|
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)
|
||||||
prlog("ERROR: ",err)
|
print('ERROR:', err)
|
||||||
|
core.clearCommandBuffer()
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Perhaps this will be moved to a separate library at one point
|
|
||||||
local utils = {
|
|
||||||
--- Writes an eml-file.
|
|
||||||
-- @param uid - the uid of the tag. Used in filename
|
|
||||||
-- @param blockData. Assumed to be on the format {'\0\1\2\3,'\b\e\e\f' ...,
|
|
||||||
-- that is, blockData[row] contains a string with the actual data, not ascii hex representation
|
|
||||||
-- return filename if all went well,
|
|
||||||
-- @reurn nil, error message if unsuccessfull
|
|
||||||
writeDumpFile = function(uid, blockData)
|
|
||||||
local destination = string.format("%s.eml", uid)
|
|
||||||
local file = io.open(destination, "w")
|
|
||||||
if file == nil then
|
|
||||||
return nil, string.format("Could not write to file %s", destination)
|
|
||||||
end
|
|
||||||
local rowlen = string.len(blockData[1])
|
|
||||||
|
|
||||||
for i,block in ipairs(blockData) do
|
|
||||||
if rowlen ~= string.len(block) then
|
|
||||||
prlog(string.format("WARNING: Dumpdata seems corrupted, line %d was not the same length as line 1",i))
|
|
||||||
end
|
|
||||||
|
|
||||||
local formatString = string.format("H%d", string.len(block))
|
|
||||||
local _,hex = bin.unpack(formatString,block)
|
|
||||||
file:write(hex.."\n")
|
|
||||||
end
|
|
||||||
file:close()
|
|
||||||
return destination
|
|
||||||
end,
|
|
||||||
}
|
|
||||||
|
|
||||||
---
|
---
|
||||||
-- Usage help
|
-- Usage help
|
||||||
local function help()
|
local function help()
|
||||||
prlog(desc)
|
print(copyright)
|
||||||
prlog("Example usage")
|
print(author)
|
||||||
prlog(example)
|
print(version)
|
||||||
|
print(desc)
|
||||||
|
print('Example usage')
|
||||||
|
print(example)
|
||||||
|
print(usage)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function debug(...)
|
|
||||||
if DEBUG then
|
|
||||||
prlog("debug:", ...)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
--- This function is a lua-implementation of
|
--- This function is a lua-implementation of
|
||||||
-- cmdhf14a.c:waitCmd(uint8_t iSelect)
|
-- cmdhf14a.c:waitCmd(uint8_t iSelect)
|
||||||
local function waitCmd(iSelect)
|
local function waitCmd(iSelect)
|
||||||
|
@ -90,55 +74,47 @@ local function waitCmd(iSelect)
|
||||||
|
|
||||||
local iLen = arg0
|
local iLen = arg0
|
||||||
if iSelect then iLen = arg1 end
|
if iSelect then iLen = arg1 end
|
||||||
debug(("Received %i octets (arg0:%d, arg1:%d)"):format(iLen, arg0, arg1))
|
dbg(("Received %i octets (arg0:%d, arg1:%d)"):format(iLen, arg0, arg1))
|
||||||
if iLen == 0 then return nil, "No response from tag" end
|
if iLen == 0 then return nil, "No response from tag" end
|
||||||
local recv = string.sub(response,count, iLen+count-1)
|
local recv = string.sub(response,count, iLen+count-1)
|
||||||
return recv
|
return recv
|
||||||
end
|
end
|
||||||
return nil, "No response from device"
|
return nil, "No response from device"
|
||||||
end
|
end
|
||||||
|
---
|
||||||
|
--
|
||||||
local function show(data)
|
local function show(data)
|
||||||
if DEBUG then
|
local formatString = ('H%d'):format(string.len(data))
|
||||||
local formatString = ("H%d"):format(string.len(data))
|
|
||||||
local _,hexdata = bin.unpack(formatString, data)
|
local _,hexdata = bin.unpack(formatString, data)
|
||||||
debug("Hexdata" , hexdata)
|
dbg('Hexdata', hexdata)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
--- Fire up a connection with a tag, return uid
|
--- Fire up a connection with a tag, return uid
|
||||||
-- @return UID if successfull
|
-- @return UID if successfull
|
||||||
-- @return nil, errormessage if unsuccessfull
|
-- @return nil, errormessage if unsuccessfull
|
||||||
|
|
||||||
local function open()
|
local function open()
|
||||||
debug("Opening connection")
|
dbg('Opening connection')
|
||||||
core.clearCommandBuffer()
|
core.clearCommandBuffer()
|
||||||
local x = string.format("hf 14a raw -r -p -s")
|
local x = string.format('hf 14a raw -r -p -s')
|
||||||
debug(x)
|
dbg(x)
|
||||||
core.console(x)
|
core.console(x)
|
||||||
debug("done")
|
dbg('done')
|
||||||
data, err = waitCmd(true)
|
data, err = waitCmd(true)
|
||||||
if err then return oops(err) end
|
if err then return oops(err) end
|
||||||
show(data)
|
show(data)
|
||||||
local formatString = ("H%d"):format(string.len(data))
|
local formatString = ('H%d'):format(string.len(data))
|
||||||
local _,uid = bin.unpack(formatString, data)
|
local _,uid = bin.unpack(formatString, data)
|
||||||
return uid
|
return uid
|
||||||
end
|
end
|
||||||
--- Shut down tag communication
|
--- Shut down tag communication
|
||||||
-- return no return values
|
-- return no return values
|
||||||
local function close()
|
local function close()
|
||||||
debug("Closing connection")
|
dbg('Closing connection')
|
||||||
core.clearCommandBuffer()
|
core.clearCommandBuffer()
|
||||||
local x = string.format("hf 14a raw -r")
|
local x = string.format('hf 14a raw -r')
|
||||||
debug(x)
|
dbg(x)
|
||||||
core.console(x)
|
core.console(x)
|
||||||
debug("done")
|
dbg('done')
|
||||||
--data, err = waitCmd(true)
|
|
||||||
--data, err = waitCmd(false)
|
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---_ Gets data from a block
|
---_ Gets data from a block
|
||||||
-- @return {block, block+1, block+2, block+3} if successfull
|
-- @return {block, block+1, block+2, block+3} if successfull
|
||||||
-- @return nil, errormessage if unsuccessfull
|
-- @return nil, errormessage if unsuccessfull
|
||||||
|
@ -147,10 +123,10 @@ local function getBlock(block)
|
||||||
|
|
||||||
core.clearCommandBuffer()
|
core.clearCommandBuffer()
|
||||||
|
|
||||||
local x = string.format("hf 14a raw -r -c -p 30 %02x", block)
|
local x = string.format('hf 14a raw -r -c -p 30 %02x', block)
|
||||||
debug(x)
|
dbg(x)
|
||||||
core.console(x)
|
core.console(x)
|
||||||
debug("done")
|
dbg('done')
|
||||||
-- By now, there should be an ACK waiting from the device, since
|
-- By now, there should be an ACK waiting from the device, since
|
||||||
-- we used the -r flag (don't read response).
|
-- we used the -r flag (don't read response).
|
||||||
|
|
||||||
|
@ -159,7 +135,7 @@ local function getBlock(block)
|
||||||
show(data)
|
show(data)
|
||||||
|
|
||||||
if string.len(data) < 18 then
|
if string.len(data) < 18 then
|
||||||
return nil, ("Expected at least 18 bytes, got %d - this tag is not NDEF-compliant"):format(string.len(data))
|
return nil, ('Expected at least 18 bytes, got %d - this tag is not NDEF-compliant'):format(string.len(data))
|
||||||
end
|
end
|
||||||
-- Now, parse out the block data
|
-- Now, parse out the block data
|
||||||
-- 0534 00B9 049C AD7F 4A00 0000 E110 1000 2155
|
-- 0534 00B9 049C AD7F 4A00 0000 E110 1000 2155
|
||||||
|
@ -171,16 +147,16 @@ local function getBlock(block)
|
||||||
return {b0, b1, b2, b3}
|
return {b0, b1, b2, b3}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function main( args)
|
local function main( args)
|
||||||
debug("script started")
|
|
||||||
|
print( string.rep('--',20) )
|
||||||
|
print( string.rep('--',20) )
|
||||||
|
dbg('script started')
|
||||||
local err, data, data2, k, v, i
|
local err, data, data2, k, v, i
|
||||||
-- Read the parameters
|
-- Read the parameters
|
||||||
for o, a in getopt.getopt(args, 'hd') do
|
for o, a in getopt.getopt(args, 'hd') do
|
||||||
if o == "h" then help() return end
|
if o == 'h' then return help() end
|
||||||
if o == "d" then DEBUG = true end
|
if o == 'd' then DEBUG = true end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Info contained within the tag (block 0 example)
|
-- Info contained within the tag (block 0 example)
|
||||||
|
@ -196,15 +172,19 @@ local function main( args)
|
||||||
|
|
||||||
-- First, get blockt 3 byte 2
|
-- First, get blockt 3 byte 2
|
||||||
local blocks, err = getBlock(0)
|
local blocks, err = getBlock(0)
|
||||||
if err then return oops(err) end
|
if err then
|
||||||
|
close()
|
||||||
|
return oops(err)
|
||||||
|
end
|
||||||
-- Block 3 contains number of blocks
|
-- Block 3 contains number of blocks
|
||||||
local b3chars = {string.byte(blocks[4], 1,4)}
|
local b3chars = {string.byte(blocks[4], 1,4)}
|
||||||
local numBlocks = b3chars[3] * 2 + 6
|
local numBlocks = b3chars[3] * 2 + 6
|
||||||
prlog("Number of blocks:", numBlocks)
|
print("Number of blocks:", numBlocks)
|
||||||
|
|
||||||
-- NDEF compliant?
|
-- NDEF compliant?
|
||||||
if b3chars[1] ~= 0xE1 then
|
if b3chars[1] ~= 0xE1 then
|
||||||
return oops("This tag is not NDEF-Compliant")
|
close()
|
||||||
|
return oops('This tag is not NDEF-Compliant')
|
||||||
end
|
end
|
||||||
|
|
||||||
local ndefVersion = b3chars[2]
|
local ndefVersion = b3chars[2]
|
||||||
|
@ -216,32 +196,31 @@ local function main( args)
|
||||||
-- Reuse existing info
|
-- Reuse existing info
|
||||||
local blockData = {blocks[1], blocks[2], blocks[3], blocks[4]}
|
local blockData = {blocks[1], blocks[2], blocks[3], blocks[4]}
|
||||||
|
|
||||||
|
|
||||||
--[[ Due to the infineon my-d move bug
|
--[[ Due to the infineon my-d move bug
|
||||||
(if I send 30 0F i receive block0f+block00+block01+block02 insted of block0f+block10+block11+block12)
|
(if I send 30 0F i receive block0f+block00+block01+block02 insted of block0f+block10+block11+block12)
|
||||||
the only way to avoid this is to send the read command as many times as block numbers
|
the only way to avoid this is to send the read command as many times as block numbers
|
||||||
removing bytes from 5 to 18 from each answer.
|
removing bytes from 5 to 18 from each answer.
|
||||||
--]]
|
--]]
|
||||||
prlog("Dumping data...please wait")
|
print('Dumping data...please wait')
|
||||||
for i=4,numBlocks-1,1 do
|
for i=4,numBlocks-1,1 do
|
||||||
blocks, err = getBlock(i)
|
blocks, err = getBlock(i)
|
||||||
if err then return oops(err) end
|
if err then close(); return oops(err) end
|
||||||
table.insert(blockData, blocks[1])
|
table.insert(blockData, blocks[1])
|
||||||
end
|
end
|
||||||
-- Deactivate field
|
-- Deactivate field
|
||||||
close()
|
close()
|
||||||
-- Print results
|
-- Print results
|
||||||
prlog(string.format("Tag manufacturer: %s", manufacturer))
|
print(string.format('Tag manufacturer: %s', manufacturer))
|
||||||
prlog(string.format("Tag UID: %s", uidHexstr))
|
print(string.format('Tag UID: %s', uidHexstr))
|
||||||
prlog(string.format("Tag NDEF version: 0x%02x", ndefVersion))
|
print(string.format('Tag NDEF version: 0x%02x', ndefVersion))
|
||||||
|
|
||||||
for k,v in ipairs(blockData) do
|
for k,v in ipairs(blockData) do
|
||||||
prlog(string.format("Block %02x: %02x %02x %02x %02x",k-1, string.byte(v, 1,4)))
|
print(string.format('Block %02x: %02x %02x %02x %02x', k-1, string.byte(v, 1,4)))
|
||||||
end
|
end
|
||||||
local filename, err = utils.writeDumpFile(uidHexstr, blockData)
|
local filename, err = utils.writeDumpFile(uidHexstr, blockData)
|
||||||
if err then return oops(err) end
|
if err then return oops(err) end
|
||||||
|
|
||||||
prlog(string.format("Dumped data into %s", filename))
|
print(string.format('Dumped data into %s', filename))
|
||||||
|
|
||||||
end
|
end
|
||||||
main(args)
|
main(args)
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
local getopt = require('getopt')
|
local getopt = require('getopt')
|
||||||
local lib14a = require('read14a')
|
local lib14a = require('read14a')
|
||||||
|
local utils = require('utils')
|
||||||
|
|
||||||
copyright = 'Copyright (c) 2017 IceSQL AB. All rights reserved.'
|
copyright = 'Copyright (c) 2017 IceSQL AB. All rights reserved.'
|
||||||
author = "Christian Herrmann"
|
author = "Christian Herrmann"
|
||||||
version = 'v1.0.3'
|
version = 'v1.0.4'
|
||||||
desc = [[
|
desc = [[
|
||||||
This script writes a empty template for 3D printing system onto a empty NTAG213 or MAGIC NTAG21*
|
This script writes a empty template for 3D printing system onto a empty NTAG213 or MAGIC NTAG21*
|
||||||
|
|
||||||
|
@ -143,7 +144,6 @@ end
|
||||||
-- 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 result[i] do
|
while result[i] do
|
||||||
|
@ -158,16 +158,19 @@ 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()
|
||||||
return nil, err
|
return nil, err
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- Usage help
|
-- Usage help
|
||||||
local function help()
|
local function help()
|
||||||
print(copyright)
|
print(copyright)
|
||||||
|
print(author)
|
||||||
print(version)
|
print(version)
|
||||||
print(desc)
|
print(desc)
|
||||||
print('Example usage')
|
print('Example usage')
|
||||||
print(example)
|
print(example)
|
||||||
|
print(usage)
|
||||||
end
|
end
|
||||||
--
|
--
|
||||||
-- Exit message
|
-- Exit message
|
||||||
|
@ -183,6 +186,7 @@ local function write_tag(uid, t)
|
||||||
|
|
||||||
print('Writing to tag')
|
print('Writing to tag')
|
||||||
core.console('hf mf dbg 0')
|
core.console('hf mf dbg 0')
|
||||||
|
utils.Sleep(0.5)
|
||||||
|
|
||||||
local cmd = ''
|
local cmd = ''
|
||||||
local pwd, pack = core.keygen_algo_d(uid)
|
local pwd, pack = core.keygen_algo_d(uid)
|
||||||
|
@ -200,6 +204,7 @@ local function write_tag(uid, t)
|
||||||
core.console(('hf mfu wrbl b 40 d %s k %08X'):format(t[40], pwd))
|
core.console(('hf mfu wrbl b 40 d %s k %08X'):format(t[40], pwd))
|
||||||
|
|
||||||
core.console('hf mf dbg 1')
|
core.console('hf mf dbg 1')
|
||||||
|
utils.Sleep(0.5)
|
||||||
print('Done')
|
print('Done')
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
|
@ -228,7 +233,7 @@ end
|
||||||
---
|
---
|
||||||
-- generates random hex numbers between 31-39
|
-- generates random hex numbers between 31-39
|
||||||
local function random_num_hex(length)
|
local function random_num_hex(length)
|
||||||
local str = ""
|
local str = ''
|
||||||
local i
|
local i
|
||||||
for i = 1, length, 1 do
|
for i = 1, length, 1 do
|
||||||
str = str..math.random(31, 39)
|
str = str..math.random(31, 39)
|
||||||
|
@ -325,15 +330,15 @@ local function main(args)
|
||||||
|
|
||||||
-- Read the parameters
|
-- Read the parameters
|
||||||
for o, a in getopt.getopt(args, 'ht1u:l:m:c:p:s:') do
|
for o, a in getopt.getopt(args, 'ht1u:l:m:c:p:s:') do
|
||||||
if o == "h" then return help() end
|
if o == 'h' then return help() end
|
||||||
if o == "t" then return selftest() end
|
if o == 't' then return selftest() end
|
||||||
if o == "u" then uid = a; useUID = true end
|
if o == 'u' then uid = a; useUID = true end
|
||||||
if o == "m" then material = a end
|
if o == 'm' then material = a end
|
||||||
if o == "c" then color = a end
|
if o == 'c' then color = a end
|
||||||
if o == "l" then length = tonumber(a) end
|
if o == 'l' then length = tonumber(a) end
|
||||||
if o == "p" then producer = a end
|
if o == 'p' then producer = a end
|
||||||
if o == "s" then sales = a end
|
if o == 's' then sales = a end
|
||||||
if o == "1" then useMAGIC = true end
|
if o == '1' then useMAGIC = true end
|
||||||
end
|
end
|
||||||
|
|
||||||
color = find(_colors, color)
|
color = find(_colors, color)
|
||||||
|
|
|
@ -1,19 +1,34 @@
|
||||||
|
|
||||||
-- The getopt-functionality is loaded from pm3/getopt.lua
|
-- The getopt-functionality is loaded from pm3/getopt.lua
|
||||||
-- Have a look there for further details
|
-- Have a look there for further details
|
||||||
getopt = require('getopt')
|
getopt = require('getopt')
|
||||||
|
|
||||||
usage = "script run parameters.lua -a 1 -blala -c -de"
|
copyright = ''
|
||||||
author = "Martin Holst Swende"
|
usage = 'script run parameters.lua -a 1 -blala -c -de'
|
||||||
|
author = 'Martin Holst Swende'
|
||||||
|
version = 'v1.0.1'
|
||||||
desc = [[
|
desc = [[
|
||||||
This is an example script to demonstrate handle parameters in scripts.
|
This is an example script to demonstrate handle parameters in scripts.
|
||||||
For more info, check the comments in the code
|
For more info, check the comments in the code
|
||||||
]]
|
]]
|
||||||
|
example = [[
|
||||||
|
]]
|
||||||
|
usage = [[
|
||||||
|
]]
|
||||||
|
---
|
||||||
|
-- Usage help
|
||||||
|
local function help()
|
||||||
|
print(copyright)
|
||||||
|
print(author)
|
||||||
|
print(version)
|
||||||
|
print(desc)
|
||||||
|
print('Example usage')
|
||||||
|
print(example)
|
||||||
|
print(usage)
|
||||||
|
end
|
||||||
|
|
||||||
local function main(args)
|
local function main(args)
|
||||||
|
|
||||||
print(desc)
|
print('These parameters were passed')
|
||||||
print("These parameters were passed")
|
|
||||||
--[[
|
--[[
|
||||||
When passing parameters,
|
When passing parameters,
|
||||||
x: means that a value should follow x
|
x: means that a value should follow x
|
||||||
|
@ -31,7 +46,8 @@ local function main(args)
|
||||||
4. The format b lala (without -) is *not* supported
|
4. The format b lala (without -) is *not* supported
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
for o, a in getopt.getopt(args, 'a:b:ced') do
|
for o, a in getopt.getopt(args, 'ha:b:ced') do
|
||||||
|
if o == 'h' then return help() end
|
||||||
print(o, a)
|
print(o, a)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue