ntag i2c 2k - fast write
[RRG-proxmark3.git] / client / luascripts / mem_spiffs_readpwd.lua
blobef529440c3b6730a8e936c7032872ce22ac4f5e2
1 local getopt = require('getopt')
2 local bin = require('bin')
3 local ansicolors = require('ansicolors')
5 copyright = 'Copyright (c) 2019 Bogito. All rights reserved.'
6 author = 'Bogito'
7 version = 'v1.1.2'
8 desc = [[
9 This script will read the flash memory of RDV4 using SPIFFS and print the stored passwords.
10 It was meant to be used as a help tool after using the BogRun standalone mode.
12 example = [[
13 -- This will read the hf_bog.log file in SPIFFS and print the stored passwords
14 script run mem_spiffs_readpwd
16 -- This will read the other.log file in SPIFFS and print the stored passwords
17 script run mem_spiffs_readpwd -f other.log
19 -- This will delete the hf_bog.log file from SPIFFS
20 script run mem_spiffs_readpwd -r
22 usage = [[
23 script run mem_spiffs_readpwd [-h] [-f <filename>] [-r]
25 arguments = [[
26 -h : this help
27 -f <filename> : filename in SPIFFS
28 -r : delete filename from SPIFFS
30 ---
31 -- This is only meant to be used when errors occur
32 local function oops(err)
33 print('ERROR:', err)
34 core.clearCommandBuffer()
35 return nil, err
36 end
37 ---
38 -- Usage help
39 local function help()
40 print(copyright)
41 print(author)
42 print(version)
43 print(desc)
44 print(ansicolors.cyan..'Usage'..ansicolors.reset)
45 print(usage)
46 print(ansicolors.cyan..'Arguments'..ansicolors.reset)
47 print(arguments)
48 print(ansicolors.cyan..'Example usage'..ansicolors.reset)
49 print(example)
50 end
51 ---
52 -- The main entry point
53 local function main(args)
55 print( string.rep('--',20) )
56 print('Read passwords stored in memory (SPIFFS)')
57 print( string.rep('--',20) )
58 print()
60 local data, length, err, removeflag
61 local filename = 'hf_bog.log'
62 local keylength = 4
64 for o, a in getopt.getopt(args, 'rf:h') do
66 -- help
67 if o == 'h' then return help() end
69 -- offset
70 if o == 'f' then filename = a end
72 -- remove
73 if o == 'r' then removeflag = true end
75 end
77 if removeflag then
78 print('Deleting file '..filename.. ' from SPIFFS if exists')
79 core.console("mem spiffs remove -f " ..filename)
80 return
81 end
83 data, length, err = core.GetFromFlashMemSpiffs(filename)
84 if data == nil then return oops('Problem while reading file from SPIFFS') end
86 --print('Filename', filename)
87 --print('Filesize (B)', length)
89 _, s = bin.unpack('H'..length, data)
91 local cnt = 0, i
92 for i = 1, length/keylength do
93 key = string.sub(s, (i-1)*8+1, i*8)
94 print(string.format('[%02d] %s',i, key))
95 cnt = cnt + 1
96 end
97 print( string.rep('--',20) )
98 print( ('[+] found %d passwords'):format(cnt))
102 main(args)