Esempio n. 1
0
    def install_jupyterhub_dependencies(stdout=False, verbose=False):
        """
        Install the required dependencies required by Jupyterhub

        :param stdout: Print output to console
        :param verbose: Include output from system utilities
        :return: True, if all packages installed successfully
        """
        pacman = package_manager.OSPackageManager(verbose=verbose)
        if not pacman.refresh_package_indexes():
            return False
        packages = None
        if stdout:
            sys.stdout.write('[+] Updating Package Indexes.\n')
            sys.stdout.flush()
        pacman.refresh_package_indexes()
        if stdout:
            sys.stdout.write('[+] Installing dependencies.\n')
            sys.stdout.flush()
        if pacman.package_manager == 'apt-get':
            packages = [
                'python3', 'python3-pip', 'python3-dev', 'nodejs', 'npm'
            ]
        elif pacman.package_manager == 'yum':
            pacman.install_packages(['curl', 'gcc-c++', 'make'])
            p = subprocess.Popen(
                'curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -',
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                shell=True,
                close_fds=True)
            p.communicate()
            if p.returncode != 0:
                sys.stderr.write('[-] Could not install nodejs source rpm.\n')
                return False
            packages = ['nodejs', 'python36', 'python36-devel']
            pacman.install_packages(packages)
        if packages:
            pacman.install_packages(packages)
        else:
            sys.stderr.write(
                '[-] A valid package manager could not be found. Currently supports only YUM '
                'and apt-get.\n')
            return False
        if stdout:
            sys.stdout.write(
                '[+] Installing configurable-http-proxy. This may take some time.\n'
            )
            sys.stdout.flush()
        p = subprocess.Popen('npm install -g configurable-http-proxy',
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             shell=True)
        p.communicate()
        if p.returncode != 0:
            sys.stderr.write(
                '[-] Failed to install configurable-http-proxy, ensure npm is installed and in $PATH: {}\n'
                ''.format(p.stderr.read()))
            return False
        return True
Esempio n. 2
0
    def install_dependencies(verbose=False):
        """
        Install the required dependencies required by Suricata

        :return: True, if all packages installed successfully
        """
        pacman = package_manager.OSPackageManager(verbose=verbose)
        if not pacman.refresh_package_indexes():
            return False
        packages = None
        if pacman.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'
            ]
        elif pacman.package_manager == 'yum':
            packages = [
                'cmake', 'make', 'gcc', 'gcc-c++', 'flex', 'bison', 'libtool',
                'automake', 'pkgconfig', 'pcre-devel', 'libpcap-devel',
                'libyaml-devel', 'jansson-devel', 'rustc', 'cargo',
                'python-pip', 'wireshark', 'zlib-devel', 'libcap-ng-devel',
                'nspr-devel', 'nss-devel', 'file-devel', 'lz4-devel'
            ]
        if packages:
            return pacman.install_packages(packages)
        return False
Esempio n. 3
0
    def install_dependencies(stdout=False, verbose=False):
        """
        Install required PF_RING dependencies

        :param stdout: Print the output to console
        :param verbose: Include output from system utilities
        :return: True, if packages were successfully installed
        """
        pkt_mng = package_manager.OSPackageManager(verbose=verbose)
        if stdout:
            sys.stdout.write('[+] Updating Package Indexes.\n')
            sys.stdout.flush()
        pkt_mng.refresh_package_indexes()
        packages = None
        if stdout:
            sys.stdout.write('[+] Installing dependencies.\n')
            sys.stdout.flush()
        if pkt_mng.package_manager == 'apt-get':
            packages = ['make', 'gcc', 'linux-headers-generic']
        elif pkt_mng.package_manager == 'yum':
            packages = ['make', 'gcc', 'kernel-devel-$(uname -r)']
        if packages:
            return pkt_mng.install_packages(packages)
        else:
            sys.stderr.write(
                '[-] A valid package manager could not be found. Currently supports only YUM '
                'and apt-get.\n')
            return False
Esempio n. 4
0
    def install_dependencies(self, apt_get_packages: Optional[List] = None, yum_packages: Optional[List] = None,
                             pre_install_function: Optional[Callable] = None) -> None:
        """
        Install OS dependencies through the package manager

        Args:
            apt_get_packages: The name of the packages available in apt-get supported repos
            yum_packages: The name of the packages available in yum supported repos
            pre_install_function: A Python function to run prior to installing these packages

        Returns:
            None
        """
        pacman = package_manager.OSPackageManager(stdout=self.stdout, verbose=self.verbose)
        packages = []
        if pacman.package_manager == 'apt-get':
            self.logger.info('apt-get detected. We will use this package manager to install dependencies.')
            packages = apt_get_packages
        elif pacman.package_manager == 'yum':
            self.logger.info('yum detected. We will use this package manager to install dependencies.')
            packages = yum_packages
        self.logger.info('Refreshing package indexes')
        if pre_install_function:
            self.logger.info('Running pre-installation function.')
            pre_install_function(pacman.package_manager)
        pacman.refresh_package_indexes()

        self.logger.debug(f'Packages: {packages}')
        if packages:
            self.logger.info(f'Installing {len(packages)} new packages.')
            pacman.install_packages(packages)
