Exemplo n.º 1
0
  def __init__(
          self,
          config=None,
          db_name='report_tracker.db',
          purge=False,
          verbose=None,
          debug=False,
          username=None,
          password=None,
      ):
      super(vulnWhispererJIRA, self).__init__(config=config)
      self.logger = logging.getLogger('vulnWhispererJira')
      if debug:
          self.logger.setLevel(logging.DEBUG)
      self.config_path = config
      self.config = vwConfig(config)
   
               
      if config is not None:
          try:
              self.logger.info('Attempting to connect to jira...')
              self.jira = \
                  JiraAPI(hostname=self.hostname,
                            username=self.username,
                            password=self.password)
              self.jira_connect = True
              self.logger.info('Connected to jira on {host}'.format(host=self.hostname))
          except Exception as e:
              self.logger.error('Exception: {}'.format(str(e)))
              raise Exception(
                  'Could not connect to nessus -- Please verify your settings in {config} are correct and try again.\nReason: {e}'.format(
                      config=self.config.config_in, e=e))
              sys.exit(1)
 
      profiles = []
      profiles = self.get_scan_profiles()
      
      if not self.config.exists_jira_profiles(profiles):
          self.config.update_jira_profiles(profiles)
          self.logger.info("Jira profiles have been created in {config}, please fill the variables before rerunning the module.".format(config=self.config_path))
          sys.exit(0)
Exemplo n.º 2
0
    def get_env_variables(self, source, scan_name):
        # function returns an array with [jira_project, jira_components, datafile_path]

        #Jira variables
        jira_section = self.config.normalize_section("{}.{}".format(source,scan_name))

        project = self.config.get(jira_section,'jira_project')
        if project == "":
            self.logger.error('JIRA project is missing on the configuration file!')
            sys.exit(0)
        
        # check that project actually exists
        if not self.jira.project_exists(project):
            self.logger.error("JIRA project '{project}' doesn't exist!".format(project=project))
            sys.exit(0)
         
        components = self.config.get(jira_section,'components').split(',')
        
        #cleaning empty array from ''
        if not components[0]:
            components = []
        
        min_critical = self.config.get(jira_section,'min_critical_to_report')
        if not min_critical:
            self.logger.error('"min_critical_to_report" variable on config file is empty.')
            sys.exit(0)
            
        #datafile path
        filename = self.get_latest_results(source, scan_name)
        
        # search data files under user specified directory
        for root, dirnames, filenames in os.walk(vwConfig(self.config_path).get(source,'write_path')):
            if filename in filenames:
                fullpath = "{}/{}".format(root,filename)
        
        if not fullpath:
            self.logger.error('Scan file path "{scan_name}" for source "{source}" has not been found.'.format(scan_name=scan_name, source=source))
            return 0

        return project, components, fullpath, min_critical
Exemplo n.º 3
0
    def __init__(
            self,
            config=None,
            db_name='report_tracker.db',
            purge=False,
            verbose=None,
            debug=False,
            username=None,
            password=None,
            section=None,
            develop=False,
        ):


        if self.CONFIG_SECTION is None:
                raise Exception('Implementing class must define CONFIG_SECTION')

        self.db_name = db_name
        self.purge = purge
        self.develop = develop


        if config is not None:
            self.config = vwConfig(config_in=config)
            self.enabled = self.config.get(self.CONFIG_SECTION, 'enabled')
            self.hostname = self.config.get(self.CONFIG_SECTION, 'hostname')
            self.username = self.config.get(self.CONFIG_SECTION, 'username')
            self.password = self.config.get(self.CONFIG_SECTION, 'password')
            self.write_path = self.config.get(self.CONFIG_SECTION, 'write_path')
            self.db_path = self.config.get(self.CONFIG_SECTION, 'db_path')
            self.verbose = self.config.getbool(self.CONFIG_SECTION, 'verbose')



        if self.db_name is not None:
            if self.db_path:
                self.database = os.path.join(self.db_path,
                                             db_name)
            else:
                self.database = \
                    os.path.abspath(os.path.join(os.path.dirname(__file__),
                                                 'database', db_name))
            if not os.path.exists(self.db_path):
                os.makedirs(self.db_path)
                self.vprint('{info} Creating directory {dir}'.format(info=bcolors.INFO, dir=self.db_path))

            if not os.path.exists(self.database):
                with open(self.database, 'w'):
                    self.vprint('{info} Creating file {dir}'.format(info=bcolors.INFO, dir=self.database))
                    pass

            try:
                self.conn = sqlite3.connect(self.database)
                self.cur = self.conn.cursor()
                self.vprint('{info} Connected to database at {loc}'.format(info=bcolors.INFO,
                                                                           loc=self.database))
            except Exception as e:
                self.vprint(
                    '{fail} Could not connect to database at {loc}\nReason: {e} - Please ensure the path exist'.format(
                        e=e,
                        fail=bcolors.FAIL, loc=self.database))
        else:

            self.vprint('{fail} Please specify a database to connect to!'.format(fail=bcolors.FAIL))
            exit(0)

        self.table_columns = [
            'scan_name',
            'scan_id',
            'last_modified',
            'filename',
            'download_time',
            'record_count',
            'source',
            'uuid',
            'processed',
        ]

        self.init()
        self.uuids = self.retrieve_uuids()
        self.processed = 0
        self.skipped = 0
        self.scan_list = []
