def run(cls, args, session): if len(args.strip()) > 0: try: index = int(args.strip()) except ValueError: raise CmdRunnerException("Invalid index '{}'".format(args)) else: index = -1 if index >= len(session["decoders"]): raise CmdRunnerException("Invalid index '{}' for decoder list length {}".format(args, len(session["decoders"]))) session["decoders"].pop(index)
def run(cls, args, session): cmd = args.strip() if len(cmd): cmd = cmd.lstrip("$").split(" ") if cmd[0] in ["runner", "encoder", "decoder"]: available_runners = {x.__name__.lower() : x for x in CmdRunner.get_subclasses()} available_encoders = {x.__name__.lower() : x for x in CmdEncoder.get_subclasses()} available_decoders = {x.__name__.lower() : x for x in CmdDecoder.get_subclasses()} cls = None list_cmd, available_clsses = {"runner" : (ListRunnersCmd, available_runners), "encoder" : (ListEncodersCmd, available_encoders), "decoder" : (ListDecodersCmd, available_decoders)}[cmd[0]] if len(cmd) == 1: list_cmd.run(None, session) print("\nFor help on an individual {} use:\n\t$help {} <name>".format(cmd[0], cmd[0])) else: cls = available_clsses.get(cmd[1].lower(), available_clsses.get(cmd[1].lower() + cmd[0])) if cls is None: raise CmdRunnerException("Unknown {} '{}''".format(cmd[0], cmd[1])) print(cls.get_help()) print() print(cls.get_args()) else: try: cls = InteractiveCmd.get_command(cmd[0]) print("Help for command ${}".format(cls.tag)) print("\n".join("\t" + x for x in cls.get_help().splitlines())) except CmdRunnerException as e: print(str(e)) return print("Available commands:") for icmd in sorted(InteractiveCmd.get_subclasses(), key=lambda x: x.__name__): if icmd == cls: continue print("\t${:20s} {}".format(icmd.tag, icmd.description)) print("\nFor help on individual modules use \"$help <module_type> <module>\", e.g.:\n\t$help runner bash\n\t$help encoder xpcmdshell\n\t$help decoder base64")
def run(cls, args, session): session_file = args.strip() if len(session_file) == 0: raise CmdRunnerException("$save_session requires <session_files> argument") _session = { "runner" : session["runner"].save(), "encoders" : [x.save() for x in session["encoders"]], "decoders" : [x.save() for x in session["decoders"]], } with open(session_file, "w") as f: json.dump(_session, f)
def run(cls, args, session, quiet=False): session_file = args.strip() if len(session_file) == 0: raise CmdRunnerException("$load_session requires <session_file> argument") if not os.path.isfile(session_file): raise CmdRunnerException("Session file '{}' does not exist".format(session_file)) with open(session_file) as f: _session = json.load(f) available_runners = {x.__name__ : x for x in CmdRunner.get_subclasses()} available_encoders = {x.__name__ : x for x in CmdEncoder.get_subclasses()} available_decoders = {x.__name__ : x for x in CmdDecoder.get_subclasses()} try: runner = available_runners[_session["runner"]["__classname__"]].load(_session["runner"]) encoders = [available_encoders[x["__classname__"]].load(x) for x in _session["encoders"]] decoders = [available_decoders[x["__classname__"]].load(x) for x in _session["decoders"]] except KeyError: raise CmdRunnerException("Invalid session") session["runner"] = runner session["encoders"] = encoders session["decoders"] = decoders if not quiet: PrintSessionCmd.run(None, session)
def run(cls, args, session): available_runners = {x.__name__.lower() : x for x in CmdRunner.get_subclasses()} match = re.match("([A-Za-z0-9_]+)(.*)", args.strip()) if match is None: raise CmdRunnerException("$set_runner requires arguments: <runner_name> [runner_arguments]") runner_arg, args = match.groups() args = args.strip() runner_cls = available_runners.get(runner_arg.lower(), available_runners.get(runner_arg.lower() + "runner")) if runner_cls is None: raise CmdRunnerException("'{}' is not a valid runner".format(runner_arg)) try: try: args, kwargs = lib.utils.get_args(args) except lib.utils.ArgsException as e: raise CmdRunnerException(str(e)) runner = runner_cls(*args, **kwargs) print(runner.get_instance()) except TypeError as e: raise CmdRunnerException("Error: {}\n\n{}".format(e, runner_cls.get_args())) session["runner"] = runner
def run(cls, args, session): available_decoders = {x.__name__.lower() : x for x in CmdDecoder.get_subclasses()} match = re.match("([0-9]+)? *([A-Za-z0-9_]+)(.*)", args) if match is None: raise CmdRunnerException("$push_decoder requires arguments: [index] <decoder_name> [decoder_arguments]") index, decoder_arg, args = match.groups() index = int(index) if index is not None else len(session["decoders"]) decoder_cls = available_decoders.get(decoder_arg.lower(), available_decoders.get(decoder_arg.lower() + "decoder")) args = args.strip() if decoder_cls is None: raise CmdRunnerException("Unknown decoder '{}'".format(decoder_arg)) try: try: args, kwargs = lib.utils.get_args(args) except lib.utils.ArgsException as e: raise CmdRunnerException(str(e)) decoder = decoder_cls(*args, **kwargs) print(decoder.get_instance()) except TypeError as e: raise CmdRunnerException("Error: {}\n\n{}".format(e, decoder_cls.get_args())) session["decoders"].insert(index, decoder)