mirror of https://github.com/MISP/PyMISP
Update get_template_id, cleanup
parent
c09ce0032c
commit
f66af15c62
|
@ -24,17 +24,17 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
if seos:
|
if seos:
|
||||||
for s in seos:
|
for s in seos:
|
||||||
template_id = pymisp.get_object_template_id(s['name'])
|
template_id = pymisp.get_object_template_id(s.template_uuid)
|
||||||
r = pymisp.add_object(args.event, template_id, s)
|
r = pymisp.add_object(args.event, template_id, s)
|
||||||
|
|
||||||
if peo:
|
if peo:
|
||||||
template_id = pymisp.get_object_template_id(peo['name'])
|
template_id = pymisp.get_object_template_id(peo.template_uuid)
|
||||||
r = pymisp.add_object(args.event, template_id, peo)
|
r = pymisp.add_object(args.event, template_id, peo)
|
||||||
for ref in peo.references:
|
for ref in peo.references:
|
||||||
r = pymisp.add_object_reference(ref)
|
r = pymisp.add_object_reference(ref)
|
||||||
|
|
||||||
if fo:
|
if fo:
|
||||||
template_id = pymisp.get_object_template_id(fo['name'])
|
template_id = pymisp.get_object_template_id(fo.template_uuid)
|
||||||
response = pymisp.add_object(args.event, template_id, fo)
|
response = pymisp.add_object(args.event, template_id, fo)
|
||||||
for ref in fo.references:
|
for ref in fo.references:
|
||||||
r = pymisp.add_object_reference(ref)
|
r = pymisp.add_object_reference(ref)
|
||||||
|
|
|
@ -1600,12 +1600,12 @@ class PyMISP(object):
|
||||||
response = session.get(url)
|
response = session.get(url)
|
||||||
return self._check_response(response)['response']
|
return self._check_response(response)['response']
|
||||||
|
|
||||||
def get_object_template_id(self, object_name):
|
def get_object_template_id(self, object_uuid):
|
||||||
templates = self.get_object_templates_list()
|
templates = self.get_object_templates_list()
|
||||||
for t in templates:
|
for t in templates:
|
||||||
if t['ObjectTemplate']['name'] == object_name:
|
if t['ObjectTemplate']['uuid'] == object_uuid:
|
||||||
return t['ObjectTemplate']['id']
|
return t['ObjectTemplate']['id']
|
||||||
raise Exception('Unable to find template name {} on the MISP instance'.format(object_name))
|
raise Exception('Unable to find template uuid {} on the MISP instance'.format(object_uuid))
|
||||||
|
|
||||||
# ###########################
|
# ###########################
|
||||||
# ####### Deprecated ########
|
# ####### Deprecated ########
|
||||||
|
|
|
@ -41,7 +41,9 @@ class FileObject(MISPObjectGenerator):
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
else:
|
else:
|
||||||
raise Exception('File buffer (BytesIO) or a path is required.')
|
raise Exception('File buffer (BytesIO) or a path is required.')
|
||||||
MISPObjectGenerator.__init__(self, 'file')
|
# PY3 way:
|
||||||
|
# super().__init__('file')
|
||||||
|
super(FileObject, self).__init__('file')
|
||||||
self.data = self.pseudofile.getvalue()
|
self.data = self.pseudofile.getvalue()
|
||||||
self.generate_attributes()
|
self.generate_attributes()
|
||||||
|
|
||||||
|
|
|
@ -83,13 +83,13 @@ class MISPObjectGenerator(AbstractMISP):
|
||||||
'data', 'misp-objects', 'objects')
|
'data', 'misp-objects', 'objects')
|
||||||
with open(os.path.join(self.misp_objects_path, template_dir, 'definition.json'), 'r') as f:
|
with open(os.path.join(self.misp_objects_path, template_dir, 'definition.json'), 'r') as f:
|
||||||
self.definition = json.load(f)
|
self.definition = json.load(f)
|
||||||
self.object_attributes = self.definition['attributes'].keys()
|
|
||||||
self.misp_event = MISPEvent()
|
self.misp_event = MISPEvent()
|
||||||
self.name = self.definition['name']
|
self.name = self.definition['name']
|
||||||
setattr(self, 'meta-category', self.definition['meta-category'])
|
setattr(self, 'meta-category', self.definition['meta-category'])
|
||||||
self.uuid = str(uuid.uuid4())
|
self.template_uuid = self.definition['uuid']
|
||||||
self.description = self.definition['description']
|
self.description = self.definition['description']
|
||||||
self.version = self.definition['version']
|
self.version = self.definition['version']
|
||||||
|
self.uuid = str(uuid.uuid4())
|
||||||
self.Attribute = []
|
self.Attribute = []
|
||||||
self.references = []
|
self.references = []
|
||||||
|
|
||||||
|
@ -121,7 +121,7 @@ class MISPObjectGenerator(AbstractMISP):
|
||||||
if self.definition.get('required'):
|
if self.definition.get('required'):
|
||||||
for r in self.definition.get('required'):
|
for r in self.definition.get('required'):
|
||||||
if r not in all_attribute_names:
|
if r not in all_attribute_names:
|
||||||
raise InvalidMISPObject('{} is required is required'.format(r))
|
raise InvalidMISPObject('{} is required'.format(r))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def add_reference(self, destination_uuid, relationship_type, comment=None):
|
def add_reference(self, destination_uuid, relationship_type, comment=None):
|
||||||
|
|
|
@ -43,7 +43,9 @@ class PEObject(MISPObjectGenerator):
|
||||||
self.pe = parsed
|
self.pe = parsed
|
||||||
else:
|
else:
|
||||||
raise Exception('Not a lief.PE.Binary: {}'.format(type(parsed)))
|
raise Exception('Not a lief.PE.Binary: {}'.format(type(parsed)))
|
||||||
MISPObjectGenerator.__init__(self, 'pe')
|
# Python3 way
|
||||||
|
# super().__init__('pe')
|
||||||
|
super(PEObject, self).__init__('pe')
|
||||||
self.generate_attributes()
|
self.generate_attributes()
|
||||||
|
|
||||||
def _is_exe(self):
|
def _is_exe(self):
|
||||||
|
@ -114,7 +116,9 @@ class PEObject(MISPObjectGenerator):
|
||||||
class PESectionObject(MISPObjectGenerator):
|
class PESectionObject(MISPObjectGenerator):
|
||||||
|
|
||||||
def __init__(self, section):
|
def __init__(self, section):
|
||||||
MISPObjectGenerator.__init__(self, 'pe-section')
|
# Python3 way
|
||||||
|
# super().__init__('pe-section')
|
||||||
|
super(PESectionObject, self).__init__('pe-section')
|
||||||
self.section = section
|
self.section = section
|
||||||
self.data = bytes(self.section.content)
|
self.data = bytes(self.section.content)
|
||||||
self.generate_attributes()
|
self.generate_attributes()
|
||||||
|
|
Loading…
Reference in New Issue