From 6312f381bfb8c8661b2b6aba70742fe58fb1ca15 Mon Sep 17 00:00:00 2001 From: Danijel Grah <1746112+alm8i@users.noreply.github.com> Date: Fri, 10 Apr 2020 16:12:05 +0200 Subject: [PATCH 1/2] C# backend Converts Sigma rule into C# Regex in LINQ query --- tools/sigma/backends/csharp.py | 163 +++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 tools/sigma/backends/csharp.py diff --git a/tools/sigma/backends/csharp.py b/tools/sigma/backends/csharp.py new file mode 100644 index 000000000..8d827a36d --- /dev/null +++ b/tools/sigma/backends/csharp.py @@ -0,0 +1,163 @@ +# Output backends for sigmac +# Copyright 2020 Danijel Grah (dgrah@nil.com) + +# 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 . + +# How to use it in your CSharp program: +# public Dictionary sigmas = new Dictionary(); +# sigmas["rules/windows/process_creation/win_cmdkey_recon.yml"] = from x in evnt where (x.Key == "1" .... + +import re +import sigma +from .base import SingleTextQueryBackend +from .mixins import MultiRuleOutputMixin + +class CSharpBackend(SingleTextQueryBackend): + """Converts Sigma rule into CSharp Regex in LINQ query.""" + identifier = "csharp" + active = True + config_required = False + default_config = ["sysmon"] + + + reEscape = re.compile('((? Date: Sat, 11 Apr 2020 15:47:23 +0200 Subject: [PATCH 2/2] comments for usage --- tools/sigma/backends/csharp.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/sigma/backends/csharp.py b/tools/sigma/backends/csharp.py index 8d827a36d..388b72ca9 100644 --- a/tools/sigma/backends/csharp.py +++ b/tools/sigma/backends/csharp.py @@ -14,9 +14,11 @@ # You should have received a copy of the GNU Lesser General Public License # along with this program. If not, see . -# How to use it in your CSharp program: +# How to use it in your CSharp program: # public Dictionary sigmas = new Dictionary(); -# sigmas["rules/windows/process_creation/win_cmdkey_recon.yml"] = from x in evnt where (x.Key == "1" .... +# Dictionary evnt = new Dictionary(); +# this.evnt.Add(Key, Value); +# sigmas["rules/windows/process_creation/win_cmdkey_recon.yml"] = THE OUTPUT OF csharp BACKEND import re import sigma