Example #1
0
    def install_dependencies(stdout=False, verbose=False):
        """
        Install the required dependencies required by Suricata

        :param stdout: Print the output to console
        :param verbose: Include detailed debug messages
        """
        log_level = logging.INFO
        if verbose:
            log_level = logging.DEBUG
        logger = get_logger('SURICATA', level=log_level, stdout=stdout)
        logger.info('Installing Dependencies.')

        pkt_mng = package_manager.OSPackageManager(stdout=stdout,
                                                   verbose=verbose)

        packages = None
        if pkt_mng.package_manager == 'apt-get':
            packages = [
                'cmake', 'make', 'gcc', 'g++', 'flex', 'bison', 'libtool',
                'automake', 'pkg-config', 'libpcre3-dev', 'libpcap-dev',
                'libyaml-dev', 'libjansson-dev', 'rustc', 'cargo',
                'python-pip', 'wireshark', 'zlib1g-dev', 'libcap-ng-dev',
                'libnspr4-dev', 'libnss3-dev', 'libmagic-dev', 'liblz4-dev',
                'tar', 'wget', 'libjemalloc-dev'
            ]
        elif pkt_mng.package_manager == 'yum':
            packages = [
                'cmake', 'make', 'gcc', 'gcc-c++', 'flex', 'bison', 'libtool',
                'automake', 'pkgconfig', 'pcre-devel', 'libpcap-devel',
                'libyaml-devel', 'jansson-devel', 'rustc', 'cargo',
                'python3-pip', 'wireshark', 'zlib-devel', 'libcap-ng-devel',
                'nspr-devel', 'nss-devel', 'file-devel', 'lz4-devel', 'tar',
                'wget', 'jemalloc-devel'
            ]
        logger.info('Refreshing Package Index.')
        try:
            pkt_mng.refresh_package_indexes()
        except general_exceptions.OsPackageManagerRefreshError as e:
            logger.warning("Failed to refresh packages.")
            logger.debug("Failed to refresh packages threw: {}".format(e))
            raise general_exceptions.OsPackageManagerRefreshError(
                'Failed to refresh packages.')
        logger.info('Installing the following packages: {}.'.format(packages))
        try:
            pkt_mng.install_packages(packages)
        except general_exceptions.OsPackageManagerInstallError as e:
            logger.warning(
                "Failed to install one or more packages: {}".format(e))
Example #2
0
    def install_dependencies(stdout=False, verbose=False):
        """
        Install the required dependencies required by Zeek

        :param stdout: Print the output to console
        :param verbose: Include detailed debug messages
        """

        log_level = logging.INFO
        if verbose:
            log_level = logging.DEBUG
        logger = get_logger('ZEEK', level=log_level, stdout=stdout)
        logger.info('Installing Dependencies.')
        pkt_mng = package_manager.OSPackageManager(stdout=stdout, verbose=verbose)
        packages = None
        if pkt_mng.package_manager == 'apt-get':
            packages = ['cmake', 'cmake3', 'make', 'gcc', 'g++', 'flex', 'bison', 'libpcap-dev', 'libssl-dev',
                        'python-dev', 'swig', 'zlib1g-dev', 'linux-headers-$(uname -r)', 'linux-headers-generic', 'tar',
                        'libjemalloc-dev']
        elif pkt_mng.package_manager == 'yum':

            packages = ['cmake', 'cmake3', 'make', 'gcc', 'gcc-c++', 'flex', 'bison', 'libpcap-devel',
                        'openssl-devel', 'python3-devel', 'python2-devel', 'swig', 'zlib-devel',
                        'kernel-devel', 'tar', 'jemalloc-devel']

            # Work around for missing dependencies in RHEL/Centos8
            try:
                pkt_mng.install_packages(['dnf-plugins-core'])
            except general_exceptions.OsPackageManagerInstallError as e:
                logger.warning("Failed to install one or more packages: {}".format(e))
            enable_powertools_p = subprocess.Popen(['yum', 'config-manager', '--set-enabled', 'PowerTools'],
                                                   stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            enable_powertools_p.communicate()

            if enable_powertools_p.returncode == 0:
                logger.info("Installed PowerTools.")
        logger.info('Refreshing Package Index.')
        try:
            pkt_mng.refresh_package_indexes()
        except general_exceptions.OsPackageManagerRefreshError as e:
            logger.warning("Failed to refresh packages.")
            logger.debug("Failed to refresh packages threw: {}".format(e))
            raise general_exceptions.OsPackageManagerRefreshError('Failed to refresh packages.')
        logger.info('Installing the following packages: {}.'.format(packages))
        try:
            pkt_mng.install_packages(packages)
        except general_exceptions.OsPackageManagerInstallError as e:
            logger.warning("Failed to install packages one or more packages: {}".format(e))
Example #3
0
 def refresh_package_indexes(self):
     """
     Refresh the package cache
     """
     params = None
     if self.package_manager == 'apt-get':
         params = 'update'
     elif self.package_manager == 'yum':
         params = 'check-update'
     if not self.package_manager:
         return False
     if self.verbose:
         p = subprocess.Popen('{} {} &> /dev/null'.format(self.package_manager, params), shell=True)
     else:
         p = subprocess.Popen('{} {} &> /dev/null'.format(self.package_manager, params), shell=True,
                              stdout=subprocess.PIPE, stderr=subprocess.PIPE)
     p.communicate()
     if p.returncode not in [0, 100]:
         self.logger.error('Could not refresh package index via {}'.format(self.package_manager))
         raise general_exceptions.OsPackageManagerRefreshError(
             "OS package manager was unable to update; exited with {}".format(p.returncode))