<commit_before># -*- coding: utf-8 -*-
"""
The source provides a JSON file with a dictionary. The keys of this dict are
identifiers and the values are lists of domains.
"""
import json

from intelmq.lib import utils
from intelmq.lib.bot import Bot

__all__ = ['FraunhoferDGAParserBot']


class FraunhoferDGAParserBot(Bot):

    def process(self):
        report = self.receive_message()
        dict_report = json.loads(utils.base64_decode(report.get("raw")))

        for key in dict_report:
            malware_name = key.split('_')[0]
            for row in dict_report[key]:
                event = self.new_event(report)
                event.add('classification.type', 'c&c')
                event.add('malware.name', malware_name)
                if not event.add('source.ip', row, raise_failure=False):
                    event.add('source.fqdn', row)
                event.add("raw", row)
                self.send_message(event)

        self.acknowledge_message()<commit_msg>DOC: fraunhofer dga: note on malware names<commit_after># -*- coding: utf-8 -*-
"""
The source provides a JSON file with a dictionary. The keys of this dict are
identifiers and the values are lists of domains.

The first part of the identifiers, before the first underscore, can be treated
as malware name. The feed provider commited to retain this schema.

An overview of all names can be found here:
https://dgarchive.caad.fkie.fraunhofer.de/pcres
"""
import json

from intelmq.lib import utils
from intelmq.lib.bot import Bot

__all__ = ['FraunhoferDGAParserBot']


class FraunhoferDGAParserBot(Bot):

    def process(self):
        report = self.receive_message()
        dict_report = json.loads(utils.base64_decode(report.get("raw")))

        for key in dict_report:
            malware_name = key.split('_')[0]
            for row in dict_report[key]:
                event = self.new_event(report)
                event.add('classification.type', 'c&c')
                event.add('malware.name', malware_name)
                if not event.add('source.ip', row, raise_failure=False):
                    event.add('source.fqdn', row)
                event.add("raw", row)
                self.send_message(event)

        self.acknowledge_message()
{'fraction_non_alphanumeric': 0.10655372269282211, 'fraction_numerical': 0.0035666518056174765, 'mean_word_length': 2.5394321766561516, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1878353', 'n_tokens_mistral': 691, 'n_tokens_neox': 648, 'n_words': 185}