text
[RRG-proxmark3.git] / client / luascripts / ntag_getsig.lua
bloba70cb8623320c9957c0bc6272379577abc9895d1
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+.'
7 author = 'Ave'
8 version = 'v1.0.0'
9 desc = [[
10 This script attempts to grab signatures from an NTAG or MFULEV1 card and print it in a machine parsable way
12 example = [[
13 script run ntag_getsig
15 usage = [[
16 script run ntag_getsig [-h]
18 arguments = [[
19 -h : This help
22 local function help()
23 print(author)
24 print(version)
25 print(desc)
26 print(ansicolors.cyan..'Usage'..ansicolors.reset)
27 print(usage)
28 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
29 print(arguments)
30 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
31 print(example)
32 end
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
40 if crc then
41 flags = flags + lib14a.ISO14A_COMMAND.ISO14A_APPEND_CRC
42 end
43 if power then
44 flags = flags + lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT
45 end
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
50 data = rawdata
52 local ignore_response = false
53 local result, err = command:sendMIX(ignore_response)
54 if result then
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
61 return returned_bytes
62 else
63 return nil
64 end
65 else
66 print("Error sending the card raw data.")
67 return nil
68 end
69 end
71 ---
72 -- The main entry point
73 function main(args)
74 -- Read the parameters
75 for o, a in getopt.getopt(args, 'h') do
76 if o == 'h' then return help() end
77 end
79 local tag, err = lib14a.read(true, false)
81 if not err then
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
88 print(text)
90 local filename = "originalitysig.csv"
91 local outfile = io.open(filename, "a")
92 if outfile ~= nil then
93 outfile:write(text.."\n")
94 io.close(outfile)
95 else
96 print(ansicolors.red.."Couldn't open file originalitysig.csv."..ansicolors.reset)
97 end
98 else
99 print(ansicolors.red.."Read FAILED."..ansicolors.reset)
104 main(args)