Beispiel #1
0
    def repository_new(self):
        """Add a repository

        .. :quickref: Module; Add repository

        Requires the `manage_modules` permission.

        If successful, will return the repository in ``repository``.
        Otherwise, errors will be available in ``errors``.

        :form name: name of the repository (should be a valid package name).
        :form address: HTTPs or SSH address of the repository.
        :form private: boolean specifying if the repository is private. See
            Administration Guide for more details on private repositories.
        """
        deploy_key = get_deploy_key()
        repository = Repository()

        if request.method == 'POST':
            for field in ['name', 'address']:
                repository[field] = request.form.get(field)
                if repository[field] is None or repository[field] == "":
                    flash("{} is required.".format(field), 'danger')
                    return validation_error()

                existing_repository = Repository.get(
                    **{field: repository[field]})
                if existing_repository:
                    flash(
                        "There is already a repository with this {}.".format(
                            field), 'danger')
                    return validation_error()

            value = request.form.get('private')
            repository['private'] = (value is not None) and (value not in [
                '0', 'False'
            ])

            if repository['private'] and deploy_key is None:
                flash(
                    "Private repositories are disabled because of a problem with your installation (you do not have a deploy key in 'conf/id_rsa.pub')",
                    'danger')
                return validation_error()

            repository['status'] = 'cloning'
            repository.save()
            repository.clone()
            return redirect({'repository': clean_repositories(repository)},
                            url_for('ModulesView:index'))

        return render({
            'repository': repository,
            'deploy_key': deploy_key
        }, 'modules/repository_new.html')
Beispiel #2
0
    def repository_update(self, id):
        """Update a repository

        .. :quickref: Module; Update repository

        Requires the `manage_modules` permission.

        :param id: id of the repository.

        :>json Repository repository: the repository.
        """
        repository = Repository(get_or_404(Repository.get_collection(),
                                           _id=id))
        repository.pull()

        return redirect({'repository': clean_repositories(repository)},
                        url_for('ModulesView:index'))
Beispiel #3
0
    def index(self):
        """Get the list of modules.

        .. :quickref: Module; Get the list of modules

        Requires the `manage_modules` permission.

        The response is a dict with several elements:

        * ``modules``, which is a list of modules, sorted by type::

            "modules": {
                "Antivirus": [
                    ...
                ],
                "Preloading": [
                    ...
                ],
                "Processing": [
                    {
                        "_id": {
                            "$oid": "MODULE_ID"
                        },
                        "acts_on": [
                            ACTS_ON_FAME_TYPES
                        ],
                        "class": "CLASS_NAME",
                        "config": [ CONFIG_OPTIONS ],
                        "description": "DESCRIPTION",
                        "enabled": false,
                        "generates": [GENERATES],
                        "name": "NAME",
                        "path": "MODULE_PATH",
                        "queue": "QUEUE",
                        "triggered_by": [
                            TRIGGERS
                        ],
                        "type": "Processing"
                    },
                    ...
                ],
                "Reporting": [
                    ...
                ],
                "Threat Intelligence": [
                    ...
                ],
                "Filetype": [
                    ...
                ]
            }

        * ``repositories``: list of configured repositories::

            "repositories": [
                {
                    "_id": {
                        "$oid": "ID"
                    },
                    "address": "[email protected]:certsocietegenerale/fame_modules.git",
                    "name": "community",
                    "private": false,
                    "status": "active"
                },
                ...
            ]

        * ``configs``: list of named configurations::

            "configs": [
                {
                    "_id": {
                        "$oid": "ID"
                    },
                    "config": [
                        {
                            "description": "List of patterns (strings) to look for in malware configurations. There should be one pattern per line.",
                            "name": "monitor",
                            "type": "text",
                            "value": null
                        }
                    ],
                    "description": "Needed in order to be able to track malware targets",
                    "name": "malware_config"
                },
                ...
            ]
        """
        types = {
            'Preloading': [],
            'Processing': [],
            'Reporting': [],
            'Threat Intelligence': [],
            'Antivirus': [],
            'Virtualization': [],
            'Filetype': []
        }

        for module in ModuleInfo.get_collection().find():
            types[module['type']].append(clean_modules(module))

        for type in types:
            types[type] = sorted(types[type], key=get_name)

        configs = Config.get_collection().find()

        repositories = clean_repositories(
            list(Repository.get_collection().find()))

        return render(
            {
                'modules': types,
                'configs': configs,
                'repositories': repositories
            }, 'modules/index.html')