def _init_plugins(): # 加载所有插件 _plugins = [] for root, dirs, files in os.walk(PATH['plugins']): files = filter(lambda x: not x.startswith("__") and x.endswith(".py"), files) for _ in files: if len(INCLUDE_PLUGINS) == 1 and INCLUDE_PLUGINS[0] == 'all': pass else: if "loader.py" not in INCLUDE_PLUGINS: INCLUDE_PLUGINS.append("loader.py") if _ not in INCLUDE_PLUGINS: continue if _ in EXCLUDE_PLUGINS: continue filename = os.path.join(root, _) mod = load_file_to_module(filename) try: mod = mod.W13SCAN() getattr(mod, 'name', 'unknown plugin') plugin = os.path.splitext(_)[0] plugin_type = os.path.split(root)[1] if getattr(mod, 'type', None) is None: setattr(mod, 'type', plugin_type) KB["registered"][plugin] = mod except AttributeError: logger.error('Filename:{} not class "{}"'.format(_, 'W13SCAN')) logger.info('Load plugin:{}'.format(len(KB["registered"])))
def __init__(self, server_addr=('', 8788), request_handler_class=ProxyHandle, bind_and_activate=True, https=True): HTTPServer.__init__(self, server_addr, request_handler_class, bind_and_activate) logger.info('HTTPServer is running at address( %s , %d )......' % (server_addr[0], server_addr[1])) self.req_plugs = [] self.ca = CAAuth(ca_file="ca.pem", cert_file='ca.crt') self.https = https
def run_threads(num_threads, thread_function, args: tuple = ()): threads = [] try: info_msg = "Staring {0} threads".format(num_threads) logger.info(info_msg) # Start the threads for num_threads in range(num_threads): thread = threading.Thread(target=exception_handled_function, name=str(num_threads), args=(thread_function, args)) thread.setDaemon(True) try: thread.start() except Exception as ex: err_msg = "error occurred while starting new thread ('{0}')".format( str(ex)) logger.critical(err_msg) break threads.append(thread) # And wait for them to all finish alive = True while alive: alive = False for thread in threads: if thread.isAlive(): alive = True time.sleep(0.1) except KeyboardInterrupt as ex: KB['continue'] = False if num_threads > 1: logger.info("waiting for threads to finish{0}".format( " (Ctrl+C was pressed)" if isinstance(ex, KeyboardInterrupt ) else "")) try: while threading.activeCount() > 1: pass except KeyboardInterrupt: raise except Exception as ex: logger.error("thread {0}: {1}".format( threading.currentThread().getName(), str(ex))) traceback.print_exc() finally: Share.dataToStdout('\n')
def _init_stdout(): # 不扫描网址 if len(conf["excludes"]): logger.info("Exclude urls:{}".format(repr(conf["excludes"]))) # 指定扫描网址 if len(conf["includes"]) and conf["includes"][0] != ".*": logger.info("Include urls:{}".format(repr(conf["includes"]))) # 不使用插件 if len(conf["exclude_plugins"]): logger.info("Exclude plugins:{}".format(repr(conf["exclude_plugins"]))) # 指定使用插件 if len(conf["include_plugins"]) and conf["include_plugins"][0] != "all": logger.info("Include plugins:{}".format(repr(conf["include_plugins"]))) # 主动探测 no_active = 'On' if str(conf["no_active"]) == "True" else "Off" logger.info("Active detection mode:{}".format(no_active))