-
Notifications
You must be signed in to change notification settings - Fork 12
Examples: simple content creation for cybox v2.0
ikiril01 edited this page Apr 23, 2013
·
4 revisions
The following code demonstrates how to create a simple CybOX document with a single Observable, representing a DLL file that was found on an endpoint.
#Import the CybOX Core, Common, and File Object bindings
import cybox.bindings.cybox_core as cybox_binding
import cybox.bindings.cybox_common as cybox_common_binding
import cybox.bindings.file_object as file_binding
#Create the Observables object, representing the root of the document
observables = cybox_binding.ObservablesType(cybox_minor_version=0,cybox_major_version=2)
#Create an observable to hold the File Object
observable = cybox_binding.ObservableType()
#Create the CybOX object and instantiate and populate File Object
obj = cybox_binding.ObjectType()
file_obj = file_binding.FileObjectType()
file_obj.set_File_Name(cybox_common_binding.StringObjectPropertyType(datatype=None,apply_condition=None, valueOf_='foobar.dll'))
file_obj.set_Size_In_Bytes(cybox_common_binding.UnsignedLongObjectPropertyType(datatype=None,apply_condition=None, valueOf_='25562'))
#Set the XSI extension type of the File Object
file_obj.set_xsi_type('FileObj:FileObjectType')
#Set the File Object as the Properties of the parent CybOX Object
obj.set_Properties(file_obj)
#Set the CybOX Object as the Observable Object
observable.set_Object(obj)
#Add the Observable to the root Observables
observables.add_Observable(observable)
#Open a file for writing and export the Observables and all of its children to an XML document
out_file = open('test.xml', 'w')
observables.export(out_file,0)
out_file.close()