Skip to content

Commit a62078a

Browse files
committed
add: Experimental expansion module to display the SIEM signatures from a sigma rule
1 parent 90e42c0 commit a62078a

File tree

3 files changed

+52
-1
lines changed

3 files changed

+52
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ For more information: [Extending MISP with Python modules](https://www.circl.lu/
3838
* [rbl](misp_modules/modules/expansion/rbl.py) - a module to get RBL (Real-Time Blackhost List) values from an attribute.
3939
* [reversedns](misp_modules/modules/expansion/reversedns.py) - Simple Reverse DNS expansion service to resolve reverse DNS from MISP attributes.
4040
* [shodan](misp_modules/modules/expansion/shodan.py) - a minimal [shodan](https://www.shodan.io/) expansion module.
41+
* [Sigma queries](misp_modules/modules/expansion/sigma_queries.py) - Experimental expansion module querying a sigma rule to convert it into all the available SIEM signatures.
4142
* [Sigma syntax validator](misp_modules/modules/expansion/sigma_syntax_validator.py) - Sigma syntax validator.
4243
* [sourcecache](misp_modules/modules/expansion/sourcecache.py) - a module to cache a specific link from a MISP instance.
4344
* [STIX2 pattern syntax validator](misp_modules/modules/expansion/stix2_pattern_syntax_validator.py) - a module to check a STIX2 pattern syntax.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
from . import _vmray
22

3-
__all__ = ['vmray_submit', 'asn_history', 'circl_passivedns', 'circl_passivessl', 'countrycode', 'cve', 'dns', 'domaintools', 'eupi', 'farsight_passivedns', 'ipasn', 'passivetotal', 'sourcecache', 'virustotal', 'whois', 'shodan', 'reversedns', 'geoip_country', 'wiki', 'iprep', 'threatminer', 'otx', 'threatcrowd', 'vulndb', 'crowdstrike_falcon', 'yara_syntax_validator', 'hashdd', 'onyphe', 'onyphe_full', 'rbl', 'xforceexchange', 'sigma_syntax_validator', 'stix2_pattern_syntax_validator']
3+
__all__ = ['vmray_submit', 'asn_history', 'circl_passivedns', 'circl_passivessl', 'countrycode', 'cve', 'dns', 'domaintools', 'eupi', 'farsight_passivedns', 'ipasn', 'passivetotal', 'sourcecache', 'virustotal', 'whois', 'shodan', 'reversedns', 'geoip_country', 'wiki', 'iprep', 'threatminer', 'otx', 'threatcrowd', 'vulndb', 'crowdstrike_falcon', 'yara_syntax_validator', 'hashdd', 'onyphe', 'onyphe_full', 'rbl', 'xforceexchange', 'sigma_syntax_validator', 'stix2_pattern_syntax_validator', 'sigma_queries']
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import sys, os, io, json
2+
try:
3+
from sigma.parser import SigmaCollectionParser
4+
from sigma.config import SigmaConfiguration
5+
from sigma.backends import getBackend, BackendOptions
6+
except ModuleNotFoundError:
7+
print("sigma or yaml is missing, use 'pip3 install sigmatools' to install it.")
8+
9+
misperrors = {'error': 'Error'}
10+
mispattributes = {'input': ['sigma'], 'output': ['text']}
11+
moduleinfo = {'version': '0.1', 'author': 'Christian Studer', 'module-type': ['expansion', 'hover'],
12+
'description': 'An expansion hover module to display the result of sigma queries.'}
13+
moduleconfig = []
14+
sigma_targets = ('es-dsl', 'es-qs', 'graylog', 'kibana', 'xpack-watcher', 'logpoint', 'splunk', 'grep', 'wdatp', 'splunkxml', 'arcsight', 'qualys')
15+
16+
def handler(q=False):
17+
if q is False:
18+
return False
19+
request = json.loads(q)
20+
if not request.get('sigma'):
21+
misperrors['error'] = 'Sigma rule missing'
22+
return misperrors
23+
config = SigmaConfiguration()
24+
backend_options = BackendOptions(None)
25+
f = io.TextIOWrapper(io.BytesIO(request.get('sigma').encode()), encoding='utf-8')
26+
parser = SigmaCollectionParser(f, config, None)
27+
targets = []
28+
old_stdout = sys.stdout
29+
result = io.StringIO()
30+
sys.stdout = result
31+
for t in sigma_targets:
32+
backend = getBackend(t)(config, backend_options, None)
33+
try:
34+
parser.generate(backend)
35+
backend.finalize()
36+
print("#NEXT")
37+
targets.append(t)
38+
except:
39+
continue
40+
sys.stdout = old_stdout
41+
results = result.getvalue()[:-5].split('#NEXT')
42+
d_result = {t: r.strip() for t,r in zip(targets, results)}
43+
return {'results': [{'types': mispattributes['output'], 'values': d_result}]}
44+
45+
def introspection():
46+
return mispattributes
47+
48+
def version():
49+
moduleinfo['config'] = moduleconfig
50+
return moduleinfo

0 commit comments

Comments
 (0)