Exemplo n.º 4
0
    def __init__(self, config=None, db_name='report_tracker.db', purge=False, verbose=None, debug=False):

        self.verbose = verbose
        self.nessus_connect = False
        self.develop = True
        self.purge = purge

        if config is not None:
            try:
                self.config = vwConfig(config_in=config)
                self.nessus_enabled = self.config.getbool('nessus', 'enabled')

                if self.nessus_enabled:
                    self.nessus_hostname = self.config.get('nessus', 'hostname')
                    self.nessus_port = self.config.get('nessus', 'port')
                    self.nessus_username = self.config.get('nessus', 'username')
                    self.nessus_password = self.config.get('nessus', 'password')
                    self.nessus_writepath = self.config.get('nessus', 'write_path')
                    self.nessus_dbpath = self.config.get('nessus', 'db_path')
                    self.nessus_trash = self.config.getbool('nessus', 'trash')
                    self.verbose = self.config.getbool('nessus', 'verbose')

                    try:
                        self.vprint(
                            '{info} Attempting to connect to nessus...'.format(info=bcolors.INFO))
                        self.nessus = NessusAPI(hostname=self.nessus_hostname,
                                                port=self.nessus_port,
                                                username=self.nessus_username,
                                                password=self.nessus_password)
                        self.nessus_connect = True
                        self.vprint(
                            '{success} Connected to nessus on {host}:{port}'.format(success=bcolors.SUCCESS,
                                                                                                        host=self.nessus_hostname,
                                                                                                        port=str(self.nessus_port)))
                    except Exception as e:
                        self.vprint(e)
                        raise Exception(
                            "{fail} Could not connect to nessus -- Please verify your settings in {config} are correct and try again.\nReason: {e}".format(config=self.config,
                                                                                                                                                           fail=bcolors.FAIL,
                                                                                                                                                           e=e))

            except Exception as e:

                self.vprint('{fail} Could not properly load your config!\nReason: {e}'.format(fail=bcolors.FAIL, e=e))
                sys.exit(0)

        if db_name is not None:
            if self.nessus_dbpath:
                self.database = os.path.join(self.nessus_dbpath, db_name)
            else:
                self.database = os.path.abspath(os.path.join(os.path.dirname( __file__ ), 'database', db_name))

            try:
                self.conn = sqlite3.connect(self.database)
                self.cur = self.conn.cursor()
                self.vprint("{info} Connected to database at {loc}".format(info=bcolors.INFO, loc=self.database))
            except Exception as e:
                self.vprint("{fail} Could not connect to database at {loc}\nReason: {e} - Please ensure the path exist".format(e=e, fail=bcolors.FAIL, loc=self.database))

        else:
            self.vprint('{fail} Please specify a database to connect to!'.format(fail=bcolors.FAIL))
            exit(0)

        self.table_columns = ['scan_name',
                              'scan_id',
                              'last_modified',
                              'filename',
                              'download_time',
                              'record_count',
                              'source',
                              'uuid',
                              'processed']
        self.init()
        self.uuids = self.retrieve_uuids()
        self.processed = 0
        self.skipped = 0
        self.scan_list = []