Files
blue-team-tools/tools/sigma/backends/ee-outliers.py
T

77 lines
2.4 KiB
Python
Raw Normal View History

2020-05-08 10:04:59 +02:00
# ee-outliers backend for sigmac
2020-05-11 11:47:56 +02:00
# NVISO (@NVISO_Labs)
2020-05-08 10:04:59 +02:00
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from .elasticsearch import ElasticsearchDSLBackend
import json
import logging
import configparser
2020-05-08 11:40:16 +02:00
from .mixins import MultiRuleOutputMixin
2020-05-08 10:04:59 +02:00
from io import StringIO
2020-05-08 11:40:16 +02:00
class OutliersBackend(ElasticsearchDSLBackend, MultiRuleOutputMixin):
2020-05-08 10:04:59 +02:00
"""ee-outliers backend"""
identifier = 'ee-outliers'
active = True
def generate(self, sigmaparser):
super().generate(sigmaparser)
self.tags = sigmaparser.parsedyaml.setdefault("tags", "")
if len(self.queries) == 1:
dsl = json.dumps(self.queries[0])
else:
dsl = json.dumps(self.queries)
self.queries = []
2020-05-08 11:40:16 +02:00
use_case_name = self.getRuleName(sigmaparser)
2020-05-08 10:04:59 +02:00
index = ''
if self.indices is not None and len(self.indices) == 1:
index = self.indices[0]
types = ["Sigma hit"]
types.extend(self.tags)
config_data = {
"es_dsl_filter": dsl,
"es_index": index,
"outlier_type": ", ".join(types),
"outlier_reason": "Sigma hit - " + self.title,
"outlier_summary": "Sigma hit - " + self.title,
"run_model": 1,
"test_model": 0
}
config = configparser.ConfigParser(interpolation=None)
2020-05-08 11:40:16 +02:00
config["simplequery_sigma_" + use_case_name] = config_data
2020-05-08 10:04:59 +02:00
output = StringIO()
config.write(output)
result = output.getvalue()
output.close()
return result
2020-05-08 11:40:16 +02:00
def finalize(self):
"""
Is called after the last file was processed with generate(). The right place if this backend is not intended to
look isolated at each rule, but generates an output which incorporates multiple rules, e.g. dashboards.
"""
pass