Remove if statement that is always true and fix indent

main
Alexander Neff 2023-04-15 15:01:03 +02:00
parent a2e56f1b24
commit 58c0bd0d2d
2 changed files with 57 additions and 59 deletions

View File

@ -65,7 +65,6 @@ def gen_cli_args():
module_parser = argparse.ArgumentParser(add_help=False) module_parser = argparse.ArgumentParser(add_help=False)
mgroup = module_parser.add_mutually_exclusive_group() mgroup = module_parser.add_mutually_exclusive_group()
mgroup.add_argument("-M", "--module", action='append', metavar='MODULE', help='module to use') mgroup.add_argument("-M", "--module", action='append', metavar='MODULE', help='module to use')
#mgroup.add_argument('-MC','--module-chain', metavar='CHAIN_COMMAND', help='Payload module chain command string to run')
module_parser.add_argument('-o', metavar='MODULE_OPTION', nargs='+', default=[], dest='module_options', help='module options') module_parser.add_argument('-o', metavar='MODULE_OPTION', nargs='+', default=[], dest='module_options', help='module options')
module_parser.add_argument('-L', '--list-modules', action='store_true', help='list available modules') module_parser.add_argument('-L', '--list-modules', action='store_true', help='list available modules')
module_parser.add_argument('--options', dest='show_module_options', action='store_true', help='display module options') module_parser.add_argument('--options', dest='show_module_options', action='store_true', help='display module options')

View File

@ -164,73 +164,72 @@ def main():
# with the new cme/config.py this can be eventually removed, as it can be imported anywhere # with the new cme/config.py this can be eventually removed, as it can be imported anywhere
setattr(protocol_object, "config", cme_config) setattr(protocol_object, "config", cme_config)
if hasattr(args, "module"): loader = ModuleLoader(args, db, cme_logger)
loader = ModuleLoader(args, db, cme_logger) modules = loader.list_modules()
modules = loader.list_modules()
if args.list_modules: if args.list_modules:
for name, props in sorted(modules.items()): for name, props in sorted(modules.items()):
cme_logger.display(f"{name:<25} {props['description']}") cme_logger.display(f"{name:<25} {props['description']}")
sys.exit(0) sys.exit(0)
elif args.module and args.show_module_options: elif args.module and args.show_module_options:
for module in args.module: for module in args.module:
cme_logger.display(f"{module} module options:\n{modules[module]['options']}") cme_logger.display(f"{module} module options:\n{modules[module]['options']}")
sys.exit(0) sys.exit(0)
elif args.module: elif args.module:
cme_logger.debug(f"Modules to be Loaded: {args.module}, {type(args.module)}") cme_logger.debug(f"Modules to be Loaded: {args.module}, {type(args.module)}")
for m in map(str.lower, args.module): for m in map(str.lower, args.module):
if m not in modules: if m not in modules:
cme_logger.error(f"Module not found: {m}") cme_logger.error(f"Module not found: {m}")
exit(1) exit(1)
cme_logger.debug(f"Loading module {m} at path {modules[m]['path']}") cme_logger.debug(f"Loading module {m} at path {modules[m]['path']}")
module = loader.init_module(modules[m]["path"]) module = loader.init_module(modules[m]["path"])
if not module.opsec_safe: if not module.opsec_safe:
if ignore_opsec: if ignore_opsec:
cme_logger.debug(f"ignore_opsec is set in the configuration, skipping prompt") cme_logger.debug(f"ignore_opsec is set in the configuration, skipping prompt")
cme_logger.display(f"Ignore OPSEC in configuration is set and OPSEC unsafe module loaded") cme_logger.display(f"Ignore OPSEC in configuration is set and OPSEC unsafe module loaded")
else: else:
ans = input( ans = input(
highlight("[!] Module is not opsec safe, are you sure you want to run this? [Y/n] ", 'red')) highlight("[!] Module is not opsec safe, are you sure you want to run this? [Y/n] ", 'red'))
if ans.lower() not in ["y", "yes", ""]:
sys.exit(1)
if not module.multiple_hosts and len(targets) > 1:
ans = input(highlight("[!] Running this module on multiple hosts doesn't really make any sense, are you sure you want to continue? [Y/n] ", 'red'))
if ans.lower() not in ["y", "yes", ""]: if ans.lower() not in ["y", "yes", ""]:
sys.exit(1) sys.exit(1)
if hasattr(module, "on_request") or hasattr(module, "has_response"): if not module.multiple_hosts and len(targets) > 1:
if hasattr(module, "required_server"): ans = input(highlight("[!] Running this module on multiple hosts doesn't really make any sense, are you sure you want to continue? [Y/n] ", 'red'))
args.server = module.required_server if ans.lower() not in ["y", "yes", ""]:
sys.exit(1)
if not args.server_port: if hasattr(module, "on_request") or hasattr(module, "has_response"):
args.server_port = server_port_dict[args.server] if hasattr(module, "required_server"):
args.server = module.required_server
# loading a module server multiple times will obviously fail if not args.server_port:
try: args.server_port = server_port_dict[args.server]
context = Context(db, cme_logger, args)
module_server = CMEServer(
module,
context,
cme_logger,
args.server_host,
args.server_port,
args.server
)
module_server.start()
protocol_object.server = module_server.server
except Exception as e:
cme_logger.error(f"Error loading module server for {module}: {e}")
cme_logger.debug(f"proto_object: {protocol_object}, type: {type(protocol_object)}") # loading a module server multiple times will obviously fail
cme_logger.debug(f"proto object dir: {dir(protocol_object)}") try:
# get currently set modules, otherwise default to empty list context = Context(db, cme_logger, args)
current_modules = getattr(protocol_object, "module", []) module_server = CMEServer(
current_modules.append(module) module,
setattr(protocol_object, "module", current_modules) context,
cme_logger.debug(f"proto object module after adding: {protocol_object.module}") cme_logger,
args.server_host,
args.server_port,
args.server
)
module_server.start()
protocol_object.server = module_server.server
except Exception as e:
cme_logger.error(f"Error loading module server for {module}: {e}")
cme_logger.debug(f"proto_object: {protocol_object}, type: {type(protocol_object)}")
cme_logger.debug(f"proto object dir: {dir(protocol_object)}")
# get currently set modules, otherwise default to empty list
current_modules = getattr(protocol_object, "module", [])
current_modules.append(module)
setattr(protocol_object, "module", current_modules)
cme_logger.debug(f"proto object module after adding: {protocol_object.module}")
if hasattr(args, "ntds") and args.ntds and not args.userntds: if hasattr(args, "ntds") and args.ntds and not args.userntds:
ans = input(highlight('[!] Dumping the ntds can crash the DC on Windows Server 2019. Use the option --user <user> to dump a specific user safely or the module -M ntdsutil [Y/n] ', 'red')) ans = input(highlight('[!] Dumping the ntds can crash the DC on Windows Server 2019. Use the option --user <user> to dump a specific user safely or the module -M ntdsutil [Y/n] ', 'red'))