def load_targets(urls, files): if not any((urls, files)): raise UsageError("option url/file is required") targets = _load_from_links_and_files( urls, files) # parse targets targets = [parse_path(target, ("parser.url",)) for target in targets] # list expand if targets: targets = tuple(chain.from_iterable(targets)) CONFIG.base.targets = targets detail_msgs = "" for target in targets: temp_msg = header("Load target", "*", target) + "\n" logger.info(temp_msg, extra={"markup": True}) detail_msgs += temp_msg if CONFIG.option.get("very_verbose", False): cprint(detail_msgs) count_msg = header("Load targets", "+", "Loaded [%d] targets" % len(targets)) logger.info(count_msg, extra={"markup": True}) if CONFIG.option.get("verbose", False): cprint(count_msg) cprint()
def load_pocs(pocs=[], poc_files=[], pocs_path=""): pocs_path = Path(CONFIG.base.root_path / "pocs") if not pocs_path else Path(pocs_path) detail_msgs = "" instances = POCS.instances count_dict = {} if not pocs and not poc_files: pocs = [str(poc) for poc in pocs_path.glob( '**/*.py') if not poc.parts[-2].startswith("_")] else: pocs = _load_from_links_and_files(pocs, poc_files) for poc in pocs: if not poc: continue poc_path = poc fname = poc logger_func = logger.info if "://" not in poc: # choose a poc from poc dir poc_path = str(pocs_path / poc) if not poc_path.endswith(".py"): poc_path += ".py" if not path.isfile(poc_path): raise ModuleLoadExceptions.FileNotFound( "%s not found" % poc_path) poc_type_dir = path.basename(path.dirname(poc)) fname, _ = path.splitext(path.basename(poc)) fname = "%s/%s" % (poc_type_dir, fname) poc_path = "file://" + poc_path else: poc_type_dir = "_" + poc[:poc.index("://")] modules, load_msg = _load_poc( poc_path, fname, "Load %s poc" % poc_type_dir, _verify_poc) if modules: if poc_type_dir not in count_dict: count_dict[poc_type_dir] = 0 count_dict[poc_type_dir] += len(modules) instances[fname] = [module.Poc() for module in modules] else: detail_msgs += load_msg logger_func = logger.error if CONFIG.option.get("very_verbose", False): cprint(load_msg) logger_func(load_msg, extra={"markup": True}) count_msg = "\n".join(header("Load %s pocs" % k, "+", "Loaded [%d] pocs" % v) for k, v in count_dict.items()) + "\n" POCS.messages = detail_msgs logger.info(count_msg, extra={"markup": True}) if CONFIG.option.get("verbose", False): cprint(count_msg)
def set_config(verbose, very_verbose, debug, attack): # set verbose flag logger.info("_set_config: set verbose flag") if very_verbose: verbose = True if debug: very_verbose = False verbose = False # set CONFIG CONFIG.option.verbose = verbose CONFIG.option.very_verbose = very_verbose CONFIG.option.debug = debug POCS.type = "attack" if attack else "check"
def start(threads, timeout): logger.info("start: start program") CONFIG.base.start = True targets = CONFIG.base.targets tasks_queue = normal_queue() results = {} pocs = [poc_s for poc_s in POCS.instances.values()] pocs = tuple(chain.from_iterable(pocs)) for target in targets: results[target] = {} for poc in pocs: tasks_queue.put((target, poc)) return _run(threads, tasks_queue, results, timeout, PLUGINS.output_handlers)
def load_config(config_path): if config_path and path.isfile(config_path): logger.info("load_config: load configuration from " + config_path) else: logger.warning( "load_config: config_path [%s] not found, use default config" % config_path) config_path = path.abspath( path.join(CONFIG.base.root_path, "data", "default_config.ini")) config = ConfigHandler(config_path) CONFIG.base.configuration = config request_config = config.get("request", {}) CONFIG.base.request = request_config options = dict(config.get("option", {})) return options
def load_plugins(plugins_path): from importlib import import_module plugins_path = Path(CONFIG.base.root_path / "plugins") if not plugins_path else Path(plugins_path) detail_msgs = "" count_dict = {} plugins = [str(plugin) for plugin in plugins_path.glob( '**/*.py') if not plugin.parts[-2].startswith("_")] for f in plugins: filename = path.basename(f) fname, _ = path.splitext(filename) plugin_type_dir = path.basename(path.dirname(f)) try: import_module("glimmer.plugins.%s.%s" % (plugin_type_dir, fname)) temp_msg = header("Load plugin", "+", "load plugin %s.%s \n" % (plugin_type_dir, fname)) if plugin_type_dir not in count_dict: count_dict[plugin_type_dir] = 0 count_dict[plugin_type_dir] += 1 logger.info(temp_msg, extra={"markup": True}) except ImportError as e: temp_msg = header("Load plugin", "-", "load plugin %s.%s error: " % (plugin_type_dir, fname) + str(e) + "\n") detail_msgs += temp_msg logger.error(temp_msg, extra={"markup": True}) if CONFIG.option.get("very_verbose", False): cprint(temp_msg) count_msg = "\n".join(header("Load %s plugin" % k, "+", "Loaded [%d] plugins" % v) for k, v in count_dict.items()) + "\n" PLUGINS.messages = detail_msgs logger.info(count_msg, extra={"markup": True}) if CONFIG.option.get("verbose", False): cprint(count_msg)
def _set_root_path(root_path): logger.info("_set_config: set root_path") CONFIG.base.root_path = Path(root_path) / "glimmer" ...
def end_plugins(): logger.info("end_plugins: destruct plugins") for plg_name, plg in PLUGINS.instances.items(): if plg_name in PLUGINS.enable_plugins_name: plg.destruct()
def init_plugins(): logger.info("init_plugins: construct plugins") for plg_name, plg in PLUGINS.instances.items(): if plg_name in PLUGINS.enable_plugins_name: plg.construct()
def patch_request(): logger.info("patch_requests: patch something about requests") _disable_warnings() _remove_ssl_verify() _upgrade_urllib3_logger_level() _patch_session()