Update read_pwd_mem_spiffs.lua

This commit is contained in:
bogiton 2019-11-08 17:46:15 +00:00 committed by GitHub
commit a0168441d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,7 +3,7 @@ local bin = require('bin')
copyright = 'Copyright (c) 2019 Bogito. All rights reserved.' copyright = 'Copyright (c) 2019 Bogito. All rights reserved.'
author = 'Bogito' author = 'Bogito'
version = 'v1.1.0' version = 'v1.1.1'
desc = desc =
[[ [[
This script will read the flash memory of RDV4 using SPIFFS and print the stored passwords. This script will read the flash memory of RDV4 using SPIFFS and print the stored passwords.
@ -16,15 +16,19 @@ example =
-- This will read the other.log file in SPIFFS and print the stored passwords -- This will read the other.log file in SPIFFS and print the stored passwords
script run read_pwd_mem_spiffs -f other.log script run read_pwd_mem_spiffs -f other.log
-- This will delete the hf_bog.log file from SPIFFS
script run read_pwd_mem_spiffs -r
]] ]]
usage = usage =
[[ [[
Usage: Usage:
script run read_pwd_mem_spiffs -h -f <filename> script run read_pwd_mem_spiffs -h -f <filename> -r
Arguments: Arguments:
-h : this help -h : this help
-f <filename> : filename in SPIFFS -f <filename> : filename in SPIFFS
-r : delete filename from SPIFFS
]] ]]
--- ---
-- This is only meant to be used when errors occur -- This is only meant to be used when errors occur
@ -49,42 +53,49 @@ end
local function main(args) local function main(args)
print( string.rep('--',20) ) print( string.rep('--',20) )
print('Read passwords stored in memory (SPIFFS)') print('Read passwords stored in memory (SPIFFS)')
print( string.rep('--',20) ) print( string.rep('--',20) )
print() print()
local data, length, err local data, length, err, removeflag
local cnt = 0
local filename = 'hf_bog.log' local filename = 'hf_bog.log'
local keylength = 4 local keylength = 4
for o, a in getopt.getopt(args, 'f:h') do for o, a in getopt.getopt(args, 'rf:h') do
-- help -- help
if o == 'h' then return help() end if o == 'h' then return help() end
-- offset -- offset
if o == 'f' then filename = a end if o == 'f' then filename = a end
-- remove
if o == 'r' then removeflag = true end
end end
if removeflag then
print('Deleting file '..filename.. ' from SPIFFS if exists')
core.console("mem spiffs remove " ..filename)
return
end
data, length, err = core.GetFromFlashMemSpiffs(filename) data, length, err = core.GetFromFlashMemSpiffs(filename)
if data == nil then return oops('Problem while reading file from SPIFFS') end if data == nil then return oops('Problem while reading file from SPIFFS') end
--print('Filename', filename) --print('Filename', filename)
--print('Filesize (B)', length) --print('Filesize (B)', length)
_, s = bin.unpack('H'..length, data) _, s = bin.unpack('H'..length, data)
local cnt = 0, i local cnt = 0, i
for i = 1, length/keylength do for i = 1, length/keylength do
key = string.sub(s, (i-1)*8+1, i*8) key = string.sub(s, (i-1)*8+1, i*8)
if key == 'FFFFFFFF' then break end print(string.format('[%02d] %s',i, key))
print(string.format('[%02d] %s',i, key)) cnt = cnt + 1
cnt = cnt + 1 end
end print( string.rep('--',20) )
print( string.rep('--',20) ) print( ('[+] found %d passwords'):format(cnt))
print( ('[+] found %d passwords'):format(cnt))
end end