def __init__(self): super(RawReportProcessor, self).__init__() from faraday import setupPlugins setupPlugins() self.pending_actions = Queue() try: plugin_manager = PluginManager( os.path.join(CONF.getConfigPath(), "plugins")) except AttributeError: get_logger().warning( "Upload reports in WEB-UI not configurated, run Faraday client and try again..." ) self._stop = True return mappers_manager = MapperManager() self.model_controller = ModelController(mappers_manager, self.pending_actions) self.model_controller.start() self.end_event = Event() plugin_controller = PluginController('PluginController', plugin_manager, mappers_manager, self.pending_actions, self.end_event) self.processor = ReportProcessor(plugin_controller, None) self._stop = False
def testSendReportWithoutPlugin(self): plugin_controller = mock.Mock(spec=PluginControllerForApi) plugin_controller.processCommandInput.return_value = (False, None, None) report_processor = ReportProcessor(plugin_controller) file_mock = mock.MagicMock(spec=file) file_mock.read.return_value = 'Stringreturned' with mock.patch('__builtin__.open', create=True) as mock_open: res = report_processor._sendReport("nmap", 'strings') self.assertFalse(res, "The plugin should not be executed")
def run(self, args): workspace = args.workspace try: self.workspace_manager.openWorkspace(workspace) except Exception as e: getLogger(self).error(("The workspace %s is not accessible, " "check configuration") % workspace) getLogger(self).error(str(e)) return -1 rp = ReportProcessor(self.plugin_controller) rp.processReport(args.filename)
def run(self, args): workspace = args.workspace try: self.workspace_manager.openWorkspace(workspace) except Exception as e: getLogger(self).error( ("The workspace %s is not accessible, " "check configuration") % workspace) getLogger(self).error(str(e)) return -1 rp = ReportProcessor() rp.processReport(args.filename)
def __init__(self): super(RawReportProcessor, self).__init__() from faraday import setupPlugins setupPlugins() self.pending_actions = Queue() try: plugin_manager = PluginManager(os.path.join(CONF.getConfigPath(), "plugins")) except AttributeError: get_logger().warning( "Upload reports in WEB-UI not configurated, run Faraday client and try again...") self._stop = True return mappers_manager = MapperManager() self.model_controller = ModelController(mappers_manager, self.pending_actions) self.model_controller.start() self.end_event = Event() plugin_controller = PluginController( 'PluginController', plugin_manager, mappers_manager, self.pending_actions, self.end_event) self.processor = ReportProcessor(plugin_controller, None) self._stop = False
class RawReportProcessor(Thread): def __init__(self): super(RawReportProcessor, self).__init__() from faraday import setupPlugins setupPlugins() self.pending_actions = Queue() try: plugin_manager = PluginManager(os.path.join(CONF.getConfigPath(), "plugins")) except AttributeError: get_logger().warning( "Upload reports in WEB-UI not configurated, run Faraday client and try again...") self._stop = True return mappers_manager = MapperManager() self.model_controller = ModelController(mappers_manager, self.pending_actions) self.model_controller.start() self.end_event = Event() plugin_controller = PluginController( 'PluginController', plugin_manager, mappers_manager, self.pending_actions, self.end_event) self.processor = ReportProcessor(plugin_controller, None) self._stop = False def stop(self): self.model_controller.stop() self._stop = True def run(self): logger.info('Tool report processor started') while not self._stop: try: workspace, file_path, cookie = UPLOAD_REPORTS_QUEUE.get(False, timeout=0.1) get_logger().info('Processing raw report {0}'.format(file_path)) # Cookie of user, used to create objects in server with the right owner. server.FARADAY_UPLOAD_REPORTS_WEB_COOKIE = cookie server.FARADAY_UPLOAD_REPORTS_OVERWRITE_SERVER_URL = "http://{0}:{1}".format( FaradayServerConfig.faraday_server.bind_address, FaradayServerConfig.faraday_server.port) self.processor.ws_name = workspace command_id = self.processor.processReport(file_path) UPLOAD_REPORTS_CMD_QUEUE.put(command_id) if not command_id: continue self.end_event.wait() get_logger().info('Report processing of report {0} finished'.format(file_path)) self.end_event.clear() except Empty: time.sleep(0.1) except KeyboardInterrupt as ex: get_logger().info('Keyboard interrupt, stopping report processing thread') self.stop() except Exception as ex: get_logger().exception(ex) continue
class RawReportProcessor(Thread): def __init__(self): super(RawReportProcessor, self).__init__() from faraday import setupPlugins setupPlugins() self.pending_actions = Queue() try: plugin_manager = PluginManager( os.path.join(CONF.getConfigPath(), "plugins")) except AttributeError: get_logger().warning( "Upload reports in WEB-UI not configurated, run Faraday client and try again..." ) self._stop = True return mappers_manager = MapperManager() self.model_controller = ModelController(mappers_manager, self.pending_actions) self.model_controller.start() self.end_event = Event() plugin_controller = PluginController('PluginController', plugin_manager, mappers_manager, self.pending_actions, self.end_event) self.processor = ReportProcessor(plugin_controller, None) self._stop = False def stop(self): self.model_controller.stop() self._stop = True def run(self): while not self._stop: try: workspace, file_path, cookie = UPLOAD_REPORTS_QUEUE.get( False, timeout=0.1) get_logger().info( 'Processing raw report {0}'.format(file_path)) # Cookie of user, used to create objects in server with the right owner. server.FARADAY_UPLOAD_REPORTS_WEB_COOKIE = cookie server.FARADAY_UPLOAD_REPORTS_OVERWRITE_SERVER_URL = "http://{0}:{1}".format( FaradayServerConfig.faraday_server.bind_address, FaradayServerConfig.faraday_server.port) self.processor.ws_name = workspace command_id = self.processor.processReport(file_path) UPLOAD_REPORTS_CMD_QUEUE.put(command_id) if not command_id: continue self.end_event.wait() get_logger().info( 'Report processing of report {0} finished'.format( file_path)) self.end_event.clear() except Empty: time.sleep(0.1) except KeyboardInterrupt as ex: get_logger().info( 'Keyboard interrupt, stopping report processing thread') self.stop() except Exception as ex: get_logger().exception(ex) continue