diff --git a/.gitignore b/.gitignore index 430ae2cad..543624a4f 100644 --- a/.gitignore +++ b/.gitignore @@ -33,6 +33,7 @@ version.c *.json.bak *.pyc *.bmp +originalitysig.csv # new build file for add-ons. Makefile.platform diff --git a/CHANGELOG.md b/CHANGELOG.md index c05e5a084..bced7ef1a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ All notable changes to this project will be documented in this file. This project uses the changelog in accordance with [keepchangelog](http://keepachangelog.com/). Please use this to write notable changes, which is not the same as git commit log... ## [unreleased][unreleased] + - Added a script to dump originality signatures from MFU EV1s and NTAGs (@aveao) - Added parsing of EF_CardAccess to display PACE algorithm, version and parameter in `hf emrtd info` (@aveao) - Change, numerous commands more uses cliparser (@tcprst, @iceman1001) - Added more originality public keys (@anon) diff --git a/client/luascripts/ntag_getsig.lua b/client/luascripts/ntag_getsig.lua new file mode 100644 index 000000000..a70cb8623 --- /dev/null +++ b/client/luascripts/ntag_getsig.lua @@ -0,0 +1,104 @@ +local getopt = require('getopt') +local lib14a = require('read14a') +local cmds = require('commands') +local ansicolors = require('ansicolors') + +copyright = 'Copyright 2021 A. Ozkal, released under GPLv2+.' +author = 'Ave' +version = 'v1.0.0' +desc = [[ +This script attempts to grab signatures from an NTAG or MFULEV1 card and print it in a machine parsable way + ]] +example = [[ + script run ntag_getsig +]] +usage = [[ + script run ntag_getsig [-h] +]] +arguments = [[ + -h : This help +]] + +local function help() + print(author) + print(version) + print(desc) + print(ansicolors.cyan..'Usage'..ansicolors.reset) + print(usage) + print(ansicolors.cyan..'Arguments'..ansicolors.reset) + print(arguments) + print(ansicolors.cyan..'Example usage'..ansicolors.reset) + print(example) +end + +-- Used to send raw data to the firmware to subsequently forward the data to the card. +-- from mifareplus.lua +local function sendRaw(rawdata, crc, power) + -- print((": %s"):format(rawdata)) + + local flags = lib14a.ISO14A_COMMAND.ISO14A_RAW + if crc then + flags = flags + lib14a.ISO14A_COMMAND.ISO14A_APPEND_CRC + end + if power then + flags = flags + lib14a.ISO14A_COMMAND.ISO14A_NO_DISCONNECT + end + + local command = Command:newMIX{cmd = cmds.CMD_HF_ISO14443A_READER, + arg1 = flags, -- Send raw + arg2 = string.len(rawdata) / 2, -- arg2 contains the length, which is half the length of the ASCII-string rawdata + data = rawdata + } + local ignore_response = false + local result, err = command:sendMIX(ignore_response) + if result then + --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 + local count,cmd,arg1,arg2,arg3,data = bin.unpack('LLLLH512',result) + + returned_bytes = string.sub(data, 1, arg1 * 2) + if #returned_bytes > 0 then + -- print((": %s"):format(returned_bytes)) -- need to multiply by 2 because the hex digits are actually two bytes when they are strings + return returned_bytes + else + return nil + end + else + print("Error sending the card raw data.") + return nil + end +end + +--- +-- The main entry point +function main(args) + -- Read the parameters + for o, a in getopt.getopt(args, 'h') do + if o == 'h' then return help() end + end + + local tag, err = lib14a.read(true, false) + + if not err then + local sig = sendRaw("3C00", true, true) + local ver = sendRaw("60", true, false) + if sig and ver then -- if false, that's a fail right there + sig = string.sub(sig, 0, -5) + ver = string.sub(ver, 0, -5) + local text = tag.name..","..ver..","..tag.uid..","..sig + print(text) + + local filename = "originalitysig.csv" + local outfile = io.open(filename, "a") + if outfile ~= nil then + outfile:write(text.."\n") + io.close(outfile) + else + print(ansicolors.red.."Couldn't open file originalitysig.csv."..ansicolors.reset) + end + else + print(ansicolors.red.."Read FAILED."..ansicolors.reset) + end + end +end + +main(args)