mirror of
https://github.com/RfidResearchGroup/proxmark3.git
synced 2025-08-19 21:03:48 -07:00
CHG: remade selftest structure
CHG: removed debugstatements
This commit is contained in:
parent
e86a89044a
commit
af3b8b2dc6
1 changed files with 25 additions and 31 deletions
|
@ -14,6 +14,7 @@ This is a script to dump and decrypt the data of a specific type of Mifare Mini
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
-h : this help
|
-h : this help
|
||||||
|
-t : selftest
|
||||||
-k <key> : Mifare Key A.
|
-k <key> : Mifare Key A.
|
||||||
]]
|
]]
|
||||||
|
|
||||||
|
@ -365,13 +366,21 @@ local function selftest()
|
||||||
local testdata = '000F42430D0A14000001D11F'..'5D738517'
|
local testdata = '000F42430D0A14000001D11F'..'5D738517'
|
||||||
local chksum = getChecksum(testdata)
|
local chksum = getChecksum(testdata)
|
||||||
local calc = calculateChecksum( utils.ConvertHexToBytes(testdata:sub(1,24)))
|
local calc = calculateChecksum( utils.ConvertHexToBytes(testdata:sub(1,24)))
|
||||||
|
local isValid = false
|
||||||
|
local validStr = "FAIL"
|
||||||
|
if calc == chksum then
|
||||||
|
isValid = true
|
||||||
|
validStr = "OK"
|
||||||
|
end
|
||||||
|
local newtestdata = updateChecksum(testdata)
|
||||||
|
local revalidated = "FAIL"
|
||||||
|
if newtestdata == testdata then
|
||||||
|
revalidated = "OK"
|
||||||
|
end
|
||||||
print ('TESTDATA :: '..testdata)
|
print ('TESTDATA :: '..testdata)
|
||||||
print ('DATA :: '..testdata:sub(1,24))
|
print ('DATA :: '..testdata:sub(1,24))
|
||||||
print (('CHKSUM :: %X'):format(chksum))
|
print (('VALID CHKSUM :: %s'):format(validStr ))
|
||||||
print (('CHKSUM CALC :: %X'):format(calc))
|
print (('UPDATE CHKSUM :: %s'):format(revalidated))
|
||||||
print ('UPDATE CHKSUM :: '..updateChecksum(testdata))
|
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
||||||
---
|
---
|
||||||
-- The main entry point
|
-- The main entry point
|
||||||
|
@ -382,18 +391,15 @@ function main(args)
|
||||||
|
|
||||||
local cmd, result, err, blockNo, keyA
|
local cmd, result, err, blockNo, keyA
|
||||||
local blocks = {}
|
local blocks = {}
|
||||||
local decryptkey = ''
|
local magic = ''
|
||||||
|
|
||||||
-- Read the parameters
|
-- Read the parameters
|
||||||
for o, a in getopt.getopt(args, 'hk:') do
|
for o, a in getopt.getopt(args, 'hk:t') do
|
||||||
if o == "h" then help() return end
|
if o == "h" then help() return end
|
||||||
if o == "k" then keyA = a end
|
if o == "k" then keyA = a end
|
||||||
|
if o == "t" then return selftest() end
|
||||||
end
|
end
|
||||||
|
|
||||||
selftest()
|
|
||||||
|
|
||||||
local tst2 = '00100100030209094312356432324E34B79A349B'
|
|
||||||
|
|
||||||
-- validate input args.
|
-- validate input args.
|
||||||
keyA = keyA or '6dd747e86975'
|
keyA = keyA or '6dd747e86975'
|
||||||
if #(keyA) ~= 12 then
|
if #(keyA) ~= 12 then
|
||||||
|
@ -410,27 +416,18 @@ function main(args)
|
||||||
if not result then
|
if not result then
|
||||||
return oops(err)
|
return oops(err)
|
||||||
end
|
end
|
||||||
|
|
||||||
core.clearCommandBuffer()
|
core.clearCommandBuffer()
|
||||||
|
|
||||||
print(result.uid, keyA)
|
|
||||||
|
|
||||||
local my = result.uid
|
|
||||||
if 1 == 1 then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Show tag info
|
-- Show tag info
|
||||||
print((' Found tag %s'):format(result.name))
|
print((' Found tag %s'):format(result.name))
|
||||||
|
|
||||||
local longrandom = RANDOM..result.uid
|
local longrandom = RANDOM..result.uid
|
||||||
local res = utils.Sha1Hex(longrandom)
|
local res = utils.Sha1Hex(longrandom)
|
||||||
res = utils.ConvertBytesToHex(utils.ConvertAsciiToBytes(res:sub(1,16)))
|
res = utils.ConvertBytesToHex(utils.ConvertAsciiToBytes(res:sub(1,16)))
|
||||||
decryptkey = utils.SwapEndiannessStr(res:sub(1,8) , 32)
|
magic = utils.SwapEndiannessStr(res:sub(1,8) , 32)
|
||||||
decryptkey = decryptkey..utils.SwapEndiannessStr( res:sub(9,16),32)
|
magic = magic..utils.SwapEndiannessStr( res:sub(9,16),32)
|
||||||
decryptkey = decryptkey..utils.SwapEndiannessStr( res:sub(17,24),32)
|
magic = magic..utils.SwapEndiannessStr( res:sub(17,24),32)
|
||||||
decryptkey = decryptkey..utils.SwapEndiannessStr( res:sub(25,32),32)
|
magic = magic..utils.SwapEndiannessStr( res:sub(25,32),32)
|
||||||
print('Decrypt key::',decryptkey)
|
|
||||||
print('Reading card data')
|
print('Reading card data')
|
||||||
print('Raw','Decrypted')
|
print('Raw','Decrypted')
|
||||||
for blockNo = 0, numBlocks-1, 1 do
|
for blockNo = 0, numBlocks-1, 1 do
|
||||||
|
@ -452,7 +449,7 @@ function main(args)
|
||||||
if string.find(blockdata, '^0+$') then
|
if string.find(blockdata, '^0+$') then
|
||||||
print(blockdata, blockdata)
|
print(blockdata, blockdata)
|
||||||
else
|
else
|
||||||
local aes = core.aes128_decrypt_ecb(decryptkey, blockdata)
|
local aes = core.aes128_decrypt_ecb(magic, blockdata)
|
||||||
local bytes = utils.ConvertAsciiToBytes(aes)
|
local bytes = utils.ConvertAsciiToBytes(aes)
|
||||||
local hex = utils.ConvertBytesToHex(bytes)
|
local hex = utils.ConvertBytesToHex(bytes)
|
||||||
print(blockdata , hex)
|
print(blockdata , hex)
|
||||||
|
@ -465,9 +462,6 @@ function main(args)
|
||||||
print(sectortrailer, sectortrailer, blockdata:sub(13,20))
|
print(sectortrailer, sectortrailer, blockdata:sub(13,20))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- checksum fyra sista bytes i varje rad. (kanske inte för s0)
|
|
||||||
-- s0b1,s1b0,s2b0,s3b0
|
|
||||||
--
|
|
||||||
end
|
end
|
||||||
|
|
||||||
main(args)
|
main(args)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue