Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def add_reference(self, referenced_uuid, relationship_type, comment=None, **kwargs):
"""Add a link (uuid) to an other object"""
if isinstance(referenced_uuid, AbstractMISP):
# Allow to pass an object or an attribute instead of its UUID
referenced_uuid = referenced_uuid.uuid
if kwargs.get('object_uuid'):
# Load existing object
object_uuid = kwargs.pop('object_uuid')
else:
# New reference
object_uuid = self.uuid
reference = MISPObjectReference()
reference.from_dict(object_uuid=object_uuid, referenced_uuid=referenced_uuid,
relationship_type=relationship_type, comment=comment, **kwargs)
self.ObjectReference.append(reference)
self.edited = True
return reference
kwargs = kwargs['Noticelist']
super(MISPNoticelist, self).from_dict(**kwargs)
class MISPRole(AbstractMISP):
def __init__(self):
super(MISPRole, self).__init__()
def from_dict(self, **kwargs):
if 'Role' in kwargs:
kwargs = kwargs['Role']
super(MISPRole, self).from_dict(**kwargs)
class MISPServer(AbstractMISP):
def __init__(self):
super(MISPServer, self).__init__()
def from_dict(self, **kwargs):
if 'Server' in kwargs:
kwargs = kwargs['Server']
super(MISPServer, self).from_dict(**kwargs)
class MISPSharingGroup(AbstractMISP):
def __init__(self):
super(MISPSharingGroup, self).__init__()
def from_dict(self, **kwargs):
if self.to_ids is None:
# Same for the to_ids flag
self.to_ids = self._definition.get('to_ids')
if not self.type:
raise NewAttributeError("The type of the attribute is required. Is the object template missing?")
super(MISPObjectAttribute, self).from_dict(**dict(self, **kwargs))
# FIXME New syntax python3 only, keep for later.
# super(MISPObjectAttribute, self).from_dict(**{**self, **kwargs})
def __repr__(self):
if hasattr(self, 'value'):
return '<{self.__class__.__name__}(object_relation={self.object_relation}, value={self.value})'.format(self=self)
return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)
class MISPShadowAttribute(AbstractMISP):
def __init__(self):
super(MISPShadowAttribute, self).__init__()
def from_dict(self, **kwargs):
if 'ShadowAttribute' in kwargs:
kwargs = kwargs['ShadowAttribute']
super(MISPShadowAttribute, self).from_dict(**kwargs)
def __repr__(self):
if hasattr(self, 'value'):
return '<{self.__class__.__name__}(type={self.type}, value={self.value})'.format(self=self)
return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)
class MISPCommunity(AbstractMISP):
def edited(self):
"""Recursively check if an object has been edited and update the flag accordingly
to the parent objects"""
if self.__edited:
return self.__edited
for p, val in self.items():
if isinstance(val, AbstractMISP) and val.edited:
self.__edited = True
break
elif isinstance(val, list) and all(isinstance(a, AbstractMISP) for a in val):
if any(a.edited for a in val):
self.__edited = True
break
return self.__edited
kwargs = kwargs['Taxonomy']
super(MISPTaxonomy, self).from_dict(**kwargs)
class MISPGalaxy(AbstractMISP):
def __init__(self):
super(MISPGalaxy, self).__init__()
def from_dict(self, **kwargs):
if 'Galaxy' in kwargs:
kwargs = kwargs['Galaxy']
super(MISPGalaxy, self).from_dict(**kwargs)
class MISPNoticelist(AbstractMISP):
def __init__(self):
super(MISPNoticelist, self).__init__()
def from_dict(self, **kwargs):
if 'Noticelist' in kwargs:
kwargs = kwargs['Noticelist']
super(MISPNoticelist, self).from_dict(**kwargs)
class MISPRole(AbstractMISP):
def __init__(self):
super(MISPRole, self).__init__()
def from_dict(self, **kwargs):
def __eq__(self, other):
if isinstance(other, AbstractMISP):
return self.to_dict() == other.to_dict()
elif isinstance(other, dict):
return self.to_dict() == other
else:
return False
def __repr__(self):
if hasattr(self, 'name'):
return '<{self.__class__.__name__}(name={self.name})'.format(self=self)
return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)
class MISPTag(AbstractMISP):
_fields_for_feed = {'name', 'colour'}
def __init__(self):
super(MISPTag, self).__init__()
def from_dict(self, **kwargs):
if kwargs.get('Tag'):
kwargs = kwargs.get('Tag')
super(MISPTag, self).from_dict(**kwargs)
def _set_default(self):
if not hasattr(self, 'colour'):
self.colour = '#ffffff'
def _to_feed(self):
super(MISPUser, self).__init__()
def from_dict(self, **kwargs):
if 'User' in kwargs:
kwargs = kwargs['User']
super(MISPUser, self).from_dict(**kwargs)
if hasattr(self, 'password') and set(self.password) == set(['*']):
self.password = None
def __repr__(self):
if hasattr(self, 'email'):
return '<{self.__class__.__name__}(email={self.email})'.format(self=self)
return '<{self.__class__.__name__}(NotInitialized)'.format(self=self)
class MISPOrganisation(AbstractMISP):
_fields_for_feed = {'name', 'uuid'}
def __init__(self):
super(MISPOrganisation, self).__init__()
def from_dict(self, **kwargs):
if 'Organisation' in kwargs:
kwargs = kwargs['Organisation']
super(MISPOrganisation, self).from_dict(**kwargs)
class MISPFeed(AbstractMISP):
def __init__(self):
super(MISPFeed, self).__init__()
def __setattr__(self, name, value):
if name[0] != '_' and not self.__edited and name in self.keys():
# The private members don't matter
# If we already have a key with that name, we're modifying it.
self.__edited = True
super(AbstractMISP, self).__setattr__(name, value)
return self.malware_binary
@deprecated(reason="Use self.to_dict() instead. Removal date: 2020-01-01.")
def _json(self): # pragma: no cover
return self.to_dict()
@deprecated(reason="Use self.to_dict() instead. Removal date: 2020-01-01.")
def _json_full(self): # pragma: no cover
return self.to_dict()
@deprecated(reason="Use self.from_dict(**kwargs) instead. Removal date: 2020-01-01.")
def set_all_values(self, **kwargs): # pragma: no cover
self.from_dict(**kwargs)
class MISPEvent(AbstractMISP):
_fields_for_feed = {'uuid', 'info', 'threat_level_id', 'analysis', 'timestamp',
'publish_timestamp', 'published', 'date', 'extends_uuid'}
def __init__(self, describe_types=None, strict_validation=False, **kwargs):
super(MISPEvent, self).__init__(**kwargs)
if strict_validation:
schema_file = 'schema.json'
else:
schema_file = 'schema-lax.json'
if sys.version_info >= (3, 4):
self.__json_schema = self._load_json(self.resources_path / schema_file)
else:
self.__json_schema = self._load_json(os.path.join(self.resources_path, schema_file))
if describe_types:
# This variable is used in add_attribute in order to avoid duplicating the structure
return to_return
@deprecated(reason="Use self.known_types instead. Removal date: 2020-01-01.")
def get_known_types(self): # pragma: no cover
return self.known_types
@deprecated(reason="Use self.from_dict(**kwargs) instead. Removal date: 2020-01-01.")
def set_all_values(self, **kwargs): # pragma: no cover
self.from_dict(**kwargs)
@deprecated(reason="Use self.to_dict() instead. Removal date: 2020-01-01.")
def _json(self): # pragma: no cover
return self.to_dict()
class MISPObjectReference(AbstractMISP):
_fields_for_feed = {'uuid', 'timestamp', 'relationship_type', 'comment',
'object_uuid', 'referenced_uuid'}
def __init__(self):
super(MISPObjectReference, self).__init__()
self.uuid = str(uuid.uuid4())
def _set_default(self):
if not hasattr(self, 'comment'):
self.comment = ''
if not hasattr(self, 'timestamp'):
self.timestamp = datetime.datetime.timestamp(datetime.datetime.now())
def from_dict(self, **kwargs):
if 'ObjectReference' in kwargs: