Exemple #1
0
    def test_values(self):
        i = Integer()
        self.assertEqual([], i.values)

        i = Integer(1)
        self.assertEqual([1], i.values)

        i = Integer([2])
        self.assertEqual([2], i.values)

        i = Integer([3, 4])
        self.assertEqual([3, 4], i.values)
 def from_obj(rsa_public_key_obj):
     if not rsa_public_key_obj:
         return None
     rsa_public_key_ = RSAPublicKey()
     rsa_public_key_.modulus = String.from_obj(rsa_public_key_obj.get_Modulus())
     rsa_public_key_.exponent = Integer.from_obj(rsa_public_key_obj.get_Exponent())
     return rsa_public_key_
 def from_dict(rsa_public_key_dict):
     if not rsa_public_key_dict:
         return None
     rsa_public_key_ = RSAPublicKey()
     rsa_public_key_.modulus = String.from_dict(rsa_public_key_dict.get('modulus'))
     rsa_public_key_.exponent = Integer.from_dict(rsa_public_key_dict.get('exponent'))
     return rsa_public_key_
    def test_numerics(self):
        p = PositiveInteger(42)
        p2 = cybox.test.round_trip(p)
        self.assertEqual(p.to_dict(), p2.to_dict())

        i = Integer(42)
        i2 = cybox.test.round_trip(i)
        self.assertEqual(i.to_dict(), i2.to_dict())

        u = UnsignedLong(42)
        u2 = cybox.test.round_trip(u)
        self.assertEqual(u.to_dict(), u2.to_dict())

        u3 = UnsignedLong("42")
        self.assertEqual(u3.value, 42)
        self.assertNotEqual(u3.value, "42")
        self.assertEqual(u3.to_dict(), u.to_dict())
Exemple #5
0
    def test_numerics(self):
        p = PositiveInteger(42)
        p2 = cybox.test.round_trip(p)
        self.assertEqual(p.to_dict(), p2.to_dict())

        i = Integer(42)
        i2 = cybox.test.round_trip(i)
        self.assertEqual(i.to_dict(), i2.to_dict())

        u = UnsignedLong(42)
        u2 = cybox.test.round_trip(u)
        self.assertEqual(u.to_dict(), u2.to_dict())

        u3 = UnsignedLong("42")
        self.assertEqual(u3.value, 42)
        self.assertNotEqual(u3.value, "42")
        self.assertEqual(u3.to_dict(), u.to_dict())
    def from_obj(dns_record_obj):
        if not dns_record_obj:
            return None

        dns_record_ = DNSRecord()
        dns_record_.description = StructuredText.from_obj(dns_record_obj.get_Description())
        dns_record_.domain_name = URI.from_obj(dns_record_obj.get_Domain_Name())
        dns_record_.ip_address = Address.from_obj(dns_record_obj.get_IP_Address())
        dns_record_.address_class = String.from_obj(dns_record_obj.get_Address_Class())
        dns_record_.entry_type = String.from_obj(dns_record_obj.get_Entry_Type())
        dns_record_.record_name = String.from_obj(dns_record_obj.get_Record_Name())
        dns_record_.record_type = String.from_obj(dns_record_obj.get_Record_Type())
        dns_record_.ttl = Integer.from_obj(dns_record_obj.get_TTL())
        dns_record_.flags = HexBinary.from_obj(dns_record_obj.get_Flags())
        dns_record_.data_length = Integer.from_obj(dns_record_obj.get_Length())
        dns_record_.record_data = dns_record_obj.get_Record_Data()

        return dns_record_
    def from_dict(dns_record_dict):
        if not dns_record_dict:
            return None

        dns_record_ = DNSRecord()
        dns_record_.description = StructuredText.from_dict(dns_record_dict.get('description'))
        dns_record_.domain_name = URI.from_dict(dns_record_dict.get('domain_name'))
        dns_record_.ip_address = Address.from_dict(dns_record_dict.get('ip_address'))
        dns_record_.address_class = String.from_dict(dns_record_dict.get('address_class'))
        dns_record_.entry_type = String.from_dict(dns_record_dict.get('entry_type'))
        dns_record_.record_name = String.from_dict(dns_record_dict.get('record_name'))
        dns_record_.record_type = String.from_dict(dns_record_dict.get('record_type'))
        dns_record_.ttl = Integer.from_dict(dns_record_dict.get('record_type'))
        dns_record_.flags = HexBinary.from_dict(dns_record_dict.get('flags'))
        dns_record_.data_length = Integer.from_dict(dns_record_dict.get('data_length'))
        dns_record_.record_data = dns_record_dict.get('record_data')

        return dns_record_
    def from_obj(addr_object):
        if not addr_object:
            return None

        addr = Address()
        ObjectProperties.from_obj(addr_object, addr)

        addr.address_value = String.from_obj(addr_object.get_Address_Value())
        addr.category = addr_object.get_category()
        addr.is_destination = addr_object.get_is_destination()
        addr.is_source = addr_object.get_is_source()
        addr.vlan_name = String.from_obj(addr_object.get_VLAN_Name())
        addr.vlan_num = Integer.from_obj(addr_object.get_VLAN_Num())

        return addr
    def from_dict(addr_dict, category=None):
        if not addr_dict:
            return None

        addr = Address()

        # Shortcut if only a string is passed as a parameter
        if not isinstance(addr_dict, dict):
            addr.address_value = String.from_dict(addr_dict)
            addr.category = category
            return addr

        ObjectProperties.from_dict(addr_dict, addr)

        addr.category = addr_dict.get('category')
        addr.is_destination = addr_dict.get('is_destination')
        addr.is_source = addr_dict.get('is_source')
        addr.address_value = String.from_dict(addr_dict.get('address_value'))
        addr.vlan_name = String.from_dict(addr_dict.get('vlan_name'))
        addr.vlan_num = Integer.from_dict(addr_dict.get('vlan_num'))

        return addr
 def test_list_numerics(self):
     i = Integer([1, 2, 3])
     i2 = Integer.from_dict({'value': ['1', '2', '3']})
     self.assertEqual(i.to_dict(), i2.to_dict())
 def __init__(self):
     super(IPv4Flags, self).__init__()
     self.reserved = Integer(0)
