Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ python:
- "3.4"
- "3.5"
- "3.6"
install: pip install tox-travis
install:
- pip install -U pip setuptools
- pip install tox-travis
script: tox
notifications:
email:
Expand Down
3 changes: 1 addition & 2 deletions cybox/bindings/pdf_file_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,11 +762,10 @@ def build(self, node):
def buildAttributes(self, node, attrs, already_processed):
value = find_attr_value_('type', node)
if value is not None:

self.type_ = value
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'ID':
obj_ = PDFFileIDType.factory()
obj_ = PDFIndirectObjectIDType.factory()
obj_.build(child_)
self.set_ID(obj_)
elif nodeName_ == 'Contents':
Expand Down
31 changes: 28 additions & 3 deletions cybox/bindings/unix_user_account_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,17 @@
from . import user_account_object


XML_NS = "http://cybox.mitre.org/objects#UnixUserAccountObject-2"


class UnixPrivilegeType(user_account_object.PrivilegeType):
"""The UnixPrivilegeType type is used to specify Unix privileges. It
extends the abstract user_account_object.PrivilegeType from the CybOX UserAccount
object."""
xmlns = XML_NS
xmlns_prefix = "UnixUserAccountObj"
xml_type = "UnixPrivilegeType"
xsi_type = "%s:%s" % (xmlns_prefix, xml_type)

