diff options
author | Malfurious <m@lfurio.us> | 2021-09-08 00:31:59 -0400 |
---|---|---|
committer | Malfurious <m@lfurio.us> | 2021-09-08 00:31:59 -0400 |
commit | 6d1d09e13bed26b323916c7d900f9e8966f55513 (patch) | |
tree | c922eea83b5feced73dbc5d5a66d78d29f5accad | |
parent | b245449d06ea111cf3d78c9c12eaf6a46c07aa2b (diff) | |
parent | c43b676086f26edb1ea989b255e0eaf356c8ad5a (diff) | |
download | lib-des-gnux-6d1d09e13bed26b323916c7d900f9e8966f55513.tar.gz lib-des-gnux-6d1d09e13bed26b323916c7d900f9e8966f55513.zip |
Merge tag 'pull-sploit-error-handling' of https://github.com/Dusoleil/lib-des-gnux
Refactor exception handling and cleanup in main.py
Refactor exception handling to be simpler and easier to read/maintain
Manually call garbage collector after exec to handle some weird python
behavior.
* tag 'pull-sploit-error-handling' of https://github.com/Dusoleil/lib-des-gnux:
Manually run garbage collection after exec
Clean up exception handling in main.py
-rw-r--r-- | tools/sploit/sploit/main.py | 46 |
1 files changed, 24 insertions, 22 deletions
diff --git a/tools/sploit/sploit/main.py b/tools/sploit/sploit/main.py index 6404786..77ef49e 100644 --- a/tools/sploit/sploit/main.py +++ b/tools/sploit/sploit/main.py @@ -1,6 +1,7 @@ import argparse import tempfile import traceback +import gc from sploit.comm import * @@ -14,18 +15,15 @@ def main(): help='target program to exploit') args = parser.parse_args() - try: - if(len(args.target)>0): - if(args.daemon): - print("Target Given. Ignoring Daemon Flag...") - target(args.script, args.target) + if(len(args.target)>0): + if(args.daemon): + print("Target Given. Ignoring Daemon Flag...") + target(args.script, args.target) + else: + if(args.daemon): + daemon(args.script) else: - if(args.daemon): - daemon(args.script) - else: - pipe(args.script) - except KeyboardInterrupt: - pass + pipe(args.script) def daemon(script): print("Running in Pipe Daemon Mode...") @@ -35,12 +33,7 @@ def daemon(script): p = Pipes(tmpdir) except KeyboardInterrupt: break - try: - runscript(script, Comm(p)); - except KeyboardInterrupt: - pass - except: - traceback.print_exc() + runscript(script, Comm(p)); del p def pipe(script): @@ -52,8 +45,17 @@ def target(script, target): runscript(script, Comm(Process(target))); def runscript(script, comm): - print("Running Script...") - code = compile(open(script).read(), script, 'exec') - exec(code, {'io': comm}) - print("Script Finished!") - comm.readall() + try: + print("Running Script...") + code = compile(open(script).read(), script, 'exec') + exec(code, {'io': comm}) + print("Script Finished!") + comm.readall() + return + except KeyboardInterrupt: + pass + except: + traceback.print_exc() + finally: + gc.collect() + print("Script Ended Early!") |