1 local getopt
= require('getopt')
2 local lib14a
= require('read14a')
3 local cmds
= require('commands')
4 local ansicolors
= require('ansicolors')
6 copyright
= 'Copyright 2021 A. Ozkal, released under GPLv2+.'
10 This script attempts to grab signatures from an NTAG or MFULEV1 card and print it in a machine parsable way
13 script run ntag_getsig
16 script run ntag_getsig [-h]
26 print(ansicolors
.cyan
..'Usage'..ansicolors
.reset
)
28 print(ansicolors
.cyan
..'Arguments'..ansicolors
.reset
)
30 print(ansicolors
.cyan
..'Example usage'..ansicolors
.reset
)
34 -- Used to send raw data to the firmware to subsequently forward the data to the card.
35 -- from mifareplus.lua
36 local function sendRaw(rawdata
, crc
, power
)
37 -- print(("<sent>: %s"):format(rawdata))
39 local flags
= lib14a
.ISO14A_COMMAND
.ISO14A_RAW
41 flags
= flags
+ lib14a
.ISO14A_COMMAND
.ISO14A_APPEND_CRC
44 flags
= flags
+ lib14a
.ISO14A_COMMAND
.ISO14A_NO_DISCONNECT
47 local command
= Command
:newMIX
{cmd
= cmds
.CMD_HF_ISO14443A_READER
,
48 arg1
= flags
, -- Send raw
49 arg2
= string.len(rawdata
) / 2, -- arg2 contains the length, which is half the length of the ASCII-string rawdata
52 local ignore_response
= false
53 local result
, err
= command
:sendMIX(ignore_response
)
55 --unpack the first 4 parts of the result as longs, and the last as an extremely long string to later be cut down based on arg1, the number of bytes returned
56 local count
,cmd
,arg1
,arg2
,arg3
,data
= bin
.unpack('LLLLH512',result
)
58 returned_bytes
= string.sub(data
, 1, arg1
* 2)
59 if #returned_bytes
> 0 then
60 -- print(("<recvd>: %s"):format(returned_bytes)) -- need to multiply by 2 because the hex digits are actually two bytes when they are strings
66 print("Error sending the card raw data.")
72 -- The main entry point
74 -- Read the parameters
75 for o
, a
in getopt
.getopt(args
, 'h') do
76 if o
== 'h' then return help() end
79 local tag, err
= lib14a
.read(true, false)
82 local sig
= sendRaw("3C00", true, true)
83 local ver
= sendRaw("60", true, false)
84 if sig
and ver
then -- if false, that's a fail right there
85 sig
= string.sub(sig
, 0, -5)
86 ver
= string.sub(ver
, 0, -5)
87 local text
= tag.name
..","..ver
..","..tag.uid
..","..sig
90 local filename
= "originalitysig.csv"
91 local outfile
= io
.open(filename
, "a")
92 if outfile
~= nil then
93 outfile
:write(text
.."\n")
96 print(ansicolors
.red
.."Couldn't open file originalitysig.csv."..ansicolors
.reset
)
99 print(ansicolors
.red
.."Read FAILED."..ansicolors
.reset
)