summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalfurious <m@lfurio.us>2025-01-01 06:51:10 -0500
committerMalfurious <m@lfurio.us>2025-01-01 06:51:10 -0500
commitf01ec45e773291c3659a1dcaf8cd9a51ece19823 (patch)
tree0db3ef432a6f3b06c07060bdb0dd61c7fd164ad2
parent3f5532857807d628a5dadaf5c30a384f873878ea (diff)
parent221742f7c5c89dc50ec4374bed5d2ccc0d7534bf (diff)
downloadnsploit-f01ec45e773291c3659a1dcaf8cd9a51ece19823.tar.gz
nsploit-f01ec45e773291c3659a1dcaf8cd9a51ece19823.zip
Merge branch 'pkg-reorg'
This branch is a rework of nsploit's intended package imports. User scripts need only import a given nsploit subpackage to obtain that package's full collection of classes, functions, etc. This is the new intended style for exploit scripts. Along the way, some modules are reorganized into different packages, the "builder" package is renamed to "payload", and some unnecessary files are consolidated. * pkg-reorg: main: Automatically provide top-level sploit modules to user scripts sploit: Expose modules' contents through package Remove extra "main.py" file comm: Promote from module to package log: Move to sploit.util package util: Promote from module to package builder: Rename package to payload and expose contents rev: Expose modules' contents through package Remove outer __init__.py file
-rw-r--r--__init__.py4
-rw-r--r--pyproject.toml2
-rwxr-xr-xsploit.py2
-rw-r--r--sploit/__init__.py16
-rw-r--r--[l---------]sploit/__main__.py78
-rw-r--r--sploit/builder/__init__.py5
-rw-r--r--sploit/comm/__init__.py1
-rw-r--r--sploit/comm/comm.py (renamed from sploit/comm.py)2
-rw-r--r--sploit/main.py65
-rw-r--r--sploit/payload/__init__.py3
-rw-r--r--sploit/payload/gadhint.py (renamed from sploit/builder/gadhint.py)0
-rw-r--r--sploit/payload/payload.py (renamed from sploit/builder/payload.py)0
-rw-r--r--sploit/payload/rop.py (renamed from sploit/builder/rop.py)4
-rw-r--r--sploit/rev/__init__.py10
-rw-r--r--sploit/rev/ldd.py4
-rw-r--r--sploit/rev/r2.py4
-rw-r--r--sploit/util/__init__.py2
-rw-r--r--sploit/util/cmd.py (renamed from sploit/util.py)0
-rw-r--r--sploit/util/log.py (renamed from sploit/log.py)0
19 files changed, 101 insertions, 101 deletions
diff --git a/__init__.py b/__init__.py
deleted file mode 100644
index 8a53886..0000000
--- a/__init__.py
+++ /dev/null
@@ -1,4 +0,0 @@
-from os.path import join, dirname
-libpath=join(dirname(__file__),"sploit")
-__path__ = [libpath]
-exec(open(join(libpath,"__init__.py")).read())
diff --git a/pyproject.toml b/pyproject.toml
index 041ee3f..5ac11e8 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -15,7 +15,7 @@ dynamic = ["version"]
"Homepage" = "https://github.com/dusoleil/sploit"
[project.scripts]
-sploit = "sploit.main:main"
+sploit = "sploit.__main__:main"
[build-system]
requires = ["hatchling"]
diff --git a/sploit.py b/sploit.py
index fd9b482..419f9b1 100755
--- a/sploit.py
+++ b/sploit.py
@@ -1,3 +1,3 @@
#!/usr/bin/env python3
-from sploit.main import main
+from sploit.__main__ import main
main()
diff --git a/sploit/__init__.py b/sploit/__init__.py
index 1eb570c..dc5943f 100644
--- a/sploit/__init__.py
+++ b/sploit/__init__.py
@@ -1,12 +1,6 @@
-from sploit import (
- arch,
- builder,
- comm,
- log,
- rev,
- symtbl,
- until,
- util,
-)
+from sploit.arch import *
+from sploit.symtbl import *
+from sploit.until import *
-__version__ = util.git_version()
+from sploit.util import git_version as __git_version
+__version__ = __git_version()
diff --git a/sploit/__main__.py b/sploit/__main__.py
index 98537fc..5d53ca6 120000..100644
--- a/sploit/__main__.py
+++ b/sploit/__main__.py
@@ -1 +1,77 @@
-../sploit.py \ No newline at end of file
+from argparse import ArgumentParser, REMAINDER
+import gc
+from os.path import isdir
+import tempfile
+import traceback
+
+from sploit.comm.comm import *
+from sploit.util.log import *
+from sploit import __version__
+
+def print_banner(color, line1=__version__, line2='', line3=''):
+ ilog()
+ ilog(' ░▒█▀▀▀█░▒█▀▀█░▒█░░░░▒█▀▀▀█░▀█▀░▀▀█▀▀ ', end='', color=ALT)
+ ilog(line1, color=ALT)
+ ilog(' ░░▀▀▀▄▄░▒█▄▄█░▒█░░░░▒█░░▒█░▒█░░░▒█░░ ', end='', color=color)
+ ilog(line2, color=ALT)
+ ilog(' ░▒█▄▄▄█░▒█░░░░▒█▄▄█░▒█▄▄▄█░▄█▄░░▒█░░ ', end='', color=ALT)
+ ilog(line3, color=ALT)
+ ilog()
+
+def main():
+ parser = ArgumentParser(description='Execute Sploit script against target')
+ parser.add_argument('script', help='Exploit script to run')
+ parser.add_argument('target', nargs=REMAINDER, help='Target cmdline or pipes directory')
+ args = parser.parse_args()
+
+ if len(args.target) == 0:
+ with tempfile.TemporaryDirectory() as tmpdir:
+ pipe(args.script, tmpdir)
+ elif len(args.target) == 1 and isdir(args.target[0]):
+ pipe(args.script, args.target[0])
+ else:
+ target(args.script, args.target)
+
+def pipe(script, tmpdir):
+ print_banner(ERROR, line3='Pipe Mode')
+ while True:
+ try:
+ p = Pipes(tmpdir)
+ except KeyboardInterrupt:
+ break
+ runscript(script, Comm(p))
+ del p
+
+def target(script, target):
+ print_banner(STATUS, line3='Subprocess Mode')
+ runscript(script, Comm(Process(target)))
+
+def user_scope(comm):
+ import sploit as lib
+ scope = { name: getattr(lib, name) for name in dir(lib) }
+ scope['__version__'] = __version__
+ scope['print'] = elog
+ scope['io'] = comm
+ return scope
+
+def runscript(script, comm):
+ try:
+ ilog("Running Script...")
+ code = compile(open(script).read(), script, 'exec')
+ exec(code, user_scope(comm))
+ ilog("Script Finished!")
+ return
+ except KeyboardInterrupt:
+ pass
+ except:
+ ilog(traceback.format_exc(), end='', color=ERROR)
+ finally:
+ comm.shutdown()
+ comm.readall()
+ gc.collect()
+
+ ilog("Script Ended Early!", color=WARNING)
+
+
+if __name__ == "__main__":
+ main()
diff --git a/sploit/builder/__init__.py b/sploit/builder/__init__.py
deleted file mode 100644
index 758d511..0000000
--- a/sploit/builder/__init__.py
+++ /dev/null
@@ -1,5 +0,0 @@
-from . import (
- gadhint,
- payload,
- rop,
-)
diff --git a/sploit/comm/__init__.py b/sploit/comm/__init__.py
new file mode 100644
index 0000000..ffbc402
--- /dev/null
+++ b/sploit/comm/__init__.py
@@ -0,0 +1 @@
+from .comm import *
diff --git a/sploit/comm.py b/sploit/comm/comm.py
index 522d540..3bc448e 100644
--- a/sploit/comm.py
+++ b/sploit/comm/comm.py
@@ -4,8 +4,8 @@ import os
import sys
import select
-from sploit.log import *
from sploit.until import bind
+from sploit.util.log import *
class Comm:
logonread = True
diff --git a/sploit/main.py b/sploit/main.py
deleted file mode 100644
index 6d71196..0000000
--- a/sploit/main.py
+++ /dev/null
@@ -1,65 +0,0 @@
-from argparse import ArgumentParser, REMAINDER
-import gc
-from os.path import isdir
-import tempfile
-import traceback
-
-from sploit.comm import *
-from sploit.log import *
-from sploit import __version__
-
-def print_banner(color, line1=__version__, line2='', line3=''):
- ilog()
- ilog(' ░▒█▀▀▀█░▒█▀▀█░▒█░░░░▒█▀▀▀█░▀█▀░▀▀█▀▀ ', end='', color=ALT)
- ilog(line1, color=ALT)
- ilog(' ░░▀▀▀▄▄░▒█▄▄█░▒█░░░░▒█░░▒█░▒█░░░▒█░░ ', end='', color=color)
- ilog(line2, color=ALT)
- ilog(' ░▒█▄▄▄█░▒█░░░░▒█▄▄█░▒█▄▄▄█░▄█▄░░▒█░░ ', end='', color=ALT)
- ilog(line3, color=ALT)
- ilog()
-
-def main():
- parser = ArgumentParser(description='Execute Sploit script against target')
- parser.add_argument('script', help='Exploit script to run')
- parser.add_argument('target', nargs=REMAINDER, help='Target cmdline or pipes directory')
- args = parser.parse_args()
-
- if len(args.target) == 0:
- with tempfile.TemporaryDirectory() as tmpdir:
- pipe(args.script, tmpdir)
- elif len(args.target) == 1 and isdir(args.target[0]):
- pipe(args.script, args.target[0])
- else:
- target(args.script, args.target)
-
-def pipe(script, tmpdir):
- print_banner(ERROR, line3='Pipe Mode')
- while True:
- try:
- p = Pipes(tmpdir)
- except KeyboardInterrupt:
- break
- runscript(script, Comm(p))
- del p
-
-def target(script, target):
- print_banner(STATUS, line3='Subprocess Mode')
- runscript(script, Comm(Process(target)))
-
-def runscript(script, comm):
- try:
- ilog("Running Script...")
- code = compile(open(script).read(), script, 'exec')
- exec(code, {'io': comm, 'print': elog})
- ilog("Script Finished!")
- return
- except KeyboardInterrupt:
- pass
- except:
- ilog(traceback.format_exc(), end='', color=ERROR)
- finally:
- comm.shutdown()
- comm.readall()
- gc.collect()
-
- ilog("Script Ended Early!", color=WARNING)
diff --git a/sploit/payload/__init__.py b/sploit/payload/__init__.py
new file mode 100644
index 0000000..78769b4
--- /dev/null
+++ b/sploit/payload/__init__.py
@@ -0,0 +1,3 @@
+from .gadhint import *
+from .payload import *
+from .rop import *
diff --git a/sploit/builder/gadhint.py b/sploit/payload/gadhint.py
index 9b077fe..9b077fe 100644
--- a/sploit/builder/gadhint.py
+++ b/sploit/payload/gadhint.py
diff --git a/sploit/builder/payload.py b/sploit/payload/payload.py
index cf105c6..cf105c6 100644
--- a/sploit/builder/payload.py
+++ b/sploit/payload/payload.py
diff --git a/sploit/builder/rop.py b/sploit/payload/rop.py
index 7b58e0e..54226b4 100644
--- a/sploit/builder/rop.py
+++ b/sploit/payload/rop.py
@@ -25,8 +25,8 @@ supported.
from graphlib import TopologicalSorter
from sploit.arch import arch, btoi, itob
-from sploit.builder.gadhint import GadHint
-from sploit.builder.payload import Payload
+from sploit.payload.gadhint import GadHint
+from sploit.payload.payload import Payload
class ROP(Payload):
"""
diff --git a/sploit/rev/__init__.py b/sploit/rev/__init__.py
index 0d0dc9b..42e2f5b 100644
--- a/sploit/rev/__init__.py
+++ b/sploit/rev/__init__.py
@@ -1,6 +1,4 @@
-from . import (
- elf,
- gadget,
- ldd,
- r2,
-)
+from .elf import *
+from .gadget import *
+from .ldd import *
+from .r2 import *
diff --git a/sploit/rev/ldd.py b/sploit/rev/ldd.py
index 1a28c7c..b773abf 100644
--- a/sploit/rev/ldd.py
+++ b/sploit/rev/ldd.py
@@ -1,5 +1,5 @@
-from sploit.util import run_cmd_cached
-from sploit.log import ilog
+from sploit.util.cmd import run_cmd_cached
+from sploit.util.log import ilog
import re
from collections import namedtuple as nt
diff --git a/sploit/rev/r2.py b/sploit/rev/r2.py
index 1be731c..e81adc9 100644
--- a/sploit/rev/r2.py
+++ b/sploit/rev/r2.py
@@ -1,8 +1,8 @@
from sploit.arch import arch
-from sploit.log import ilog
from sploit.rev.gadget import Gadget
from sploit.symtbl import Symtbl
-from sploit.util import run_cmd_cached
+from sploit.util.cmd import run_cmd_cached
+from sploit.util.log import ilog
from collections import namedtuple as nt
from functools import cache
diff --git a/sploit/util/__init__.py b/sploit/util/__init__.py
new file mode 100644
index 0000000..32a079b
--- /dev/null
+++ b/sploit/util/__init__.py
@@ -0,0 +1,2 @@
+from .cmd import *
+from .log import *
diff --git a/sploit/util.py b/sploit/util/cmd.py
index 3a2b842..3a2b842 100644
--- a/sploit/util.py
+++ b/sploit/util/cmd.py
diff --git a/sploit/log.py b/sploit/util/log.py
index 823b252..823b252 100644
--- a/sploit/log.py
+++ b/sploit/util/log.py