def _set_plugins(): # TODO # load plugin scripts .pyc file support if conf.plugins: founds = [] cache_plugins = copy.deepcopy(conf.plugins) for found in glob.glob( os.path.join(paths.POCSUITE_PLUGINS_PATH, "*.py*")): dirname, filename = os.path.split(found) plugin_name = os.path.splitext(filename)[0] if found.endswith(('__init__.py', '__init__.pyc')): continue if plugin_name not in conf.plugins: continue cache_plugins.remove(plugin_name) founds.append(found) if len(cache_plugins) > 0: for file in cache_plugins: if os.path.exists(file): founds.append(file) for file in founds: debug_msg = "loading plugin script '{0}'".format(file) logger.debug(debug_msg) load_file_to_module(file)
def _set_pocs_modules(): # TODO # load poc scripts .pyc file support if conf.poc: # step1. load system packed poc from pocsuite3/pocs folder exists_poc_with_ext = list( filter(lambda x: x not in ['__init__.py', '__init__.pyc'], os.listdir(paths.POCSUITE_POCS_PATH))) exists_pocs = dict([os.path.splitext(x) for x in exists_poc_with_ext]) for poc in conf.poc: load_poc_sucess = False if any([poc in exists_poc_with_ext, poc in exists_pocs]): poc_name, poc_ext = os.path.splitext(poc) if poc_ext in ['.py', '.pyc']: file_path = os.path.join(paths.POCSUITE_POCS_PATH, poc) else: file_path = os.path.join(paths.POCSUITE_POCS_PATH, poc + exists_pocs.get(poc)) if file_path: info_msg = "loading PoC script '{0}'".format(file_path) logger.info(info_msg) load_poc_sucess = load_file_to_module(file_path) # step2. load poc from given file path try: if not load_poc_sucess: if not poc.startswith('ssvid-') and check_file(poc): info_msg = "loading PoC script '{0}'".format(poc) logger.info(info_msg) load_poc_sucess = load_file_to_module(poc) except PocsuiteSystemException: logger.error('PoC file "{0}" not found'.format(repr(poc))) continue # step3. load poc from seebug website using plugin 'poc_from_seebug' if not load_poc_sucess: if poc.startswith('ssvid-'): info_msg = "loading Poc script 'https://www.seebug.org/vuldb/{0}'".format( poc) logger.info(info_msg) if "poc_from_seebug" not in conf.plugins: conf.plugins.append('poc_from_seebug') load_poc_sucess = True load_keyword_poc_sucess = False if conf.vul_keyword: # step4. load poc with vul_keyword search seebug website info_msg = "loading PoC script from seebug website using search keyword '{0}' ".format( conf.vul_keyword) logger.info(info_msg) conf.plugins.append('poc_from_seebug') load_keyword_poc_sucess = True if all([not kb.registered_pocs, not load_keyword_poc_sucess]): error_msg = "no PoC loaded, please check your PoC file" logger.error(error_msg) raise PocsuiteSystemException(error_msg)
def _set_pocs_modules(): # TODO # load poc scripts .pyc file support if conf.poc: load_poc_sucess = False # step1. load system packed poc from pocsuite3/pocs folder for found in glob.glob(os.path.join(paths.POCSUITE_POCS_PATH, "*.py*")): dirname, filename = os.path.split(found) poc_name = os.path.splitext(filename)[0] for poc in conf.poc: if found.endswith(('__init__.py', '__init__.pyc')): continue if poc in (filename, poc_name): info_msg = "loading PoC script '{0}'".format(found) logger.info(info_msg) load_poc_sucess = load_file_to_module(found) # step2. load poc from given file path try: if not load_poc_sucess: for poc in conf.poc: if not poc.startswith('ssvid-') and check_file(poc): info_msg = "loading PoC script '{0}'".format(poc) logger.info(info_msg) load_poc_sucess = load_file_to_module(poc) except PocsuiteSystemException: logger.error('PoC file "{0}" not found'.format(repr(conf.poc))) raise SystemExit # step3. load poc from seebug website using plugin 'poc_from_seebug' if not load_poc_sucess: for poc in conf.poc: if poc.startswith('ssvid-'): info_msg = "loading Poc script 'https://www.seebug.org/vuldb/{0}'".format( poc) logger.info(info_msg) if "poc_from_seebug" not in conf.plugins: conf.plugins.append('poc_from_seebug') load_poc_sucess = True if conf.vul_keyword: # step4. load poc with vul_keyword search seebug website info_msg = "loading PoC script from seebug website using search keyword '{0}' ".format( conf.vul_keyword) logger.info(info_msg) conf.plugins.append('poc_from_seebug') load_poc_sucess = True if (conf.poc or conf.vul_keyword) and not load_poc_sucess: error_msg = "" logger.error(error_msg) raise PocsuiteSyntaxException(error_msg)
def _set_plugins(): # TODO # load plugin scripts .pyc file support if conf.plugins: for found in glob.glob(os.path.join(paths.POCSUITE_PLUGINS_PATH, "*.py*")): dirname, filename = os.path.split(found) plugin_name = os.path.splitext(filename)[0] if found.endswith(('__init__.py', '__init__.pyc')): continue if plugin_name not in conf.plugins: continue debug_msg = "loading plugin script '{0}'".format(found) logger.debug(debug_msg) load_file_to_module(found)
def command_use(self, module_path, *args, **kwargs): if module_path.isdigit(): index = int(module_path) if index >= len(self.last_search): logger.warning("Index out of range") return module_path = self.last_search[index] module_path = module_path + ".py" try: load_file_to_module(module_path) self.current_module = kb.current_poc self.current_module.pocsuite3_module_path = module_path.rstrip( ".py") except Exception as err: logger.error(str(err))
def add_poc_from_file(self, filename): ret = False if os.path.exists(filename): try: load_file_to_module(filename) ret = True except SystemExit: pass except Exception as ex: msg = "[PLUGIN] load PoC script failed: {0}".format(str(ex)) single_time_warn_message(msg) else: err_msg = "[PLUGIN] invalid pocsuite3 PoC file {}".format(filename) logger.error(err_msg) return ret
def command_use(self, module_path, *args, **kwargs): if module_path.isdigit(): index = int(module_path) if index >= len(self.last_search): logger.warning("Index out of range") return module_path = self.last_search[index] if not module_path.endswith(".py"): module_path = module_path + ".py" if not os.path.exists(module_path): module_path = os.path.join(paths.POCSUITE_ROOT_PATH, module_path) if not os.path.exists(module_path): errMsg = "No such file: '{0}'".format(module_path) logger.error(errMsg) return try: load_file_to_module(module_path) self.current_module = kb.current_poc self.current_module.pocsuite3_module_path = ltrim(rtrim(module_path, ".py"), os.path.join(paths.POCSUITE_ROOT_PATH, "")) except Exception as err: logger.error(str(err))
def _set_pocs_modules(): # TODO # load poc scripts .pyc file support if conf.ssvid: conf.plugins.append('poc_from_seebug') if not (conf.poc or conf.vul_keyword) and conf.poc_keyword: conf.poc = [paths.POCSUITE_POCS_PATH] if conf.poc: exists_poc_with_ext = list( filter(lambda x: x not in ['__init__.py', '__init__.pyc'], os.listdir(paths.POCSUITE_POCS_PATH))) exists_pocs = dict([os.path.splitext(x) for x in exists_poc_with_ext]) for poc in conf.poc: # load poc from pocsuite3/pocs folder or other local path try: _pocs = [] load_poc_sucess = False if os.path.isfile(poc): _pocs.append(poc) elif any([poc in exists_poc_with_ext, poc in exists_pocs]): poc_name, poc_ext = os.path.splitext(poc) if poc_ext in ['.py', '.pyc']: file_path = os.path.join(paths.POCSUITE_POCS_PATH, poc) else: file_path = os.path.join(paths.POCSUITE_POCS_PATH, poc + exists_pocs.get(poc)) _pocs.append(file_path) elif check_path(poc): for root, _, files in os.walk(poc): files = filter( lambda x: not x.startswith("__") and x.endswith( ".py"), files) _pocs.extend( map(lambda x: os.path.join(root, x), files)) for p in _pocs: file_content = open(p, encoding='utf-8').read() if 'register_poc' not in file_content: continue if conf.poc_keyword: attr_field = re.search(r'vulID.*?def .*?\(', file_content, re.DOTALL) if attr_field and conf.poc_keyword.lower( ) not in attr_field.group().lower(): continue info_msg = "loading PoC script '{0}'".format(p) logger.info(info_msg) load_poc_sucess = load_file_to_module(p) or load_poc_sucess except PocsuiteSystemException: logger.error('PoC file "{0}" not found'.format(repr(poc))) continue # load poc from seebug website using plugin 'poc_from_seebug' if not load_poc_sucess and poc.startswith('ssvid-'): info_msg = "loading Poc script 'https://www.seebug.org/vuldb/{0}'".format( poc) logger.info(info_msg) if "poc_from_seebug" not in conf.plugins: conf.plugins.append('poc_from_seebug') if conf.vul_keyword: # step4. load poc with vul_keyword search seebug website info_msg = "loading PoC script from seebug website using search keyword '{0}' ".format( conf.vul_keyword) logger.info(info_msg) conf.plugins.append('poc_from_seebug')