2017-04-20 21:29:45 +08:00
|
|
|
local getopt = require('getopt')
|
|
|
|
local utils = require('utils')
|
2020-04-05 18:56:35 +08:00
|
|
|
local ansicolors = require('ansicolors')
|
2017-04-20 21:29:45 +08:00
|
|
|
|
2018-04-03 17:24:58 +08:00
|
|
|
copyright = ''
|
2017-04-20 21:29:45 +08:00
|
|
|
author = "Iceman"
|
2020-12-28 20:36:37 +08:00
|
|
|
version = 'v1.0.3'
|
2018-04-03 17:24:58 +08:00
|
|
|
desc = [[
|
|
|
|
This script tries to set UID on a mifare Ultralight magic card which either
|
2019-03-09 17:34:43 +08:00
|
|
|
- answers to chinese backdoor commands
|
2018-04-03 17:24:58 +08:00
|
|
|
- brickable magic tag (must write in one session)
|
2020-12-28 20:36:37 +08:00
|
|
|
|
|
|
|
It defaults to GEN1A type of uid changeable card.
|
2018-04-03 17:24:58 +08:00
|
|
|
]]
|
|
|
|
example = [[
|
2020-12-28 20:36:37 +08:00
|
|
|
-- backdoor magic tag (gen1a)
|
2020-08-14 00:40:27 +08:00
|
|
|
script run hf_mfu_setuid -u 11223344556677
|
2019-03-09 17:34:43 +08:00
|
|
|
|
2020-12-28 20:36:37 +08:00
|
|
|
-- backdoor magic tag (gen1b)
|
2020-08-14 00:40:27 +08:00
|
|
|
script run hf_mfu_setuid -b -u 11223344556677
|
2020-12-28 20:36:37 +08:00
|
|
|
|
|
|
|
-- brickable magic tag (gen2)
|
|
|
|
script run hf_mfu_setuid -2 -u 11223344556677
|
2018-04-03 17:24:58 +08:00
|
|
|
]]
|
|
|
|
usage = [[
|
2020-12-28 20:36:37 +08:00
|
|
|
script run hf_mfu_setuid [-h] [-b] [-2] [-u <uid>]
|
2020-04-05 18:56:35 +08:00
|
|
|
]]
|
|
|
|
arguments = [[
|
2019-03-09 17:34:43 +08:00
|
|
|
-h : this help
|
|
|
|
-u <UID> : UID (14 hexsymbols)
|
2020-12-28 20:36:37 +08:00
|
|
|
-b : write to magic tag GEN1B
|
|
|
|
-2 : write to brickable magic tag GEN2
|
2017-04-20 21:29:45 +08:00
|
|
|
]]
|
2018-04-03 17:24:58 +08:00
|
|
|
|
|
|
|
local DEBUG = true
|
|
|
|
local bxor = bit32.bxor
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2017-04-20 21:29:45 +08:00
|
|
|
-- A debug printout-function
|
2018-04-03 17:24:58 +08:00
|
|
|
local function dbg(args)
|
|
|
|
if not DEBUG then return end
|
2019-04-29 00:46:06 +08:00
|
|
|
if type(args) == 'table' then
|
2019-03-09 17:34:43 +08:00
|
|
|
local i = 1
|
|
|
|
while args[i] do
|
|
|
|
dbg(args[i])
|
|
|
|
i = i+1
|
|
|
|
end
|
|
|
|
else
|
2019-04-29 00:46:06 +08:00
|
|
|
print('###', args)
|
2019-03-09 17:34:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
---
|
2017-04-20 21:29:45 +08:00
|
|
|
-- This is only meant to be used when errors occur
|
2018-04-03 17:24:58 +08:00
|
|
|
local function oops(err)
|
2019-04-29 00:46:06 +08:00
|
|
|
print('ERROR:', err)
|
2019-04-29 01:26:26 +08:00
|
|
|
core.clearCommandBuffer()
|
2019-03-09 17:34:43 +08:00
|
|
|
return nil, err
|
2017-04-20 21:29:45 +08:00
|
|
|
end
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2017-04-20 21:29:45 +08:00
|
|
|
-- Usage help
|
2018-04-03 17:24:58 +08:00
|
|
|
local function help()
|
2019-03-09 17:34:43 +08:00
|
|
|
print(copyright)
|
|
|
|
print(author)
|
|
|
|
print(version)
|
|
|
|
print(desc)
|
2020-04-05 18:56:35 +08:00
|
|
|
print(ansicolors.cyan..'Usage'..ansicolors.reset)
|
2019-04-29 04:54:00 +08:00
|
|
|
print(usage)
|
2020-04-05 18:56:35 +08:00
|
|
|
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
|
|
|
|
print(arguments)
|
|
|
|
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
|
|
|
|
print(example)
|
2017-04-20 21:29:45 +08:00
|
|
|
end
|
2018-04-03 17:24:58 +08:00
|
|
|
--
|
|
|
|
--- Set UID on magic command enabled
|
2020-12-28 20:36:37 +08:00
|
|
|
function magicUID(b0, b1, b2, isgen1a)
|
2018-04-03 17:24:58 +08:00
|
|
|
|
2020-12-30 08:31:40 +08:00
|
|
|
if isgen1a then
|
2020-12-28 20:36:37 +08:00
|
|
|
print('Using backdoor Magic tag (gen1a) function')
|
|
|
|
else
|
|
|
|
print('Using backdoor Magic tag (gen1b) function')
|
|
|
|
end
|
2017-04-20 21:29:45 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
-- write block 0
|
2020-10-01 06:29:24 +08:00
|
|
|
core.console('hf 14a raw -k -a -b 7 40')
|
2020-12-30 08:31:40 +08:00
|
|
|
if isgen1a then
|
2020-12-28 20:36:37 +08:00
|
|
|
core.console('hf 14a raw -k -a 43')
|
|
|
|
end
|
2019-04-29 00:46:06 +08:00
|
|
|
core.console('hf 14a raw -c -a A200'..b0)
|
2018-04-03 17:24:58 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
-- write block 1
|
2020-10-01 06:29:24 +08:00
|
|
|
core.console('hf 14a raw -k -a -b 7 40')
|
2020-12-30 08:31:40 +08:00
|
|
|
if isgen1a then
|
2020-12-28 20:36:37 +08:00
|
|
|
core.console('hf 14a raw -k -a 43')
|
|
|
|
end
|
2019-04-29 00:46:06 +08:00
|
|
|
core.console('hf 14a raw -c -a A201'..b1)
|
2018-04-03 17:24:58 +08:00
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
-- write block 2
|
2020-10-01 06:29:24 +08:00
|
|
|
core.console('hf 14a raw -k -a -b 7 40')
|
2020-12-30 08:31:40 +08:00
|
|
|
if isgen1a then
|
2020-12-28 20:36:37 +08:00
|
|
|
core.console('hf 14a raw -k -a 43')
|
|
|
|
end
|
2019-04-29 00:46:06 +08:00
|
|
|
core.console('hf 14a raw -c -a A202'..b2)
|
2018-04-03 17:24:58 +08:00
|
|
|
end
|
|
|
|
--
|
2019-03-09 17:34:43 +08:00
|
|
|
--- Set UID on magic but brickable
|
2018-04-03 17:24:58 +08:00
|
|
|
function brickableUID(b0, b1, b2)
|
2019-03-09 17:34:43 +08:00
|
|
|
|
|
|
|
print('Using BRICKABLE Magic tag function')
|
|
|
|
|
2020-10-01 06:29:24 +08:00
|
|
|
core.console('hf 14a raw -k -s -3')
|
2019-03-09 17:34:43 +08:00
|
|
|
|
|
|
|
-- write block 0
|
2020-10-01 06:29:24 +08:00
|
|
|
core.console('hf 14a raw -k -c A200'..b0)
|
2019-03-09 17:34:43 +08:00
|
|
|
|
|
|
|
-- write block 1
|
2020-10-01 06:29:24 +08:00
|
|
|
core.console('hf 14a raw -k -c A201'..b1)
|
2019-03-09 17:34:43 +08:00
|
|
|
|
|
|
|
-- write block 2
|
2020-10-01 06:29:24 +08:00
|
|
|
core.console('hf 14a raw -k -c A202'..b2)
|
2018-04-03 17:24:58 +08:00
|
|
|
end
|
2019-03-09 17:34:43 +08:00
|
|
|
---
|
2017-04-20 21:29:45 +08:00
|
|
|
-- The main entry point
|
|
|
|
function main(args)
|
|
|
|
|
2019-03-09 17:34:43 +08:00
|
|
|
print( string.rep('--',20) )
|
|
|
|
print( string.rep('--',20) )
|
|
|
|
print()
|
|
|
|
|
|
|
|
local uid = '04112233445566'
|
|
|
|
local tagtype = 1
|
|
|
|
|
|
|
|
-- Read the parameters
|
2020-12-28 20:36:37 +08:00
|
|
|
for o, a in getopt.getopt(args, 'hu:b2') do
|
2019-04-29 00:46:06 +08:00
|
|
|
if o == 'h' then return help() end
|
|
|
|
if o == 'u' then uid = a end
|
|
|
|
if o == 'b' then tagtype = 2 end
|
2020-12-28 20:36:37 +08:00
|
|
|
if o == '2' then tagtype = 3 end
|
2019-03-09 17:34:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
-- uid string checks
|
|
|
|
if uid == nil then return oops('empty uid string') end
|
|
|
|
if #uid == 0 then return oops('empty uid string') end
|
|
|
|
if #uid ~= 14 then return oops('uid wrong length. Should be 7 hex bytes') end
|
|
|
|
|
|
|
|
local uidbytes = utils.ConvertHexToBytes(uid)
|
|
|
|
|
|
|
|
local bcc1 = bxor(0x88, uidbytes[1], uidbytes[2], uidbytes[3])
|
|
|
|
local bcc2 = bxor(uidbytes[4], uidbytes[5], uidbytes[6], uidbytes[7])
|
|
|
|
|
|
|
|
local block0 = string.format('%02X%02X%02X%02X', uidbytes[1], uidbytes[2], uidbytes[3], bcc1)
|
|
|
|
local block1 = string.format('%02X%02X%02X%02X', uidbytes[4], uidbytes[5], uidbytes[6], uidbytes[7])
|
|
|
|
local block2 = string.format('%02X%02X%02X%02X', bcc2, 0x48, 0x00, 0x00)
|
|
|
|
|
|
|
|
print('new UID | '..uid)
|
|
|
|
|
|
|
|
core.clearCommandBuffer()
|
|
|
|
|
2020-12-30 08:31:40 +08:00
|
|
|
if tagtype == 3 then
|
2019-03-09 17:34:43 +08:00
|
|
|
brickableUID(block0, block1, block2)
|
|
|
|
else
|
2020-12-28 20:36:37 +08:00
|
|
|
local is_gen1a = (tagtype == 1)
|
|
|
|
magicUID(block0, block1, block2, is_gen1a)
|
2019-03-09 17:34:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
--halt
|
2019-04-29 00:46:06 +08:00
|
|
|
core.console('hf 14a raw -c -a 5000')
|
2017-04-20 21:29:45 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
main(args)
|