Exemple #12
0
 def test_integer(self):
     i = Integer(42)
     self.assertEqual(i.datatype, "int")
     self.assertEqual(i.value, 42)
Exemple #13
0
 def test_list_numerics(self):
     i = Integer([1, 2, 3])
     i2 = Integer.from_dict({'value': ['1', '2', '3']})
     self.assertEqual(i.to_dict(), i2.to_dict())
Exemple #14
0
 def test_coerce_to_int(self):
     val = 42
     i = Integer(val)
     self.assertEqual(val, i.value)
     self.assertEqual(val, int(i))
Exemple #15
0
# https://cybox.readthedocs.org/en/stable/_modules/cybox/common/digitalsignature.html#DigitalSignature
digital_signature = DigitalSignature()
digital_signature.certificate_issuer = String('')
digital_signature.certificate_subject = String('')
digital_signature.signature_description = String('')
digital_signature.signature_exists = None
digital_signature.signature_verified = None

# https://cybox.readthedocs.org/en/stable/_modules/cybox/objects/win_executable_file_object.html#PEExports
exports = PEExports()
exports.exported_functions = PEExportedFunctions()
exports.exports_time_stamp = DateTime()
exports.name = String()
exports.number_of_addresses = Long()
exports.number_of_functions = Integer()
exports.number_of_names = Long()

# The Extraneous_Bytes field specifies the number of extraneous bytes contained in the PE binary.
extraneous_bytes = Integer()

# https://cybox.readthedocs.org/en/stable/_modules/cybox/objects/win_executable_file_object.html#PEHeaders
headers = PEHeaders()
headers.dos_header = DOSHeader()
headers.entropy = Entropy()
headers.file_header = PEFileHeader()
headers.hashes = HashList()
headers.optional_header = PEOptionalHeader()
headers.signature = HexBinary()

# https://cybox.readthedocs.org/en/stable/_modules/cybox/objects/win_executable_file_object.html#PEImportList