Esempio n. 5
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))
Esempio n. 6
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))
Esempio n. 7
0
    def install_dependencies():
        """
        Install required PF_RING dependencies

        :return: True, if packages were successfully installed
        """
        pkt_mng = package_manager.OSPackageManager()
        if not pkt_mng.refresh_package_indexes():
            return False
        packages = None
        if pkt_mng.package_manager == 'apt-get':
            packages = ['make', 'gcc', 'linux-headers-generic']
        elif pkt_mng.package_manager == 'yum':
            packages = ['make', 'gcc', 'kernel-devel-$(uname -r)']
        if packages:
            return pkt_mng.install_packages(packages)
        return False
Esempio n. 8
0
 def setup_kibana(self):
     """
     Create required directories, files, and variables to run ElasticSearch successfully;
     """
     try:
         pacman = package_manager.OSPackageManager(stdout=self.stdout, verbose=self.verbose)
     except general_exceptions.InvalidOsPackageManagerDetectedError:
         self.logger.error("No valid OS package manager detected.")
         raise kibana_exceptions.InstallKibanaError("No valid OS package manager detected.")
     try:
         pacman.refresh_package_indexes()
         pacman.install_packages(['curl'])
     except (general_exceptions.OsPackageManagerInstallError, general_exceptions.OsPackageManagerRefreshError):
         self.logger.error("Failed to install one or more packages; {}".format(["curl"]))
         raise kibana_exceptions.InstallKibanaError("Failed to install one or more packages; {}".format(["curl"]))
     self._create_kibana_directories()
     self._copy_kibana_files_and_directories()
     self._create_kibana_environment_variables()
     self._setup_default_kibana_configs()
     try:
         utilities.set_ownership_of_file(self.configuration_directory, user='******', group='dynamite')
         utilities.set_ownership_of_file(self.install_directory, user='******', group='dynamite')
         utilities.set_ownership_of_file(self.log_directory, user='******', group='dynamite')
     except Exception as e:
         self.logger.error("General error occurred while attempting to set permissions on root directories.")
         self.logger.debug(
             "General error occurred while attempting to set permissions on root directories; {}".format(e))
         raise kibana_exceptions.InstallKibanaError(
             "General error occurred while attempting to set permissions on root directories; {}".format(e))
     try:
         sysctl = systemctl.SystemCtl()
     except general_exceptions.CallProcessError:
         raise kibana_exceptions.InstallKibanaError("Could not find systemctl.")
     self.logger.info("Installing Kibana systemd Service.")
     if not sysctl.install_and_enable(os.path.join(const.DEFAULT_CONFIGS, 'systemd', 'kibana.service')):
         raise kibana_exceptions.InstallKibanaError("Failed to install Kibana systemd service.")
     self._install_kibana_objects()
Esempio n. 9
0
    def install_dependencies():
        """
        Install the required dependencies required by Zeek

        :return: True, if all packages installed successfully
        """
        pacman = package_manager.OSPackageManager()
        if not pacman.refresh_package_indexes():
            return False
        packages = None
        if pacman.package_manager == 'apt-get':
            packages = [
                'cmake', 'make', 'gcc', 'g++', 'flex', 'bison', 'libpcap-dev',
                'libssl-dev', 'python-dev', 'swig', 'zlib1g-dev'
            ]
        elif pacman.package_manager == 'yum':
            packages = [
                'cmake', 'make', 'gcc', 'gcc-c++', 'flex', 'bison',
                'libpcap-devel', 'openssl-devel', 'python-devel', 'swig',
                'zlib-devel'
            ]
        if packages:
            return pacman.install_packages(packages)
        return False
Esempio n. 10
0
    def install_dependencies(stdout=True, verbose=False):
        """
        Install the required dependencies required by Jupyterhub

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

        log_level = logging.INFO
        if verbose:
            log_level = logging.DEBUG
        logger = get_logger('LAB', level=log_level, stdout=stdout)

        pkt_mng = package_manager.OSPackageManager(stdout=stdout,
                                                   verbose=verbose)
        packages = None
        logger.info('Updating Package Indexes.')
        pkt_mng.refresh_package_indexes()
        logger.info('Installing dependencies.')
        if pkt_mng.package_manager == 'apt-get':
            packages = [
                'build-essential', 'python3', 'python3-pip', 'python3-dev',
                'nodejs', 'npm'
            ]
        elif pkt_mng.package_manager == 'yum':
            p = subprocess.Popen(
                'curl --silent --location https://rpm.nodesource.com/setup_10.x | sudo bash -',
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                shell=True,
                close_fds=True)
            p.communicate()
            if p.returncode != 0:
                logger.error('Could not install nodejs source rpm.')
                raise general_exceptions.OsPackageManagerInstallError(
                    "Could not install nodejs from third-party RPM; https://rpm.nodesource.com/setup_10.x"
                )
            packages = [
                'gcc72-c++', 'gcc', 'gcc-c++', 'nodejs', 'python36',
                'python36-devel'
            ]
        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))
        logger.info(
            'Installing configurable-http-proxy. This may take some time.')
        p = subprocess.Popen('npm install -g configurable-http-proxy',
                             stdout=subprocess.PIPE,
                             stderr=subprocess.PIPE,
                             shell=True)
        p.communicate()
        if p.returncode != 0:
            try:
                err_msg = p.stderr.read()
            except ValueError:
                err_msg = p.returncode
            logger.error(
                'Failed to install configurable-http-proxy, ensure npm is installed and in $PATH: {}'
                ''.format(err_msg))
            raise general_exceptions.OsPackageManagerInstallError(
                "Could not install configurable-http-proxy via npm; {}".format(
                    err_msg))