2018-11-06 21:37:34 +08:00
|
|
|
local getopt = require('getopt')
|
|
|
|
local bin = require('bin')
|
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
copyright = 'Copyright (c) 2018 Bogito. All rights reserved.'
|
2018-11-06 21:37:34 +08:00
|
|
|
author = "Bogito"
|
2019-01-02 01:01:40 +08:00
|
|
|
version = 'v1.0.1'
|
|
|
|
desc =
|
|
|
|
[[
|
2018-11-06 21:37:34 +08:00
|
|
|
This script will read the flash memory of RDV4 and print the stored passwords.
|
|
|
|
It was meant to be used as a help tool after using the BogRun standalone mode.
|
2019-01-02 01:01:40 +08:00
|
|
|
|
|
|
|
(Iceman) script adapted to read and print keys in the default dictionary flashmemory sections.
|
2018-11-06 21:37:34 +08:00
|
|
|
]]
|
2019-01-02 01:01:40 +08:00
|
|
|
usage =
|
|
|
|
[[
|
2018-11-06 21:37:34 +08:00
|
|
|
Usage:
|
2019-01-02 01:01:40 +08:00
|
|
|
script run read_pwd_mem -h -o <offset> -l <length> -k <keylength>
|
2018-11-06 21:37:34 +08:00
|
|
|
|
|
|
|
Arguments:
|
2019-01-02 01:01:40 +08:00
|
|
|
-h : this help
|
|
|
|
-o <offset> : memory offset, default is 0
|
|
|
|
-l <length> : length in bytes, default is 256
|
|
|
|
-k <keylen> : key length in bytes <4|6|8> , default is 4
|
2019-01-11 01:55:56 +08:00
|
|
|
-m : print Mifare dictionary keys
|
|
|
|
-t : print t55xx dictionary passwords
|
|
|
|
-i : print iClass dictionary keys
|
2018-11-06 21:37:34 +08:00
|
|
|
]]
|
2019-01-02 01:01:40 +08:00
|
|
|
example =
|
|
|
|
[[
|
2018-11-06 21:37:34 +08:00
|
|
|
-- This will scan the first 256 bytes of flash memory for stored passwords
|
|
|
|
script run read_pwd_mem
|
|
|
|
|
|
|
|
-- This will scan 256 bytes of flash memory at offset 64 for stored passwords
|
|
|
|
script run read_pwd_mem -o 64
|
|
|
|
|
|
|
|
-- This will scan 32 bytes of flash memory at offset 64 for stored passwords
|
|
|
|
script run read_pwd_mem -o 64 -l 32
|
2019-01-02 01:01:40 +08:00
|
|
|
|
|
|
|
-- This will print found
|
|
|
|
script run read_pwd_mem -o 241664 -k 6
|
2018-11-06 21:37:34 +08:00
|
|
|
]]
|
2019-01-02 01:01:40 +08:00
|
|
|
---
|
|
|
|
-- This is only meant to be used when errors occur
|
|
|
|
local function oops(err)
|
|
|
|
print("ERROR: ", err)
|
|
|
|
return nil, err
|
|
|
|
end
|
|
|
|
---
|
2018-11-06 21:37:34 +08:00
|
|
|
-- Usage help
|
|
|
|
local function help()
|
2019-01-02 01:01:40 +08:00
|
|
|
print(copyright)
|
|
|
|
print(version)
|
2018-11-06 21:37:34 +08:00
|
|
|
print(desc)
|
|
|
|
print(usage)
|
2019-01-02 01:01:40 +08:00
|
|
|
print('Example usage:')
|
2018-11-06 21:37:34 +08:00
|
|
|
print(example)
|
|
|
|
end
|
2019-01-02 01:01:40 +08:00
|
|
|
---
|
|
|
|
-- The main entry point
|
2018-11-06 21:37:34 +08:00
|
|
|
local function main(args)
|
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
print( string.rep('--',20) )
|
|
|
|
print( string.rep('--',20) )
|
|
|
|
print()
|
|
|
|
|
|
|
|
local data, err, quadlet
|
|
|
|
local cnt = 0
|
2018-11-06 21:37:34 +08:00
|
|
|
local offset = 0
|
|
|
|
local length = 256
|
2019-01-02 01:01:40 +08:00
|
|
|
local keylength = 4
|
|
|
|
local usedkey = false
|
2018-11-06 21:37:34 +08:00
|
|
|
|
2019-01-11 01:55:56 +08:00
|
|
|
for o, a in getopt.getopt(args, 'ho:l:k:mti') do
|
2019-01-02 01:01:40 +08:00
|
|
|
|
|
|
|
-- help
|
2018-11-06 21:37:34 +08:00
|
|
|
if o == "h" then return help() end
|
2019-01-02 01:01:40 +08:00
|
|
|
|
|
|
|
-- offset
|
2018-11-06 21:37:34 +08:00
|
|
|
if o == "o" then offset = tonumber(a) end
|
2019-01-02 01:01:40 +08:00
|
|
|
|
|
|
|
-- num of bytes to read
|
2018-11-06 21:37:34 +08:00
|
|
|
if o == "l" then length = tonumber(a) end
|
2019-01-02 01:01:40 +08:00
|
|
|
|
|
|
|
-- keylength
|
|
|
|
if o == "k" then keylength = tonumber(a); usedkey = true end
|
2019-01-11 01:55:56 +08:00
|
|
|
|
|
|
|
if o == "m" then keylength =6; usedkey = true; offset = 0x3F000-0x4000; end
|
|
|
|
if o == "t" then keylength =4; usedkey = true; offset = 0x3F000-0x3000; end
|
|
|
|
if o == "i" then keylength =8; usedkey = true; offset = 0x3F000-0x5000; end
|
2018-11-06 21:37:34 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
if length < 0 or length > 256 then
|
2019-01-02 01:01:40 +08:00
|
|
|
return oops('Error: Length is not valid. Must be less than 256')
|
2018-11-06 21:37:34 +08:00
|
|
|
end
|
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
if (offset < 0) or (offset % 4 ~= 0) then
|
|
|
|
return oops('Error: Offset is not valid. Mod-4 values are only allowed.')
|
2018-11-06 21:37:34 +08:00
|
|
|
end
|
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
print('Memory offset', offset)
|
|
|
|
print('Length ', length)
|
|
|
|
print('Key length ', keylength)
|
|
|
|
print( string.rep('--',20) )
|
2018-11-06 21:37:34 +08:00
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
if usedkey then length = 4096 end
|
|
|
|
|
|
|
|
data, err = core.GetFromFlashMem(offset, length)
|
|
|
|
if err then return oops(err) end
|
2018-11-06 21:37:34 +08:00
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
if usedkey then
|
2018-11-06 21:37:34 +08:00
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
_, keys, s = bin.unpack('SH'..length-2, data)
|
|
|
|
if keys == 0xFFFF then return "No keys found in section" end
|
|
|
|
|
|
|
|
local kl = keylength * 2
|
|
|
|
for i = 1, keys do
|
|
|
|
|
|
|
|
key = string.sub(s, (i - 1) * kl + 1, i * kl )
|
|
|
|
print(string.format("[%02d] %s",i, key))
|
|
|
|
end
|
|
|
|
print( string.rep('--',20) )
|
|
|
|
print( ('[+] found %d passwords'):format(keys))
|
|
|
|
else
|
2018-11-06 21:37:34 +08:00
|
|
|
|
2019-01-02 01:01:40 +08:00
|
|
|
_, s = bin.unpack('H'..length, data)
|
|
|
|
|
|
|
|
local cnt = 0, i
|
|
|
|
for i = 1, (length/keylength) do
|
|
|
|
|
|
|
|
key = string.sub(s, (i-1)*8+1, i*8)
|
|
|
|
if key == "FFFFFFFF" then break end
|
|
|
|
print(string.format("[%02d] %s",i, key))
|
|
|
|
cnt = cnt + 1
|
|
|
|
end
|
|
|
|
print( string.rep('--',20) )
|
|
|
|
print( ('[+] found %d passwords'):format(cnt))
|
2018-11-06 21:37:34 +08:00
|
|
|
end
|
2019-01-02 01:01:40 +08:00
|
|
|
print( string.rep('--',20) )
|
2018-11-06 21:37:34 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
main(args)
|