From 33e7f2f3c0e9e948b78b0494947bad29860f0a5b Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Fri, 17 Nov 2017 23:20:13 -0500 Subject: [PATCH 01/15] Implement new PDF objects and add test module --- cybox/bindings/pdf_file_object.py | 3 +- cybox/objects/pdf_file_object.py | 200 +++++++++++++++++++++++++++- cybox/test/objects/pdf_file_test.py | 70 ++++++++++ 3 files changed, 266 insertions(+), 7 deletions(-) create mode 100644 cybox/test/objects/pdf_file_test.py diff --git a/cybox/bindings/pdf_file_object.py b/cybox/bindings/pdf_file_object.py index 901489f3..f9893243 100644 --- a/cybox/bindings/pdf_file_object.py +++ b/cybox/bindings/pdf_file_object.py @@ -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': diff --git a/cybox/objects/pdf_file_object.py b/cybox/objects/pdf_file_object.py index 9d1f8c8f..5b044168 100644 --- a/cybox/objects/pdf_file_object.py +++ b/cybox/objects/pdf_file_object.py @@ -6,7 +6,38 @@ import cybox.bindings.pdf_file_object as pdf_file_binding from cybox.objects.file_object import File -from cybox.common import DateTime, PositiveInteger, String, NonNegativeInteger, Double +from cybox.common import (DateTime, HashList, PositiveInteger, String, + NonNegativeInteger, Double, HexBinary, Integer) + + +def validate_pdf_object_type(instance, value): + if value is None: + return + elif value in PDFIndirectObject.TYPES: + return + else: + err = "Type must be one of %s. Received '%s'." % (PDFIndirectObject.TYPES, value) + raise ValueError(err) + + +def validate_pdf_ref_entry_type(instance, value): + if value is None: + return + elif value in PDFXrefEntry.TYPES: + return + else: + err = "Type must be one of %s. Received '%s'." % (PDFXrefEntry.TYPES, value) + raise ValueError(err) + + +def validate_id_string(instance, value): + if value is None: + return + elif len(instance) > 2: + err = "ID_String only has a max occurrence of 2." + raise ValueError(err) + else: + return class PDFKeywordCount(entities.Entity): @@ -73,6 +104,166 @@ class PDFFileMetadata(entities.Entity): keyword_counts = fields.TypedField("Keyword_Counts", PDFKeywordCounts) +class PDFFileID(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFFileIDType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + id_string = fields.TypedField("ID_String", String, multiple=True, preset_hook=validate_id_string) + + +class PDFIndirectObjectID(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFIndirectObjectIDType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + object_number = fields.TypedField("Object_Number", PositiveInteger) + generation_number = fields.TypedField("Generation_Number", NonNegativeInteger) + + +class PDFDictionary(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFDictionaryType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + object_reference = fields.TypedField("Object_Reference", PDFIndirectObjectID) + raw_contents = fields.TypedField("Raw_Contents", String) + + +class PDFStream(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFStreamType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + raw_stream = fields.TypedField("Raw_Stream", String) + raw_stream_hashes = fields.TypedField("Raw_Stream_Hashes", HashList) + decoded_stream = fields.TypedField("Decoded_Stream", HexBinary) + decoded_stream_hashes = fields.TypedField("Decoded_Stream_Hashes", HashList) + + +class PDFIndirectObjectContents(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFIndirectObjectContentsType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + non_stream_contents = fields.TypedField("Non_Stream_Contents", String) + stream_contents = fields.TypedField("Stream_Contents", PDFStream) + + +class PDFIndirectObject(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFIndirectObjectType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + TYPE_BOOLEAN = "Boolean" + TYPE_INTEGER = "Integer" + TYPE_STRING = "String" + TYPE_NAME = "Name" + TYPE_ARRAY = "Array" + TYPE_DICTIONARY = "Dictionary" + TYPE_STREAM = "Stream" + TYPE_NULL = "Null" + TYPES = (TYPE_BOOLEAN, TYPE_INTEGER, TYPE_STRING, TYPE_NAME, TYPE_ARRAY, + TYPE_DICTIONARY, TYPE_STREAM, TYPE_NULL) + + type_ = fields.TypedField("type_", key_name="type", preset_hook=validate_pdf_object_type) + id_ = fields.TypedField("ID", PDFIndirectObjectID) + contents = fields.TypedField("Contents", PDFIndirectObjectContents) + offset = fields.TypedField("Offset", PositiveInteger) + hashes = fields.TypedField("Hashes", HashList) + + +class PDFIndirectObjectList(entities.EntityList): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFIndirectObjectListType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + indirect_object = fields.TypedField("Indirect_Object", PDFIndirectObject, multiple=True) + + +class PDFTrailer(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFTrailerType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + size = fields.TypedField("Size", PositiveInteger) + prev = fields.TypedField("Prev", PositiveInteger) + root = fields.TypedField("Root", PDFIndirectObjectID) + encrypt = fields.TypedField("Encrypt", PDFDictionary) + info = fields.TypedField("Info", PDFIndirectObjectID) + id_ = fields.TypedField("ID", PDFFileID) + last_cross_reference_offset = fields.TypedField("Last_Cross_Reference_Offset", PositiveInteger) + offset = fields.TypedField("Offset", PositiveInteger) + hashes = fields.TypedField("Hashes", HashList) + + +class PDFTrailerList(entities.EntityList): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFTrailerListType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + trailer = fields.TypedField("Trailer", PDFTrailer, multiple=True) + + +class PDFXrefEntry(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFXrefEntryType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + TYPE_USE = "In-Use" + TYPE_FREE = "Free" + TYPES = (TYPE_USE, TYPE_FREE) + + type_ = fields.TypedField("type_", key_name="type", preset_hook=validate_pdf_ref_entry_type) + byte_offset = fields.TypedField("Byte_Offset", Integer) + object_number = fields.TypedField("Object_Number", NonNegativeInteger) + generation_number = fields.TypedField("Generation_Number", NonNegativeInteger) + + +class PDFXrefEntryList(entities.EntityList): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFXrefEntryListType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + cross_reference_entry = fields.TypedField("Cross_Reference_Entry", PDFXrefEntry, multiple=True) + + +class PDFXrefTableSubsection(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFXrefTableSubsectionType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + first_object_number = fields.TypedField("First_Object_Number", NonNegativeInteger) + number_of_objects = fields.TypedField("Number_Of_Objects", NonNegativeInteger) + cross_reference_entries = fields.TypedField("Cross_Reference_Entries", PDFXrefEntryList) + + +class PDFXrefTableSubsectionList(entities.EntityList): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFXrefTableSubsectionListType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + subsection = fields.TypedField("Subsection", PDFXrefTableSubsection, multiple=True) + + +class PDFXRefTable(entities.Entity): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFXRefTableType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + subsections = fields.TypedField("Subsections", PDFXrefTableSubsectionList) + offset = fields.TypedField("Offset", PositiveInteger) + hashes = fields.TypedField("Hashes", HashList) + + +class PDFXRefTableList(entities.EntityList): + _binding = pdf_file_binding + _binding_class = pdf_file_binding.PDFXRefTableListType + _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + + cross_reference_table = fields.TypedField("Cross_Reference_Table", PDFXRefTable, multiple=True) + + class PDFFile(File): _binding = pdf_file_binding _binding_class = pdf_file_binding.PDFFileObjectType @@ -82,7 +273,6 @@ class PDFFile(File): metadata = fields.TypedField("Metadata", PDFFileMetadata) version = fields.TypedField("Version", Double) - #TODO: implement remaining elements - #indirect_objects = fields.TypedField("Indirect_Objects", PDFIndirectObjectList) - #cross_reference_tables = fields.TypedField("Cross_Reference_Tables", PDFXrefTableList) - #trailers = fields.TypedField("Trailers", PDFTrailerList) + indirect_objects = fields.TypedField("Indirect_Objects", PDFIndirectObjectList) + cross_reference_tables = fields.TypedField("Cross_Reference_Tables", PDFXRefTableList) + trailers = fields.TypedField("Trailers", PDFTrailerList) diff --git a/cybox/test/objects/pdf_file_test.py b/cybox/test/objects/pdf_file_test.py new file mode 100644 index 00000000..0a0a4459 --- /dev/null +++ b/cybox/test/objects/pdf_file_test.py @@ -0,0 +1,70 @@ +# Copyright (c) 2017, The MITRE Corporation. All rights reserved. +# See LICENSE.txt for complete terms. + +import unittest + +from cybox.objects.pdf_file_object import PDFFile + +from cybox.test.objects import ObjectTestCase + + +class TestArchiveFile(ObjectTestCase, unittest.TestCase): + object_type = 'PDFFileObjectType' + klass = PDFFile + + _full_dict = { + 'indirect_objects': [ + { + 'id': { + 'object_number': 1, + 'generation_number': 0 + }, + 'contents': { + 'non_stream_contents': '<< /Type /Catalog /Outlines 2 0 R>>' + } + }, + { + 'id': { + 'object_number': 2, + 'generation_number': 0 + }, + 'contents': { + 'non_stream_contents': '<< /Type Outlines /Count 0>>' + } + } + ], + 'file_name': 'test.pdf', + 'size_in_bytes': 25523, + 'trailers': [{ + 'last_cross_reference_offset': 408, + 'root': { + 'object_number': 1, + 'generation_number': 0 + }, + 'size': 3 + }], + 'version': 1.4, + 'cross_reference_tables': [{'subsections': [{ + 'cross_reference_entries': [ + { + 'byte_offset': 0, + 'generation_number': 65535 + }, + { + 'byte_offset': 9, + 'generation_number': 0 + }, + { + 'byte_offset': 74, + 'generation_number': 0 + } + ], + 'number_of_objects': 3, + 'first_object_number': 0 + }]}], + 'xsi:type': object_type + } + + +if __name__ == '__main__': + unittest.main() From a33820ca62845950b5f617f368d9e2572fe053bb Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Fri, 17 Nov 2017 23:21:05 -0500 Subject: [PATCH 02/15] Formatting fixes --- cybox/common/hashes.py | 1 + cybox/common/properties.py | 1 + cybox/core/__init__.py | 2 +- cybox/objects/account_object.py | 1 - cybox/objects/artifact_object.py | 2 +- cybox/objects/as_object.py | 1 + cybox/objects/code_object.py | 1 + cybox/objects/disk_object.py | 1 + cybox/objects/dns_cache_object.py | 3 +- cybox/objects/dns_query_object.py | 9 +- cybox/objects/file_object.py | 14 +- cybox/objects/http_session_object.py | 16 +- cybox/objects/memory_object.py | 3 +- cybox/objects/network_connection_object.py | 9 +- cybox/objects/network_packet_object.py | 141 ++++++------------ cybox/objects/network_subnet_object.py | 1 + cybox/objects/system_object.py | 4 + cybox/objects/user_account_object.py | 1 + cybox/objects/volume_object.py | 1 + cybox/objects/whois_object.py | 6 + cybox/objects/win_computer_account_object.py | 3 +- cybox/objects/win_driver_object.py | 1 + cybox/objects/win_event_log_object.py | 1 + cybox/objects/win_executable_file_object.py | 5 + cybox/objects/win_file_object.py | 2 + cybox/objects/win_handle_object.py | 3 +- cybox/objects/win_kernel_hook_object.py | 6 +- cybox/objects/win_kernel_object.py | 2 + .../objects/win_memory_page_region_object.py | 2 - cybox/objects/win_prefetch_object.py | 2 + cybox/objects/win_process_object.py | 1 + cybox/objects/win_registry_key_object.py | 3 +- cybox/objects/win_service_object.py | 1 + cybox/objects/win_system_object.py | 1 + cybox/objects/win_system_restore_object.py | 4 +- cybox/objects/win_task_object.py | 11 +- cybox/objects/win_volume_object.py | 1 + cybox/objects/x509_certificate_object.py | 1 + setup.py | 1 + 39 files changed, 121 insertions(+), 148 deletions(-) diff --git a/cybox/common/hashes.py b/cybox/common/hashes.py index 651ef50d..6cbdd911 100644 --- a/cybox/common/hashes.py +++ b/cybox/common/hashes.py @@ -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 diff --git a/cybox/common/properties.py b/cybox/common/properties.py index 0ac54644..9ce8e180 100644 --- a/cybox/common/properties.py +++ b/cybox/common/properties.py @@ -243,6 +243,7 @@ def from_dict(cls, cls_dict): return attr + class String(BaseProperty): _binding_class = common_binding.StringObjectPropertyType default_datatype = "string" diff --git a/cybox/core/__init__.py b/cybox/core/__init__.py index 4ae6d612..b66e3797 100644 --- a/cybox/core/__init__.py +++ b/cybox/core/__init__.py @@ -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 diff --git a/cybox/objects/account_object.py b/cybox/objects/account_object.py index 82255efb..5adfb9f0 100644 --- a/cybox/objects/account_object.py +++ b/cybox/objects/account_object.py @@ -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) - diff --git a/cybox/objects/artifact_object.py b/cybox/objects/artifact_object.py index ac20622e..29b9039c 100644 --- a/cybox/objects/artifact_object.py +++ b/cybox/objects/artifact_object.py @@ -63,7 +63,7 @@ class Artifact(ObjectProperties): hashes = fields.TypedField("Hashes", HashList) # packaging = fields.TypedField("Packaging", Packaging, multiple=True) # TODO: Support this as a TypedField - type_ = fields.TypedField("type_", key_name="type", preset_hook=validate_artifact_type) + type_ = fields.TypedField("type_", key_name="type", preset_hook=validate_artifact_type) content_type = fields.TypedField("content_type") content_type_version = fields.TypedField("content_type_version") suspected_malicious = fields.TypedField("suspected_malicious") diff --git a/cybox/objects/as_object.py b/cybox/objects/as_object.py index 7154afb7..ffe1c8dd 100644 --- a/cybox/objects/as_object.py +++ b/cybox/objects/as_object.py @@ -19,5 +19,6 @@ class AutonomousSystem(ObjectProperties): handle = fields.TypedField("Handle", String) regional_internet_registry = fields.TypedField("Regional_Internet_Registry", String) + # Add alias for the "proper", but completely unhelpful name, "AS" AS = AutonomousSystem diff --git a/cybox/objects/code_object.py b/cybox/objects/code_object.py index 1c5aff44..bc69c603 100644 --- a/cybox/objects/code_object.py +++ b/cybox/objects/code_object.py @@ -24,6 +24,7 @@ class TargetedPlatforms(entities.EntityList): _binding = code_binding _binding_class = code_binding.TargetedPlatformsType _namespace = "http://cybox.mitre.org/objects#CodeObject-2" + targeted_platform = fields.TypedField("Targeted_Platform", PlatformSpecification, multiple=True) diff --git a/cybox/objects/disk_object.py b/cybox/objects/disk_object.py index 39240eb7..c364f824 100644 --- a/cybox/objects/disk_object.py +++ b/cybox/objects/disk_object.py @@ -13,6 +13,7 @@ class PartitionList(entities.EntityList): _binding = disk_binding _binding_class = disk_binding.PartitionListType _namespace = "http://cybox.mitre.org/objects#DiskObject-2" + partition = fields.TypedField("Partition", DiskPartition, multiple=True) diff --git a/cybox/objects/dns_cache_object.py b/cybox/objects/dns_cache_object.py index adca421a..0dcddb33 100644 --- a/cybox/objects/dns_cache_object.py +++ b/cybox/objects/dns_cache_object.py @@ -25,5 +25,4 @@ class DNSCache(ObjectProperties): _XSI_NS = "DNSCacheObj" _XSI_TYPE = "DNSCacheObjectType" - dns_cache_entry = fields.TypedField("DNS_Cache_Entry", DNSCacheEntry, - multiple=True) + dns_cache_entry = fields.TypedField("DNS_Cache_Entry", DNSCacheEntry, multiple=True) diff --git a/cybox/objects/dns_query_object.py b/cybox/objects/dns_query_object.py index 85e3eedf..a8a3f899 100644 --- a/cybox/objects/dns_query_object.py +++ b/cybox/objects/dns_query_object.py @@ -37,11 +37,8 @@ class DNSQuery(ObjectProperties): successful = fields.TypedField("successful") transaction_id = fields.TypedField("Transaction_ID", HexBinary) question = fields.TypedField("Question", DNSQuestion) - answer_resource_records = fields.TypedField("Answer_Resource_Records", - DNSResourceRecords) - authority_resource_records = fields.TypedField("Authority_Resource_Records", - DNSResourceRecords) - additional_records = fields.TypedField("Additional_Records", - DNSResourceRecords) + answer_resource_records = fields.TypedField("Answer_Resource_Records", DNSResourceRecords) + authority_resource_records = fields.TypedField("Authority_Resource_Records", DNSResourceRecords) + additional_records = fields.TypedField("Additional_Records", DNSResourceRecords) date_ran = fields.TypedField("Date_Ran", DateTime) service_used = fields.TypedField("Service_Used", String) diff --git a/cybox/objects/file_object.py b/cybox/objects/file_object.py index 151cf1c3..ca92364a 100644 --- a/cybox/objects/file_object.py +++ b/cybox/objects/file_object.py @@ -43,6 +43,7 @@ class EntryPointSignatureList(entities.EntityList): _binding = file_binding _binding_class = file_binding.EntryPointSignatureListType _namespace = 'http://cybox.mitre.org/objects#FileObject-2' + entry_point_signature = fields.TypedField("Entry_Point_Signature", EntryPointSignature, multiple=True) @@ -64,6 +65,7 @@ class PackerList(entities.EntityList): _binding = file_binding _binding_class = file_binding.PackerListType _namespace = 'http://cybox.mitre.org/objects#FileObject-2' + packer = fields.TypedField("Packer", Packer, multiple=True) @@ -71,6 +73,7 @@ class SymLinksList(entities.EntityList): _binding = file_binding _binding_class = file_binding.SymLinksListType _namespace = 'http://cybox.mitre.org/objects#FileObject-2' + sym_link = fields.TypedField("Sym_Link", String, multiple=True) @@ -106,23 +109,20 @@ class File(ObjectProperties): magic_number = fields.TypedField("Magic_Number", HexBinary) file_format = fields.TypedField("File_Format", String) hashes = fields.TypedField("Hashes", HashList) - digital_signatures = fields.TypedField("Digital_Signatures", - DigitalSignatureList) + digital_signatures = fields.TypedField("Digital_Signatures", DigitalSignatureList) modified_time = fields.TypedField("Modified_Time", DateTime) accessed_time = fields.TypedField("Accessed_Time", DateTime) created_time = fields.TypedField("Created_Time", DateTime) # Subclasses must redefine these, since the abstract types # cannot be instantiated. - file_attributes_list = fields.TypedField("File_Attributes_List", - FileAttribute) # abstract - permissions = fields.TypedField("Permissions", FilePermissions) # abstract + file_attributes_list = fields.TypedField("File_Attributes_List", FileAttribute) # abstract + permissions = fields.TypedField("Permissions", FilePermissions) # abstract user_owner = fields.TypedField("User_Owner", String) packer_list = fields.TypedField("Packer_List", PackerList) peak_entropy = fields.TypedField("Peak_Entropy", Double) sym_links = fields.TypedField("Sym_Links", SymLinksList) byte_runs = fields.TypedField("Byte_Runs", ByteRuns) - extracted_features = fields.TypedField("Extracted_Features", - ExtractedFeatures) + extracted_features = fields.TypedField("Extracted_Features", ExtractedFeatures) encryption_algorithm = fields.TypedField("Encryption_Algorithm", String) decryption_key = fields.TypedField("Decryption_Key", String) compression_method = fields.TypedField("Compression_Method", String) diff --git a/cybox/objects/http_session_object.py b/cybox/objects/http_session_object.py index 6221a79c..d68dbb41 100644 --- a/cybox/objects/http_session_object.py +++ b/cybox/objects/http_session_object.py @@ -97,8 +97,7 @@ class HTTPClientRequest(entities.Entity): _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2" http_request_line = fields.TypedField("HTTP_Request_Line", HTTPRequestLine) - http_request_header = fields.TypedField("HTTP_Request_Header", - HTTPRequestHeader) + http_request_header = fields.TypedField("HTTP_Request_Header", HTTPRequestHeader) http_message_body = fields.TypedField("HTTP_Message_Body", HTTPMessage) @@ -117,8 +116,7 @@ class HTTPResponseHeaderFields(entities.Entity): _binding_class = http_session_binding.HTTPResponseHeaderFieldsType _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2" - access_control_allow_origin = \ - fields.TypedField("Access_Control_Allow_Origin", String) + access_control_allow_origin = fields.TypedField("Access_Control_Allow_Origin", String) accept_ranges = fields.TypedField("Accept_Ranges", String) age = fields.TypedField("Age", Integer) cache_control = fields.TypedField("Cache_Control", String) @@ -144,8 +142,7 @@ class HTTPResponseHeaderFields(entities.Entity): retry_after = fields.TypedField("Retry_After", Integer) server = fields.TypedField("Server", String) set_cookie = fields.TypedField("Set_Cookie", String) - strict_transport_security = fields.TypedField("Strict_Transport_Security", - String) + strict_transport_security = fields.TypedField("Strict_Transport_Security", String) trailer = fields.TypedField("Trailer", String) transfer_encoding = fields.TypedField("Transfer_Encoding", String) vary = fields.TypedField("Vary", String) @@ -174,8 +171,7 @@ class HTTPServerResponse(entities.Entity): _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2" http_status_line = fields.TypedField("HTTP_Status_Line", HTTPStatusLine) - http_response_header = fields.TypedField("HTTP_Response_Header", - HTTPResponseHeader) + http_response_header = fields.TypedField("HTTP_Response_Header", HTTPResponseHeader) http_message_body = fields.TypedField("HTTP_Message_Body", HTTPMessage) @@ -197,6 +193,4 @@ class HTTPSession(ObjectProperties): _XSI_NS = "HTTPSessionObj" _XSI_TYPE = "HTTPSessionObjectType" - http_request_response = fields.TypedField("HTTP_Request_Response", - HTTPRequestResponse, - multiple=True) + http_request_response = fields.TypedField("HTTP_Request_Response", HTTPRequestResponse, multiple=True) diff --git a/cybox/objects/memory_object.py b/cybox/objects/memory_object.py index 2193af10..1775d58a 100644 --- a/cybox/objects/memory_object.py +++ b/cybox/objects/memory_object.py @@ -26,5 +26,4 @@ class Memory(ObjectProperties): block_type = fields.TypedField("Block_Type", String) region_start_address = fields.TypedField("Region_Start_Address", HexBinary) region_end_address = fields.TypedField("Region_End_Address", HexBinary) - extracted_features = fields.TypedField("Extracted_Features", - ExtractedFeatures) + extracted_features = fields.TypedField("Extracted_Features", ExtractedFeatures) diff --git a/cybox/objects/network_connection_object.py b/cybox/objects/network_connection_object.py index fae1100f..51ddfcdd 100644 --- a/cybox/objects/network_connection_object.py +++ b/cybox/objects/network_connection_object.py @@ -32,11 +32,8 @@ class NetworkConnection(ObjectProperties): layer3_protocol = fields.TypedField('Layer3_Protocol', String) layer4_protocol = fields.TypedField('Layer4_Protocol', String) layer7_protocol = fields.TypedField('Layer7_Protocol', String) - source_socket_address = fields.TypedField('Source_Socket_Address', - SocketAddress) + source_socket_address = fields.TypedField('Source_Socket_Address', SocketAddress) source_tcp_state = fields.TypedField('Source_TCP_State') - destination_socket_address = fields.TypedField('Destination_Socket_Address', - SocketAddress) + destination_socket_address = fields.TypedField('Destination_Socket_Address', SocketAddress) destination_tcp_state = fields.TypedField('Destination_TCP_State') - layer7_connections = fields.TypedField('Layer7_Connections', - Layer7Connections) + layer7_connections = fields.TypedField('Layer7_Connections', Layer7Connections) diff --git a/cybox/objects/network_packet_object.py b/cybox/objects/network_packet_object.py index df26f39f..0401a3bb 100644 --- a/cybox/objects/network_packet_object.py +++ b/cybox/objects/network_packet_object.py @@ -105,8 +105,7 @@ class RouterSolicitation(entities.Entity): _binding_class = network_packet_binding.RouterSolicitationType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - options = fields.TypedField("Options", RouterSolicitationOptions, - multiple=True) + options = fields.TypedField("Options", RouterSolicitationOptions, multiple=True) class NDPMTU(entities.Entity): @@ -123,7 +122,7 @@ class Prefix(entities.Entity): _binding_class = network_packet_binding.PrefixType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice + # TODO: choice ipv6_addr = fields.TypedField("IPv6_Addr", Address) ip_addr_prefix = fields.TypedField("IP_Addr_Prefix", Address) @@ -147,7 +146,7 @@ class RouterAdvertisementOptions(entities.Entity): _binding_class = network_packet_binding.RouterAdvertisementOptionsType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice + # TODO: choice src_link_addr = fields.TypedField("Src_Link_Addr", NDPLinkAddr) mtu = fields.TypedField("MTU", NDPMTU) prefix_info = fields.TypedField("Prefix_Info", NDPPrefixInfo) @@ -158,8 +157,7 @@ class RouterAdvertisement(entities.Entity): _binding_class = network_packet_binding.RouterAdvertisementType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - managed_address_config_flag = \ - fields.TypedField("managed_address_config_flag") + managed_address_config_flag = fields.TypedField("managed_address_config_flag") other_config_flag = fields.TypedField("other_config_flag") cur_hop_limit = fields.TypedField("Cur_Hop_Limit", Integer) router_lifetime = fields.TypedField("Router_Lifetime", Integer) @@ -220,8 +218,7 @@ class RedirectOptions(entities.Entity): _namespace = "http://cybox.mitre.org/objects#PacketObject-2" target_link_addr = fields.TypedField("Target_Link_Addr", NDPLinkAddr) - redirected_header = fields.TypedField("Redirected_Header", - NDPRedirectedHeader) + redirected_header = fields.TypedField("Redirected_Header", NDPRedirectedHeader) class Redirect(entities.Entity): @@ -242,14 +239,10 @@ class NDP(entities.Entity): icmpv6_header = fields.TypedField("ICMPv6_Header", ICMPv6Header) #TODO: choice between these 5 - router_solicitation = fields.TypedField("Router_Solicitation", - RouterSolicitation) - router_advertisement = fields.TypedField("Router_Advertisement", - RouterAdvertisement) - neighbor_solicitation = fields.TypedField("Neighbor_Solicitation", - NeighborSolicitation) - neighbor_advertisement = fields.TypedField("Neighbor_Advertisement", - NeighborAdvertisement) + router_solicitation = fields.TypedField("Router_Solicitation", RouterSolicitation) + router_advertisement = fields.TypedField("Router_Advertisement", RouterAdvertisement) + neighbor_solicitation = fields.TypedField("Neighbor_Solicitation", NeighborSolicitation) + neighbor_advertisement = fields.TypedField("Neighbor_Advertisement", NeighborAdvertisement) redirect = fields.TypedField("Redirect", Redirect) @@ -340,35 +333,23 @@ class ICMPv4DestinationUnreachable(entities.Entity): _binding_class = network_packet_binding.ICMPv4DestinationUnreachableType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice - destination_network_unreachable = \ - fields.TypedField("Destination_Network_Unreachable") - destination_host_unreachable = \ - fields.TypedField("Destination_Host_Unreachable") - destination_protocol_unreachable = \ - fields.TypedField("Destination_Protocol_Unreachable") - destination_port_unreachable = \ - fields.TypedField("Destination_Port_Unreachable") - fragmentation_required = fields.TypedField("Fragmentation_Required", - FragmentationRequired) + # TODO: choice + destination_network_unreachable = fields.TypedField("Destination_Network_Unreachable") + destination_host_unreachable = fields.TypedField("Destination_Host_Unreachable") + destination_protocol_unreachable = fields.TypedField("Destination_Protocol_Unreachable") + destination_port_unreachable = fields.TypedField("Destination_Port_Unreachable") + fragmentation_required = fields.TypedField("Fragmentation_Required", FragmentationRequired) source_route_failed = fields.TypedField("Source_Route_Failed") - destination_network_unknown = \ - fields.TypedField("Destination_Network_Unknown") + destination_network_unknown = fields.TypedField("Destination_Network_Unknown") destination_host_unknown = fields.TypedField("Destination_Host_Unknown") source_host_isolated = fields.TypedField("Source_Host_Isolated") - network_administratively_prohibited = \ - fields.TypedField("Network_Administratively_Prohibited") - host_administratively_prohibited = \ - fields.TypedField("Host_Administratively_Prohibited") - network_unreachable_for_tos = \ - fields.TypedField("Network_Unreachable_For_TOS") - host_unreachable_for_tos = \ - fields.TypedField("Host_Unreachable_For_TOS") - communication_administratively_prohibited = \ - fields.TypedField("Communication_Administratively_Prohibited") + network_administratively_prohibited = fields.TypedField("Network_Administratively_Prohibited") + host_administratively_prohibited = fields.TypedField("Host_Administratively_Prohibited") + network_unreachable_for_tos = fields.TypedField("Network_Unreachable_For_TOS") + host_unreachable_for_tos = fields.TypedField("Host_Unreachable_For_TOS") + communication_administratively_prohibited = fields.TypedField("Communication_Administratively_Prohibited") host_precedence_violation = fields.TypedField("Host_Precedence_Violation") - precedence_cutoff_in_effect = \ - fields.TypedField("Precedence_Cutoff_In_Effect") + precedence_cutoff_in_effect = fields.TypedField("Precedence_Cutoff_In_Effect") class ICMPv4SourceQuench(entities.Entity): @@ -389,7 +370,6 @@ class ICMPv4RedirectMessage(entities.Entity): host_redirect = fields.TypedField("Host_Redirect") tos_network_redirect = fields.TypedField("ToS_Network_Redirect") tos_host_redirect = fields.TypedField("ToS_Host_Redirect") - ip_address = fields.TypedField("IP_Address", Address) @@ -400,8 +380,7 @@ class ICMPv4TimeExceeded(entities.Entity): # TODO: choice ttl_exceeded_in_transit = fields.TypedField("TTL_Exceeded_In_Transit") - frag_reassembly_time_exceeded = \ - fields.TypedField("Frag_Reassembly_Time_Exceeded") + frag_reassembly_time_exceeded = fields.TypedField("Frag_Reassembly_Time_Exceeded") class ICMPv4ErrorMessageContent(entities.Entity): @@ -418,14 +397,11 @@ class ICMPv4ErrorMessage(entities.Entity): _binding_class = network_packet_binding.ICMPv4ErrorMessageType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - destination_unreachable = fields.TypedField("Destination_Unreachable", - ICMPv4DestinationUnreachable) + destination_unreachable = fields.TypedField("Destination_Unreachable", ICMPv4DestinationUnreachable) source_quench = fields.TypedField("Source_Quench", ICMPv4SourceQuench) - redirect_message = fields.TypedField("Redirect_Message", - ICMPv4RedirectMessage) + redirect_message = fields.TypedField("Redirect_Message", ICMPv4RedirectMessage) time_exceeded = fields.TypedField("Time_Exceeded", ICMPv4TimeExceeded) - error_msg_content = fields.TypedField("Error_Msg_Content", - ICMPv4ErrorMessageContent) + error_msg_content = fields.TypedField("Error_Msg_Content", ICMPv4ErrorMessageContent) class _ICMPEchoReply(entities.Entity): @@ -466,8 +442,7 @@ class ICMPv4TimestampRequest(entities.Entity): _namespace = "http://cybox.mitre.org/objects#PacketObject-2" timestamp = fields.TypedField("Timestamp") - originate_timestamp = fields.TypedField("Originate_Timestamp", - UnsignedInteger) + originate_timestamp = fields.TypedField("Originate_Timestamp", UnsignedInteger) class ICMPv4TimestampReply(entities.Entity): @@ -476,12 +451,9 @@ class ICMPv4TimestampReply(entities.Entity): _namespace = "http://cybox.mitre.org/objects#PacketObject-2" timestamp_reply = fields.TypedField("Timestamp_Reply") - originate_timestamp = fields.TypedField("Originate_Timestamp", - UnsignedInteger) - receive_timestamp = fields.TypedField("Receive_Timestamp", - UnsignedInteger) - transmit_timestamp = fields.TypedField("Transmit_Timestamp", - UnsignedInteger) + originate_timestamp = fields.TypedField("Originate_Timestamp", UnsignedInteger) + receive_timestamp = fields.TypedField("Receive_Timestamp", UnsignedInteger) + transmit_timestamp = fields.TypedField("Transmit_Timestamp", UnsignedInteger) class ICMPv4AddressMaskRequest(entities.Entity): @@ -526,16 +498,11 @@ class ICMPv4InfoMessage(entities.Entity): #TODO: choice of first 6 echo_reply = fields.TypedField("Echo_Reply", ICMPv4EchoReply) echo_request = fields.TypedField("Echo_Request", ICMPv4EchoRequest) - timestamp_request = fields.TypedField("Timestamp_Request", - ICMPv4TimestampRequest) + timestamp_request = fields.TypedField("Timestamp_Request", ICMPv4TimestampRequest) timestamp_reply = fields.TypedField("Timestamp_Reply", ICMPv4TimestampReply) - address_mask_request = fields.TypedField("Address_Mask_Request", - ICMPv4AddressMaskRequest) - address_mask_reply = fields.TypedField("Address_Mask_Reply", - ICMPv4AddressMaskReply) - - info_msg_content = fields.TypedField("Info_Msg_Content", - ICMPv4InfoMessageContent) + address_mask_request = fields.TypedField("Address_Mask_Request", ICMPv4AddressMaskRequest) + address_mask_reply = fields.TypedField("Address_Mask_Reply", ICMPv4AddressMaskReply) + info_msg_content = fields.TypedField("Info_Msg_Content", ICMPv4InfoMessageContent) class ICMPv4Traceroute(entities.Entity): @@ -543,8 +510,7 @@ class ICMPv4Traceroute(entities.Entity): _binding_class = network_packet_binding.ICMPv4TracerouteType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - outbound_packet_forward_success = \ - fields.TypedField("Outbound_Packet_Forward_Success") + outbound_packet_forward_success = fields.TypedField("Outbound_Packet_Forward_Success") outbound_packet_no_route = fields.TypedField("Outbound_Packet_no_Route") identifier = fields.TypedField("Identifier", HexBinary) outbound_hop_count = fields.TypedField("Outbound_Hop_Count", HexBinary) @@ -617,7 +583,7 @@ class OptionData(entities.Entity): option_type = fields.TypedField("Option_Type", IPv6Option) option_data_len = fields.TypedField("Option_Data_Len", HexBinary) - #TODO: choice + # TODO: choice pad1 = fields.TypedField("Pad1", Pad1) padn = fields.TypedField("PadN", PadN) @@ -679,8 +645,7 @@ class AuthenticationHeader(entities.Entity): next_header = fields.TypedField("Next_Header", String) header_ext_len = fields.TypedField("Header_Ext_Len", HexBinary) - security_parameters_index = fields.TypedField("Security_Parameters_Index", - HexBinary) + security_parameters_index = fields.TypedField("Security_Parameters_Index", HexBinary) sequence_number = fields.TypedField("Sequence_Number", HexBinary) authentication_data = fields.TypedField("Authentication_Data", HexBinary) @@ -690,8 +655,7 @@ class EncapsulatingSecurityPayload(entities.Entity): _binding_class = network_packet_binding.EncapsulatingSecurityPayloadType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - security_parameters_index = fields.TypedField("Security_Parameters_Index", - HexBinary) + security_parameters_index = fields.TypedField("Security_Parameters_Index", HexBinary) sequence_number = fields.TypedField("Sequence_Number", HexBinary) payload_data = fields.TypedField("Payload_Data", HexBinary) padding = fields.TypedField("Padding", HexBinary) @@ -705,7 +669,7 @@ class IPv6ExtHeader(entities.Entity): _binding_class = network_packet_binding.IPv6ExtHeaderType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice + # TODO: choice hop_by_hop_options = fields.TypedField("Hop_by_Hop_Options", HopByHopOptions) routing = fields.TypedField("Routing", Routing) fragment = fields.TypedField("Fragment", Fragment) @@ -729,7 +693,7 @@ class ICMPv6DestinationUnreachable(entities.Entity): _binding_class = network_packet_binding.ICMPv6DestinationUnreachableType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice + # TODO: choice no_route = fields.TypedField("No_Route") comm_prohibited = fields.TypedField("Comm_Prohibited") beyond_scope = fields.TypedField("Beyond_Scope") @@ -753,10 +717,9 @@ class ICMPv6TimeExceeded(entities.Entity): _binding_class = network_packet_binding.ICMPv6TimeExceededType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice + # TODO: choice hop_limit_exceeded = fields.TypedField("Hop_Limit_Exceeded") - fragment_reassem_time_exceeded = \ - fields.TypedField("Fragment_Reassem_Time_Exceeded") + fragment_reassem_time_exceeded = fields.TypedField("Fragment_Reassem_Time_Exceeded") class ICMPv6ParameterProblem(entities.Entity): @@ -764,12 +727,10 @@ class ICMPv6ParameterProblem(entities.Entity): _binding_class = network_packet_binding.ICMPv6ParameterProblemType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice of first 3 + # TODO: choice of first 3 erroneous_header_field = fields.TypedField("Erroneous_Header_Field") - unrecognized_next_header_type = \ - fields.TypedField("Unrecognized_Next_Header_Type") + unrecognized_next_header_type = fields.TypedField("Unrecognized_Next_Header_Type") unrecognized_ipv6_option = fields.TypedField("Unrecognized_IPv6_Option") - pointer = fields.TypedField("Pointer", HexBinary) @@ -778,12 +739,10 @@ class ICMPv6ErrorMessage(entities.Entity): _binding_class = network_packet_binding.ICMPv6ErrorMessageType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - destination_unreachable = fields.TypedField("Destination_Unreachable", - ICMPv6DestinationUnreachable) + destination_unreachable = fields.TypedField("Destination_Unreachable", ICMPv6DestinationUnreachable) packet_too_big = fields.TypedField("Packet_Too_Big", ICMPv6PacketTooBig) time_exceeded = fields.TypedField("Time_Exceeded", ICMPv6TimeExceeded) - parameter_problem = fields.TypedField("Parameter_Problem", - ICMPv6ParameterProblem) + parameter_problem = fields.TypedField("Parameter_Problem", ICMPv6ParameterProblem) invoking_packet = fields.TypedField("Invoking_Packet", HexBinary) @@ -792,12 +751,10 @@ class ICMPv6InfoMessage(entities.Entity): _binding_class = network_packet_binding.ICMPv6InfoMessageType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice of first 2 + # TODO: choice of first 2 echo_request = fields.TypedField("Echo_Request", ICMPv6EchoRequest) echo_reply = fields.TypedField("Echo_Reply", ICMPv6EchoReply) - - info_msg_content = fields.TypedField("Info_Msg_Content", - ICMPv6InfoMessageContent) + info_msg_content = fields.TypedField("Info_Msg_Content", ICMPv6InfoMessageContent) class ICMPv6Packet(entities.Entity): @@ -815,7 +772,7 @@ class InternetLayer(entities.Entity): _binding_class = network_packet_binding.InternetLayerType _namespace = "http://cybox.mitre.org/objects#PacketObject-2" - #TODO: choice + # TODO: choice ipv4 = fields.TypedField("IPv4", IPv4Packet) icmpv4 = fields.TypedField("ICMPv4", ICMPv4Packet) ipv6 = fields.TypedField("IPv6", IPv6Packet) diff --git a/cybox/objects/network_subnet_object.py b/cybox/objects/network_subnet_object.py index 707aab50..dc82f573 100644 --- a/cybox/objects/network_subnet_object.py +++ b/cybox/objects/network_subnet_object.py @@ -13,6 +13,7 @@ class Routes(entities.EntityList): _binding = network_subnet_binding _binding_class = network_subnet_binding.RoutesType _namespace = "http://cybox.mitre.org/objects#NetworkSubnetObject-2" + route = fields.TypedField("Route", NetworkRouteEntry, multiple=True) diff --git a/cybox/objects/system_object.py b/cybox/objects/system_object.py index df25f5fc..0509a5d3 100644 --- a/cybox/objects/system_object.py +++ b/cybox/objects/system_object.py @@ -13,12 +13,14 @@ class DHCPServerList(entities.EntityList): _binding_class = system_binding.DHCPServerListType _namespace = "http://cybox.mitre.org/objects#SystemObject-2" + dhcp_server_address = fields.TypedField("DHCP_Server_Address", Address, multiple=True) class IPGatewayList(entities.EntityList): _binding_class = system_binding.IPGatewayListType _namespace = "http://cybox.mitre.org/objects#SystemObject-2" + ip_gateway_address = fields.TypedField("IP_Gateway_Address", Address, multiple=True) @@ -34,6 +36,7 @@ class IPInfo(entities.Entity): class IPInfoList(entities.EntityList): _binding_class = system_binding.IPInfoListType _namespace = "http://cybox.mitre.org/objects#SystemObject-2" + ip_info_list = fields.TypedField("IP_Info_List", IPInfo, multiple=True) @@ -80,6 +83,7 @@ class NetworkInterface(entities.Entity): class NetworkInterfaceList(entities.EntityList): _binding_class = system_binding.NetworkInterfaceListType _namespace = "http://cybox.mitre.org/objects#SystemObject-2" + network_interface = fields.TypedField("Network_Interface", NetworkInterface, multiple=True) diff --git a/cybox/objects/user_account_object.py b/cybox/objects/user_account_object.py index 229289d1..d5f4c9df 100644 --- a/cybox/objects/user_account_object.py +++ b/cybox/objects/user_account_object.py @@ -34,6 +34,7 @@ class PrivilegeList(entities.EntityList): _binding = user_account_binding _binding_class = user_account_binding.PrivilegeListType _namespace = 'http://cybox.mitre.org/objects#UserAccountObject-2' + privilege = fields.TypedField("Privilege", Privilege, multiple=True) diff --git a/cybox/objects/volume_object.py b/cybox/objects/volume_object.py index d6972629..cc739340 100644 --- a/cybox/objects/volume_object.py +++ b/cybox/objects/volume_object.py @@ -12,6 +12,7 @@ class FileSystemFlagList(entities.EntityList): _binding = volume_binding _binding_class = volume_binding.FileSystemFlagListType _namespace = "http://cybox.mitre.org/objects#VolumeObject-2" + file_system_flag = fields.TypedField("File_System_Flag", String, multiple=True) diff --git a/cybox/objects/whois_object.py b/cybox/objects/whois_object.py index ab00a441..f6684c75 100644 --- a/cybox/objects/whois_object.py +++ b/cybox/objects/whois_object.py @@ -16,8 +16,10 @@ class WhoisNameservers(entities.EntityList): _binding = whois_binding _binding_class = whois_binding.WhoisNameserversType _namespace = "http://cybox.mitre.org/objects#WhoisObject-2" + nameserver = fields.TypedField("Nameserver", URI, multiple=True) + class WhoisStatus(BaseProperty): _binding = whois_binding _binding_class = whois_binding.WhoisStatusType @@ -29,8 +31,10 @@ class WhoisStatuses(entities.EntityList): _binding = whois_binding _binding_class = whois_binding.WhoisStatusesType _namespace = "http://cybox.mitre.org/objects#WhoisObject-2" + status = fields.TypedField("Status", WhoisStatus, multiple=True) + class WhoisContact(entities.Entity): _binding = whois_binding _binding_class = whois_binding.WhoisContactType @@ -50,6 +54,7 @@ class WhoisContacts(entities.EntityList): _binding = whois_binding _binding_class = whois_binding.WhoisContactsType _namespace = "http://cybox.mitre.org/objects#WhoisObject-2" + contact = fields.TypedField("Contact", WhoisContact, multiple=True) @@ -65,6 +70,7 @@ class WhoisRegistrants(entities.EntityList): _binding = whois_binding _binding_class = whois_binding.WhoisRegistrantsType _namespace = "http://cybox.mitre.org/objects#WhoisObject-2" + registrant = fields.TypedField("Registrant", WhoisRegistrant, multiple=True) diff --git a/cybox/objects/win_computer_account_object.py b/cybox/objects/win_computer_account_object.py index 64640207..59b5c9ce 100644 --- a/cybox/objects/win_computer_account_object.py +++ b/cybox/objects/win_computer_account_object.py @@ -55,8 +55,7 @@ class WinComputerAccount(Account): _XSI_NS = "WinComputerAccountObj" _XSI_TYPE = "WindowsComputerAccountObjectType" - fully_qualified_name = fields.TypedField("Fully_Qualified_Name", - FullyQualifiedName) + fully_qualified_name = fields.TypedField("Fully_Qualified_Name", FullyQualifiedName) kerberos = fields.TypedField("Kerberos", Kerberos) security_id = fields.TypedField("Security_ID", String) # TODO: implement common.SIDType diff --git a/cybox/objects/win_driver_object.py b/cybox/objects/win_driver_object.py index 8a4a5b6a..4f7c789d 100644 --- a/cybox/objects/win_driver_object.py +++ b/cybox/objects/win_driver_object.py @@ -32,6 +32,7 @@ class DeviceObjectList(entities.EntityList): _namespace = "http://cybox.mitre.org/objects#WinDriverObject-3" _XSI_NS = "WinDriverObj" _XSI_TYPE = "DeviceObjectListType" + device_object_struct = fields.TypedField("Device_Object_Struct", DeviceObjectStruct, multiple=True) diff --git a/cybox/objects/win_event_log_object.py b/cybox/objects/win_event_log_object.py index 34164b34..7fd9c78b 100644 --- a/cybox/objects/win_event_log_object.py +++ b/cybox/objects/win_event_log_object.py @@ -12,6 +12,7 @@ class UnformattedMessageList(entities.EntityList): _binding = win_event_log_binding _binding_class = win_event_log_binding.UnformattedMessageListType _namespace = "http://cybox.mitre.org/objects#WinEventLogObject-2" + unformatted_message = fields.TypedField("Unformatted_Message", String, multiple=True) diff --git a/cybox/objects/win_executable_file_object.py b/cybox/objects/win_executable_file_object.py index 2e4a8507..19dbab08 100644 --- a/cybox/objects/win_executable_file_object.py +++ b/cybox/objects/win_executable_file_object.py @@ -44,6 +44,7 @@ class PEExportedFunction(entities.Entity): class PEExportedFunctions(entities.EntityList): _binding_class = win_executable_file_binding.PEExportedFunctionsType _namespace = "http://cybox.mitre.org/objects#WinExecutableFileObject-2" + exported_function = fields.TypedField("Exported_Function", PEExportedFunction, multiple=True) @@ -201,6 +202,7 @@ class PEImportedFunction(entities.Entity): class PEImportedFunctions(entities.EntityList): _binding_class = win_executable_file_binding.PEImportedFunctionsType _namespace = "http://cybox.mitre.org/objects#WinExecutableFileObject-2" + imported_function = fields.TypedField("Imported_Function", PEImportedFunction, multiple=True) @@ -219,6 +221,7 @@ class PEImport(entities.Entity): class PEImportList(entities.EntityList): _binding_class = win_executable_file_binding.PEImportListType _namespace = "http://cybox.mitre.org/objects#WinExecutableFileObject-2" + import_ = fields.TypedField("Import", PEImport, multiple=True) @@ -250,6 +253,7 @@ class PEResource(entities.Entity): class PEResourceList(entities.EntityList): _binding_class = win_executable_file_binding.PEResourceListType _namespace = "http://cybox.mitre.org/objects#WinExecutableFileObject-2" + resource = fields.TypedField("Resource", PEResource, multiple=True) #VersionInfoResource temporary fix @@ -301,6 +305,7 @@ class PESection(entities.Entity): class PESectionList(entities.EntityList): _binding_class = win_executable_file_binding.PESectionListType _namespace = "http://cybox.mitre.org/objects#WinExecutableFileObject-2" + section = fields.TypedField("Section", PESection, multiple=True) diff --git a/cybox/objects/win_file_object.py b/cybox/objects/win_file_object.py index 8a9c023c..b85a13bc 100644 --- a/cybox/objects/win_file_object.py +++ b/cybox/objects/win_file_object.py @@ -23,6 +23,7 @@ class StreamList(entities.EntityList): _binding = win_file_binding _binding_class = win_file_binding.StreamListType _namespace = 'http://cybox.mitre.org/objects#WinFileObject-2' + stream = fields.TypedField("Stream", Stream, multiple=True) @@ -36,6 +37,7 @@ class WindowsFileAttributes(FileAttribute, entities.EntityList): _binding = win_file_binding _binding_class = win_file_binding.WindowsFileAttributesType _namespace = 'http://cybox.mitre.org/objects#WinFileObject-2' + attribute = fields.TypedField("Attribute", WindowsFileAttribute, multiple=True) diff --git a/cybox/objects/win_handle_object.py b/cybox/objects/win_handle_object.py index d18350e2..3fd0e082 100644 --- a/cybox/objects/win_handle_object.py +++ b/cybox/objects/win_handle_object.py @@ -28,4 +28,5 @@ class WinHandleList(entities.EntityList): _binding = win_handle_binding _binding_class = win_handle_binding.WindowsHandleListType _namespace = 'http://cybox.mitre.org/objects#WinHandleObject-2' - handle = fields.TypedField("Handle", WinHandle, multiple=True) \ No newline at end of file + + handle = fields.TypedField("Handle", WinHandle, multiple=True) diff --git a/cybox/objects/win_kernel_hook_object.py b/cybox/objects/win_kernel_hook_object.py index dbda7f26..ad58997f 100644 --- a/cybox/objects/win_kernel_hook_object.py +++ b/cybox/objects/win_kernel_hook_object.py @@ -15,10 +15,8 @@ class WinKernelHook(ObjectProperties): _XSI_NS = "WinKernelHookObj" _XSI_TYPE = "WindowsKernelHookObjectType" - digital_signature_hooking = fields.TypedField("Digital_Signature_Hooking", - DigitalSignature) - digital_signature_hooked = fields.TypedField("Digital_Signature_Hooked", - DigitalSignature) + digital_signature_hooking = fields.TypedField("Digital_Signature_Hooking", DigitalSignature) + digital_signature_hooked = fields.TypedField("Digital_Signature_Hooked", DigitalSignature) hooking_address = fields.TypedField("Hooking_Address", UnsignedLong) hook_description = fields.TypedField("Hook_Description", String) hooked_function = fields.TypedField("Hooked_Function", String) diff --git a/cybox/objects/win_kernel_object.py b/cybox/objects/win_kernel_object.py index 1a251851..591def6a 100644 --- a/cybox/objects/win_kernel_object.py +++ b/cybox/objects/win_kernel_object.py @@ -24,6 +24,7 @@ class IDTEntryList(entities.EntityList): _binding = win_kernel_binding _binding_class = win_kernel_binding.IDTEntryListType _namespace = "http://cybox.mitre.org/objects#WinKernelObject-2" + idt_entry = fields.TypedField("IDT_Entry", IDTEntry, multiple=True) @@ -43,6 +44,7 @@ class SSDTEntryList(entities.EntityList): _binding = win_kernel_binding _binding_class = win_kernel_binding.SSDTEntryListType _namespace = "http://cybox.mitre.org/objects#WinKernelObject-2" + ssdt_entry = fields.TypedField("SSDT_Entry", SSDTEntry, multiple=True) diff --git a/cybox/objects/win_memory_page_region_object.py b/cybox/objects/win_memory_page_region_object.py index 5c984372..98f492e8 100644 --- a/cybox/objects/win_memory_page_region_object.py +++ b/cybox/objects/win_memory_page_region_object.py @@ -19,7 +19,6 @@ class WinMemoryPageRegion(Memory): is_mapped = fields.TypedField("is_mapped") is_protected = fields.TypedField("is_protected") is_volatile = fields.TypedField("is_volatile") - hashes = fields.TypedField("Hashes", HashList) name = fields.TypedField("Name", String) memory_source = fields.TypedField("Memory_Source", String) @@ -29,7 +28,6 @@ class WinMemoryPageRegion(Memory): region_end_address = fields.TypedField("Region_End_Address", HexBinary) extracted_features = fields.TypedField("Extracted_Features", ExtractedFeatures) allocation_base_address = fields.TypedField("Allocation_Base_Address", HexBinary) - type_ = fields.TypedField("Type", String) allocation_protect = fields.TypedField("Allocation_Protect", String) state = fields.TypedField("State", String) diff --git a/cybox/objects/win_prefetch_object.py b/cybox/objects/win_prefetch_object.py index 87325967..812541eb 100644 --- a/cybox/objects/win_prefetch_object.py +++ b/cybox/objects/win_prefetch_object.py @@ -14,6 +14,7 @@ class AccessedFileList(entities.EntityList): _binding = win_prefetch_binding _binding_class = win_prefetch_binding.AccessedFileListType _namespace = "http://cybox.mitre.org/objects#WinPrefetchObject-2" + accessed_file = fields.TypedField("Accessed_File", String, multiple=True) @@ -21,6 +22,7 @@ class AccessedDirectoryList(entities.EntityList): _binding = win_prefetch_binding _binding_class = win_prefetch_binding.AccessedDirectoryListType _namespace = "http://cybox.mitre.org/objects#WinPrefetchObject-2" + accessed_directory = fields.TypedField("Accessed_Directory", String, multiple=True) diff --git a/cybox/objects/win_process_object.py b/cybox/objects/win_process_object.py index 949fbaa7..b24b3470 100644 --- a/cybox/objects/win_process_object.py +++ b/cybox/objects/win_process_object.py @@ -17,6 +17,7 @@ class MemorySectionList(entities.EntityList): _binding = win_process_binding _binding_class = win_process_binding.MemorySectionListType _namespace = "http://cybox.mitre.org/objects#WinProcessObject-2" + memory_section = fields.TypedField("Memory_Section", Memory, multiple=True) diff --git a/cybox/objects/win_registry_key_object.py b/cybox/objects/win_registry_key_object.py index 6f88504c..64984399 100644 --- a/cybox/objects/win_registry_key_object.py +++ b/cybox/objects/win_registry_key_object.py @@ -26,6 +26,7 @@ class RegistryValues(entities.EntityList): _binding = win_registry_key_binding _binding_class = win_registry_key_binding.RegistryValuesType _namespace = "http://cybox.mitre.org/objects#WinRegistryKeyObject-2" + value = fields.TypedField("Value", RegistryValue, multiple=True) @@ -33,6 +34,7 @@ class RegistrySubkeys(entities.EntityList): _binding = win_registry_key_binding _binding_class = win_registry_key_binding.RegistrySubkeysType _namespace = "http://cybox.mitre.org/objects#WinRegistryKeyObject-2" + subkey = fields.TypedField("Subkey", type_="cybox.objects.win_registry_key_object.WinRegistryKey", multiple=True) @@ -53,4 +55,3 @@ class WinRegistryKey(ObjectProperties): number_subkeys = fields.TypedField("Number_Subkeys", UnsignedInteger) subkeys = fields.TypedField("Subkeys", RegistrySubkeys) byte_runs = fields.TypedField("Byte_Runs", ByteRuns) - diff --git a/cybox/objects/win_service_object.py b/cybox/objects/win_service_object.py index dc9b0ae7..c5f35e2c 100644 --- a/cybox/objects/win_service_object.py +++ b/cybox/objects/win_service_object.py @@ -14,6 +14,7 @@ class ServiceDescriptionList(entities.EntityList): _binding = win_service_binding _binding_class = win_service_binding.ServiceDescriptionListType _namespace = "http://cybox.mitre.org/objects#WinServiceObject-2" + description = fields.TypedField("Description", String, multiple=True) diff --git a/cybox/objects/win_system_object.py b/cybox/objects/win_system_object.py index 00a84548..104afd4c 100644 --- a/cybox/objects/win_system_object.py +++ b/cybox/objects/win_system_object.py @@ -25,6 +25,7 @@ class GlobalFlagList(entities.EntityList): _binding = win_system_binding _binding_class = win_system_binding.GlobalFlagListType _namespace = "http://cybox.mitre.org/objects#WinSystemObject-2" + global_flag = fields.TypedField("Global_Flag", GlobalFlag, multiple=True) diff --git a/cybox/objects/win_system_restore_object.py b/cybox/objects/win_system_restore_object.py index 323d761c..663b271a 100644 --- a/cybox/objects/win_system_restore_object.py +++ b/cybox/objects/win_system_restore_object.py @@ -12,6 +12,7 @@ class HiveList(entities.EntityList): _binding = win_system_restore_binding _binding_class = win_system_restore_binding.HiveListType _namespace = "http://cybox.mitre.org/objects#WinSystemObject-2" + hive = fields.TypedField("Hive", String, multiple=True) @@ -32,14 +33,11 @@ class WinSystemRestore(ObjectProperties): changelog_entry_flags = fields.TypedField("ChangeLog_Entry_Flags", String) changelog_entry_sequence_number = fields.TypedField("ChangeLog_Entry_Sequence_Number", Long) created = fields.TypedField("Created", DateTime) - file_attributes = fields.TypedField("File_Attributes", String) new_file_name = fields.TypedField("New_File_Name", String) original_file_name = fields.TypedField("Original_File_Name", String) original_short_file_name = fields.TypedField("Original_Short_File_Name", String) process_name = fields.TypedField("Process_Name", String) - change_event = fields.TypedField("Change_Event", String) changelog_entry_type = fields.TypedField("ChangeLog_Entry_Type", String) - registry_hive_list = fields.TypedField("Registry_Hive_List", HiveList) diff --git a/cybox/objects/win_task_object.py b/cybox/objects/win_task_object.py index 12f7e82c..53a78c17 100644 --- a/cybox/objects/win_task_object.py +++ b/cybox/objects/win_task_object.py @@ -20,8 +20,7 @@ class Trigger(entities.Entity): trigger_end = fields.TypedField("Trigger_End", DateTime) trigger_frequency = fields.TypedField("Trigger_Frequency", String) trigger_max_run_time = fields.TypedField("Trigger_Max_Run_Time", Duration) - trigger_session_change_type = fields.TypedField( - "Trigger_Session_Change_Type", String) + trigger_session_change_type = fields.TypedField("Trigger_Session_Change_Type", String) trigger_type = fields.TypedField("Trigger_Type", String) @@ -29,6 +28,7 @@ class TriggerList(entities.EntityList): _binding = win_task_binding _binding_class = win_task_binding.TriggerListType _namespace = 'http://cybox.mitre.org/objects#WinTaskObject-2' + trigger = fields.TypedField("Trigger", Trigger, multiple=True) @@ -69,17 +69,16 @@ class TaskAction(entities.Entity): action_type = fields.TypedField("Action_Type", String) action_id = fields.TypedField("Action_ID", String) iemailaction = fields.TypedField("IEmailAction", EmailMessage) - icomhandleraction = fields.TypedField("IComHandlerAction", - IComHandlerAction) + icomhandleraction = fields.TypedField("IComHandlerAction", IComHandlerAction) iexecaction = fields.TypedField("IExecAction", IExecAction) - ishowmessageaction = fields.TypedField("IShowMessageAction", - IShowMessageAction) + ishowmessageaction = fields.TypedField("IShowMessageAction", IShowMessageAction) class TaskActionList(entities.EntityList): _binding = win_task_binding _binding_class = win_task_binding.TaskActionListType _namespace = 'http://cybox.mitre.org/objects#WinTaskObject-2' + action = fields.TypedField("Action", TaskAction, multiple=True) diff --git a/cybox/objects/win_volume_object.py b/cybox/objects/win_volume_object.py index 54924ad5..033bf9e9 100644 --- a/cybox/objects/win_volume_object.py +++ b/cybox/objects/win_volume_object.py @@ -13,6 +13,7 @@ class WindowsVolumeAttributesList(entities.EntityList): _binding = win_volume_binding _binding_class = win_volume_binding.WindowsVolumeAttributesListType _namespace = "http://cybox.mitre.org/objects#WinVolumeObject-2" + attribute = fields.TypedField("Attribute", String, multiple=True) diff --git a/cybox/objects/x509_certificate_object.py b/cybox/objects/x509_certificate_object.py index ec3cc60b..e87b8d52 100644 --- a/cybox/objects/x509_certificate_object.py +++ b/cybox/objects/x509_certificate_object.py @@ -16,6 +16,7 @@ class Validity(entities.Entity): not_before = fields.TypedField("Not_Before", DateTime) not_after = fields.TypedField("Not_After", DateTime) + class RSAPublicKey(entities.Entity): _binding = x509_certificate_binding _binding_class = x509_certificate_binding.RSAPublicKeyType diff --git a/setup.py b/setup.py index fca219a4..0673dc64 100644 --- a/setup.py +++ b/setup.py @@ -11,6 +11,7 @@ BASE_DIR = dirname(abspath(__file__)) VERSION_FILE = join(BASE_DIR, 'cybox', 'version.py') + def get_version(): with open(VERSION_FILE) as f: for line in f.readlines(): From c745c442b1e0c591b139ae740f58dfca64eadf82 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 21 Nov 2017 08:29:05 -0500 Subject: [PATCH 03/15] Update PDF test file. --- cybox/test/objects/pdf_file_test.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/cybox/test/objects/pdf_file_test.py b/cybox/test/objects/pdf_file_test.py index 0a0a4459..72e21b87 100644 --- a/cybox/test/objects/pdf_file_test.py +++ b/cybox/test/objects/pdf_file_test.py @@ -8,7 +8,7 @@ from cybox.test.objects import ObjectTestCase -class TestArchiveFile(ObjectTestCase, unittest.TestCase): +class TestArchiveFileInstance(ObjectTestCase, unittest.TestCase): object_type = 'PDFFileObjectType' klass = PDFFile @@ -66,5 +66,28 @@ class TestArchiveFile(ObjectTestCase, unittest.TestCase): } +class TestArchiveFilePattern(ObjectTestCase, unittest.TestCase): + object_type = 'PDFFileObjectType' + klass = PDFFile + + _full_dict = { + 'xsi:type': object_type, + 'version': { + 'value': 1.2, + 'condition': 'GreaterThan' + }, + 'metadata': { + 'keyword_counts': { + 'js_count': { + 'non_obfuscated_count': { + 'value': 3, + 'condition': 'GreaterThanOrEqual' + } + } + } + } + } + + if __name__ == '__main__': unittest.main() From 8df84681c6e280178b67084f90cea9a975ac9edd Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 21 Nov 2017 09:56:47 -0500 Subject: [PATCH 04/15] Add description support in cybox.core.Object, closes #300 --- cybox/core/object.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/cybox/core/object.py b/cybox/core/object.py index f5a13e63..cda2465c 100644 --- a/cybox/core/object.py +++ b/cybox/core/object.py @@ -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 @@ -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 @@ -51,6 +52,8 @@ class Object(entities.Entity): Currently only supports the following data members: - id\_ - idref + - has_changed + - description - properties - related_objects - domain specific object properties @@ -61,11 +64,13 @@ class Object(entities.Entity): id_ = fields.IdField("id", postset_hook=_cache_object) idref = fields.IdrefField("idref") + has_changed = fields.TypedField("has_changed") + description = fields.TypedField("Description", StructuredText) properties = fields.TypedField("Properties", ObjectProperties, factory=ObjectPropertiesFactory, postset_hook=_modify_properties_parent) - 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) + related_objects = fields.TypedField("Related_Objects", "cybox.core.object.RelatedObjects") - 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: @@ -173,8 +178,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 From 5d5e3ee7f8cd012ce9dcc47ff30cd5ecedb33fa8 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 21 Nov 2017 13:16:44 -0500 Subject: [PATCH 05/15] Add Raw_Artifact_Reference to Artifact. closes #301 --- cybox/objects/artifact_object.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/cybox/objects/artifact_object.py b/cybox/objects/artifact_object.py index 29b9039c..e909b6b9 100644 --- a/cybox/objects/artifact_object.py +++ b/cybox/objects/artifact_object.py @@ -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. import base64 import bz2 @@ -23,6 +23,16 @@ def validate_artifact_type(instance, value): raise ValueError(err) +def validate_byte_order_endianness(instance, value): + if value is None: + return + elif value in RawArtifact.ENDIANNESS: + return + else: + err = "Type must be one of %s. Received '%s'." % (RawArtifact.ENDIANNESS, value) + raise ValueError(err) + + class RawArtifact(String): _binding_class = artifact_binding.RawArtifactType _namespace = 'http://cybox.mitre.org/objects#ArtifactObject-2' @@ -67,6 +77,9 @@ class Artifact(ObjectProperties): content_type = fields.TypedField("content_type") content_type_version = fields.TypedField("content_type_version") suspected_malicious = fields.TypedField("suspected_malicious") + # TODO: xs:choice + raw_artifact = fields.TypedField("Raw_Artifact", RawArtifact) + raw_artifact_reference = fields.TypedField("Raw_Artifact_Reference") def __init__(self, data=None, type_=None): super(Artifact, self).__init__() @@ -152,8 +165,7 @@ def to_obj(self, ns_info=None): elif isinstance(p, Encoding): packaging.add_Encoding(p_obj) else: - raise ValueError("Unsupported Packaging Type: %s" % - type(p)) + raise ValueError("Unsupported Packaging Type: %s" % type(p)) artifact_obj.Packaging = packaging if self.packed_data: From f89cc4251e8905964400fdfcb3a1dca90e2cdc6e Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 21 Nov 2017 14:47:44 -0500 Subject: [PATCH 06/15] New UnixAccount object and test --- cybox/objects/unix_user_account_object.py | 41 +++++++++++++++++ cybox/test/objects/unix_user_account_test.py | 46 ++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 cybox/objects/unix_user_account_object.py create mode 100644 cybox/test/objects/unix_user_account_test.py diff --git a/cybox/objects/unix_user_account_object.py b/cybox/objects/unix_user_account_object.py new file mode 100644 index 00000000..a3ca4aeb --- /dev/null +++ b/cybox/objects/unix_user_account_object.py @@ -0,0 +1,41 @@ +# Copyright (c) 2017, The MITRE Corporation. All rights reserved. +# See LICENSE.txt for complete terms. + +from mixbox import entities +from mixbox import fields + +import cybox.bindings.unix_user_account_object as unix_user_account_binding +from cybox.common import String, NonNegativeInteger, UnsignedInteger +from cybox.objects.user_account_object import Group, Privilege, UserAccount + + +class UnixGroup(Group): + _binding = unix_user_account_binding + _binding_class = unix_user_account_binding.UnixGroupType + _namespace = 'http://cybox.mitre.org/objects#UnixUserAccountObject-2' + _XSI_NS = "UnixUserAccountObj" + _XSI_TYPE = "UnixGroupType" + + group_id = fields.TypedField("Group_ID", NonNegativeInteger) + + +class UnixPrivilege(Privilege): + _binding = unix_user_account_binding + _binding_class = unix_user_account_binding.UnixPrivilegeType + _namespace = 'http://cybox.mitre.org/objects#UnixUserAccountObject-2' + _XSI_NS = "UnixUserAccountObj" + _XSI_TYPE = "UnixPrivilegeType" + + permissions_mask = fields.TypedField("Permissions_Mask", String) + + +class UnixUserAccount(UserAccount): + _binding = unix_user_account_binding + _binding_class = unix_user_account_binding.UnixUserAccountObjectType + _namespace = 'http://cybox.mitre.org/objects#UnixUserAccountObject-2' + _XSI_NS = "UnixUserAccountObj" + _XSI_TYPE = "UnixUserAccountObjectType" + + group_id = fields.TypedField("Group_ID", UnsignedInteger) + user_id = fields.TypedField("User_ID", UnsignedInteger) + login_shell = fields.TypedField("Login_Shell", String) diff --git a/cybox/test/objects/unix_user_account_test.py b/cybox/test/objects/unix_user_account_test.py new file mode 100644 index 00000000..b486ec8d --- /dev/null +++ b/cybox/test/objects/unix_user_account_test.py @@ -0,0 +1,46 @@ +# Copyright (c) 2017, The MITRE Corporation. All rights reserved. +# See LICENSE.txt for complete terms. + +import unittest + +from mixbox.vendor.six import u + +from cybox.objects.unix_user_account_object import UnixUserAccount +from cybox.test.objects import ObjectTestCase + + +class TestUnixUserAccount(ObjectTestCase, unittest.TestCase): + object_type = "UnixUserAccountObjectType" + klass = UnixUserAccount + + _full_dict = { + # Account-specific fields + 'disabled': False, + 'locked_out': True, + 'description': u('An account'), + 'domain': u('ADMIN'), + 'group_list': [ + { + 'group_id': 'group_id0', + 'xsi:type': 'UnixGroupType' + } + ], + 'privilege_list': [ + { + 'privilege': 'privilege_0', + 'xsi:type': 'UnixPrivilegeType' + } + ], + 'password_required': True, + 'full_name': u("Guido van Rossum"), + 'home_directory': u("/home/guido/"), + 'last_login': "2001-01-01T06:56:50+04:00", + 'script_path': u("/bin/bash"), + 'username': u("guido"), + 'user_password_age': u("P90D"), + 'xsi:type': object_type, + } + + +if __name__ == "__main__": + unittest.main() From be1651e3d334f492f2ea64cca6a22903daa1ceab Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 21 Nov 2017 14:48:28 -0500 Subject: [PATCH 07/15] Format, docs and small object modifications --- cybox/core/observable.py | 2 ++ cybox/objects/__init__.py | 2 +- cybox/objects/pdf_file_object.py | 2 +- cybox/objects/user_account_object.py | 17 +++++++++-------- docs/api/coverage.rst | 2 +- 5 files changed, 14 insertions(+), 11 deletions(-) diff --git a/cybox/core/observable.py b/cybox/core/observable.py index 18045dc0..a477d1c7 100644 --- a/cybox/core/observable.py +++ b/cybox/core/observable.py @@ -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. """ diff --git a/cybox/objects/__init__.py b/cybox/objects/__init__.py index c3df4ef0..003da935 100644 --- a/cybox/objects/__init__.py +++ b/cybox/objects/__init__.py @@ -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']), diff --git a/cybox/objects/pdf_file_object.py b/cybox/objects/pdf_file_object.py index 5b044168..64b7d93d 100644 --- a/cybox/objects/pdf_file_object.py +++ b/cybox/objects/pdf_file_object.py @@ -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 diff --git a/cybox/objects/user_account_object.py b/cybox/objects/user_account_object.py index d5f4c9df..56d0fe11 100644 --- a/cybox/objects/user_account_object.py +++ b/cybox/objects/user_account_object.py @@ -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 @@ -11,23 +11,24 @@ class Group(entities.Entity): """An abstract class for account groups.""" - - def __init__(self): - raise TypeError("Cannot instantiate abstract type.") + _binding = user_account_binding + _binding_class = user_account_binding.GroupType + _namespace = 'http://cybox.mitre.org/objects#UserAccountObject-2' class GroupList(entities.EntityList): _binding = user_account_binding _binding_class = user_account_binding.GroupListType _namespace = 'http://cybox.mitre.org/objects#UserAccountObject-2' + group = fields.TypedField("Group", Group, multiple=True) class Privilege(entities.Entity): """An abstract class for account privileges.""" - - def __init__(self): - raise TypeError("Cannot instantiate abstract type.") + _binding = user_account_binding + _binding_class = user_account_binding.PrivilegeType + _namespace = 'http://cybox.mitre.org/objects#UserAccountObject-2' class PrivilegeList(entities.EntityList): @@ -53,6 +54,6 @@ class UserAccount(Account): username = fields.TypedField('Username', String) user_password_age = fields.TypedField('User_Password_Age', Duration) - # These should be overriden by subclasses + # These should be overridden by subclasses group_list = fields.TypedField('Group_List', GroupList) privilege_list = fields.TypedField('Privilege_List', PrivilegeList) diff --git a/docs/api/coverage.rst b/docs/api/coverage.rst index eedfacca..355ca8c6 100644 --- a/docs/api/coverage.rst +++ b/docs/api/coverage.rst @@ -60,7 +60,7 @@ Network Route Entry Object ✓ Full :class:`cybox.obje Network Route Object ✓ Full :class:`cybox.objects.network_route_object.NetRoute` Network Socket Object ✓ Full :class:`cybox.objects.network_socket_object.NetworkSocket` Network Subnet Object ✓ Full :class:`cybox.objects.network_subnet_object.NetworkSubnet` -PDF File Object ⚠ Partial :class:`cybox.objects.pdf_file_object.PDFFile` +PDF File Object ✓ Full :class:`cybox.objects.pdf_file_object.PDFFile` Pipe Object ✓ Full :class:`cybox.objects.pipe_object.Pipe` Port Object ✓ Full :class:`cybox.objects.port_object.Port` Process Object ✓ Full :class:`cybox.objects.process_object.Process` From 6315d36ca0f32fc0007f551ebdee0985ec5bed7c Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 21 Nov 2017 14:51:13 -0500 Subject: [PATCH 08/15] Update test name classes. --- cybox/test/objects/pdf_file_test.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cybox/test/objects/pdf_file_test.py b/cybox/test/objects/pdf_file_test.py index 72e21b87..ac5e4c9e 100644 --- a/cybox/test/objects/pdf_file_test.py +++ b/cybox/test/objects/pdf_file_test.py @@ -8,7 +8,7 @@ from cybox.test.objects import ObjectTestCase -class TestArchiveFileInstance(ObjectTestCase, unittest.TestCase): +class TestPDFFileInstance(ObjectTestCase, unittest.TestCase): object_type = 'PDFFileObjectType' klass = PDFFile @@ -66,7 +66,7 @@ class TestArchiveFileInstance(ObjectTestCase, unittest.TestCase): } -class TestArchiveFilePattern(ObjectTestCase, unittest.TestCase): +class TestPDFFilePattern(ObjectTestCase, unittest.TestCase): object_type = 'PDFFileObjectType' klass = PDFFile From 5b1d6a21056c8c976a4e72b68c271b1e8e6dfda2 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 21 Nov 2017 14:55:34 -0500 Subject: [PATCH 09/15] Remove extraneous code --- cybox/objects/artifact_object.py | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/cybox/objects/artifact_object.py b/cybox/objects/artifact_object.py index e909b6b9..9e440e85 100644 --- a/cybox/objects/artifact_object.py +++ b/cybox/objects/artifact_object.py @@ -23,16 +23,6 @@ def validate_artifact_type(instance, value): raise ValueError(err) -def validate_byte_order_endianness(instance, value): - if value is None: - return - elif value in RawArtifact.ENDIANNESS: - return - else: - err = "Type must be one of %s. Received '%s'." % (RawArtifact.ENDIANNESS, value) - raise ValueError(err) - - class RawArtifact(String): _binding_class = artifact_binding.RawArtifactType _namespace = 'http://cybox.mitre.org/objects#ArtifactObject-2' From 296df6e2cecc3e400f0cd8513e10f30c215bb686 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Wed, 22 Nov 2017 11:07:28 -0500 Subject: [PATCH 10/15] Fix RawArtifact attribute settings. Some general improvements. Added tests. closes #296 --- cybox/objects/artifact_object.py | 83 ++++++++++++++----- cybox/test/objects/artifact_test.py | 121 ++++++++++++++++++++++++++++ 2 files changed, 182 insertions(+), 22 deletions(-) diff --git a/cybox/objects/artifact_object.py b/cybox/objects/artifact_object.py index 9e440e85..c5393828 100644 --- a/cybox/objects/artifact_object.py +++ b/cybox/objects/artifact_object.py @@ -23,11 +23,27 @@ def validate_artifact_type(instance, value): raise ValueError(err) +def validate_byte_order_endianness(instance, value): + if value is None: + return + elif value in RawArtifact.ENDIANNESS: + return + else: + err = "Type must be one of %s. Received '%s'." % (RawArtifact.ENDIANNESS, value) + raise ValueError(err) + + class RawArtifact(String): - _binding_class = artifact_binding.RawArtifactType + _binding = artifact_binding + _binding_class = _binding.RawArtifactType _namespace = 'http://cybox.mitre.org/objects#ArtifactObject-2' - byte_order = fields.TypedField("byte_order") + BIG_ENDIAN = "Big-endian" + LITTLE_ENDIAN = "Little-endian" + MIDDLE_ENDIAN = "Middle-endian" + ENDIANNESS = (BIG_ENDIAN, LITTLE_ENDIAN, MIDDLE_ENDIAN) + + byte_order = fields.TypedField("byte_order", postset_hook=validate_byte_order_endianness) class Packaging(entities.Entity): @@ -47,7 +63,8 @@ def unpack(self, packed_data): class Artifact(ObjectProperties): # Warning: Do not attempt to get or set Raw_Artifact directly. Use `data` - # or `packed_data` respectively. Raw_Artifact will be set on export. + # or `packed_data` respectively. The Raw_Artifact value will be set on + # export. You can set BaseObjectProperties or PatternFieldGroup attributes. _binding = artifact_binding _binding_class = _binding.ArtifactObjectType _namespace = 'http://cybox.mitre.org/objects#ArtifactObject-2' @@ -62,7 +79,8 @@ class Artifact(ObjectProperties): TYPES = (TYPE_FILE, TYPE_FILE_SYSTEM, TYPE_GENERIC, TYPE_MEMORY, TYPE_NETWORK) hashes = fields.TypedField("Hashes", HashList) - # packaging = fields.TypedField("Packaging", Packaging, multiple=True) # TODO: Support this as a TypedField + # TODO: Support packaging as a TypedField + # packaging = fields.TypedField("Packaging", Packaging, multiple=True) type_ = fields.TypedField("type_", key_name="type", preset_hook=validate_artifact_type) content_type = fields.TypedField("content_type") content_type_version = fields.TypedField("content_type_version") @@ -94,6 +112,7 @@ def __init__(self, data=None, type_=None): # for `data` has access to this attribute. self._packed_data = None self.data = data + self.raw_artifact = RawArtifact() @property def data(self): @@ -159,7 +178,8 @@ def to_obj(self, ns_info=None): artifact_obj.Packaging = packaging if self.packed_data: - artifact_obj.Raw_Artifact = RawArtifact(self.packed_data).to_obj(ns_info=ns_info) + self.raw_artifact.value = self.packed_data + artifact_obj.Raw_Artifact = self.raw_artifact.to_obj(ns_info=ns_info) return artifact_obj @@ -169,7 +189,8 @@ def to_dict(self): if self.packaging: artifact_dict['packaging'] = [p.to_dict() for p in self.packaging] if self.packed_data: - artifact_dict['raw_artifact'] = RawArtifact(self.packed_data).to_dict() + self.raw_artifact.value = self.packed_data + artifact_dict['raw_artifact'] = self.raw_artifact.to_dict() return artifact_dict @@ -179,7 +200,7 @@ def from_obj(cls, cls_obj): return None artifact = super(Artifact, cls).from_obj(cls_obj) - + packaging = cls_obj.Packaging if packaging: for c in packaging.Compression: @@ -191,8 +212,8 @@ def from_obj(cls, cls_obj): raw_artifact = cls_obj.Raw_Artifact if raw_artifact: - data = RawArtifact.from_obj(raw_artifact).value - artifact.packed_data = six.text_type(data) + artifact.raw_artifact = RawArtifact.from_obj(raw_artifact) + artifact.packed_data = six.text_type(artifact.raw_artifact.value) return artifact @@ -202,7 +223,7 @@ def from_dict(cls, cls_dict): return None artifact = super(Artifact, cls).from_dict(cls_dict) - + for layer in cls_dict.get('packaging', []): if layer.get('packaging_type') == "compression": artifact.packaging.append(CompressionFactory.from_dict(layer)) @@ -213,8 +234,8 @@ def from_dict(cls, cls_dict): raw_artifact = cls_dict.get('raw_artifact') if raw_artifact: - data = RawArtifact.from_dict(raw_artifact).value - artifact.packed_data = six.text_type(data) + artifact.raw_artifact = RawArtifact.from_dict(raw_artifact) + artifact.packed_data = six.text_type(artifact.raw_artifact.value) return artifact @@ -232,9 +253,10 @@ class Compression(Packaging): compression_mechanism = fields.TypedField("compression_mechanism") compression_mechanism_ref = fields.TypedField("compression_mechanism_ref") - def __init__(self, compression_mechanism=None): + def __init__(self, compression_mechanism=None, compression_mechanism_ref=None): super(Compression, self).__init__() self.compression_mechanism = compression_mechanism + self.compression_mechanism_ref = compression_mechanism_ref def to_dict(self): dict_ = super(Compression, self).to_dict() @@ -244,7 +266,7 @@ def to_dict(self): class ZlibCompression(Compression): def __init__(self): - super(ZlibCompression, self).__init__("zlib") + super(ZlibCompression, self).__init__(compression_mechanism="zlib") def pack(self, data): return zlib.compress(data) @@ -256,7 +278,7 @@ def unpack(self, packed_data): class Bz2Compression(Compression): def __init__(self): - super(Bz2Compression, self).__init__("bz2") + super(Bz2Compression, self).__init__(compression_mechanism="bz2") def pack(self, data): return bz2.compress(data) @@ -278,10 +300,13 @@ class Encryption(Packaging): encryption_key = fields.TypedField("encryption_key") encryption_key_ref = fields.TypedField("encryption_key_ref") - def __init__(self, encryption_mechanism=None, encryption_key=None): + def __init__(self, encryption_mechanism=None, encryption_key=None, + encryption_mechanism_ref=None, encryption_key_ref=None): super(Encryption, self).__init__() self.encryption_mechanism = encryption_mechanism self.encryption_key = encryption_key + self.encryption_mechanism_ref = encryption_mechanism_ref + self.encryption_key_ref = encryption_key_ref def to_dict(self): dict_ = super(Encryption, self).to_dict() @@ -292,7 +317,10 @@ def to_dict(self): class XOREncryption(Encryption): def __init__(self, key=None): - super(XOREncryption, self).__init__("xor", key) + super(XOREncryption, self).__init__( + encryption_mechanism="xor", + encryption_key=key + ) def pack(self, data): return xor(data, self.encryption_key) @@ -303,7 +331,10 @@ def unpack(self, packed_data): class PasswordProtectedZipEncryption(Encryption): def __init__(self, key=None): - super(PasswordProtectedZipEncryption, self).__init__("PasswordProtected", key) + super(PasswordProtectedZipEncryption, self).__init__( + encryption_mechanism="PasswordProtected", + encryption_key=key + ) # `pack` is not implemented @@ -330,6 +361,14 @@ class Encoding(Packaging): _binding_class = _binding.EncodingType algorithm = fields.TypedField("algorithm") + character_set = fields.TypedField("character_set") + custom_character_set_ref = fields.TypedField("custom_character_set_ref") + + def __init__(self, algorithm=None, character_set=None, custom_character_set_ref=None): + super(Encoding, self).__init__() + self.algorithm = algorithm + self.character_set = character_set + self.custom_character_set_ref = custom_character_set_ref def to_dict(self): dict_ = super(Encoding, self).to_dict() @@ -351,14 +390,14 @@ class EncryptionFactory(entities.EntityFactory): def entity_class(cls, key): if key == "xor": return XOREncryption - elif key == 'PasswordProtected': + elif key == "PasswordProtected": return PasswordProtectedZipEncryption else: raise ValueError("Unsupported encryption mechanism: %s" % key) @classmethod def dictkey(cls, mapping): - return mapping.get('encryption_mechanism') + return mapping.get("encryption_mechanism") @classmethod def objkey(cls, obj): @@ -377,7 +416,7 @@ def entity_class(cls, key): @classmethod def dictkey(cls, mapping): - return mapping.get('compression_mechanism') + return mapping.get("compression_mechanism") @classmethod def objkey(cls, obj): @@ -394,7 +433,7 @@ def entity_class(cls, key): @classmethod def dictkey(cls, mapping): - return mapping.get('algorithm', "Base64") # default is Base64 + return mapping.get("algorithm", "Base64") # default is Base64 @classmethod def objkey(cls, obj): diff --git a/cybox/test/objects/artifact_test.py b/cybox/test/objects/artifact_test.py index 96ff04f4..4292dd2c 100644 --- a/cybox/test/objects/artifact_test.py +++ b/cybox/test/objects/artifact_test.py @@ -135,6 +135,127 @@ def test_encryption(self): self.assertEqual(self.binary_data, a2.data) +class TestArtifactInstance(ObjectTestCase, unittest.TestCase): + object_type = "ArtifactObjectType" + klass = Artifact + + _full_dict = { + "packaging": [ + { + "packaging_type": "encoding", + "algorithm": "Base64" + } + ], + "xsi:type": object_type, + "raw_artifact": "1MOyoQIABAAAAAAAAAAAAP//AAABAAAAsmdKQq6RBwBGAAAARgAAAADAnzJBjADg" + "GLEMrQgARQAAOAAAQABAEWVHwKiqCMCoqhSAGwA1ACSF7RAyAQAAAQAAAAAAAAZn" + "b29nbGUDY29tAAAQAAGyZ0pCwJMHAGIAAABiAAAAAOAYsQytAMCfMkGMCABFAABU" + "y+wAAIARmT7AqKoUwKiqCAA1gBsAQMclEDKBgAABAAEAAAAABmdvb2dsZQNjb20A" + "ABAAAcAMABAAAQAAAQ4AEA92PXNwZjEgcHRyID9hbGy2Z0pCFKYHAEYAAABGAAAA" + "AMCfMkGMAOAYsQytCABFAAA4AABAAEARZUfAqKoIwKiqFIAbADUAJJ6w928BAAAB" + "AAAAAAAABmdvb2dsZQNjb20AAA8AAbdnSkJZFgUAKgEAACoBAAAA4BixDK0AwJ8y" + "QYwIAEUAARzMuwAAgBGXp8CoqhTAqKoIADWAGwEI1vP3b4GAAAEABgAAAAYGZ29v" + "Z2xlA2NvbQAADwABwAwADwABAAACKAAKACgFc210cDTADMAMAA8AAQAAAigACgAK" + "BXNtdHA1wAzADAAPAAEAAAIoAAoACgVzbXRwNsAMwAwADwABAAACKAAKAAoFc210" + "cDHADMAMAA8AAQAAAigACgAKBXNtdHAywAzADAAPAAEAAAIoAAoAKAVzbXRwM8AM" + "wCoAAQABAAACWAAE2O8lGsBAAAEAAQAAAlgABEDppxnAVgABAAEAAAJYAARCZgkZ" + "wGwAAQABAAACWAAE2O85GcCCAAEAAQAAAlgABNjvJRnAmAABAAEAAAJYAATY7zka" + "v2dKQo/HBABGAAAARgAAAADAnzJBjADgGLEMrQgARQAAOAAAQABAEWVHwKiqCMCo" + "qhSAGwA1ACRMcUmhAQAAAQAAAAAAAAZnb29nbGUDY29tAAAdAAG/Z0pCn+YGAEYA" + "AABGAAAAAOAYsQytAMCfMkGMCABFAAA4zM0AAIARmHnAqKoUwKiqCAA1gBsAJMvw" + "SaGBgAABAAAAAAAABmdvb2dsZQNjb20AAB0AAcdnSkJp5QQAVQAAAFUAAAAAwJ8y" + "QYwA4BixDK0IAEUAAEcAAEAAQBFlOMCoqgjAqKoUgBsANQAzF8KbuwEAAAEAAAAA" + "AAADMTA0ATkDMTkyAjY2B2luLWFkZHIEYXJwYQAADAABx2dKQmPnBACBAAAAgQAA" + "AADgGLEMrQDAnzJBjAgARQAAc80bAACAEZfwwKiqFMCoqggANYAbAF+CtZu7gYAA" + "AQABAAAAAAMxMDQBOQMxOTICNjYHaW4tYWRkcgRhcnBhAAAMAAHADAAMAAEAAVEl" + "ACAMNjYtMTkyLTktMTA0A2dlbgl0d3RlbGVjb20DbmV0AA5oSkJ/dwoASgAAAEoA" + "AAAAwJ8yQYwA4BixDK0IAEUAADwAAEAAQBFlQ8CoqgjAqKoUgBsANQAor2F1wAEA" + "AAEAAAAAAAADd3d3Bm5ldGJzZANvcmcAAAEAAQ5oSkKONgsAWgAAAFoAAAAA4Bix" + "DK0AwJ8yQYwIAEUAAEzP+QAAgBGVOcCoqhTAqKoIADWAGwA4oxd1wIGAAAEAAQAA" + "AAADd3d3Bm5ldGJzZANvcmcAAAEAAcAMAAEAAQABQO8ABMyYvgwfaEpCfQkHAEoA" + "AABKAAAAAMCfMkGMAOAYsQytCABFAAA8b0xAAEAR9fbAqKoIwKiqFIAbADUAKDQy" + "8NQBAAABAAAAAAAAA3d3dwZuZXRic2QDb3JnAAAcAAEfaEpC4akKAGYAAABmAAAA" + "AOAYsQytAMCfMkGMCABFAABY0FoAAIARlMzAqKoUwKiqCAA1gBsARF8b8NSBgAAB" + "AAEAAAAAA3d3dwZuZXRic2QDb3JnAAAcAAHADAAcAAEAAVGAABAgAQT4AAQABwLg" + "gf/+UpprW2hKQrD8BwBKAAAASgAAAADAnzJBjADgGLEMrQgARQAAPAAAQABAEWVD" + "wKiqCMCoqhSAGwA1ACilzX85AQAAAQAAAAAAAAN3d3cGbmV0YnNkA29yZwAAHAAB" + "W2hKQjP+BwBmAAAAZgAAAADgGLEMrQDAnzJBjAgARQAAWNRPAACAEZDXwKiqFMCo" + "qggANYAbAETQ8n85gYAAAQABAAAAAAN3d3cGbmV0YnNkA29yZwAAHAABwAwAHAAB" + "AAFRRAAQIAEE+AAEAAcC4IH//lKaa2RoSkKSOgsASgAAAEoAAAAAwJ8yQYwA4Bix" + "DK0IAEUAADwAAEAAQBFlQ8CoqgjAqKoUgBsANQAojWmNswEAAAEAAAAAAAADd3d3" + "Bmdvb2dsZQNjb20AABwAAWRoSkIsewsAXgAAAF4AAAAA4BixDK0AwJ8yQYwIAEUA" + "AFDUbQAAgBGQwcCoqhTAqKoIADWAGwA8DcGNs4GAAAEAAQAAAAADd3d3Bmdvb2ds" + "ZQNjb20AABwAAcAMAAUAAQAAAnkACAN3d3cBbMAQbmhKQqZWBQBMAAAATAAAAADA" + "nzJBjADgGLEMrQgARQAAPgAAQABAEWVBwKiqCMCoqhSAGwA1ACo9CtyiAQAAAQAA" + "AAAAAAN3d3cBbAZnb29nbGUDY29tAAAcAAFuaEpCv5cFAEwAAABMAAAAAOAYsQyt" + "AMCfMkGMCABFAAA+1TkAAIARkAfAqKoUwKiqCAA1gBsAKryJ3KKBgAABAAAAAAAA" + "A3d3dwFsBmdvb2dsZQNjb20AABwAAZdoSkI8HgMASwAAAEsAAAAAwJ8yQYwA4Bix" + "DK0IAEUAAD0AAEAAQBFlQsCoqgjAqKoUgBsANQApiGG8HwEAAAEAAAAAAAADd3d3" + "B2V4YW1wbGUDY29tAAAcAAGXaEpC86wGAEsAAABLAAAAAOAYsQytAMCfMkGMCABF" + "AAA91p8AAIARjqLAqKoUwKiqCAA1gBsAKQfhvB+BgAABAAAAAAAAA3d3dwdleGFt" + "cGxlA2NvbQAAHAABomhKQhCDDABPAAAATwAAAADAnzJBjADgGLEMrQgARQAAQQAA" + "QABAEWU+wKiqCMCoqhSAGwA1AC1EKCZtAQAAAQAAAAAAAAN3d3cHZXhhbXBsZQdu" + "b3RnaW5oAAAcAAGjaEpC0IAAAE8AAABPAAAAAOAYsQytAMCfMkGMCABFAABB1y4A" + "AIARjg/AqKoUwKiqCAA1gBsALb+kJm2FgwABAAAAAAAAA3d3dwdleGFtcGxlB25v" + "dGdpbmgAABwAAcFoSkIsFQoARwAAAEcAAAAAwJ8yQYwA4BixDK0IAEUAADkAAEAA" + "QBFlRsCoqgjAqKoUgBsANQAlQm7+4wEAAAEAAAAAAAADd3d3A2lzYwNvcmcAAP8A" + "AcFoSkLIMAsAcwAAAHMAAAAA4BixDK0AwJ8yQYwIAEUAAGXY9AAAgBGMJcCoqhTA" + "qKoIADWAGwBRy2T+44GAAAEAAgAAAAADd3d3A2lzYwNvcmcAAP8AAcAMABwAAQAA" + "AlgAECABBPgAAAACAAAAAAAAAA3ADAABAAEAAAJYAATMmLhYwWhKQrQ/CwBSAAAA" + "UgAAAADAnzJBjADgGLEMrQgARQAARAAAQABAEWU7wKiqCMCoqhSAHAA1ADACNVpT" + "AQAAAQAAAAAAAAExATABMAMxMjcHaW4tYWRkcgRhcnBhAAAMAAHBaEpCAEILAGkA" + "AABpAAAAAOAYsQytAMCfMkGMCABFAABb2PUAAIARjC7AqKoUwKiqCAA1gBwAR/kw" + "WlOFgAABAAEAAAAAATEBMAEwAzEyNwdpbi1hZGRyBGFycGEAAAwAAcAMAAwAAQAA" + "DhAACwlsb2NhbGhvc3QAwWhKQkZLCwBDAAAAQwAAAADAnzJBjADgGLEMrQgARQAA" + "NQAAQABAEWVKwKiqCMCoqhSAHQA1ACGYvSCKAQAAAQAAAAAAAANpc2MDb3JnAAAC" + "AAHBaEpC2ogLAIEAAACBAAAAABKpADIjAGAIReRVCABFAABzh94AAIARapXAqKo4" + "2Q0EGAarADUAXznwMm4BAAABAAAAAAAABV9sZGFwBF90Y3AXRGVmYXVsdC1GaXJz" + "dC1TaXRlLU5hbWUGX3NpdGVzAmRjBl9tc2Rjcwt1dGVsc3lzdGVtcwVsb2NhbAAA" + "IQABwWhKQrWSCwCmAAAApgAAAADgGLEMrQDAnzJBjAgARQAAmNj3AACAEYvvwKiq" + "FMCoqggANYAdAIR72CCKgYAAAQAEAAAAAANpc2MDb3JnAAACAAHADAACAAEAAA4Q" + "AA4GbnMtZXh0BG5ydDHADMAMAAIAAQAADhAADgZucy1leHQEc3RoMcAMwAwAAgAB" + "AAAOEAAJBm5zLWV4dMAMwAwAAgABAAAOEAAOBm5zLWV4dARsZ2ExwAzBaEpCPdYL" + "AIEAAACBAAAAAGAIReRVABKpADIjCABFAABzAABAADoR+HPZDQQYwKiqOAA1BqsA" + "X7VsMm6FgwABAAAAAAAABV9sZGFwBF90Y3AXRGVmYXVsdC1GaXJzdC1TaXRlLU5h" + "bWUGX3NpdGVzAmRjBl9tc2Rjcwt1dGVsc3lzdGVtcwVsb2NhbAAAIQABwWhKQszY" + "CwBiAAAAYgAAAAASqQAyIwBgCEXkVQgARQAAVIfwAACAEWqiwKiqONkNBBgGrAA1" + "AEB8UfFhAQAAAQAAAAAAAAVfbGRhcARfdGNwAmRjBl9tc2Rjcwt1dGVsc3lzdGVt" + "cwVsb2NhbAAAIQABwWhKQmEcDABiAAAAYgAAAABgCEXkVQASqQAyIwgARQAAVAAA" + "QAA6EfiS2Q0EGMCoqjgANQasAED3zfFhhYMAAQAAAAAAAAVfbGRhcARfdGNwAmRj" + "Bl9tc2Rjcwt1dGVsc3lzdGVtcwVsb2NhbAAAIQABwWhKQoAeDACMAAAAjAAAAAAS" + "qQAyIwBgCEXkVQgARQAAfofxAACAEWp3wKiqONkNBBgGrQA1AGp3mINhAQAAAQAA" + "AAAAAAVfbGRhcARfdGNwJDA1YjUyOTJiLTM0YjgtNGZiNy04NWEzLThiZWVmNWZk" + "MjA2OQdkb21haW5zBl9tc2Rjcwt1dGVsc3lzdGVtcwVsb2NhbAAAIQABwWhKQmRr" + "DACMAAAAjAAAAABgCEXkVQASqQAyIwgARQAAfgAAQAA6Efho2Q0EGMCoqjgANQat" + "AGrzFINhhYMAAQAAAAAAAAVfbGRhcARfdGNwJDA1YjUyOTJiLTM0YjgtNGZiNy04" + "NWEzLThiZWVmNWZkMjA2OQdkb21haW5zBl9tc2Rjcwt1dGVsc3lzdGVtcwVsb2Nh" + "bAAAIQABwWhKQvn4DQBTAAAAUwAAAAASqQAyIwBgCEXkVQgARQAARYf1AACAEWqs" + "wKiqONkNBBgGrgA1ADEajdBgAQAAAQAAAAAAAAVHUklNTQt1dGVsc3lzdGVtcwVs" + "b2NhbAAAAQABwWhKQhU7DgBTAAAAUwAAAABgCEXkVQASqQAyIwgARQAARQAAQAA6" + "Efih2Q0EGMCoqjgANQauADGWCdBghYMAAQAAAAAAAAVHUklNTQt1dGVsc3lzdGVt" + "cwVsb2NhbAAAAQAByWhKQuJzBQBTAAAAUwAAAAASqQAyIwBgCEXkVQgARQAARYf7" + "AACAEWqmwKiqONkNBBgGrwA1ADF0iXZjAQAAAQAAAAAAAAVHUklNTQt1dGVsc3lz" + "dGVtcwVsb2NhbAAAAQAByWhKQj+6BQBTAAAAUwAAAABgCEXkVQASqQAyIwgARQAA" + "RQAAQAA6Efih2Q0EGMCoqjgANQavADHwBXZjhYMAAQAAAAAAAAVHUklNTQt1dGVs" + "c3lzdGVtcwVsb2NhbAAAAQAB", + "type": "Network Traffic" + } + + +class TestArtifactPattern(ObjectTestCase, unittest.TestCase): + object_type = "ArtifactObjectType" + klass = Artifact + + _full_dict = { + "xsi:type": object_type, + "raw_artifact": { + "value": "777777076578616D706C6503636F6D", + "condition": "Contains" + }, + "type": "Network Traffic" + } + + def _get_data(artifact): return artifact.data From 42c810cc372068ee209b416bf0db46a0568c050e Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Wed, 22 Nov 2017 15:16:21 -0500 Subject: [PATCH 11/15] Update Windows and Unix bindings, objects and tests. closes #299 --- cybox/bindings/unix_user_account_object.py | 31 ++++++++++++++++++-- cybox/bindings/user_account_object.py | 4 +-- cybox/bindings/win_user_account_object.py | 19 ++++++++++++ cybox/objects/unix_user_account_object.py | 18 +++++++++--- cybox/objects/user_account_object.py | 18 ++++++++++++ cybox/objects/win_user_object.py | 19 +++++------- cybox/test/objects/unix_user_account_test.py | 10 +++++-- cybox/test/objects/win_user_test.py | 14 +++++++-- 8 files changed, 107 insertions(+), 26 deletions(-) diff --git a/cybox/bindings/unix_user_account_object.py b/cybox/bindings/unix_user_account_object.py index 03bfce25..50f4ef8c 100644 --- a/cybox/bindings/unix_user_account_object.py +++ b/cybox/bindings/unix_user_account_object.py @@ -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 @@ -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: @@ -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 @@ -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: @@ -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) @@ -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" ] diff --git a/cybox/bindings/user_account_object.py b/cybox/bindings/user_account_object.py index 4d2645b9..8f43ee53 100644 --- a/cybox/bindings/user_account_object.py +++ b/cybox/bindings/user_account_object.py @@ -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): @@ -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): diff --git a/cybox/bindings/win_user_account_object.py b/cybox/bindings/win_user_account_object.py index ea67024c..2afe4bfb 100644 --- a/cybox/bindings/win_user_account_object.py +++ b/cybox/bindings/win_user_account_object.py @@ -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 @@ -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: @@ -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 @@ -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: diff --git a/cybox/objects/unix_user_account_object.py b/cybox/objects/unix_user_account_object.py index a3ca4aeb..e7f8ffc4 100644 --- a/cybox/objects/unix_user_account_object.py +++ b/cybox/objects/unix_user_account_object.py @@ -1,34 +1,40 @@ # Copyright (c) 2017, The MITRE Corporation. All rights reserved. # See LICENSE.txt for complete terms. -from mixbox import entities from mixbox import fields import cybox.bindings.unix_user_account_object as unix_user_account_binding from cybox.common import String, NonNegativeInteger, UnsignedInteger -from cybox.objects.user_account_object import Group, Privilege, UserAccount +from cybox.objects.user_account_object import (Group, GroupList, Privilege, + PrivilegeList, UserAccount) class UnixGroup(Group): _binding = unix_user_account_binding _binding_class = unix_user_account_binding.UnixGroupType _namespace = 'http://cybox.mitre.org/objects#UnixUserAccountObject-2' - _XSI_NS = "UnixUserAccountObj" _XSI_TYPE = "UnixGroupType" group_id = fields.TypedField("Group_ID", NonNegativeInteger) +class UnixGroupList(GroupList): + group = fields.TypedField("Group", UnixGroup, multiple=True) + + class UnixPrivilege(Privilege): _binding = unix_user_account_binding _binding_class = unix_user_account_binding.UnixPrivilegeType _namespace = 'http://cybox.mitre.org/objects#UnixUserAccountObject-2' - _XSI_NS = "UnixUserAccountObj" _XSI_TYPE = "UnixPrivilegeType" permissions_mask = fields.TypedField("Permissions_Mask", String) +class UnixPrivilegeList(PrivilegeList): + privilege = fields.TypedField("Privilege", UnixPrivilege, multiple=True) + + class UnixUserAccount(UserAccount): _binding = unix_user_account_binding _binding_class = unix_user_account_binding.UnixUserAccountObjectType @@ -39,3 +45,7 @@ class UnixUserAccount(UserAccount): group_id = fields.TypedField("Group_ID", UnsignedInteger) user_id = fields.TypedField("User_ID", UnsignedInteger) login_shell = fields.TypedField("Login_Shell", String) + + # Override abstract types + group_list = fields.TypedField('Group_List', UnixGroupList) + privilege_list = fields.TypedField('Privilege_List', UnixPrivilegeList) diff --git a/cybox/objects/user_account_object.py b/cybox/objects/user_account_object.py index 56d0fe11..2363be92 100644 --- a/cybox/objects/user_account_object.py +++ b/cybox/objects/user_account_object.py @@ -14,6 +14,15 @@ class Group(entities.Entity): _binding = user_account_binding _binding_class = user_account_binding.GroupType _namespace = 'http://cybox.mitre.org/objects#UserAccountObject-2' + _XSI_TYPE = None # overridden by subclasses + + def to_dict(self): + d = super(Group, self).to_dict() + + if self._XSI_TYPE: + d['xsi:type'] = self._XSI_TYPE + + return d class GroupList(entities.EntityList): @@ -29,6 +38,15 @@ class Privilege(entities.Entity): _binding = user_account_binding _binding_class = user_account_binding.PrivilegeType _namespace = 'http://cybox.mitre.org/objects#UserAccountObject-2' + _XSI_TYPE = None # overridden by subclasses + + def to_dict(self): + d = super(Privilege, self).to_dict() + + if self._XSI_TYPE: + d['xsi:type'] = self._XSI_TYPE + + return d class PrivilegeList(entities.EntityList): diff --git a/cybox/objects/win_user_object.py b/cybox/objects/win_user_object.py index f6abadb3..c8dbce58 100644 --- a/cybox/objects/win_user_object.py +++ b/cybox/objects/win_user_object.py @@ -1,38 +1,35 @@ -# 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 import cybox.bindings.win_user_account_object as win_user_binding from cybox.common import String -from cybox.objects.user_account_object import (GroupList, PrivilegeList, - UserAccount) +from cybox.objects.user_account_object import (Group, GroupList, Privilege, + PrivilegeList, UserAccount) -class WinGroup(entities.Entity): +class WinGroup(Group): _binding = win_user_binding _binding_class = win_user_binding.WindowsGroupType _namespace = 'http://cybox.mitre.org/objects#WinUserAccountObject-2' + _XSI_TYPE = "WindowsGroupType" name = fields.TypedField("Name", String) - # TODO: Allow these to be represented as single strings in to/from_dict - class WinGroupList(GroupList): group = fields.TypedField("Group", WinGroup, multiple=True) -class WinPrivilege(entities.Entity): +class WinPrivilege(Privilege): _binding = win_user_binding _binding_class = win_user_binding.WindowsPrivilegeType _namespace = 'http://cybox.mitre.org/objects#WinUserAccountObject-2' + _XSI_TYPE = "WindowsPrivilegeType" user_right = fields.TypedField("User_Right", String) - # TODO: Allow these to be represented as single strings in to/from_dict - class WinPrivilegeList(PrivilegeList): privilege = fields.TypedField("Privilege", WinPrivilege, multiple=True) @@ -48,6 +45,6 @@ class WinUser(UserAccount): security_id = fields.TypedField('Security_ID', String) security_type = fields.TypedField('Security_Type', String) - #Override abstract types here + # Override abstract types group_list = fields.TypedField('Group_List', WinGroupList) privilege_list = fields.TypedField('Privilege_List', WinPrivilegeList) diff --git a/cybox/test/objects/unix_user_account_test.py b/cybox/test/objects/unix_user_account_test.py index b486ec8d..9ccdda0e 100644 --- a/cybox/test/objects/unix_user_account_test.py +++ b/cybox/test/objects/unix_user_account_test.py @@ -17,17 +17,17 @@ class TestUnixUserAccount(ObjectTestCase, unittest.TestCase): # Account-specific fields 'disabled': False, 'locked_out': True, - 'description': u('An account'), + 'description': u('An UNIX account'), 'domain': u('ADMIN'), 'group_list': [ { - 'group_id': 'group_id0', + 'group_id': 12345, 'xsi:type': 'UnixGroupType' } ], 'privilege_list': [ { - 'privilege': 'privilege_0', + 'permissions_mask': u("rwx"), 'xsi:type': 'UnixPrivilegeType' } ], @@ -38,6 +38,10 @@ class TestUnixUserAccount(ObjectTestCase, unittest.TestCase): 'script_path': u("/bin/bash"), 'username': u("guido"), 'user_password_age': u("P90D"), + # UnixUser-specific fields + 'group_id': 123, + 'user_id': 7874, + 'login_shell': u("/etc/profile"), 'xsi:type': object_type, } diff --git a/cybox/test/objects/win_user_test.py b/cybox/test/objects/win_user_test.py index fa48bbef..dc903b9a 100644 --- a/cybox/test/objects/win_user_test.py +++ b/cybox/test/objects/win_user_test.py @@ -20,12 +20,20 @@ class TestWinUser(ObjectTestCase, unittest.TestCase): # UserAccount-specific fields 'password_required': True, 'full_name': u("Steve Ballmer"), - 'group_list': [{'name': u("LocalAdministrators")}], + 'group_list': [ + { + 'name': u("LocalAdministrators"), + 'xsi:type': 'WindowsGroupType' + } + ], 'home_directory': u("C:\\\\Users\\\\ballmer\\\\"), 'last_login': "2011-05-12T07:14:01+07:00", 'privilege_list': [ - {'user_right': u("SeDebugPrivilege")} - ], + { + 'user_right': u("SeDebugPrivilege"), + 'xsi:type': 'WindowsPrivilegeType' + } + ], 'username': u("ballmer"), 'user_password_age': u("P180D"), # WinUser-specific fields From d43ed1cf1ac5d7134ebd6ca411dd1a32765c6441 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Fri, 24 Nov 2017 10:33:07 -0500 Subject: [PATCH 12/15] Update Object documentation --- cybox/core/object.py | 19 ++++++++++++++++--- cybox/utils/__init__.py | 1 - 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/cybox/core/object.py b/cybox/core/object.py index cda2465c..610aa63b 100644 --- a/cybox/core/object.py +++ b/cybox/core/object.py @@ -47,7 +47,10 @@ 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\_ @@ -56,7 +59,16 @@ class Object(entities.Entity): - 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 @@ -65,9 +77,10 @@ class Object(entities.Entity): 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.DomainSpecificObjectProperties", factory=ExternalTypeFactory) + 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") def __init__(self, properties=None, id_=None, idref=None): diff --git a/cybox/utils/__init__.py b/cybox/utils/__init__.py index 2cfcbd35..b826ec94 100644 --- a/cybox/utils/__init__.py +++ b/cybox/utils/__init__.py @@ -3,7 +3,6 @@ """Common utility methods""" -#importlib is imported below import os from mixbox.vendor import six From b77089c4f06fae0981ab62f2cc21d01d648b504c Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Fri, 24 Nov 2017 10:34:53 -0500 Subject: [PATCH 13/15] Update configuration --- setup.py | 10 +++------- tox.ini | 2 -- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/setup.py b/setup.py index 0673dc64..88b06922 100644 --- a/setup.py +++ b/setup.py @@ -1,7 +1,7 @@ #!/usr/bin/env python -# Copyright (c) 2015 - The MITRE Corporation -# For license information, see the LICENSE.txt file +# Copyright (c) 2015, The MITRE Corporation. All rights reserved. +# See LICENSE.txt for complete terms. from os.path import abspath, dirname, join @@ -25,16 +25,12 @@ def get_version(): readme = f.read() install_requires = [ + 'importlib ; python_version=="2.6"', 'lxml>=2.2.3', 'mixbox>=1.0.2', 'python-dateutil', ] -try: - import importlib -except ImportError: - install_requires.append('importlib') - setup( name="cybox", version=get_version(), diff --git a/tox.ini b/tox.ini index 12e162aa..eb39f8ea 100644 --- a/tox.ini +++ b/tox.ini @@ -8,7 +8,6 @@ commands = deps = -rrequirements.txt [testenv:rhel6] -basepython=python2.6 commands = nosetests cybox --exclude=ciq_test.py # Pin specific versions of LXML and python-dateutil which match what is on RHEL6 @@ -18,7 +17,6 @@ deps = nose==1.3.7 [testenv:docs] -basepython=python2.7 commands = sphinx-build -W -b html -d {envtmpdir}/doctrees docs {envtmpdir}/html From 28c308267a0f73aba76dc554d8fe0c19167024f7 Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Fri, 24 Nov 2017 10:48:06 -0500 Subject: [PATCH 14/15] Update Travis CI configuration --- .travis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 77f9e91b..eb9b61f5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: From 480580eccfb9ecae51fd31241df6cbe4296781ca Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Tue, 28 Nov 2017 08:55:11 -0500 Subject: [PATCH 15/15] Validate Byte_Order in pre-set hook. Fix PDFFile validation --- cybox/objects/artifact_object.py | 2 +- cybox/objects/pdf_file_object.py | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/cybox/objects/artifact_object.py b/cybox/objects/artifact_object.py index c5393828..333ae292 100644 --- a/cybox/objects/artifact_object.py +++ b/cybox/objects/artifact_object.py @@ -43,7 +43,7 @@ class RawArtifact(String): MIDDLE_ENDIAN = "Middle-endian" ENDIANNESS = (BIG_ENDIAN, LITTLE_ENDIAN, MIDDLE_ENDIAN) - byte_order = fields.TypedField("byte_order", postset_hook=validate_byte_order_endianness) + byte_order = fields.TypedField("byte_order", preset_hook=validate_byte_order_endianness) class Packaging(entities.Entity): diff --git a/cybox/objects/pdf_file_object.py b/cybox/objects/pdf_file_object.py index 64b7d93d..3063a259 100644 --- a/cybox/objects/pdf_file_object.py +++ b/cybox/objects/pdf_file_object.py @@ -33,7 +33,7 @@ def validate_pdf_ref_entry_type(instance, value): def validate_id_string(instance, value): if value is None: return - elif len(instance) > 2: + elif len(instance.id_string) >= 2: err = "ID_String only has a max occurrence of 2." raise ValueError(err) else: @@ -126,6 +126,7 @@ class PDFDictionary(entities.Entity): _binding_class = pdf_file_binding.PDFDictionaryType _namespace = 'http://cybox.mitre.org/objects#PDFFileObject-1' + # TODO: xs:choice object_reference = fields.TypedField("Object_Reference", PDFIndirectObjectID) raw_contents = fields.TypedField("Raw_Contents", String) @@ -215,6 +216,7 @@ class PDFXrefEntry(entities.Entity): TYPES = (TYPE_USE, TYPE_FREE) type_ = fields.TypedField("type_", key_name="type", preset_hook=validate_pdf_ref_entry_type) + # TODO: Byte_Offset and Object_Number xs:choice byte_offset = fields.TypedField("Byte_Offset", Integer) object_number = fields.TypedField("Object_Number", NonNegativeInteger) generation_number = fields.TypedField("Generation_Number", NonNegativeInteger)