summaryrefslogtreecommitdiffstats
path: root/sploit/main.py
blob: 6d711964f8ffbd38cea8091c13a99fa32d82fdcd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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)