Esempio n. 1
0
def main(distribution):

    # dependencies
    if distribution == 'fedora':
        dnf_install_packages('libjpeg-devel', 'openssl-devel',
                             'python3-tkinter')
    else:
        apt_install_packages('libjpeg-dev', 'libssl-dev', 'python3-tk')

    pip3_install_packages('pluginbase', 'Pillow', 'cryptography', 'pyopenssl',
                          'matplotlib', 'docker', 'networkx')

    # install yara
    _install_yara(distribution)

    # install checksec.sh
    _install_checksec(distribution)

    # build extraction docker container
    logging.info('Building fact extraction container')

    output, return_code = execute_shell_command_get_return_code(
        'docker pull fkiecad/fact_extractor')
    if return_code != 0:
        raise InstallationError(
            f'Failed to pull extraction container:\n{output}')

    # installing common code modules
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_yara.git')
    pip3_install_packages(
        'git+https://github.com/mass-project/common_analysis_base.git')

    # install plug-in dependencies
    _install_plugins(distribution)

    # configure environment
    _edit_environment()

    # create directories
    _create_firmware_directory()

    # compiling yara signatures
    compile_signatures()
    _, yarac_return = execute_shell_command_get_return_code(
        'yarac -d test_flag=false ../test/unit/analysis/test.yara ../analysis/signatures/Yara_Base_Plugin.yc'
    )
    if yarac_return != 0:
        raise InstallationError('Failed to compile yara test signatures')

    with OperateInDirectory('../../'):
        with suppress(FileNotFoundError):
            Path('start_fact_backend').unlink()
        Path('start_fact_backend').symlink_to('src/start_fact_backend.py')

    return 0
Esempio n. 2
0
def main(skip_docker, distribution):
    apt_packages_path = INSTALL_DIR / 'apt-pkgs-backend.txt'
    dnf_packages_path = INSTALL_DIR / 'dnf-pkgs-backend.txt'

    if distribution != 'fedora':
        pkgs = read_package_list_from_file(apt_packages_path)
        apt_install_packages(*pkgs)
    else:
        pkgs = read_package_list_from_file(dnf_packages_path)
        dnf_install_packages(*pkgs)

    install_pip_packages(PIP_DEPENDENCIES)

    # install yara
    _install_yara()

    _install_checksec()

    if not skip_docker:
        _install_docker_images()

    # install plug-in dependencies
    _install_plugins(distribution, skip_docker)

    # configure environment
    _edit_environment()

    # create directories
    _create_firmware_directory()

    # compiling yara signatures
    compile_signatures()
    _, yarac_return = execute_shell_command_get_return_code('yarac -d test_flag=false ../test/unit/analysis/test.yara ../analysis/signatures/Yara_Base_Plugin.yc')
    if yarac_return != 0:
        raise InstallationError('Failed to compile yara test signatures')

    with OperateInDirectory('../../'):
        with suppress(FileNotFoundError):
            Path('start_fact_backend').unlink()
        Path('start_fact_backend').symlink_to('src/start_fact_backend.py')

    return 0
Esempio n. 3
0
def _install_nginx(distribution):
    if distribution != 'fedora':
        apt_install_packages('nginx')
    else:
        dnf_install_packages('nginx')
    _generate_and_install_certificate()
    _configure_nginx()
    if distribution == 'fedora':
        execute_commands_and_raise_on_return_code([
            'sudo restorecon -v /etc/nginx/fact.*',
            'sudo semanage fcontext -at httpd_log_t "/var/log/fact(/.*)?" || true',
            'sudo restorecon -v -R /var/log/fact'
        ],
                                                  error=
                                                  'restore selinux context')
    nginx_output, nginx_code = execute_shell_command_get_return_code(
        'sudo nginx -s reload')
    if nginx_code != 0:
        raise InstallationError(
            'Failed to start nginx\n{}'.format(nginx_output))
Esempio n. 4
0
def main(distribution):  # pylint: disable=too-many-statements
    _update_package_sources(distribution)
    _update_submodules()

    BIN_DIR.mkdir(exist_ok=True)

    apt_packages_path = INSTALL_DIR / 'apt-pkgs-common.txt'
    dnf_packages_path = INSTALL_DIR / 'dnf-pkgs-common.txt'

    if distribution != 'fedora':
        pkgs = read_package_list_from_file(apt_packages_path)
        apt_install_packages(*pkgs)
    else:
        pkgs = read_package_list_from_file(dnf_packages_path)
        dnf_install_packages(*pkgs)

    if not is_virtualenv():
        install_pip()
    elif distribution != 'fedora':
        run_cmd_with_logging('pip install -U pip setuptools wheel')
    else:
        # on fedora, extra setuptools will break some system tools like selinux ones
        run_cmd_with_logging('pip install -U pip wheel')
    install_pip_packages(PIP_DEPENDENCIES)

    # VarietyJS (is executed by update_statistic.py)
    if (BIN_DIR / 'spec').exists():
        logging.warning('variety spec not overwritten')
    else:
        install_github_project('variety/variety', [
            'git checkout 2f4d815', 'mv -f variety.js ../../bin/',
            'mv -f spec ../../bin/'
        ])

    with OperateInDirectory('../../'):
        with suppress(FileNotFoundError):
            Path('start_all_installed_fact_components').unlink()
        Path('start_all_installed_fact_components').symlink_to(
            'src/start_fact.py')

    return 0
