]> git.zerfleddert.de Git - proxmark3-svn/blob - client/scripts/hard.lua
ADD: added the 'hf mf hardnested' to be called within LUA scripts.
[proxmark3-svn] / client / scripts / hard.lua
1 local cmds = require('commands')
2 local getopt = require('getopt')
3 local utils = require('utils')
4 local lib14a = require('read14a')
5
6 example = "script iterates over all possible sectors for a tag and runs hardnested attack against them to collect the keys."
7 author = "Iceman"
8 desc =
9 [[
10 This script iterates over all possible sectors for a tag and runs hardnested attack against them to collect the keys.
11
12 Arguments:
13 -k Known key, 6 bytes (12 hex digits)
14 Examples :
15 script hard -b 112233445566
16 ]]
17
18 local numBlocks = 64
19 local numSectors = 16
20 local DEBUG = TRUE
21 ---
22 -- A debug printout-function
23 function dbg(args)
24 if not DEBUG then return end
25
26 if type(args) == "table" then
27 local i = 1
28 while result[i] do
29 dbg(result[i])
30 i = i+1
31 end
32 else
33 print("###", args)
34 end
35 end
36 ---
37 -- This is only meant to be used when errors occur
38 function oops(err)
39 print("ERROR: ",err)
40 return nil,err
41 end
42 ---
43 -- Usage help
44 function help()
45 print(desc)
46 print("Example usage")
47 print(example)
48 end
49 --
50 -- Exit message
51 function ExitMsg(msg)
52 print( string.rep('--',20) )
53 print( string.rep('--',20) )
54 print(msg)
55 print()
56 end
57 ---
58 -- a simple selftest function,
59 local function selftest()
60 return nil
61 end
62
63 ---
64 -- The main entry point
65 function main(args)
66
67 local blockno = '00'
68 local keytype = 0 --A 01==B
69 local key = 'fc00018778f7'
70 local trgkey = ''
71
72 local data
73 -- Read the parameters
74 for o, a in getopt.getopt(args, 'hk:t') do
75 if o == "h" then return help() end
76 if o == "k" then key = a end
77 if o == "t" then return selftest() end
78 end
79
80 -- Turn off Debug
81 local cmdSetDbgOff = "hf mf dbg 0"
82 core.console( cmdSetDbgOff)
83 -- identify tag
84 result, err = lib14a.read1443a(false)
85 if not result then
86 return oops(err)
87 end
88 core.clearCommandBuffer()
89
90 -- Show tag info
91 print((' Found tag %s'):format(result.name))
92
93 local keys = {}
94 -- loop
95 for i=4, 12 , 4 do
96 for trgkeytype=0,1 do
97 local trgblockno = ("%02d"):format(i)
98 local err, found_key = core.hardnested(blockno, keytype, key, trgblockno, trgkeytype, trgkey, 0,0,0,0)
99
100 table.insert( keys , { ["success"] = err, ["sector"] = i, ["type"] = trgkeytype, ["key"] = utils.ConvertAsciiToHex(found_key) } )
101 end
102 end
103 --print
104 for k,v in pairs(keys) do
105 for a,b in pairs(v) do print(a,b) end
106 end
107 end
108
109 main(args)
Impressum, Datenschutz