mirror of https://github.com/MISP/misp-modules
fix: Making yara query an expansion module for single attributes atm
parent
1d530a7fa6
commit
1c10fd5e50
|
@ -1,5 +1,5 @@
|
|||
import json
|
||||
import sys
|
||||
import re
|
||||
|
||||
misperrors = {'error': 'Error'}
|
||||
moduleinfo = {'version': '1', 'author': 'Christian STUDER',
|
||||
|
@ -7,10 +7,10 @@ moduleinfo = {'version': '1', 'author': 'Christian STUDER',
|
|||
'module-type': ['expansion', 'hover'],
|
||||
'require_standard_format': True}
|
||||
moduleconfig = []
|
||||
mispattributes = {'input': ['md5', 'sha1', 'sha256', 'filename|md5', 'filename|sha1', 'filename|sha256'], 'output': ['yara rule']}
|
||||
mispattributes = {'input': ['md5', 'sha1', 'sha256', 'filename|md5', 'filename|sha1', 'filename|sha256'], 'output': ['yara']}
|
||||
|
||||
def hash_cond(hashtype, hashvalue):
|
||||
condition = 'hash.{}(0, filesize) == {}'.format(hashtype, hashvalue.lower())
|
||||
def get_hash_condition(hashtype, hashvalue):
|
||||
condition = 'hash.{}(0, filesize) == "{}"'.format(hashtype, hashvalue.lower())
|
||||
return condition, 'hash'
|
||||
|
||||
def handler(q=False):
|
||||
|
@ -21,20 +21,16 @@ def handler(q=False):
|
|||
if 'event_id' in request:
|
||||
del request['event_id']
|
||||
uuid = request.pop('attribute_uuid') if 'attribute_uuid' in request else None
|
||||
rules = []
|
||||
types = []
|
||||
for attribute_type, value in request.items():
|
||||
if 'filename' in attribute_type:
|
||||
_, attribute_type = attribute_type.split('|')
|
||||
_, value = value.split('|')
|
||||
condition, required_module = hash_cond(attribute_type, value)
|
||||
condition = '\r\n\t\t'.join([condition])
|
||||
import_section = '\r\n'.join(['import "{}"'.format(required_module)])
|
||||
rule_start = 'rule %s {' % uuid if uuid else 'rule {'
|
||||
condition = '\tcondition:\r\n\t\t{}'.format(condition)
|
||||
rules.append('\r\n'.join([rule_start, condition, '}']))
|
||||
types.append('yara')
|
||||
return {'results': [{'types': [t], 'values': [v]} for t, v in zip(types, rules)]}
|
||||
attribute_type, value = list(request.items())[0]
|
||||
if 'filename' in attribute_type:
|
||||
_, attribute_type = attribute_type.split('|')
|
||||
_, value = value.split('|')
|
||||
condition, required_module = get_hash_condition(attribute_type, value)
|
||||
import_section = 'import "{}"'.format(required_module)
|
||||
rule_start = 'import "hash" \r\nrule %s_%s {' % (attribute_type.upper(), re.sub(r'\W+', '_', uuid)) if uuid else 'import "hash"\r\nrule %s {' % attribute_type.upper()
|
||||
condition = '\tcondition:\r\n\t\t{}'.format(condition)
|
||||
rule = '\r\n'.join([rule_start, condition, '}'])
|
||||
return {'results': [{'types': mispattributes['output'], 'values': [rule]}]}
|
||||
|
||||
def introspection():
|
||||
return mispattributes
|
||||
|
|
Loading…
Reference in New Issue