Esempio n. 5
0
def main(distribution):
    logging.info('Setting up mongo database')

    if distribution in ['xenial', 'debian']:
        _add_mongo_mirror(distribution)
        apt_update_sources()
        apt_install_packages('mongodb-org')
    elif distribution in ['fedora']:
        dnf_install_packages('mongodb-org-3.6.8')
    else:
        apt_install_packages('mongodb')

    # creating DB directory
    fact_db_directory = _get_db_directory()
    mkdir_output, _ = execute_shell_command_get_return_code(
        'sudo mkdir -p --mode=0744 {}'.format(fact_db_directory))
    chown_output, chown_code = execute_shell_command_get_return_code(
        'sudo chown {}:{} {}'.format(os.getuid(), os.getgid(),
                                     fact_db_directory))
    if chown_code != 0:
        raise InstallationError(
            'Failed to set up database directory. Check if parent folder exists\n{}'
            .format('\n'.join((mkdir_output, chown_output))))

    # initializing DB authentication
    logging.info('Initialize database')
    with OperateInDirectory('..'):
        init_output, init_code = execute_shell_command_get_return_code(
            'python3 init_database.py')
    if init_code != 0:
        raise InstallationError(
            'Unable to initialize database\n{}'.format(init_output))

    with OperateInDirectory('../../'):
        with suppress(FileNotFoundError):
            Path('start_fact_db').unlink()
        Path('start_fact_db').symlink_to('src/start_fact_db.py')

    return 0
Esempio n. 6
0
def main(distribution):  # pylint: disable=too-many-statements

    if distribution == 'fedora':
        logging.info('Updating system')
        dnf_update_sources()
    else:
        apt_install_packages('apt-transport-https')
        logging.info('Updating system')
        apt_update_sources()

    _, is_repository = execute_shell_command_get_return_code('git status')
    if is_repository == 0:
        # update submodules
        git_output, git_code = execute_shell_command_get_return_code(
            '(cd ../../ && git submodule foreach "git pull")')
        if git_code != 0:
            raise InstallationError(
                'Failed to update submodules\n{}'.format(git_output))
    else:
        logging.warning(
            'FACT is not set up using git. Note that *adding submodules* won\'t work!!'
        )

    # make bin dir
    BIN_DIR.mkdir(exist_ok=True)

    if distribution == 'fedora':
        dnf_install_packages('python3')
        dnf_install_packages('python3-devel')
        # build-essential not available on fedora, getting equivalent
        dnf_install_packages('gcc')
        dnf_install_packages('gcc-c++')
        dnf_install_packages('make')
        dnf_install_packages('automake')
        dnf_install_packages('kernel-devel')
        dnf_install_packages('autoconf')
        dnf_install_packages('libtool')
        dnf_install_packages('git')
        dnf_install_packages('unzip')
    else:
        # install python3 and general build stuff
        apt_install_packages('python3', 'python3-dev', 'build-essential',
                             'automake', 'autoconf', 'libtool', 'git', 'unzip')
        if not distribution == 'xenial':
            pip3_install_packages('testresources')

    if distribution == 'fedora':
        dnf_remove_packages('python3-pip', 'python3-setuptools',
                            'python3-wheel')
    else:
        # get a bug free recent pip version
        apt_remove_packages('python3-pip', 'python3-setuptools',
                            'python3-wheel')

    install_pip('python3')
    pip3_install_packages('setuptools==49.6.0')

    if distribution != 'fedora':
        # install python2
        apt_install_packages('python', 'python-dev')
        with suppress(InstallationError):
            apt_remove_packages('python-pip')
        install_pip('python2')

    if distribution == 'fedora':
        dnf_install_packages('file-devel')
        dnf_install_packages('libffi-devel')
        dnf_install_packages('python3-tlsh')
        dnf_install_packages('python3-ssdeep')
    else:
        # install general python dependencies
        apt_install_packages('libmagic-dev')
        apt_install_packages('libfuzzy-dev')
        apt_install_packages('python3-tlsh')
        pip3_install_packages('ssdeep')

    pip3_install_packages(
        'git+https://github.com/fkie-cad/fact_helper_file.git')
    pip3_install_packages('psutil')
    pip3_install_packages('pytest==6.1.2', 'pytest-cov', 'pylint',
                          'python-magic', 'xmltodict', 'yara-python==3.7.0',
                          'appdirs')

    pip3_install_packages(
        'lief==0.10.1')  # FIXME: unpin version when install bug is fixed

    pip3_install_packages('requests')

    # install python MongoDB bindings
    pip3_install_packages('pymongo', 'pyyaml')

    # VarietyJS (is executed by update_statistic.py)
    if (BIN_DIR / 'spec').exists():
        logging.warning('variety spec not overwritten')
    else:
        install_github_project('variety/variety', [
            'git checkout 2f4d815', 'mv -f variety.js ../../bin',
            'mv -f spec ../../bin'
        ])

    #  installing common code modules
    pip3_install_packages('hurry.filesize')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_files.git')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_mongo.git')
    pip3_install_packages(
        'git+https://github.com/mass-project/common_helper_encoder.git')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_filter.git')
    pip3_install_packages(
        'git+https://github.com/fkie-cad/common_helper_process.git')

    with OperateInDirectory('../../'):
        with suppress(FileNotFoundError):
            Path('start_all_installed_fact_components').unlink()
        Path('start_all_installed_fact_components').symlink_to(
            'src/start_fact.py')

    return 0