Beispiel #1
0
    def test_namespace_count(self):
        h = HashList()
        h.append(EMPTY_MD5)
        h.append(EMPTY_SHA1)
        h.append(EMPTY_SHA224)
        h.append(EMPTY_SHA256)
        h.append(EMPTY_SHA384)
        h.append(EMPTY_SHA512)
        logger.info(h.to_xml())

        ns_list = cybox.test.round_trip(h, list_=True)._get_namespaces()
        logger.info(ns_list)

        # Only "common" and "vocabs" should be here. "xsi" is only added later
        self.assertEqual(2, len(ns_list))
Beispiel #2
0
    def test_namespace_count(self):
        h = HashList()
        h.append(EMPTY_MD5)
        h.append(EMPTY_SHA1)
        h.append(EMPTY_SHA224)
        h.append(EMPTY_SHA256)
        h.append(EMPTY_SHA384)
        h.append(EMPTY_SHA512)
        print h.to_xml()

        ns_list = cybox.test.round_trip(h, list_=True)._get_namespaces()
        print ns_list

        # Only "common" and "vocabs" should be here. "xsi" is only added later
        self.assertEqual(2, len(ns_list))
Beispiel #3
0
class File(ObjectProperties):
    _binding = file_binding
    _binding_class = file_binding.FileObjectType
    _namespace = 'http://cybox.mitre.org/objects#FileObject-2'
    _XSI_NS = "FileObj"
    _XSI_TYPE = "FileObjectType"

    is_packed = cybox.TypedField("is_packed")
    file_name = cybox.TypedField("File_Name", String)
    file_path = cybox.TypedField("File_Path", FilePath)
    device_path = cybox.TypedField("Device_Path", String)
    full_path = cybox.TypedField("Full_Path", String)
    file_extension = cybox.TypedField("File_Extension", String)
    size_in_bytes = cybox.TypedField("Size_In_Bytes", UnsignedLong)
    magic_number = cybox.TypedField("Magic_Number", HexBinary)
    file_format = cybox.TypedField("File_Format", String)
    modified_time = cybox.TypedField("Modified_Time", String)
    accessed_time = cybox.TypedField("Accessed_Time", String)
    created_time = cybox.TypedField("Created_Time", DateTime)
    hashes = cybox.TypedField("Hashes", HashList)
    extracted_features = cybox.TypedField("Extracted_Features",
                                          ExtractedFeatures)

    # Not supported yet:
    # - Digital_Signatures
    # - File_Attributes_List
    # - Permissions
    # - User_Owner
    # - Packer_List
    # - Peak_Entropy
    # - Sym_Links
    # - Extracted_Features
    # - Byte Runs

    def __init__(self):
        super(File, self).__init__()
        self.is_packed = None

    @property
    def md5(self):
        if self.hashes is None:
            return None
        return self.hashes.md5

    @md5.setter
    def md5(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.md5 = value

    @property
    def sha1(self):
        if self.hashes is None:
            return None
        return self.hashes.sha1

    @sha1.setter
    def sha1(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha1 = value

    @property
    def sha256(self):
        if self.hashes is None:
            return None
        return self.hashes.sha256

    @sha256.setter
    def sha256(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha256 = value

    @property
    def size(self):
        """`size` is an alias for `size_in_bytes`"""
        return self.size_in_bytes

    @size.setter
    def size(self, value):
        """`size` is an alias for `size_in_bytes`"""
        self.size_in_bytes = value

    def add_hash(self, hash_):
        if hash_ is not None:
            if self.hashes is None:
                self.hashes = HashList()
            self.hashes.append(hash_)
Beispiel #4
0
class File(ObjectProperties):
    _binding = file_binding
    _binding_class = file_binding.FileObjectType
    _namespace = 'http://cybox.mitre.org/objects#FileObject-2'
    _XSI_NS = "FileObj"
    _XSI_TYPE = "FileObjectType"

    is_packed = fields.TypedField("is_packed")
    is_masqueraded = fields.TypedField("is_masqueraded")
    file_name = fields.TypedField("File_Name", String)
    file_path = fields.TypedField("File_Path", FilePath)
    device_path = fields.TypedField("Device_Path", String)
    full_path = fields.TypedField("Full_Path", String)
    file_extension = fields.TypedField("File_Extension", String)
    size_in_bytes = fields.TypedField("Size_In_Bytes", UnsignedLong)
    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)
    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
    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)
    encryption_algorithm = fields.TypedField("Encryption_Algorithm", String)
    decryption_key = fields.TypedField("Decryption_Key", String)
    compression_method = fields.TypedField("Compression_Method", String)
    compression_version = fields.TypedField("Compression_Version", String)
    compression_comment = fields.TypedField("Compression_Comment", String)

    def __init__(self):
        super(File, self).__init__()
        self.is_packed = None

    @property
    def md5(self):
        if self.hashes is None:
            return None
        return self.hashes.md5

    @md5.setter
    def md5(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.md5 = value

    @property
    def sha1(self):
        if self.hashes is None:
            return None
        return self.hashes.sha1

    @sha1.setter
    def sha1(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha1 = value

    @property
    def sha224(self):
        if self.hashes is None:
            return None
        return self.hashes.sha224

    @sha224.setter
    def sha224(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha224 = value

    @property
    def sha256(self):
        if self.hashes is None:
            return None
        return self.hashes.sha256

    @sha256.setter
    def sha256(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha256 = value

    @property
    def sha384(self):
        if self.hashes is None:
            return None
        return self.hashes.sha384

    @sha384.setter
    def sha384(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha384 = value

    @property
    def sha512(self):
        if self.hashes is None:
            return None
        return self.hashes.sha512

    @sha512.setter
    def sha512(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha512 = value

    @property
    def size(self):
        """`size` is an alias for `size_in_bytes`"""
        return self.size_in_bytes

    @size.setter
    def size(self, value):
        """`size` is an alias for `size_in_bytes`"""
        self.size_in_bytes = value

    def add_hash(self, hash_):
        if hash_ is not None:
            if self.hashes is None:
                self.hashes = HashList()
            self.hashes.append(hash_)
Beispiel #5
0
class File(ObjectProperties):
    _binding = file_binding
    _binding_class = file_binding.FileObjectType
    _namespace = 'http://cybox.mitre.org/objects#FileObject-2'
    _XSI_NS = "FileObj"
    _XSI_TYPE = "FileObjectType"

    is_packed = cybox.TypedField("is_packed")
    is_masqueraded = cybox.TypedField("is_masqueraded")
    file_name = cybox.TypedField("File_Name", String)
    file_path = cybox.TypedField("File_Path", FilePath)
    device_path = cybox.TypedField("Device_Path", String)
    full_path = cybox.TypedField("Full_Path", String)
    file_extension = cybox.TypedField("File_Extension", String)
    size_in_bytes = cybox.TypedField("Size_In_Bytes", UnsignedLong)
    magic_number = cybox.TypedField("Magic_Number", HexBinary)
    file_format = cybox.TypedField("File_Format", String)
    hashes = cybox.TypedField("Hashes", HashList)
    digital_signatures = cybox.TypedField("Digital_Signatures",
                                          DigitalSignatureList)
    modified_time = cybox.TypedField("Modified_Time", DateTime)
    accessed_time = cybox.TypedField("Accessed_Time", DateTime)
    created_time = cybox.TypedField("Created_Time", DateTime)
    # Subclasses must redefine these, since the abstract types
    # cannot be instantiated.
    file_attributes_list = cybox.TypedField("File_Attributes_List",
                                            FileAttribute)  # abstract
    permissions = cybox.TypedField("Permissions", FilePermissions)  # abstract
    user_owner = cybox.TypedField("User_Owner", String)
    packer_list = cybox.TypedField("Packer_List", PackerList)
    peak_entropy = cybox.TypedField("Peak_Entropy", Double)
    sym_links = cybox.TypedField("Sym_Links", SymLinksList)
    byte_runs = cybox.TypedField("Byte_Runs", ByteRuns)
    extracted_features = cybox.TypedField("Extracted_Features",
                                          ExtractedFeatures)
    encryption_algorithm = cybox.TypedField("Encryption_Algorithm", String)
    decryption_key = cybox.TypedField("Decryption_Key", String)
    compression_method = cybox.TypedField("Compression_Method", String)
    compression_version = cybox.TypedField("Compression_Version", String)
    compression_comment = cybox.TypedField("Compression_Comment", String)

    def __init__(self):
        super(File, self).__init__()
        self.is_packed = None

    @property
    def md5(self):
        if self.hashes is None:
            return None
        return self.hashes.md5

    @md5.setter
    def md5(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.md5 = value

    @property
    def sha1(self):
        if self.hashes is None:
            return None
        return self.hashes.sha1

    @sha1.setter
    def sha1(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha1 = value

    @property
    def sha224(self):
        if self.hashes is None:
            return None
        return self.hashes.sha224

    @sha224.setter
    def sha224(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha224 = value

    @property
    def sha256(self):
        if self.hashes is None:
            return None
        return self.hashes.sha256

    @sha256.setter
    def sha256(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha256 = value

    @property
    def sha384(self):
        if self.hashes is None:
            return None
        return self.hashes.sha384

    @sha384.setter
    def sha384(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha384 = value

    @property
    def sha512(self):
        if self.hashes is None:
            return None
        return self.hashes.sha512

    @sha512.setter
    def sha512(self, value):
        if self.hashes is None:
            self.hashes = HashList()
        self.hashes.sha512 = value

    @property
    def size(self):
        """`size` is an alias for `size_in_bytes`"""
        return self.size_in_bytes

    @size.setter
    def size(self, value):
        """`size` is an alias for `size_in_bytes`"""
        self.size_in_bytes = value

    def add_hash(self, hash_):
        if hash_ is not None:
            if self.hashes is None:
                self.hashes = HashList()
            self.hashes.append(hash_)