proxmark3/client/luascripts/mem_spiffs_readpwd.lua

103 lines
2.6 KiB
Lua
Raw Normal View History

2019-11-03 02:08:59 +08:00
local getopt = require('getopt')
local bin = require('bin')
2020-04-05 18:49:25 +08:00
local ansicolors = require('ansicolors')
2019-11-03 02:08:59 +08:00
copyright = 'Copyright (c) 2019 Bogito. All rights reserved.'
author = 'Bogito'
2020-04-05 18:49:25 +08:00
version = 'v1.1.2'
desc = [[
2019-11-03 02:08:59 +08:00
This script will read the flash memory of RDV4 using SPIFFS and print the stored passwords.
It was meant to be used as a help tool after using the BogRun standalone mode.
]]
2020-04-05 18:49:25 +08:00
example = [[
2019-11-03 02:08:59 +08:00
-- This will read the hf_bog.log file in SPIFFS and print the stored passwords
script run mem_spiffs_readpwd
2019-11-03 02:08:59 +08:00
-- This will read the other.log file in SPIFFS and print the stored passwords
script run mem_spiffs_readpwd -f other.log
2019-12-03 21:53:08 +08:00
2019-11-09 01:46:15 +08:00
-- This will delete the hf_bog.log file from SPIFFS
script run mem_spiffs_readpwd -r
2019-11-03 02:08:59 +08:00
]]
2020-04-05 18:49:25 +08:00
usage = [[
script run mem_spiffs_readpwd [-h] [-f <filename>] [-r]
2020-04-05 18:49:25 +08:00
]]
arguments = [[
2019-11-03 02:08:59 +08:00
-h : this help
-f <filename> : filename in SPIFFS
2019-11-09 01:46:15 +08:00
-r : delete filename from SPIFFS
2019-11-03 02:08:59 +08:00
]]
---
-- This is only meant to be used when errors occur
local function oops(err)
print('ERROR:', err)
core.clearCommandBuffer()
return nil, err
end
---
-- Usage help
local function help()
print(copyright)
print(author)
print(version)
print(desc)
2020-04-05 18:49:25 +08:00
print(ansicolors.cyan..'Usage'..ansicolors.reset)
2019-11-03 02:08:59 +08:00
print(usage)
2020-04-05 18:49:25 +08:00
print(ansicolors.cyan..'Arguments'..ansicolors.reset)
print(arguments)
print(ansicolors.cyan..'Example usage'..ansicolors.reset)
print(example)
2019-11-03 02:08:59 +08:00
end
---
-- The main entry point
local function main(args)
print( string.rep('--',20) )
2019-11-09 01:46:15 +08:00
print('Read passwords stored in memory (SPIFFS)')
2019-11-03 02:08:59 +08:00
print( string.rep('--',20) )
print()
2019-11-09 01:46:15 +08:00
local data, length, err, removeflag
2019-11-03 02:08:59 +08:00
local filename = 'hf_bog.log'
2019-11-09 01:46:15 +08:00
local keylength = 4
2019-11-03 02:08:59 +08:00
2019-11-09 01:46:15 +08:00
for o, a in getopt.getopt(args, 'rf:h') do
2019-11-08 19:01:46 +08:00
2019-11-03 02:08:59 +08:00
-- help
if o == 'h' then return help() end
-- offset
if o == 'f' then filename = a end
2019-12-03 21:53:08 +08:00
2019-11-09 01:46:15 +08:00
-- remove
if o == 'r' then removeflag = true end
2019-11-08 19:01:46 +08:00
2019-11-09 01:46:15 +08:00
end
2019-11-08 19:01:46 +08:00
2019-11-09 01:46:15 +08:00
if removeflag then
print('Deleting file '..filename.. ' from SPIFFS if exists')
core.console("mem spiffs remove " ..filename)
return
end
2019-12-03 21:53:08 +08:00
2019-11-03 02:08:59 +08:00
data, length, err = core.GetFromFlashMemSpiffs(filename)
if data == nil then return oops('Problem while reading file from SPIFFS') end
2019-11-08 19:01:46 +08:00
--print('Filename', filename)
2019-11-09 01:46:15 +08:00
--print('Filesize (B)', length)
2019-11-08 19:01:46 +08:00
2019-11-09 01:46:15 +08:00
_, s = bin.unpack('H'..length, data)
2019-11-03 02:08:59 +08:00
2019-11-09 01:46:15 +08:00
local cnt = 0, i
for i = 1, length/keylength do
key = string.sub(s, (i-1)*8+1, i*8)
print(string.format('[%02d] %s',i, key))
cnt = cnt + 1
end
print( string.rep('--',20) )
print( ('[+] found %d passwords'):format(cnt))
2019-11-03 02:08:59 +08:00
end
main(args)