mirror of https://github.com/MISP/misp-modules
new: [expansion:jinja_template_rendering] Added new module to rendre a jinja template based on the provided data
parent
1c184040e6
commit
a6930be862
|
@ -18,7 +18,7 @@ __all__ = ['cuckoo_submit', 'vmray_submit', 'bgpranking', 'circl_passivedns', 'c
|
|||
'assemblyline_submit', 'assemblyline_query', 'ransomcoindb', 'malwarebazaar',
|
||||
'lastline_query', 'lastline_submit', 'sophoslabs_intelix', 'cytomic_orion', 'censys_enrich',
|
||||
'trustar_enrich', 'recordedfuture', 'html_to_markdown', 'socialscan', 'passive-ssh',
|
||||
'qintel_qsentry', 'mwdb', 'hashlookup', 'mmdb_lookup', 'ipqs_fraud_and_risk_scoring', 'clamav']
|
||||
'qintel_qsentry', 'mwdb', 'hashlookup', 'mmdb_lookup', 'ipqs_fraud_and_risk_scoring', 'clamav', 'jinja_template_rendering']
|
||||
|
||||
|
||||
minimum_required_fields = ('type', 'uuid', 'value')
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
#!/usr/bin/env python\
|
||||
|
||||
import json
|
||||
from jinja2.sandbox import SandboxedEnvironment
|
||||
|
||||
misperrors = {'error': 'Error'}
|
||||
mispattributes = {'input': ['text'], 'output': ['text']}
|
||||
moduleinfo = {'version': '0.1', 'author': 'Sami Mokaddem',
|
||||
'description': 'Render the template with the data passed',
|
||||
'module-type': ['expansion']}
|
||||
|
||||
default_template = '- Default template -'
|
||||
|
||||
def renderTemplate(data, template=default_template):
|
||||
env = SandboxedEnvironment()
|
||||
return env.from_string(template).render(data)
|
||||
|
||||
def handler(q=False):
|
||||
if q is False:
|
||||
return False
|
||||
request = json.loads(q)
|
||||
if request.get('text'):
|
||||
data = request['text']
|
||||
else:
|
||||
return False
|
||||
data = json.loads(data)
|
||||
template = data.get('template', default_template)
|
||||
templateData = data.get('data', {})
|
||||
try:
|
||||
rendered = renderTemplate(templateData, template)
|
||||
except TypeError:
|
||||
rendered = ''
|
||||
|
||||
r = {'results': [{'types': mispattributes['output'],
|
||||
'values':[rendered]}]}
|
||||
return r
|
||||
|
||||
|
||||
def introspection():
|
||||
return mispattributes
|
||||
|
||||
|
||||
def version():
|
||||
return moduleinfo
|
Loading…
Reference in New Issue