2017-09-22 17:03:25 +02:00
|
|
|
"""STIX 2.0 Cyber Observable Objects.
|
2017-05-03 23:35:33 +02:00
|
|
|
|
2017-05-09 17:03:19 +02:00
|
|
|
Embedded observable object types, such as Email MIME Component, which is
|
2017-09-22 17:03:25 +02:00
|
|
|
embedded in Email Message objects, inherit from ``_STIXBase`` instead of
|
|
|
|
Observable and do not have a ``_type`` attribute.
|
2017-05-09 17:03:19 +02:00
|
|
|
"""
|
|
|
|
|
2017-09-01 22:37:49 +02:00
|
|
|
from collections import OrderedDict
|
2017-08-14 16:29:17 +02:00
|
|
|
|
2017-10-26 17:39:45 +02:00
|
|
|
from ..base import _Extension, _Observable, _STIXBase
|
|
|
|
from ..exceptions import (AtLeastOnePropertyError, DependentPropertiesError,
|
|
|
|
ParseError)
|
|
|
|
from ..properties import (BinaryProperty, BooleanProperty, DictionaryProperty,
|
|
|
|
EmbeddedObjectProperty, EnumProperty, FloatProperty,
|
|
|
|
HashesProperty, HexProperty, IntegerProperty,
|
|
|
|
ListProperty, ObjectReferenceProperty, Property,
|
|
|
|
StringProperty, TimestampProperty, TypeProperty)
|
|
|
|
from ..utils import get_dict
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ObservableProperty(Property):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Property for holding Cyber Observable Objects.
|
|
|
|
"""
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
def clean(self, value):
|
|
|
|
try:
|
|
|
|
dictified = get_dict(value)
|
|
|
|
except ValueError:
|
|
|
|
raise ValueError("The observable property must contain a dictionary")
|
|
|
|
if dictified == {}:
|
2017-08-24 00:36:24 +02:00
|
|
|
raise ValueError("The observable property must contain a non-empty dictionary")
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
valid_refs = dict((k, v['type']) for (k, v) in dictified.items())
|
|
|
|
|
|
|
|
for key, obj in dictified.items():
|
|
|
|
parsed_obj = parse_observable(obj, valid_refs)
|
|
|
|
dictified[key] = parsed_obj
|
|
|
|
|
|
|
|
return dictified
|
|
|
|
|
|
|
|
|
|
|
|
class ExtensionsProperty(DictionaryProperty):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Property for representing extensions on Observable objects.
|
2017-07-14 20:55:57 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, enclosing_type=None, required=False):
|
|
|
|
self.enclosing_type = enclosing_type
|
|
|
|
super(ExtensionsProperty, self).__init__(required)
|
|
|
|
|
|
|
|
def clean(self, value):
|
|
|
|
try:
|
|
|
|
dictified = get_dict(value)
|
|
|
|
except ValueError:
|
|
|
|
raise ValueError("The extensions property must contain a dictionary")
|
|
|
|
if dictified == {}:
|
2017-08-24 00:36:24 +02:00
|
|
|
raise ValueError("The extensions property must contain a non-empty dictionary")
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
if self.enclosing_type in EXT_MAP:
|
|
|
|
specific_type_map = EXT_MAP[self.enclosing_type]
|
|
|
|
for key, subvalue in dictified.items():
|
|
|
|
if key in specific_type_map:
|
|
|
|
cls = specific_type_map[key]
|
|
|
|
if type(subvalue) is dict:
|
|
|
|
dictified[key] = cls(**subvalue)
|
|
|
|
elif type(subvalue) is cls:
|
|
|
|
dictified[key] = subvalue
|
|
|
|
else:
|
|
|
|
raise ValueError("Cannot determine extension type.")
|
|
|
|
else:
|
2018-04-12 20:20:24 +02:00
|
|
|
raise ParseError("Can't parse unknown extension type: {}".format(key))
|
2017-07-14 20:55:57 +02:00
|
|
|
else:
|
2017-08-24 00:36:24 +02:00
|
|
|
raise ValueError("The enclosing type '%s' has no extensions defined" % self.enclosing_type)
|
2017-07-14 20:55:57 +02:00
|
|
|
return dictified
|
2017-05-03 23:35:33 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class Artifact(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716219>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-03 23:35:33 +02:00
|
|
|
_type = 'artifact'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('mime_type', StringProperty()),
|
|
|
|
('payload_bin', BinaryProperty()),
|
|
|
|
('url', StringProperty()),
|
|
|
|
('hashes', HashesProperty()),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-03 23:35:33 +02:00
|
|
|
|
2017-05-18 15:48:01 +02:00
|
|
|
def _check_object_constraints(self):
|
|
|
|
super(Artifact, self)._check_object_constraints()
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
self._check_mutually_exclusive_properties(["payload_bin", "url"])
|
|
|
|
self._check_properties_dependency(["hashes"], ["url"])
|
|
|
|
|
2017-05-03 23:35:33 +02:00
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class AutonomousSystem(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716221>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-04 00:19:30 +02:00
|
|
|
_type = 'autonomous-system'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
2017-10-11 21:10:06 +02:00
|
|
|
('number', IntegerProperty(required=True)),
|
2017-08-14 16:29:17 +02:00
|
|
|
('name', StringProperty()),
|
|
|
|
('rir', StringProperty()),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-04 00:19:30 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class Directory(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716223>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'directory'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('path', StringProperty(required=True)),
|
|
|
|
('path_enc', StringProperty()),
|
2017-05-09 03:03:15 +02:00
|
|
|
# these are not the created/modified timestamps of the object itself
|
2017-08-14 16:29:17 +02:00
|
|
|
('created', TimestampProperty()),
|
|
|
|
('modified', TimestampProperty()),
|
|
|
|
('accessed', TimestampProperty()),
|
|
|
|
('contains_refs', ListProperty(ObjectReferenceProperty(valid_types=['file', 'directory']))),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class DomainName(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716225>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'domain-name'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('value', StringProperty(required=True)),
|
|
|
|
('resolves_to_refs', ListProperty(ObjectReferenceProperty(valid_types=['ipv4-addr', 'ipv6-addr', 'domain-name']))),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class EmailAddress(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716227>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-07-12 23:02:51 +02:00
|
|
|
_type = 'email-addr'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('value', StringProperty(required=True)),
|
|
|
|
('display_name', StringProperty()),
|
|
|
|
('belongs_to_ref', ObjectReferenceProperty(valid_types='user-account')),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-05 18:32:02 +02:00
|
|
|
|
|
|
|
|
2017-05-09 17:03:19 +02:00
|
|
|
class EmailMIMEComponent(_STIXBase):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716231>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('body', StringProperty()),
|
|
|
|
('body_raw_ref', ObjectReferenceProperty(valid_types=['artifact', 'file'])),
|
|
|
|
('content_type', StringProperty()),
|
|
|
|
('content_disposition', StringProperty()),
|
|
|
|
])
|
2017-05-09 17:03:19 +02:00
|
|
|
|
2017-05-18 15:48:01 +02:00
|
|
|
def _check_object_constraints(self):
|
|
|
|
super(EmailMIMEComponent, self)._check_object_constraints()
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
self._check_at_least_one_property(["body", "body_raw_ref"])
|
|
|
|
|
2017-05-09 17:03:19 +02:00
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class EmailMessage(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716229>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 17:03:19 +02:00
|
|
|
_type = 'email-message'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('is_multipart', BooleanProperty(required=True)),
|
|
|
|
('date', TimestampProperty()),
|
|
|
|
('content_type', StringProperty()),
|
|
|
|
('from_ref', ObjectReferenceProperty(valid_types='email-addr')),
|
|
|
|
('sender_ref', ObjectReferenceProperty(valid_types='email-addr')),
|
|
|
|
('to_refs', ListProperty(ObjectReferenceProperty(valid_types='email-addr'))),
|
|
|
|
('cc_refs', ListProperty(ObjectReferenceProperty(valid_types='email-addr'))),
|
|
|
|
('bcc_refs', ListProperty(ObjectReferenceProperty(valid_types='email-addr'))),
|
|
|
|
('subject', StringProperty()),
|
|
|
|
('received_lines', ListProperty(StringProperty)),
|
|
|
|
('additional_header_fields', DictionaryProperty()),
|
|
|
|
('body', StringProperty()),
|
|
|
|
('body_multipart', ListProperty(EmbeddedObjectProperty(type=EmailMIMEComponent))),
|
|
|
|
('raw_email_ref', ObjectReferenceProperty(valid_types='artifact')),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 17:03:19 +02:00
|
|
|
|
2017-05-18 15:48:01 +02:00
|
|
|
def _check_object_constraints(self):
|
|
|
|
super(EmailMessage, self)._check_object_constraints()
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
self._check_properties_dependency(["is_multipart"], ["body_multipart"])
|
2017-06-08 16:09:18 +02:00
|
|
|
if self.get("is_multipart") is True and self.get("body"):
|
|
|
|
# 'body' MAY only be used if is_multipart is false.
|
|
|
|
raise DependentPropertiesError(self.__class__, [("is_multipart", "body")])
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
|
2017-05-09 17:03:19 +02:00
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class ArchiveExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716235>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'archive-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('contains_refs', ListProperty(ObjectReferenceProperty(valid_types='file'), required=True)),
|
|
|
|
('version', StringProperty()),
|
|
|
|
('comment', StringProperty()),
|
|
|
|
])
|
2017-05-12 17:22:23 +02:00
|
|
|
|
|
|
|
|
2017-05-15 19:48:41 +02:00
|
|
|
class AlternateDataStream(_STIXBase):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716239>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('name', StringProperty(required=True)),
|
|
|
|
('hashes', HashesProperty()),
|
|
|
|
('size', IntegerProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class NTFSExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716237>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'ntfs-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('sid', StringProperty()),
|
|
|
|
('alternate_data_streams', ListProperty(EmbeddedObjectProperty(type=AlternateDataStream))),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class PDFExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716241>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'pdf-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('version', StringProperty()),
|
|
|
|
('is_optimized', BooleanProperty()),
|
|
|
|
('document_info_dict', DictionaryProperty()),
|
|
|
|
('pdfid0', StringProperty()),
|
|
|
|
('pdfid1', StringProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class RasterImageExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716243>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'raster-image-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('image_height', IntegerProperty()),
|
|
|
|
('image_weight', IntegerProperty()),
|
|
|
|
('bits_per_pixel', IntegerProperty()),
|
|
|
|
('image_compression_algorithm', StringProperty()),
|
|
|
|
('exif_tags', DictionaryProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
class WindowsPEOptionalHeaderType(_STIXBase):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716248>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('magic_hex', HexProperty()),
|
|
|
|
('major_linker_version', IntegerProperty()),
|
|
|
|
('minor_linker_version', IntegerProperty()),
|
|
|
|
('size_of_code', IntegerProperty()),
|
|
|
|
('size_of_initialized_data', IntegerProperty()),
|
|
|
|
('size_of_uninitialized_data', IntegerProperty()),
|
|
|
|
('address_of_entry_point', IntegerProperty()),
|
|
|
|
('base_of_code', IntegerProperty()),
|
|
|
|
('base_of_data', IntegerProperty()),
|
|
|
|
('image_base', IntegerProperty()),
|
|
|
|
('section_alignment', IntegerProperty()),
|
|
|
|
('file_alignment', IntegerProperty()),
|
|
|
|
('major_os_version', IntegerProperty()),
|
|
|
|
('minor_os_version', IntegerProperty()),
|
|
|
|
('major_image_version', IntegerProperty()),
|
|
|
|
('minor_image_version', IntegerProperty()),
|
|
|
|
('major_subsystem_version', IntegerProperty()),
|
|
|
|
('minor_subsystem_version', IntegerProperty()),
|
|
|
|
('win32_version_value_hex', HexProperty()),
|
|
|
|
('size_of_image', IntegerProperty()),
|
|
|
|
('size_of_headers', IntegerProperty()),
|
|
|
|
('checksum_hex', HexProperty()),
|
|
|
|
('subsystem_hex', HexProperty()),
|
|
|
|
('dll_characteristics_hex', HexProperty()),
|
|
|
|
('size_of_stack_reserve', IntegerProperty()),
|
|
|
|
('size_of_stack_commit', IntegerProperty()),
|
|
|
|
('size_of_heap_reserve', IntegerProperty()),
|
|
|
|
('size_of_heap_commit', IntegerProperty()),
|
|
|
|
('loader_flags_hex', HexProperty()),
|
|
|
|
('number_of_rva_and_sizes', IntegerProperty()),
|
|
|
|
('hashes', HashesProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
2017-05-18 15:48:01 +02:00
|
|
|
def _check_object_constraints(self):
|
|
|
|
super(WindowsPEOptionalHeaderType, self)._check_object_constraints()
|
2017-05-17 21:33:28 +02:00
|
|
|
self._check_at_least_one_property()
|
|
|
|
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
class WindowsPESection(_STIXBase):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716250>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('name', StringProperty(required=True)),
|
|
|
|
('size', IntegerProperty()),
|
|
|
|
('entropy', FloatProperty()),
|
|
|
|
('hashes', HashesProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class WindowsPEBinaryExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716245>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'windows-pebinary-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('pe_type', StringProperty(required=True)), # open_vocab
|
|
|
|
('imphash', StringProperty()),
|
|
|
|
('machine_hex', HexProperty()),
|
|
|
|
('number_of_sections', IntegerProperty()),
|
|
|
|
('time_date_stamp', TimestampProperty(precision='second')),
|
|
|
|
('pointer_to_symbol_table_hex', HexProperty()),
|
|
|
|
('number_of_symbols', IntegerProperty()),
|
|
|
|
('size_of_optional_header', IntegerProperty()),
|
|
|
|
('characteristics_hex', HexProperty()),
|
|
|
|
('file_header_hashes', HashesProperty()),
|
|
|
|
('optional_header', EmbeddedObjectProperty(type=WindowsPEOptionalHeaderType)),
|
|
|
|
('sections', ListProperty(EmbeddedObjectProperty(type=WindowsPESection))),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class File(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716233>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-03 23:35:33 +02:00
|
|
|
_type = 'file'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('hashes', HashesProperty()),
|
|
|
|
('size', IntegerProperty()),
|
|
|
|
('name', StringProperty()),
|
|
|
|
('name_enc', StringProperty()),
|
|
|
|
('magic_number_hex', HexProperty()),
|
|
|
|
('mime_type', StringProperty()),
|
2017-05-09 03:03:15 +02:00
|
|
|
# these are not the created/modified timestamps of the object itself
|
2017-08-14 16:29:17 +02:00
|
|
|
('created', TimestampProperty()),
|
|
|
|
('modified', TimestampProperty()),
|
|
|
|
('accessed', TimestampProperty()),
|
|
|
|
('parent_directory_ref', ObjectReferenceProperty(valid_types='directory')),
|
|
|
|
('is_encrypted', BooleanProperty()),
|
|
|
|
('encryption_algorithm', StringProperty()),
|
|
|
|
('decryption_key', StringProperty()),
|
|
|
|
('contains_refs', ListProperty(ObjectReferenceProperty)),
|
|
|
|
('content_ref', ObjectReferenceProperty(valid_types='artifact')),
|
2017-10-06 20:24:46 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
2017-05-18 15:48:01 +02:00
|
|
|
def _check_object_constraints(self):
|
|
|
|
super(File, self)._check_object_constraints()
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
self._check_properties_dependency(["is_encrypted"], ["encryption_algorithm", "decryption_key"])
|
|
|
|
self._check_at_least_one_property(["hashes", "name"])
|
2017-05-09 21:28:32 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class IPv4Address(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716252>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'ipv4-addr'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('value', StringProperty(required=True)),
|
|
|
|
('resolves_to_refs', ListProperty(ObjectReferenceProperty(valid_types='mac-addr'))),
|
|
|
|
('belongs_to_refs', ListProperty(ObjectReferenceProperty(valid_types='autonomous-system'))),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class IPv6Address(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716254>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'ipv6-addr'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('value', StringProperty(required=True)),
|
|
|
|
('resolves_to_refs', ListProperty(ObjectReferenceProperty(valid_types='mac-addr'))),
|
|
|
|
('belongs_to_refs', ListProperty(ObjectReferenceProperty(valid_types='autonomous-system'))),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class MACAddress(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716256>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'mac-addr'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('value', StringProperty(required=True)),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class Mutex(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716258>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'mutex'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
2017-10-06 20:24:46 +02:00
|
|
|
('name', StringProperty(required=True)),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class HTTPRequestExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716262>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'http-request-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('request_method', StringProperty(required=True)),
|
|
|
|
('request_value', StringProperty(required=True)),
|
|
|
|
('request_version', StringProperty()),
|
|
|
|
('request_header', DictionaryProperty()),
|
|
|
|
('message_body_length', IntegerProperty()),
|
|
|
|
('message_body_data_ref', ObjectReferenceProperty(valid_types='artifact')),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class ICMPExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716264>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'icmp-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('icmp_type_hex', HexProperty(required=True)),
|
|
|
|
('icmp_code_hex', HexProperty(required=True)),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class SocketExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716266>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'socket-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-10-06 20:24:46 +02:00
|
|
|
('address_family', EnumProperty(allowed=[
|
2017-05-15 19:48:41 +02:00
|
|
|
"AF_UNSPEC",
|
|
|
|
"AF_INET",
|
|
|
|
"AF_IPX",
|
|
|
|
"AF_APPLETALK",
|
|
|
|
"AF_NETBIOS",
|
|
|
|
"AF_INET6",
|
|
|
|
"AF_IRDA",
|
|
|
|
"AF_BTH",
|
2017-08-14 16:29:17 +02:00
|
|
|
], required=True)),
|
|
|
|
('is_blocking', BooleanProperty()),
|
|
|
|
('is_listening', BooleanProperty()),
|
2017-10-06 20:24:46 +02:00
|
|
|
('protocol_family', EnumProperty(allowed=[
|
2017-05-15 19:48:41 +02:00
|
|
|
"PF_INET",
|
|
|
|
"PF_IPX",
|
|
|
|
"PF_APPLETALK",
|
|
|
|
"PF_INET6",
|
|
|
|
"PF_AX25",
|
|
|
|
"PF_NETROM"
|
2017-08-14 16:29:17 +02:00
|
|
|
])),
|
|
|
|
('options', DictionaryProperty()),
|
2017-10-06 20:24:46 +02:00
|
|
|
('socket_type', EnumProperty(allowed=[
|
2017-05-15 19:48:41 +02:00
|
|
|
"SOCK_STREAM",
|
|
|
|
"SOCK_DGRAM",
|
|
|
|
"SOCK_RAW",
|
|
|
|
"SOCK_RDM",
|
|
|
|
"SOCK_SEQPACKET",
|
2017-08-14 16:29:17 +02:00
|
|
|
])),
|
2017-10-11 21:10:06 +02:00
|
|
|
('socket_descriptor', IntegerProperty()),
|
|
|
|
('socket_handle', IntegerProperty()),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class TCPExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716271>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'tcp-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('src_flags_hex', HexProperty()),
|
|
|
|
('dst_flags_hex', HexProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class NetworkTraffic(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716260>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'network-traffic'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('start', TimestampProperty()),
|
|
|
|
('end', TimestampProperty()),
|
|
|
|
('is_active', BooleanProperty()),
|
|
|
|
('src_ref', ObjectReferenceProperty(valid_types=['ipv4-addr', 'ipv6-addr', 'mac-addr', 'domain-name'])),
|
|
|
|
('dst_ref', ObjectReferenceProperty(valid_types=['ipv4-addr', 'ipv6-addr', 'mac-addr', 'domain-name'])),
|
|
|
|
('src_port', IntegerProperty()),
|
|
|
|
('dst_port', IntegerProperty()),
|
|
|
|
('protocols', ListProperty(StringProperty, required=True)),
|
|
|
|
('src_byte_count', IntegerProperty()),
|
|
|
|
('dst_byte_count', IntegerProperty()),
|
|
|
|
('src_packets', IntegerProperty()),
|
|
|
|
('dst_packets', IntegerProperty()),
|
|
|
|
('ipfix', DictionaryProperty()),
|
|
|
|
('src_payload_ref', ObjectReferenceProperty(valid_types='artifact')),
|
|
|
|
('dst_payload_ref', ObjectReferenceProperty(valid_types='artifact')),
|
|
|
|
('encapsulates_refs', ListProperty(ObjectReferenceProperty(valid_types='network-traffic'))),
|
|
|
|
('encapsulates_by_ref', ObjectReferenceProperty(valid_types='network-traffic')),
|
2017-10-06 20:24:46 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
2017-05-18 15:48:01 +02:00
|
|
|
def _check_object_constraints(self):
|
|
|
|
super(NetworkTraffic, self)._check_object_constraints()
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
self._check_at_least_one_property(["src_ref", "dst_ref"])
|
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class WindowsProcessExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716275>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'windows-process-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('aslr_enabled', BooleanProperty()),
|
|
|
|
('dep_enabled', BooleanProperty()),
|
|
|
|
('priority', StringProperty()),
|
|
|
|
('owner_sid', StringProperty()),
|
|
|
|
('window_title', StringProperty()),
|
|
|
|
('startup_info', DictionaryProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class WindowsServiceExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716277>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'windows-service-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('service_name', StringProperty(required=True)),
|
|
|
|
('descriptions', ListProperty(StringProperty)),
|
|
|
|
('display_name', StringProperty()),
|
|
|
|
('group_name', StringProperty()),
|
2017-10-06 20:24:46 +02:00
|
|
|
('start_type', EnumProperty(allowed=[
|
2017-05-15 19:48:41 +02:00
|
|
|
"SERVICE_AUTO_START",
|
|
|
|
"SERVICE_BOOT_START",
|
|
|
|
"SERVICE_DEMAND_START",
|
|
|
|
"SERVICE_DISABLED",
|
|
|
|
"SERVICE_SYSTEM_ALERT",
|
2017-08-14 16:29:17 +02:00
|
|
|
])),
|
|
|
|
('service_dll_refs', ListProperty(ObjectReferenceProperty(valid_types='file'))),
|
2017-10-06 20:24:46 +02:00
|
|
|
('service_type', EnumProperty(allowed=[
|
2017-05-15 19:48:41 +02:00
|
|
|
"SERVICE_KERNEL_DRIVER",
|
|
|
|
"SERVICE_FILE_SYSTEM_DRIVER",
|
|
|
|
"SERVICE_WIN32_OWN_PROCESS",
|
|
|
|
"SERVICE_WIN32_SHARE_PROCESS",
|
2017-08-14 16:29:17 +02:00
|
|
|
])),
|
2017-10-06 20:24:46 +02:00
|
|
|
('service_status', EnumProperty(allowed=[
|
2017-05-15 19:48:41 +02:00
|
|
|
"SERVICE_CONTINUE_PENDING",
|
|
|
|
"SERVICE_PAUSE_PENDING",
|
|
|
|
"SERVICE_PAUSED",
|
|
|
|
"SERVICE_RUNNING",
|
|
|
|
"SERVICE_START_PENDING",
|
|
|
|
"SERVICE_STOP_PENDING",
|
|
|
|
"SERVICE_STOPPED",
|
2017-08-14 16:29:17 +02:00
|
|
|
])),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class Process(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716273>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'process'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('is_hidden', BooleanProperty()),
|
|
|
|
('pid', IntegerProperty()),
|
|
|
|
('name', StringProperty()),
|
2017-05-09 03:03:15 +02:00
|
|
|
# this is not the created timestamps of the object itself
|
2017-08-14 16:29:17 +02:00
|
|
|
('created', TimestampProperty()),
|
|
|
|
('cwd', StringProperty()),
|
|
|
|
('arguments', ListProperty(StringProperty)),
|
|
|
|
('command_line', StringProperty()),
|
|
|
|
('environment_variables', DictionaryProperty()),
|
|
|
|
('opened_connection_refs', ListProperty(ObjectReferenceProperty(valid_types='network-traffic'))),
|
|
|
|
('creator_user_ref', ObjectReferenceProperty(valid_types='user-account')),
|
|
|
|
('binary_ref', ObjectReferenceProperty(valid_types='file')),
|
|
|
|
('parent_ref', ObjectReferenceProperty(valid_types='process')),
|
|
|
|
('child_refs', ListProperty(ObjectReferenceProperty('process'))),
|
2017-10-06 20:24:46 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
2017-05-18 15:48:01 +02:00
|
|
|
def _check_object_constraints(self):
|
|
|
|
# no need to check windows-service-ext, since it has a required property
|
|
|
|
super(Process, self)._check_object_constraints()
|
2017-05-17 21:33:28 +02:00
|
|
|
try:
|
|
|
|
self._check_at_least_one_property()
|
2017-06-08 16:09:18 +02:00
|
|
|
if "windows-process-ext" in self.get('extensions', {}):
|
2017-05-17 21:33:28 +02:00
|
|
|
self.extensions["windows-process-ext"]._check_at_least_one_property()
|
|
|
|
except AtLeastOnePropertyError as enclosing_exc:
|
2017-06-08 16:09:18 +02:00
|
|
|
if 'extensions' not in self:
|
2017-05-17 21:33:28 +02:00
|
|
|
raise enclosing_exc
|
|
|
|
else:
|
2017-06-08 16:09:18 +02:00
|
|
|
if "windows-process-ext" in self.get('extensions', {}):
|
2017-05-17 21:33:28 +02:00
|
|
|
self.extensions["windows-process-ext"]._check_at_least_one_property()
|
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class Software(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716282>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'software'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('name', StringProperty(required=True)),
|
|
|
|
('cpe', StringProperty()),
|
|
|
|
('languages', ListProperty(StringProperty)),
|
|
|
|
('vendor', StringProperty()),
|
|
|
|
('version', StringProperty()),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class URL(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716284>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'url'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('value', StringProperty(required=True)),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-18 20:04:28 +02:00
|
|
|
class UNIXAccountExt(_Extension):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716289>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = 'unix-account-ext'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('gid', IntegerProperty()),
|
|
|
|
('groups', ListProperty(StringProperty)),
|
|
|
|
('home_dir', StringProperty()),
|
|
|
|
('shell', StringProperty()),
|
|
|
|
])
|
2017-05-15 19:48:41 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class UserAccount(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716286>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'user-account'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('user_id', StringProperty(required=True)),
|
|
|
|
('account_login', StringProperty()),
|
|
|
|
('account_type', StringProperty()), # open vocab
|
|
|
|
('display_name', StringProperty()),
|
|
|
|
('is_service_account', BooleanProperty()),
|
|
|
|
('is_privileged', BooleanProperty()),
|
|
|
|
('can_escalate_privs', BooleanProperty()),
|
|
|
|
('is_disabled', BooleanProperty()),
|
|
|
|
('account_created', TimestampProperty()),
|
|
|
|
('account_expires', TimestampProperty()),
|
|
|
|
('password_last_changed', TimestampProperty()),
|
|
|
|
('account_first_login', TimestampProperty()),
|
|
|
|
('account_last_login', TimestampProperty()),
|
2017-10-06 20:24:46 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
class WindowsRegistryValueType(_STIXBase):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716293>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'windows-registry-value-type'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('name', StringProperty(required=True)),
|
|
|
|
('data', StringProperty()),
|
2017-10-06 20:24:46 +02:00
|
|
|
('data_type', EnumProperty(allowed=[
|
2017-05-10 17:52:59 +02:00
|
|
|
'REG_NONE',
|
|
|
|
'REG_SZ',
|
|
|
|
'REG_EXPAND_SZ',
|
|
|
|
'REG_BINARY',
|
|
|
|
'REG_DWORD',
|
|
|
|
'REG_DWORD_BIG_ENDIAN',
|
|
|
|
'REG_LINK',
|
|
|
|
'REG_MULTI_SZ',
|
|
|
|
'REG_RESOURCE_LIST',
|
|
|
|
'REG_FULL_RESOURCE_DESCRIPTION',
|
|
|
|
'REG_RESOURCE_REQUIREMENTS_LIST',
|
|
|
|
'REG_QWORD',
|
|
|
|
'REG_INVALID_TYPE',
|
2017-08-14 16:29:17 +02:00
|
|
|
])),
|
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class WindowsRegistryKey(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716291>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'windows-registry-key'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('key', StringProperty(required=True)),
|
|
|
|
('values', ListProperty(EmbeddedObjectProperty(type=WindowsRegistryValueType))),
|
2017-05-09 03:03:15 +02:00
|
|
|
# this is not the modified timestamps of the object itself
|
2017-08-14 16:29:17 +02:00
|
|
|
('modified', TimestampProperty()),
|
|
|
|
('creator_user_ref', ObjectReferenceProperty(valid_types='user-account')),
|
|
|
|
('number_of_subkeys', IntegerProperty()),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-05-09 03:03:15 +02:00
|
|
|
|
2017-05-10 17:52:59 +02:00
|
|
|
@property
|
|
|
|
def values(self):
|
|
|
|
# Needed because 'values' is a property on collections.Mapping objects
|
|
|
|
return self._inner['values']
|
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
class X509V3ExtenstionsType(_STIXBase):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716298>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
_type = 'x509-v3-extensions-type'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('basic_constraints', StringProperty()),
|
|
|
|
('name_constraints', StringProperty()),
|
|
|
|
('policy_constraints', StringProperty()),
|
|
|
|
('key_usage', StringProperty()),
|
|
|
|
('extended_key_usage', StringProperty()),
|
|
|
|
('subject_key_identifier', StringProperty()),
|
|
|
|
('authority_key_identifier', StringProperty()),
|
|
|
|
('subject_alternative_name', StringProperty()),
|
|
|
|
('issuer_alternative_name', StringProperty()),
|
|
|
|
('subject_directory_attributes', StringProperty()),
|
|
|
|
('crl_distribution_points', StringProperty()),
|
|
|
|
('inhibit_any_policy', StringProperty()),
|
|
|
|
('private_key_usage_period_not_before', TimestampProperty()),
|
|
|
|
('private_key_usage_period_not_after', TimestampProperty()),
|
|
|
|
('certificate_policies', StringProperty()),
|
|
|
|
('policy_mappings', StringProperty()),
|
|
|
|
])
|
2017-05-11 21:42:56 +02:00
|
|
|
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
|
2017-05-10 00:03:46 +02:00
|
|
|
class X509Certificate(_Observable):
|
2018-02-21 22:42:25 +01:00
|
|
|
"""For more detailed information on this object's properties, see
|
|
|
|
`the STIX 2.0 specification <http://docs.oasis-open.org/cti/stix/v2.0/cs01/part4-cyber-observable-objects/stix-v2.0-cs01-part4-cyber-observable-objects.html#_Toc496716296>`__.
|
2018-02-22 15:55:15 +01:00
|
|
|
""" # noqa
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-05-09 03:03:15 +02:00
|
|
|
_type = 'x509-certificate'
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
('is_self_signed', BooleanProperty()),
|
|
|
|
('hashes', HashesProperty()),
|
|
|
|
('version', StringProperty()),
|
|
|
|
('serial_number', StringProperty()),
|
|
|
|
('signature_algorithm', StringProperty()),
|
|
|
|
('issuer', StringProperty()),
|
|
|
|
('validity_not_before', TimestampProperty()),
|
|
|
|
('validity_not_after', TimestampProperty()),
|
|
|
|
('subject', StringProperty()),
|
|
|
|
('subject_public_key_algorithm', StringProperty()),
|
|
|
|
('subject_public_key_modulus', StringProperty()),
|
|
|
|
('subject_public_key_exponent', IntegerProperty()),
|
|
|
|
('x509_v3_extensions', EmbeddedObjectProperty(type=X509V3ExtenstionsType)),
|
2017-08-31 21:52:48 +02:00
|
|
|
('extensions', ExtensionsProperty(enclosing_type=_type)),
|
2017-08-14 16:29:17 +02:00
|
|
|
])
|
2017-06-14 15:34:42 +02:00
|
|
|
|
|
|
|
|
2017-07-14 20:55:57 +02:00
|
|
|
OBJ_MAP_OBSERVABLE = {
|
|
|
|
'artifact': Artifact,
|
|
|
|
'autonomous-system': AutonomousSystem,
|
|
|
|
'directory': Directory,
|
|
|
|
'domain-name': DomainName,
|
2017-07-12 23:02:51 +02:00
|
|
|
'email-addr': EmailAddress,
|
2017-07-14 20:55:57 +02:00
|
|
|
'email-message': EmailMessage,
|
|
|
|
'file': File,
|
|
|
|
'ipv4-addr': IPv4Address,
|
|
|
|
'ipv6-addr': IPv6Address,
|
|
|
|
'mac-addr': MACAddress,
|
|
|
|
'mutex': Mutex,
|
|
|
|
'network-traffic': NetworkTraffic,
|
|
|
|
'process': Process,
|
|
|
|
'software': Software,
|
|
|
|
'url': URL,
|
|
|
|
'user-account': UserAccount,
|
|
|
|
'windows-registry-key': WindowsRegistryKey,
|
|
|
|
'x509-certificate': X509Certificate,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
EXT_MAP = {
|
2017-08-24 00:36:24 +02:00
|
|
|
'file': {
|
|
|
|
'archive-ext': ArchiveExt,
|
|
|
|
'ntfs-ext': NTFSExt,
|
|
|
|
'pdf-ext': PDFExt,
|
|
|
|
'raster-image-ext': RasterImageExt,
|
|
|
|
'windows-pebinary-ext': WindowsPEBinaryExt
|
|
|
|
},
|
|
|
|
'network-traffic': {
|
|
|
|
'http-request-ext': HTTPRequestExt,
|
|
|
|
'icmp-ext': ICMPExt,
|
|
|
|
'socket-ext': SocketExt,
|
|
|
|
'tcp-ext': TCPExt,
|
|
|
|
},
|
|
|
|
'process': {
|
|
|
|
'windows-process-ext': WindowsProcessExt,
|
|
|
|
'windows-service-ext': WindowsServiceExt,
|
|
|
|
},
|
|
|
|
'user-account': {
|
|
|
|
'unix-account-ext': UNIXAccountExt,
|
|
|
|
},
|
2017-07-14 20:55:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-08-31 21:52:48 +02:00
|
|
|
def parse_observable(data, _valid_refs=None, allow_custom=False):
|
2017-08-14 20:37:49 +02:00
|
|
|
"""Deserialize a string or file-like object into a STIX Cyber Observable
|
|
|
|
object.
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
Args:
|
|
|
|
data: The STIX 2 string to be parsed.
|
2017-08-14 20:37:49 +02:00
|
|
|
_valid_refs: A list of object references valid for the scope of the
|
|
|
|
object being parsed. Use empty list if no valid refs are present.
|
|
|
|
allow_custom: Whether to allow custom properties or not.
|
|
|
|
Default: False.
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
Returns:
|
|
|
|
An instantiated Python STIX Cyber Observable object.
|
|
|
|
"""
|
|
|
|
|
|
|
|
obj = get_dict(data)
|
2017-08-31 21:52:48 +02:00
|
|
|
obj['_valid_refs'] = _valid_refs or []
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
if 'type' not in obj:
|
2017-08-24 21:46:36 +02:00
|
|
|
raise ParseError("Can't parse observable with no 'type' property: %s" % str(obj))
|
2017-07-14 20:55:57 +02:00
|
|
|
try:
|
|
|
|
obj_class = OBJ_MAP_OBSERVABLE[obj['type']]
|
|
|
|
except KeyError:
|
2018-04-10 18:54:27 +02:00
|
|
|
if allow_custom:
|
|
|
|
# flag allows for unknown custom objects too, but will not
|
|
|
|
# be parsed into STIX observable object, just returned as is
|
|
|
|
return obj
|
2017-08-24 21:46:36 +02:00
|
|
|
raise ParseError("Can't parse unknown observable type '%s'! For custom observables, "
|
|
|
|
"use the CustomObservable decorator." % obj['type'])
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
if 'extensions' in obj and obj['type'] in EXT_MAP:
|
|
|
|
for name, ext in obj['extensions'].items():
|
2018-04-10 18:54:27 +02:00
|
|
|
try:
|
|
|
|
ext_class = EXT_MAP[obj['type']][name]
|
|
|
|
except KeyError:
|
|
|
|
if not allow_custom:
|
2018-04-12 20:20:24 +02:00
|
|
|
raise ParseError("Can't parse unknown extension type '%s' for observable type '%s'!" % (name, obj['type']))
|
2018-04-10 18:54:27 +02:00
|
|
|
else: # extension was found
|
|
|
|
obj['extensions'][name] = ext_class(allow_custom=allow_custom, **obj['extensions'][name])
|
2017-07-14 20:55:57 +02:00
|
|
|
|
|
|
|
return obj_class(allow_custom=allow_custom, **obj)
|
|
|
|
|
|
|
|
|
|
|
|
def _register_observable(new_observable):
|
|
|
|
"""Register a custom STIX Cyber Observable type.
|
|
|
|
"""
|
|
|
|
|
|
|
|
OBJ_MAP_OBSERVABLE[new_observable._type] = new_observable
|
|
|
|
|
|
|
|
|
2017-08-14 16:29:17 +02:00
|
|
|
def CustomObservable(type='x-custom-observable', properties=None):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Custom STIX Cyber Observable Object type decorator.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
>>> @CustomObservable('x-custom-observable', [
|
|
|
|
... ('property1', StringProperty(required=True)),
|
|
|
|
... ('property2', IntegerProperty()),
|
|
|
|
... ])
|
|
|
|
... class MyNewObservableType():
|
|
|
|
... pass
|
2017-06-14 15:34:42 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
def custom_builder(cls):
|
|
|
|
|
|
|
|
class _Custom(cls, _Observable):
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-06-14 15:34:42 +02:00
|
|
|
_type = type
|
2017-08-14 16:29:17 +02:00
|
|
|
_properties = OrderedDict()
|
2017-08-14 17:52:34 +02:00
|
|
|
_properties.update([
|
2017-08-14 16:29:17 +02:00
|
|
|
('type', TypeProperty(_type)),
|
|
|
|
])
|
|
|
|
|
2017-08-28 20:30:53 +02:00
|
|
|
if not properties or not isinstance(properties, list):
|
2017-08-14 16:29:17 +02:00
|
|
|
raise ValueError("Must supply a list, containing tuples. For example, [('property1', IntegerProperty())]")
|
|
|
|
|
2017-08-30 21:33:28 +02:00
|
|
|
# Check properties ending in "_ref/s" are ObjectReferenceProperties
|
2017-08-31 21:52:48 +02:00
|
|
|
for prop_name, prop in properties:
|
2017-08-30 22:15:05 +02:00
|
|
|
if prop_name.endswith('_ref') and not isinstance(prop, ObjectReferenceProperty):
|
2017-08-30 21:33:28 +02:00
|
|
|
raise ValueError("'%s' is named like an object reference property but "
|
|
|
|
"is not an ObjectReferenceProperty." % prop_name)
|
2017-08-30 22:15:05 +02:00
|
|
|
elif (prop_name.endswith('_refs') and (not isinstance(prop, ListProperty)
|
|
|
|
or not isinstance(prop.contained, ObjectReferenceProperty))):
|
|
|
|
raise ValueError("'%s' is named like an object reference list property but "
|
2017-08-30 21:33:28 +02:00
|
|
|
"is not a ListProperty containing ObjectReferenceProperty." % prop_name)
|
|
|
|
|
2017-06-14 15:34:42 +02:00
|
|
|
_properties.update(properties)
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
_Observable.__init__(self, **kwargs)
|
2017-09-20 23:13:51 +02:00
|
|
|
try:
|
|
|
|
cls.__init__(self, **kwargs)
|
|
|
|
except (AttributeError, TypeError) as e:
|
|
|
|
# Don't accidentally catch errors raised in a custom __init__()
|
|
|
|
if ("has no attribute '__init__'" in str(e) or
|
|
|
|
str(e) == "object.__init__() takes no parameters"):
|
|
|
|
return
|
|
|
|
raise e
|
2017-06-14 15:34:42 +02:00
|
|
|
|
2017-07-14 20:55:57 +02:00
|
|
|
_register_observable(_Custom)
|
2017-06-14 15:34:42 +02:00
|
|
|
return _Custom
|
|
|
|
|
|
|
|
return custom_builder
|
2017-08-24 00:36:24 +02:00
|
|
|
|
|
|
|
|
|
|
|
def _register_extension(observable, new_extension):
|
|
|
|
"""Register a custom extension to a STIX Cyber Observable type.
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
observable_type = observable._type
|
|
|
|
except AttributeError:
|
2017-08-24 21:46:36 +02:00
|
|
|
raise ValueError("Unknown observable type. Custom observables must be "
|
|
|
|
"created with the @CustomObservable decorator.")
|
2017-08-24 00:36:24 +02:00
|
|
|
|
|
|
|
try:
|
|
|
|
EXT_MAP[observable_type][new_extension._type] = new_extension
|
|
|
|
except KeyError:
|
|
|
|
if observable_type not in OBJ_MAP_OBSERVABLE:
|
2017-08-24 21:46:36 +02:00
|
|
|
raise ValueError("Unknown observable type '%s'. Custom observables "
|
|
|
|
"must be created with the @CustomObservable decorator."
|
|
|
|
% observable_type)
|
2017-08-24 00:36:24 +02:00
|
|
|
else:
|
|
|
|
EXT_MAP[observable_type] = {new_extension._type: new_extension}
|
|
|
|
|
|
|
|
|
2017-10-06 20:24:46 +02:00
|
|
|
def CustomExtension(observable=None, type='x-custom-observable', properties=None):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Decorator for custom extensions to STIX Cyber Observables.
|
2017-08-24 00:36:24 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
if not observable or not issubclass(observable, _Observable):
|
|
|
|
raise ValueError("'observable' must be a valid Observable class!")
|
|
|
|
|
|
|
|
def custom_builder(cls):
|
|
|
|
|
|
|
|
class _Custom(cls, _Extension):
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_type = type
|
|
|
|
_properties = {
|
|
|
|
'extensions': ExtensionsProperty(enclosing_type=_type),
|
|
|
|
}
|
2017-10-06 20:24:46 +02:00
|
|
|
|
2017-10-06 21:05:39 +02:00
|
|
|
if not isinstance(properties, dict) or not properties:
|
2017-10-06 20:24:46 +02:00
|
|
|
raise ValueError("'properties' must be a dict!")
|
|
|
|
|
2017-08-24 00:36:24 +02:00
|
|
|
_properties.update(properties)
|
|
|
|
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
_Extension.__init__(self, **kwargs)
|
2017-09-20 23:13:51 +02:00
|
|
|
try:
|
|
|
|
cls.__init__(self, **kwargs)
|
|
|
|
except (AttributeError, TypeError) as e:
|
|
|
|
# Don't accidentally catch errors raised in a custom __init__()
|
|
|
|
if ("has no attribute '__init__'" in str(e) or
|
|
|
|
str(e) == "object.__init__() takes no parameters"):
|
|
|
|
return
|
|
|
|
raise e
|
2017-08-24 00:36:24 +02:00
|
|
|
|
|
|
|
_register_extension(observable, _Custom)
|
|
|
|
return _Custom
|
|
|
|
|
|
|
|
return custom_builder
|