def __init__(self, args): self._original_excepthook = sys.excepthook self.args = args logger = getLogger(self) if args.creds_file: try: with open(args.creds_file, 'r') as fp: creds = json.loads(fp.read()) username = creds.get('username') password = creds.get('password') session_cookie = login_user(CONF.getServerURI(), username, password) if session_cookie: logger.info('Login successful') CONF.setDBUser(username) CONF.setDBSessionCookies(session_cookie) else: logger.error('Login failed') except (IOError, ValueError): logger.error("Credentials file couldn't be loaded") self._mappers_manager = MapperManager() pending_actions = Queue() self._model_controller = ModelController(self._mappers_manager, pending_actions) self._plugin_manager = PluginManager( os.path.join(CONF.getConfigPath(), "plugins"), pending_actions=pending_actions, ) self._workspace_manager = WorkspaceManager(self._mappers_manager) # Create a PluginController and send this to UI selected. self._plugin_controller = PluginController('PluginController', self._plugin_manager, self._mappers_manager, pending_actions) if self.args.cli: self.app = CliApp(self._workspace_manager, self._plugin_controller) if self.args.keep_old: CONF.setMergeStrategy("old") else: CONF.setMergeStrategy("new") else: self.app = UiFactory.create(self._model_controller, self._plugin_manager, self._workspace_manager, self._plugin_controller, self.args.gui) self.timer = TimerClass() self.timer.start()
def try_login_user(server_uri, api_username, api_password): try: session_cookie = login_user(server_uri, api_username, api_password) return session_cookie except requests.exceptions.SSLError: print( "SSL certificate validation failed.\nYou can use the --cert option in Faraday to set the path of the cert" ) sys.exit(-1) except requests.exceptions.MissingSchema: print("The Faraday server URL is incorrect, please try again.") sys.exit(-2)
def main(): signal.signal(signal.SIGINT, signal_handler) parser = argparse.ArgumentParser(description='Search duplicated objects on Faraday') parser.add_argument('-w', '--workspace', help='Search duplicated objects into this workspace', required=True) parser.add_argument('-s', '--server', help='Faraday server', required=False, default="http://127.0.0.1:5985/") parser.add_argument('-u', '--user', help='Faraday user', required=False, default="") parser.add_argument('-p', '--password', help='Faraday password', required=False, default="") parser.add_argument('-o', '--output', help='Choose a custom output directory', required=False) parser.add_argument('-l', '--log', help='Choose a custom log level', required=False) args = parser.parse_args() lockf = ".lock.pod" if not lock_file(lockf): print ("You can run only one instance of searcher (%s)" % lockf) exit(0) workspace = '' if args.workspace: workspace = args.workspace else: print("You must enter a workspace in command line, please use --help to read more") os.remove(lockf) exit(0) _server = 'http://127.0.0.1:5985/' if args.server: _server = args.server _user = '******' if args.user: _user = args.user _password = '******' if args.password: _password = args.password output = 'output/' if args.output: output = args.output loglevel = 'debug' if args.log: loglevel = args.log for d in [output, 'log/']: if not os.path.isdir(d): os.makedirs(d) numeric_level = getattr(logging, loglevel.upper(), None) if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % loglevel) if not logger.handlers: logger.propagate = 0 logger.setLevel(numeric_level) fh = logging.FileHandler('log/searcher.log') fh.setLevel(numeric_level) # create console handler with a higher log level ch = logging.StreamHandler() ch.setLevel(numeric_level) # create formatter and add it to the handlers formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') fh.setFormatter(formatter) ch.setFormatter(formatter) logger.addHandler(fh) logger.addHandler(ch) try: session_cookie = login_user(_server, _user, _password) if not session_cookie: raise UserWarning('Invalid credentials!') else: CONF.setDBUser(_user) CONF.setDBSessionCookies(session_cookie) server.AUTH_USER = _user server.AUTH_PASS = _password server.SERVER_URL = _server server.FARADAY_UP = False logger.info('Started') logger.info('Searching objects into workspace %s ' % workspace) logger.debug("Getting hosts ...") hosts = models.get_hosts(workspace) logger.debug("Getting services ...") services = models.get_services(workspace) logger.debug("Getting vulnerabilities ...") vulns = models.get_all_vulns(workspace) if validate_rules(): process_vulnerabilities(workspace, vulns, _server) process_services(workspace, services, _server) process_hosts(workspace, hosts, _server) # Remove lockfile os.remove(lockf) logger.info('Finished') except ResourceDoesNotExist: logger.error("Resource not found") os.remove(lockf) exit(0) except Exception as errorMsg: logger.error(errorMsg) os.remove(lockf) exit(0)
def main(): signal.signal(signal.SIGINT, signal_handler) parser = argparse.ArgumentParser( description='Search duplicated objects on Faraday') parser.add_argument('-w', '--workspace', help='Search duplicated objects into this workspace', required=True) parser.add_argument('-s', '--server', help='Faraday server', required=False, default="http://127.0.0.1:5985/") parser.add_argument('-u', '--user', help='Faraday user', required=False, default="") parser.add_argument('-p', '--password', help='Faraday password', required=False, default="") parser.add_argument('-o', '--output', help='Choose a custom output directory', required=False) parser.add_argument('-l', '--log', help='Choose a custom log level', required=False) args = parser.parse_args() lockf = ".lock.pod" if not lock_file(lockf): print("You can run only one instance of searcher (%s)" % lockf) exit(0) workspace = '' if args.workspace: workspace = args.workspace else: print( "You must enter a workspace in command line, please use --help to read more" ) os.remove(lockf) exit(0) _server = 'http://127.0.0.1:5985/' if args.server: _server = args.server _user = '******' if args.user: _user = args.user _password = '******' if args.password: _password = args.password output = 'output/' if args.output: output = args.output loglevel = 'debug' if args.log: loglevel = args.log for d in [output, 'log/']: if not os.path.isdir(d): os.makedirs(d) numeric_level = getattr(logging, loglevel.upper(), None) if not isinstance(numeric_level, int): raise ValueError('Invalid log level: %s' % loglevel) if not logger.handlers: logger.propagate = 0 logger.setLevel(numeric_level) fh = logging.FileHandler('log/searcher.log') fh.setLevel(numeric_level) # create console handler with a higher log level ch = logging.StreamHandler() ch.setLevel(numeric_level) # create formatter and add it to the handlers formatter = logging.Formatter( '%(asctime)s - %(name)s - %(levelname)s: %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p') fh.setFormatter(formatter) ch.setFormatter(formatter) logger.addHandler(fh) logger.addHandler(ch) try: session_cookie = login_user(_server, _user, _password) if not session_cookie: raise UserWarning('Invalid credentials!') else: CONF.setDBUser(_user) CONF.setDBSessionCookies(session_cookie) server.AUTH_USER = _user server.AUTH_PASS = _password server.SERVER_URL = _server server.FARADAY_UP = False logger.info('Started') logger.info('Searching objects into workspace %s ' % workspace) logger.debug("Getting hosts ...") hosts = models.get_hosts(workspace) logger.debug("Getting services ...") services = models.get_services(workspace) logger.debug("Getting vulnerabilities ...") vulns = models.get_all_vulns(workspace) if validate_rules(): process_vulnerabilities(workspace, vulns, _server) process_services(workspace, services, _server) process_hosts(workspace, hosts, _server) # Remove lockfile os.remove(lockf) logger.info('Finished') except ResourceDoesNotExist: logger.error("Resource not found") os.remove(lockf) exit(0) except Exception as errorMsg: logger.error(errorMsg) os.remove(lockf) exit(0)
def __init__(self, args): self._original_excepthook = sys.excepthook self.args = args logger = getLogger(self) if args.creds_file: try: with open(args.creds_file, 'r') as fp: creds = json.loads(fp.read()) username = creds.get('username') password = creds.get('password') session_cookie = login_user(CONF.getServerURI(), username, password) if session_cookie: logger.info('Login successful') CONF.setDBUser(username) CONF.setDBSessionCookies(session_cookie) else: logger.error('Login failed') except (IOError, ValueError): logger.error("Credentials file couldn't be loaded") self._mappers_manager = MapperManager() pending_actions = Queue() self._model_controller = ModelController(self._mappers_manager, pending_actions) self._plugin_manager = PluginManager( os.path.join(CONF.getConfigPath(), "plugins"), pending_actions=pending_actions, ) self._workspace_manager = WorkspaceManager( self._mappers_manager) # Create a PluginController and send this to UI selected. self._plugin_controller = PluginController( 'PluginController', self._plugin_manager, self._mappers_manager, pending_actions ) if self.args.cli: self.app = CliApp(self._workspace_manager, self._plugin_controller) if self.args.keep_old: CONF.setMergeStrategy("old") else: CONF.setMergeStrategy("new") else: self.app = UiFactory.create(self._model_controller, self._plugin_manager, self._workspace_manager, self._plugin_controller, self.args.gui) self.timer = TimerClass() self.timer.start()