diff options
author | Malfurious <m@lfurio.us> | 2022-03-14 00:43:15 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2022-03-14 00:43:15 -0400 |
commit | 616c8b8eadbde6fbb2fe16a6a2167e04f9d16382 (patch) | |
tree | 6560d8b5fea2b40d041f52683cd7accc61ce67a5 /sploit/rev/elf.py | |
parent | dcba5f2b3d13f5142e4e552bdd717286f953bf1a (diff) | |
parent | c493a8f8073702bcdccdbc40bf09931e201c9013 (diff) | |
download | nsploit-616c8b8eadbde6fbb2fe16a6a2167e04f9d16382.tar.gz nsploit-616c8b8eadbde6fbb2fe16a6a2167e04f9d16382.zip |
Merge tag 'pull-sploit-rev' of https://github.com/Dusoleil/lib-des-gnux
Add rev for basic reverse engineering
* tag 'pull-sploit-rev' of https://github.com/Dusoleil/lib-des-gnux:
sploit: Move __attr_filter__ to a general place in util
sploit: Filter all magic python members by default in mem module
sploit: add stack base pointer to locals symtbl
sploit: print hex of addresses in rev logs
sploit: add status logging to rev module
sploit: lazy load libs for ELF
sploit: cache results of external commands
sploit: add the rest of r2 functions through elf
sploit: typo fix in rev.r2
sploit: cache ELF loads
sploit: add ELF helper class to rev
sploit: consolidate r2 symbol search calls
sploit: fix r2 module syntax error
sploit: reverse direction of r2 get_locals offsets
sploit: add r2 funcionality to rev module
sploit: add ldd ability to rev module
sploit: add rev module to sploit
Diffstat (limited to 'sploit/rev/elf.py')
-rw-r--r-- | sploit/rev/elf.py | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/sploit/rev/elf.py b/sploit/rev/elf.py new file mode 100644 index 0000000..7bfd31f --- /dev/null +++ b/sploit/rev/elf.py @@ -0,0 +1,56 @@ +from sploit.rev import ldd, r2 +from sploit.util import __attr_filter__ + +class ELF: + def __init__(self, path): + self.path = path + self.sym = r2.get_elf_symbols(self.path) + libs = ldd.get_libraries(self.path) + self.libs = self.__LIBS__(libs) + self.locals = self.__LOCALS__(self) + + def __str__(self): + s = 'ELF: ' + s += self.path + s += '\nSymbol Table' + s += '\n------------' + s += '\n' + s += str(self.sym) + s += '\n------------' + s += '\nLibararies' + s += '\n------------' + s += str(self.libs) + return s + + class __LIBS__(dict): + def __init__(self, libs): + super().__init__({lib.name:lib.path for lib in libs.values() if lib.path}) + def __getitem__(self, lib): + get = super().__getitem__ + if(type(get(lib))==str):self[lib] = ELF(get(lib)) + return get(lib) + def __str__(self): + s = '' + for name,lib in self.items(): + s += '\n' + str(name) + ' => ' + lib if(type(lib)==str) else str(lib.path) + return s + + class __LOCALS__: + def __init__(self, elf): + self.elf = elf + def __getattribute__(self, sym): + if(sym in (['elf'] + __attr_filter__)): + return object.__getattribute__(self,sym) + return r2.get_locals(self.elf.path, getattr(self.elf.sym, sym)) + + def retaddr(self, caller, callee): + return [c.ret_addr for c in r2.get_call_returns(self.path, caller, callee)] + + def retgad(self): + return r2.ret_gadget(self.path) + + def gad(self, gad): + return [g.addr for g in r2.rop_gadget(self.path, gad)] + + def egad(self, gad): + return r2.rop_gadget_exact(self.path, gad).addr |