# Output backends for sigmac
# Copyright 2016-2018 Thomas Patzke, Florian Roth, Roey
# 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 .
import re
import sigma
from .base import SingleTextQueryBackend
from .mixins import MultiRuleOutputMixin
class SplunkBackend(SingleTextQueryBackend):
"""Converts Sigma rule into Splunk Search Processing Language (SPL)."""
identifier = "splunk"
active = True
index_field = "index"
# \ -> \\
# \* -> \*
# \\* -> \\*
reEscape = re.compile('("|(?"
panel_inf = "
"
queries = dash_pre
reEscape = re.compile('("|(?", ">")
self.queries += query
self.queries += self.panel_suf
def finalize(self):
self.queries += self.dash_suf
return self.queries
class CrowdStrikeBackend(SplunkBackend):
"""Converts Sigma rule into CrowdStrike Search Processing Language (SPL)."""
identifier = "crowdstrike"
def generate(self, sigmaparser):
lgs = sigmaparser.parsedyaml.get("logsource")
if lgs.get("product") == "windows" and (lgs.get("service") == "sysmon" or lgs.get("category") == "process_creation" or lgs.get("service") == "security"):
fieldmappings = sigmaparser.config.fieldmappings
detections = sigmaparser.definitions
all_fields = dict()
for det in detections.values():
try:
for field, value in det.items():
if "|" in field:
field = field.split("|")[0]
if any([item for item in fieldmappings.keys() if field == item]):
if field == "EventID" and str(value) == str(1) and lgs.get("service") == "sysmon":
all_fields.update(det)
elif field != "EventID":
all_fields.update(det)
else:
raise NotImplementedError("Not supported fields!")
else:
raise NotImplementedError("Not supported fields!")
except AttributeError: # ignore if detection is not a dict
pass
table_fields = sigmaparser.parsedyaml.get("fields", [])
res_table_fields = []
for fl in table_fields:
if fl in fieldmappings.keys():
res_table_fields.append(fl)
sigmaparser.parsedyaml["fields"] = res_table_fields
return super().generate(sigmaparser)
else:
raise NotImplementedError("Not supported logsources!")
def generateMapItemTypedNode(self, fieldname, value):
return super().generateMapItemTypedNode(fieldname=fieldname, value=value)