1 local getopt
= require('getopt')
2 local utils
= require('utils')
3 local ansicolors
= require('ansicolors')
9 This script tries to set UID on a mifare Ultralight magic card which either
10 - answers to chinese backdoor commands
11 - brickable magic tag (must write in one session)
13 It defaults to GEN1A type of uid changeable card.
16 -- backdoor magic tag (gen1a)
17 script run hf_mfu_setuid -u 11223344556677
19 -- backdoor magic tag (gen1b)
20 script run hf_mfu_setuid -b -u 11223344556677
22 -- brickable magic tag (gen2)
23 script run hf_mfu_setuid -2 -u 11223344556677
26 script run hf_mfu_setuid [-h] [-b] [-2] [-u <uid>]
30 -u <UID> : UID (14 hexsymbols)
31 -b : write to magic tag GEN1B
32 -2 : write to brickable magic tag GEN2
36 local bxor
= bit32
.bxor
38 -- A debug printout-function
39 local function dbg(args
)
40 if not DEBUG
then return end
41 if type(args
) == 'table' then
52 -- This is only meant to be used when errors occur
53 local function oops(err
)
55 core
.clearCommandBuffer()
65 print(ansicolors
.cyan
..'Usage'..ansicolors
.reset
)
67 print(ansicolors
.cyan
..'Arguments'..ansicolors
.reset
)
69 print(ansicolors
.cyan
..'Example usage'..ansicolors
.reset
)
73 --- Set UID on magic command enabled
74 function magicUID(b0
, b1
, b2
, isgen1a
)
77 print('Using backdoor Magic tag (gen1a) function')
79 print('Using backdoor Magic tag (gen1b) function')
83 core
.console('hf 14a raw -k -a -b 7 40')
85 core
.console('hf 14a raw -k -a 43')
87 core
.console('hf 14a raw -c -a A200'..b0
)
90 core
.console('hf 14a raw -k -a -b 7 40')
92 core
.console('hf 14a raw -k -a 43')
94 core
.console('hf 14a raw -c -a A201'..b1
)
97 core
.console('hf 14a raw -k -a -b 7 40')
99 core
.console('hf 14a raw -k -a 43')
101 core
.console('hf 14a raw -c -a A202'..b2
)
104 --- Set UID on magic but brickable
105 function brickableUID(b0
, b1
, b2
)
107 print('Using BRICKABLE Magic tag function')
109 core
.console('hf 14a raw -k -s -3')
112 core
.console('hf 14a raw -k -c A200'..b0
)
115 core
.console('hf 14a raw -k -c A201'..b1
)
118 core
.console('hf 14a raw -k -c A202'..b2
)
121 -- The main entry point
124 print( string.rep('--',20) )
125 print( string.rep('--',20) )
128 local uid
= '04112233445566'
131 -- Read the parameters
132 for o
, a
in getopt
.getopt(args
, 'hu:b2') do
133 if o
== 'h' then return help() end
134 if o
== 'u' then uid
= a
end
135 if o
== 'b' then tagtype
= 2 end
136 if o
== '2' then tagtype
= 3 end
140 if uid
== nil then return oops('empty uid string') end
141 if #uid
== 0 then return oops('empty uid string') end
142 if #uid
~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end
144 local uidbytes
= utils
.ConvertHexToBytes(uid
)
146 local bcc1
= bxor(0x88, uidbytes
[1], uidbytes
[2], uidbytes
[3])
147 local bcc2
= bxor(uidbytes
[4], uidbytes
[5], uidbytes
[6], uidbytes
[7])
149 local block0
= string.format('%02X%02X%02X%02X', uidbytes
[1], uidbytes
[2], uidbytes
[3], bcc1
)
150 local block1
= string.format('%02X%02X%02X%02X', uidbytes
[4], uidbytes
[5], uidbytes
[6], uidbytes
[7])
151 local block2
= string.format('%02X%02X%02X%02X', bcc2
, 0x48, 0x00, 0x00)
153 print('new UID | '..uid
)
155 core
.clearCommandBuffer()
158 brickableUID(block0
, block1
, block2
)
160 local is_gen1a
= (tagtype
== 1)
161 magicUID(block0
, block1
, block2
, is_gen1a
)
165 core
.console('hf 14a raw -c -a 5000')