subclass = None
superclass = user_account_object.PrivilegeType
Expand Down Expand Up @@ -55,6 +62,10 @@ def export(self, lwrite, level, namespace_='UnixUserAccountObj:', name_='UnixPri
lwrite('/>%s' % (eol_, ))
def exportAttributes(self, lwrite, level, already_processed, namespace_='UnixUserAccountObj:', name_='UnixPrivilegeType'):
super(UnixPrivilegeType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='UnixPrivilegeType')
if 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
xsi_type = " xsi:type='%s:%s'" % (self.xmlns_prefix, self.xml_type)
lwrite(xsi_type)
def exportChildren(self, lwrite, level, namespace_='UnixUserAccountObj:', name_='UnixPrivilegeType', fromsubclass_=False, pretty_print=True):
super(UnixPrivilegeType, self).exportChildren(lwrite, level, 'UnixUserAccountObj:', name_, True, pretty_print=pretty_print)
if pretty_print:
Expand Down Expand Up @@ -84,6 +95,10 @@ class UnixGroupType(user_account_object.GroupType):
"""The UnixGroupType type is used for specifying Unix groups. It
extends the abstract user_account_object.GroupType from the Cybox UserAccount
construct."""
xmlns = XML_NS
xmlns_prefix = "UnixUserAccountObj"
xml_type = "UnixGroupType"
xsi_type = "%s:%s" % (xmlns_prefix, xml_type)

subclass = None
superclass = user_account_object.GroupType
Expand Down Expand Up @@ -127,6 +142,10 @@ def export(self, lwrite, level, namespace_='UnixUserAccountObj:', name_='UnixGro
lwrite('/>%s' % (eol_, ))
def exportAttributes(self, lwrite, level, already_processed, namespace_='UnixUserAccountObj:', name_='UnixGroupType'):
super(UnixGroupType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='UnixGroupType')
if 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
xsi_type = " xsi:type='%s:%s'" % (self.xmlns_prefix, self.xml_type)
lwrite(xsi_type)
def exportChildren(self, lwrite, level, namespace_='UnixUserAccountObj:', name_='UnixGroupType', fromsubclass_=False, pretty_print=True):
super(UnixGroupType, self).exportChildren(lwrite, level, 'UnixUserAccountObj:', name_, True, pretty_print=pretty_print)
if pretty_print:
Expand All @@ -146,7 +165,7 @@ def buildAttributes(self, node, attrs, already_processed):
super(UnixGroupType, self).buildAttributes(node, attrs, already_processed)
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'Group_ID':
obj_ = cybox_common.UnsignedIntegerObjectPropertyType.factory()
obj_ = cybox_common.NonNegativeIntegerObjectPropertyType.factory()
obj_.build(child_)
self.set_Group_ID(obj_)
super(UnixGroupType, self).buildChildren(child_, node, nodeName_, True)
Expand Down Expand Up @@ -429,12 +448,18 @@ def main():
else:
usage()


# Register abstract types
setattr(user_account_object, "UnixGroupType", UnixGroupType)
setattr(user_account_object, "UnixPrivilegeType", UnixPrivilegeType)


if __name__ == '__main__':
#import pdb; pdb.set_trace()
main()

__all__ = [
"UnixUserAccountObjectType",
"UnixGroupType",
"UnixPrivilegeType"
"UnixPrivilegeType",
"UnixUserAccountObjectType"
]
4 changes: 2 additions & 2 deletions cybox/bindings/user_account_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def export(self, lwrite, level, namespace_='UserAccountObj:', name_='PrivilegeTy
else:
lwrite('/>%s' % (eol_, ))
def exportAttributes(self, lwrite, level, already_processed, namespace_='UserAccountObj:', name_='PrivilegeType'):
lwrite(' xsi:type="%s%s"' % (namespace_, name_))
pass
def exportChildren(self, lwrite, level, namespace_='UserAccountObj:', name_='PrivilegeType', fromsubclass_=False, pretty_print=True):
pass
def build(self, node):
Expand Down Expand Up @@ -268,7 +268,7 @@ def export(self, lwrite, level, namespace_='UserAccountObj:', name_='GroupType',
else:
lwrite('/>%s' % (eol_, ))
def exportAttributes(self, lwrite, level, already_processed, namespace_='UserAccountObj:', name_='GroupType'):
lwrite(' xsi:type="%s%s"' % (namespace_, name_))
pass
def exportChildren(self, lwrite, level, namespace_='UserAccountObj:', name_='GroupType', fromsubclass_=False, pretty_print=True):
pass
def build(self, node):
Expand Down
19 changes: 19 additions & 0 deletions cybox/bindings/win_user_account_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,16 @@
from . import user_account_object


XML_NS = "http://cybox.mitre.org/objects#WinUserAccountObject-2"


class WindowsPrivilegeType(user_account_object.PrivilegeType):
"""Windows Privilege represents a single privilege that a user may have
within Windows."""
xmlns = XML_NS
xmlns_prefix = "WinUserAccountObj"
xml_type = "WindowsPrivilegeType"
xsi_type = "%s:%s" % (xmlns_prefix, xml_type)

subclass = None
superclass = user_account_object.PrivilegeType
Expand Down Expand Up @@ -54,6 +61,10 @@ def export(self, lwrite, level, namespace_='WinUserAccountObj:', name_='WindowsP
lwrite('/>%s' % (eol_, ))
def exportAttributes(self, lwrite, level, already_processed, namespace_='WinUserAccountObj:', name_='WindowsPrivilegeType'):
super(WindowsPrivilegeType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='WindowsPrivilegeType')
if 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
xsi_type = " xsi:type='%s:%s'" % (self.xmlns_prefix, self.xml_type)
lwrite(xsi_type)
def exportChildren(self, lwrite, level, namespace_='WinUserAccountObj:', name_='WindowsPrivilegeType', fromsubclass_=False, pretty_print=True):
super(WindowsPrivilegeType, self).exportChildren(lwrite, level, 'WinUserAccountObj:', name_, True, pretty_print=pretty_print)
if pretty_print:
Expand Down Expand Up @@ -81,6 +92,10 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):

class WindowsGroupType(user_account_object.GroupType):
"""Windows Group represents a single windows group."""
xmlns = XML_NS
xmlns_prefix = "WinUserAccountObj"
xml_type = "WindowsGroupType"
xsi_type = "%s:%s" % (xmlns_prefix, xml_type)

subclass = None
superclass = user_account_object.GroupType
Expand Down Expand Up @@ -124,6 +139,10 @@ def export(self, lwrite, level, namespace_='WinUserAccountObj:', name_='WindowsG
lwrite('/>%s' % (eol_, ))
def exportAttributes(self, lwrite, level, already_processed, namespace_='WinUserAccountObj:', name_='WindowsGroupType'):
super(WindowsGroupType, self).exportAttributes(lwrite, level, already_processed, namespace_, name_='WindowsGroupType')
if 'xsi:type' not in already_processed:
already_processed.add('xsi:type')
xsi_type = " xsi:type='%s:%s'" % (self.xmlns_prefix, self.xml_type)
lwrite(xsi_type)
def exportChildren(self, lwrite, level, namespace_='WinUserAccountObj:', name_='WindowsGroupType', fromsubclass_=False, pretty_print=True):
super(WindowsGroupType, self).exportChildren(lwrite, level, 'WinUserAccountObj:', name_, True, pretty_print=pretty_print)
if pretty_print:
Expand Down
1 change: 1 addition & 0 deletions cybox/common/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class HashList(entities.EntityList):
_binding = common_binding
_binding_class = common_binding.HashListType
_namespace = 'http://cybox.mitre.org/common-2'

hashes = fields.TypedField("Hash", Hash, multiple=True)

@property
Expand Down
1 change: 1 addition & 0 deletions cybox/common/properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ def from_dict(cls, cls_dict):

return attr


class String(BaseProperty):
_binding_class = common_binding.StringObjectPropertyType
default_datatype = "string"
Expand Down
2 changes: 1 addition & 1 deletion cybox/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from .frequency import Frequency

from .object import (DomainSpecificObjectProperties, Object, RelatedObject,
Relationship)
Relationship)

from .action_reference import ActionReference
from .associated_object import AssociatedObject, AssociationType
Expand Down
30 changes: 25 additions & 5 deletions cybox/core/object.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.
from mixbox import entities
from mixbox import fields
Expand All @@ -7,6 +7,7 @@
import cybox
import cybox.utils
import cybox.bindings.cybox_core as core_binding
from cybox.common import StructuredText
from cybox.common.object_properties import ObjectPropertiesFactory, ObjectProperties
from cybox.common.vocabs import VocabField
from cybox.common.vocabs import ObjectRelationship as Relationship
Expand Down Expand Up @@ -46,26 +47,43 @@ def _cache_object(instance, value=None):


class Object(entities.Entity):
"""The CybOX Object element.
"""
The CybOX Object construct identifies and specifies the characteristics of
a specific cyber-relevant object (e.g. a file, a registry key or a
process).

Currently only supports the following data members:
- id\_
- idref
- has_changed
- description
- properties
- related_objects
- domain specific object properties
- domain_specific_object_properties

Notes:
By default ``cybox.core.object.Object`` will cache objects when
instantiated. If your are experiencing memory issues in your
environment, we encourage the use of ``cybox.utils.caches.cache_clear()``
in your script to prevent an Out of Memory error. Depending on your
use case, it can be after serialization or if a certain threshold is
met (e.g. %30 of memory consumed by cache mechanism).

"""
_binding = core_binding
_binding_class = _binding.ObjectType
_namespace = 'http://cybox.mitre.org/cybox-2'

id_ = fields.IdField("id", postset_hook=_cache_object)
idref = fields.IdrefField("idref")
has_changed = fields.TypedField("has_changed")
state = VocabField("State")
description = fields.TypedField("Description", StructuredText)
properties = fields.TypedField("Properties", ObjectProperties, factory=ObjectPropertiesFactory, postset_hook=_modify_properties_parent)
domain_specific_object_properties = fields.TypedField("Domain_Specific_Object_Properties", "cybox.core.object.DomainSpecificObjectProperties", factory=ExternalTypeFactory)
related_objects = fields.TypedField("Related_Objects", "cybox.core.object.RelatedObjects")
domain_specific_object_properties = fields.TypedField("Domain_Specific_Object_Properties", "cybox.core.DomainSpecificObjectProperties", factory=ExternalTypeFactory)

def __init__(self, properties=None, type_=None, id_=None, idref=None):
def __init__(self, properties=None, id_=None, idref=None):
super(Object, self).__init__()

if properties:
Expand Down Expand Up @@ -173,8 +191,10 @@ class RelatedObjects(entities.EntityList):
_namespace = "http://cybox.mitre.org/cybox-2"
_binding = core_binding
_binding_class = _binding.RelatedObjectsType

related_object = fields.TypedField("Related_Object", RelatedObject, multiple=True)


class DomainSpecificObjectProperties(entities.Entity):
"""The Cybox DomainSpecificObjectProperties base class."""
_binding = core_binding
Expand Down
2 changes: 2 additions & 0 deletions cybox/core/observable.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,10 @@ class Keywords(entities.EntityList):
_binding = core_binding
_binding_class = core_binding.KeywordsType
_namespace = 'http://cybox.mitre.org/cybox-2'

keyword = fields.TypedField("Keyword", Unicode, multiple=True)


class Observable(entities.Entity):
"""A single Observable.
"""
Expand Down
2 changes: 1 addition & 1 deletion cybox/objects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def get_class_for_object_type(self, object_type):
('UnixNetworkRouteEntryObjectType', None, 'unix_network_route_entry_object', 'http://cybox.mitre.org/objects#UnixNetworkRouteEntryObject-2', ['NetworkRouteEntryObjectType', 'AddressObjectType']),
('UnixPipeObjectType', None, 'unix_pipe_object', 'http://cybox.mitre.org/objects#UnixPipeObject', ['PipeObjectType']),
('UnixProcessObjectType', None, 'unix_process_object', 'http://cybox.mitre.org/objects#UnixProcessObject-2', ['ProcessObjectType', 'AddressObjectType', 'PortObjectType']),
('UnixUserAccountObjectType', None, 'unix_user_account_object', 'http://cybox.mitre.org/objects#UnixUserAccountObject-2', ['UserAccountObjectType', 'AccountObjectType']),
('UnixUserAccountObjectType', 'cybox.objects.unix_user_account_object.UnixUserAccount', 'unix_user_account_object', 'http://cybox.mitre.org/objects#UnixUserAccountObject-2', ['UserAccountObjectType', 'AccountObjectType']),
('UnixVolumeObjectType', None, 'unix_volume_object', 'http://cybox.mitre.org/objects#UnixVolumeObject-2', ['VolumeObjectType']),
('URIObjectType', 'cybox.objects.uri_object.URI', 'uri_object', 'http://cybox.mitre.org/objects#URIObject-2', []),
('URLHistoryObjectType', None, 'url_history_object', 'http://cybox.mitre.org/objects#URLHistoryObject-1', ['URIObjectType','HostnameObjectType']),
Expand Down
1 change: 0 additions & 1 deletion cybox/objects/account_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,3 @@ class Account(ObjectProperties):
creation_date = fields.TypedField("Creation_Date", DateTime)
modified_date = fields.TypedField("Modified_Date", DateTime)
last_accessed_time = fields.TypedField("Last_Accessed_Time", DateTime)

Loading