text
stringlengths
81
112k
Load data from json file :param file: Readable file or path to file :type file: FileIO | str | unicode :param decoder: Use custom json decoder :type decoder: T <= flotils.loadable.DateTimeDecoder :return: Json data :rtype: None | int | float | str | list | dict :...
Save data to json file :param file: Writable file or path to file :type file: FileIO | str | unicode :param val: Value or struct to save :type val: None | int | float | str | list | dict :param pretty: Format data to be readable (default: False) :type pretty: bool ...
Load data from yaml file :param file: Readable object or path to file :type file: FileIO | str | unicode :return: Yaml data :rtype: None | int | float | str | unicode | list | dict :raises IOError: Failed to load def _load_yaml_file(self, file): """ Load data fr...
Save data to yaml file :param file: Writable object or path to file :type file: FileIO | str | unicode :param val: Value or struct to save :type val: None | int | float | str | unicode | list | dict :raises IOError: Failed to save def _save_yaml_file(self, file, val): "...
Load settings dict :param path: Path to settings file :type path: str | unicode :return: Loaded settings :rtype: dict :raises IOError: If file not found or error accessing file :raises TypeError: Settings file does not contain dict def load_settings(self, path): ...
Save settings to file :param path: File path to save :type path: str | unicode :param settings: Settings to save :type settings: dict :param readable: Format file to be human readable (default: False) :type readable: bool :rtype: None :raises IOError: If ...
Load file :param path: Path to file :type path: str | unicode :return: Loaded settings :rtype: None | str | unicode | int | list | dict :raises IOError: If file not found or error accessing file def load_file(self, path): """ Load file :param path: Path...
Save to file :param path: File path to save :type path: str | unicode :param data: To save :type data: None | str | unicode | int | list | dict :param readable: Format file to be human readable (default: False) :type readable: bool :rtype: None :raises IO...
Get the module name :return: Module name :rtype: str | unicode def name(self): """ Get the module name :return: Module name :rtype: str | unicode """ res = type(self).__name__ if self._id: res += ".{}".format(self._id) return...
Get function name of calling method :return: The name of the calling function (expected to be called in self.error/debug/..) :rtype: str | unicode def _get_function_name(self): """ Get function name of calling method :return: The name of the calling function ...
Start the interface :param blocking: Should the call block until stop() is called (default: False) :type blocking: bool :rtype: None def start(self, blocking=False): """ Start the interface :param blocking: Should the call block until stop() is called ...
Extract YARA signatures embedded in Yara/Yara indicatorItem nodes. This is done regardless of logic structure in the OpenIOC. def get_embedded_yara(self, iocid): """ Extract YARA signatures embedded in Yara/Yara indicatorItem nodes. This is done regardless of logic structure in the Open...
get_yara_condition_string input indicator_node: this is the node we walk down parameters_node: this contains all the parameters in the ioc, so we can look up parameters nodes as we walk them. ids_to_process: set of ids to upgrade condition_string:...
Write out yara signatures to a file. def write_yara(self, output_file): """ Write out yara signatures to a file. """ fout = open(output_file, 'wb') fout.write('\n') for iocid in self.yara_signatures: signature = self.yara_signatures[iocid] fout.w...
Make an arbitrary directory. This is safe to call for Python 2 users. :param fdir: Directory path to make. :return: def safe_makedirs(fdir): """ Make an arbitrary directory. This is safe to call for Python 2 users. :param fdir: Directory path to make. :return: """ if os.path.isdir(f...
converts the iocs in self.iocs from openioc 1.1 to openioc 1.0 format. the converted iocs are stored in the dictionary self.iocs_10 :return: A list of iocid values which had errors downgrading. def convert_to_10(self): """ converts the iocs in self.iocs from openioc 1.1 to openioc 1.0 f...
Recursively walk a indicator logic tree, starting from a Indicator node. Converts OpenIOC 1.1 Indicator/IndicatorItems to Openioc 1.0 and preserves order. :param old_node: An Indicator node, which we walk down to convert :param new_node: An Indicator node, which we add new IndicatorItem and In...
Serializes IOCs to a directory. :param directory: Directory to write IOCs to. If not provided, the current working directory is used. :param source: Dictionary contianing iocid -> IOC mapping. Defaults to self.iocs_10. This is not normally modifed by a user for this class. :return: def write...
Writes IOCs to a directory that have been pruned of some or all IOCs. :param directory: Directory to write IOCs to. If not provided, the current working directory is used. :param pruned_source: Iterable containing a set of iocids. Defaults to self.iocs_10. :return: def write_pruned_iocs(self...
Create a node for DnsEntryItem/RecordName :return: A IndicatorItem represented as an Element node def make_dnsentryitem_recordname(dns_name, condition='contains', negate=False, preserve_case=False): """ Create a node for DnsEntryItem/RecordName :return: A IndicatorItem represented as an Eleme...
Create a node for DriverItem/DeviceItem/DeviceName :return: A IndicatorItem represented as an Element node def make_driveritem_deviceitem_devicename(device_name, condition='is', negate=False, preserve_case=False): """ Create a node for DriverItem/DeviceItem/DeviceName :return: A IndicatorItem...
Create a node for DriverItem/DriverName :return: A IndicatorItem represented as an Element node def make_driveritem_drivername(driver_name, condition='contains', negate=False, preserve_case=False): """ Create a node for DriverItem/DriverName :return: A IndicatorItem represented as an Element ...
Create a node for EventLogItem/EID :return: A IndicatorItem represented as an Element node def make_eventlogitem_eid(eid, condition='is', negate=False): """ Create a node for EventLogItem/EID :return: A IndicatorItem represented as an Element node """ document = 'EventLogItem' sea...
Create a node for EventLogItem/log :return: A IndicatorItem represented as an Element node def make_eventlogitem_log(log, condition='is', negate=False, preserve_case=False): """ Create a node for EventLogItem/log :return: A IndicatorItem represented as an Element node """ document = '...
Create a node for EventLogItem/message :return: A IndicatorItem represented as an Element node def make_eventlogitem_message(message, condition='contains', negate=False, preserve_case=False): """ Create a node for EventLogItem/message :return: A IndicatorItem represented as an Element node ...
Create a node for FileItem/FileAttributes :return: A IndicatorItem represented as an Element node def make_fileitem_fileattributes(attributes, condition='contains', negate=False, preserve_case=False): """ Create a node for FileItem/FileAttributes :return: A IndicatorItem represented as an Ele...
Create a node for FileItem/FileExtension :return: A IndicatorItem represented as an Element node def make_fileitem_fileextension(extension, condition='is', negate=False, preserve_case=False): """ Create a node for FileItem/FileExtension :return: A IndicatorItem represented as an Element node ...
Create a node for FileItem/FileName :return: A IndicatorItem represented as an Element node def make_fileitem_filename(filename, condition='is', negate=False, preserve_case=False): """ Create a node for FileItem/FileName :return: A IndicatorItem represented as an Element node """ docu...
Create a node for FileItem/FilePath :return: A IndicatorItem represented as an Element node def make_fileitem_filepath(filepath, condition='contains', negate=False, preserve_case=False): """ Create a node for FileItem/FilePath :return: A IndicatorItem represented as an Element node """ ...
Create a node for FileItem/FullPath :return: A IndicatorItem represented as an Element node def make_fileitem_fullpath(fullpath, condition='contains', negate=False, preserve_case=False): """ Create a node for FileItem/FullPath :return: A IndicatorItem represented as an Element node """ ...
Create a node for FileItem/Md5sum :return: A IndicatorItem represented as an Element node def make_fileitem_md5sum(md5, condition='is', negate=False): """ Create a node for FileItem/Md5sum :return: A IndicatorItem represented as an Element node """ document = 'FileItem' search = '...
Create a node for FileItem/PEInfo/DetectedAnomalies/string :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_detectedanomalies_string(anomaly, condition='is', negate=False, preserve_case=False): """ Create a node for FileItem/PEInfo/DetectedAnomalies/string :ret...
Create a node for FileItem/PEInfo/DetectedEntryPointSignature/Name :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_detectedentrypointsignature_name(entrypoint_name, condition='is', negate=False, preserve_case=False): ...
Create a node for FileItem/PEInfo/DigitalSignature/SignatureExists :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_digitalsignature_signatureexists(sig_exists, condition='is', negate=False): """ Create a node for FileItem/PEInfo/DigitalSignature/SignatureExists ...
Create a node for FileItem/PEInfo/DigitalSignature/SignatureVerified :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_digitalsignature_signatureverified(sig_verified, condition='is', negate=False): """ Create a node for FileItem/PEInfo/DigitalSignature/SignatureVerified...
Create a node for FileItem/PEInfo/Exports/DllName :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_exports_dllname(dll_name, condition='is', negate=False, preserve_case=False): """ Create a node for FileItem/PEInfo/Exports/DllName :return: A IndicatorItem repre...
Create a node for FileItem/PEInfo/Exports/NumberOfFunctions :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_exports_numberoffunctions(function_count, condition='is', negate=False): """ Create a node for FileItem/PEInfo/Exports/NumberOfFunctions :return: A Indi...
Create a node for FileItem/PEInfo/ImportedModules/Module/ImportedFunctions/string :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_importedmodules_module_importedfunctions_string(imported_function, condition='is', ...
Create a node for FileItem/PEInfo/ImportedModules/Module/Name :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_importedmodules_module_name(imported_module, condition='is', negate=False, preserve_case=False): """ Creat...
Create a node for FileItem/PEInfo/PETimeStamp :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_petimestamp(compile_time, condition='is', negate=False): """ Create a node for FileItem/PEInfo/PETimeStamp :return: A IndicatorItem represented as an Element node ...
Create a node for FileItem/PEInfo/ResourceInfoList/ResourceInfoItem/Name :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_resourceinfolist_resourceinfoitem_name(resource_name, condition='is', negate=False, preserve...
Create a node for FileItem/PEInfo/Type :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_type(petype, condition='is', negate=False, preserve_case=False): """ Create a node for FileItem/PEInfo/Type :return: A IndicatorItem represented as an Element node """ ...
Create a node for FileItem/SizeInBytes :return: A IndicatorItem represented as an Element node def make_fileitem_sizeinbytes(filesize, condition='is', negate=False): """ Create a node for FileItem/SizeInBytes :return: A IndicatorItem represented as an Element node """ document = 'File...
Create a node for FileItem/StreamList/Stream/Name :return: A IndicatorItem represented as an Element node def make_fileitem_streamlist_stream_name(stream_name, condition='is', negate=False, preserve_case=False): """ Create a node for FileItem/StreamList/Stream/Name :return: A IndicatorItem re...
Create a node for FileItem/StringList/string :return: A IndicatorItem represented as an Element node def make_fileitem_stringlist_string(file_string, condition='contains', negate=False, preserve_case=False): """ Create a node for FileItem/StringList/string :return: A IndicatorItem represented...
Create a node for FileItem/Username :return: A IndicatorItem represented as an Element node def make_fileitem_username(file_owner, condition='is', negate=False, preserve_case=False): """ Create a node for FileItem/Username :return: A IndicatorItem represented as an Element node """ do...
Create a node for HookItem/HookedFunction :return: A IndicatorItem represented as an Element node def make_hookitem_hookedfunction(hooked_function, condition='is', negate=False, preserve_case=False): """ Create a node for HookItem/HookedFunction :return: A IndicatorItem represented as an Elem...
Create a node for HookItem/HookingModule :return: A IndicatorItem represented as an Element node def make_hookitem_hookingmodule(hooking_module, condition='contains', negate=False, preserve_case=False): """ Create a node for HookItem/HookingModule :return: A IndicatorItem represented as an El...
Create a node for PortItem/remotePort :return: A IndicatorItem represented as an Element node def make_portitem_remoteport(remote_port, condition='is', negate=False): """ Create a node for PortItem/remotePort :return: A IndicatorItem represented as an Element node """ document = 'Port...
Create a node for PrefetchItem/AccessedFileList/AccessedFile :return: A IndicatorItem represented as an Element node def make_prefetchitem_accessedfilelist_accessedfile(accessed_file, condition='contains', negate=False, preserve_case=False): """ Crea...
Create a node for PrefetchItem/ApplicationFileName :return: A IndicatorItem represented as an Element node def make_prefetchitem_applicationfilename(application_filename, condition='is', negate=False, preserve_case=False): """ Create a node for PrefetchItem/ApplicationFileName :return: A Indi...
Create a node for PrefetchItem/ApplicationFullPath :return: A IndicatorItem represented as an Element node def make_prefetchitem_applicationfullpath(application_fullpath, condition='contains', negate=False, preserve_case=False): """ Create a node for PrefetchI...
Create a node for ProcessItem/HandleList/Handle/Name :return: A IndicatorItem represented as an Element node def make_processitem_handlelist_handle_name(handle_name, condition='contains', negate=False, preserve_case=False): """ Create a node for ProcessItem/HandleList/Handle/Name :return: A I...
Create a node for ProcessItem/PortList/PortItem/remoteIP :return: A IndicatorItem represented as an Element node def make_processitem_portlist_portitem_remoteip(remote_ip, condition='is', negate=False): """ Create a node for ProcessItem/PortList/PortItem/remoteIP :return: A IndicatorItem repr...
Create a node for ProcessItem/SectionList/MemorySection/Name :return: A IndicatorItem represented as an Element node def make_processitem_sectionlist_memorysection_name(section_name, condition='contains', negate=False, preserve_case=False): """ Creat...
Create a node for ProcessItem/SectionList/MemorySection/PEInfo/Exports/ExportedFunctions/string :return: A IndicatorItem represented as an Element node def make_processitem_sectionlist_memorysection_peinfo_exports_exportedfunctions_string(export_function, condition='is', ...
Create a node for ProcessItem/StringList/string :return: A IndicatorItem represented as an Element node def make_processitem_stringlist_string(string, condition='contains', negate=False, preserve_case=False): """ Create a node for ProcessItem/StringList/string :return: A IndicatorItem represe...
Create a node for ProcessItem/Username :return: A IndicatorItem represented as an Element node def make_processitem_username(username, condition='contains', negate=False, preserve_case=False): """ Create a node for ProcessItem/Username :return: A IndicatorItem represented as an Element node ...
Create a node for ProcessItem/arguments :return: A IndicatorItem represented as an Element node def make_processitem_arguments(arguments, condition='contains', negate=False, preserve_case=False): """ Create a node for ProcessItem/arguments :return: A IndicatorItem represented as an Element no...
Create a node for ProcessItem/path :return: A IndicatorItem represented as an Element node def make_processitem_path(path, condition='contains', negate=False, preserve_case=False): """ Create a node for ProcessItem/path :return: A IndicatorItem represented as an Element node """ docum...
Create a node for RegistryItem/KeyPath :return: A IndicatorItem represented as an Element node def make_registryitem_keypath(keypath, condition='contains', negate=False, preserve_case=False): """ Create a node for RegistryItem/KeyPath :return: A IndicatorItem represented as an Element node ...
Create a node for RegistryItem/Text :return: A IndicatorItem represented as an Element node def make_registryitem_text(text, condition='contains', negate=False, preserve_case=False): """ Create a node for RegistryItem/Text :return: A IndicatorItem represented as an Element node """ do...
Create a node for RegistryItem/ValueName :return: A IndicatorItem represented as an Element node def make_registryitem_valuename(valuename, condition='is', negate=False, preserve_case=False): """ Create a node for RegistryItem/ValueName :return: A IndicatorItem represented as an Element node ...
Create a node for ServiceItem/description :return: A IndicatorItem represented as an Element node def make_serviceitem_description(description, condition='contains', negate=False, preserve_case=False): """ Create a node for ServiceItem/description :return: A IndicatorItem represented as an El...
Create a node for ServiceItem/descriptiveName :return: A IndicatorItem represented as an Element node def make_serviceitem_descriptivename(descriptive_name, condition='is', negate=False, preserve_case=False): """ Create a node for ServiceItem/descriptiveName :return: A IndicatorItem represent...
Create a node for ServiceItem/name :return: A IndicatorItem represented as an Element node def make_serviceitem_name(name, condition='is', negate=False, preserve_case=False): """ Create a node for ServiceItem/name :return: A IndicatorItem represented as an Element node """ document = ...
Create a node for ServiceItem/pathmd5sum :return: A IndicatorItem represented as an Element node def make_serviceitem_pathmd5sum(path_md5, condition='is', negate=False): """ Create a node for ServiceItem/pathmd5sum :return: A IndicatorItem represented as an Element node """ document =...
Create a node for ServiceItem/serviceDLL :return: A IndicatorItem represented as an Element node def make_serviceitem_servicedll(servicedll, condition='contains', negate=False, preserve_case=False): """ Create a node for ServiceItem/serviceDLL :return: A IndicatorItem represented as an Elemen...
Create a node for ServiceItem/serviceDLLSignatureExists :return: A IndicatorItem represented as an Element node def make_serviceitem_servicedllsignatureexists(dll_sig_exists, condition='is', negate=False): """ Create a node for ServiceItem/serviceDLLSignatureExists :return: A IndicatorItem re...
Create a node for ServiceItem/serviceDLLSignatureVerified :return: A IndicatorItem represented as an Element node def make_serviceitem_servicedllsignatureverified(dll_sig_verified, condition='is', negate=False): """ Create a node for ServiceItem/serviceDLLSignatureVerified :return: A Indicato...
Create a node for ServiceItem/serviceDLLmd5sum :return: A IndicatorItem represented as an Element node def make_serviceitem_servicedllmd5sum(servicedll_md5, condition='is', negate=False): """ Create a node for ServiceItem/serviceDLLmd5sum :return: A IndicatorItem represented as an Element nod...
Create a node for SystemInfoItem/hostname :return: A IndicatorItem represented as an Element node def make_systeminfoitem_hostname(hostname, condition='contains', negate=False, preserve_case=False): """ Create a node for SystemInfoItem/hostname :return: A IndicatorItem represented as an Eleme...
Create a node for SystemRestoreItem/OriginalFileName :return: A IndicatorItem represented as an Element node def make_systemrestoreitem_originalfilename(original_filename, condition='contains', negate=False, preserve_case=False): """ Create a node for SystemRestoreItem/OriginalFileName :retur...
Create a node for FileItem/PEInfo/VersionInfoList/VersionInfoItem/ + key name No validation of the key is performed. :return: A IndicatorItem represented as an Element node def make_fileitem_peinfo_versioninfoitem(key, value, condition='is', negate=False, preserve_case=False): """ Create a no...
Fix the ordering of children under the criteria node to ensure that IndicatorItem/Indicator order is preserved, as per XML Schema. :return: def fix_schema_node_ordering(parent): """ Fix the ordering of children under the criteria node to ensure that IndicatorItem/Indicator order ...
This makes a Indicator node element. These allow the construction of a logic tree within the IOC. :param operator: String 'AND' or 'OR'. The constants ioc_api.OR and ioc_api.AND may be used as well. :param nid: This is used to provide a GUID for the Indicator. The ID should NOT be specified under normal circ...
This makes a IndicatorItem element. This contains the actual threat intelligence in the IOC. :param condition: This is the condition of the item ('is', 'contains', 'matches', etc). The following contants in ioc_api may be used: ==================== ===================================================== Constant ...
This returns the first top level Indicator node under the criteria node. :param root_node: Root node of an etree. :return: an elementTree Element item, or None if no item is found. def get_top_level_indicator_node(root_node): """ This returns the first top level Indicator node under the criteria node....
Serialize an IOC, as defined by a set of etree Elements, to a .IOC file. :param root: etree Element to write out. Should have the tag 'OpenIOC' :param output_dir: Directory to write the ioc out to. default is current working directory. :param force: If set, skip the root node tag check. :return: True...
Serialize an IOC, as defined by a set of etree Elements, to a String. :param root: etree Element to serialize. Should have the tag 'OpenIOC' :param force: Skip the root node tag check. :return: def write_ioc_string(root, force=False): """ Serialize an IOC, as defined by a set of etree Elements, to...
Opens an IOC file, or XML string. Returns the root element, top level indicator element, and parameters element. If the IOC or string fails to parse, an IOCParseError is raised. This is a helper function used by __init__. :param fn: This is a path to a file to open, or a string conta...
This generates all parts of an IOC, but without any definition. This is a helper function used by __init__. :param name: string, Name of the ioc :param description: string, description of the ioc :param author: string, author name/email address :param links: ist of tuples. Eac...
Set the last modified date of a IOC to the current date. User may specify the date they want to set as well. :param date: Date value to set the last modified date to. This should be in the xsdDate form. This defaults to the current date if it is not provided. xsdDate Form: YYYY-MM-DD...
Set the published date of a IOC to the current date. User may specify the date they want to set as well. :param date: Date value to set the published date to. This should be in the xsdDate form. This defaults to the current date if it is not provided. xsdDate Form: YYYY-MM-DDTHH:MM:S...
Set the created date of a IOC to the current date. User may specify the date they want to set as well. :param date: Date value to set the created date to. This should be in the xsdDate form. This defaults to the current date if it is not provided. xsdDate form: YYYY-MM-DDTHH:MM:SS ...
Add a a parameter to the IOC. :param indicator_id: The unique Indicator/IndicatorItem id the parameter is associated with. :param content: The value of the parameter. :param name: The name of the parameter. :param ptype: The type of the parameter content. :return: True :...
Add a Link metadata element to the IOC. :param rel: Type of the link. :param value: Value of the link text. :param href: A href value assigned to the link. :return: True def add_link(self, rel, value, href=None): """ Add a Link metadata element to the IOC. :par...
Update the name (short description) of an IOC This creates the short description node if it is not present. :param name: Value to set the short description too :return: def update_name(self, name): """ Update the name (short description) of an IOC This creates the sho...
Update the description) of an IOC This creates the description node if it is not present. :param description: Value to set the description too :return: True def update_description(self, description): """ Update the description) of an IOC This creates the description no...
Update link nodes, based on the existing link/@rel values. This requires specifying a link/@rel value to update, and either a new link/@rel value, or a new link/text() value for all links which match the link/@rel value. Optionally, only the first link which matches the link/@rel value...
Rewrite the text() value of a link based on the link/@rel and link/text() value. This is similar to update_link_rel_based but users link/@rel AND link/text() values to determine which links have their link/@text() values updated. :param old_rel: The link/@rel value used to select link nodes to...
Updates the parameter attached to an Indicator or IndicatorItem node. All inputs must be strings or unicode objects. :param parameter_id: The unique id of the parameter to modify :param content: The value of the parameter. :param name: The name of the parameter. :param param_ty...
Removes link nodes based on the function arguments. This can remove link nodes based on the following combinations of arguments: link/@rel link/@rel & link/text() link/@rel & link/@href link/@rel & link/text() & link/@href :param rel: link/@rel value to ...
Removes a Indicator or IndicatorItem node from the IOC. By default, if nodes are removed, any children nodes are inherited by the removed node. It has the ability to delete all children Indicator and IndicatorItem nodes underneath an Indicator node if the 'prune' argument is set. ...
Removes parameters based on function arguments. This can remove parameters based on the following param values: param/@id param/@name param/@ref_id Each input is mutually exclusive. Calling this function with multiple values set will cause an IOCParseError ...
Removes the name (short_description node) from the metadata node, if present. :return: True if the node is removed. False is the node is node is not present. def remove_name(self): """ Removes the name (short_description node) from the metadata node, if present. :return: True if the ...
Removes the description node from the metadata node, if present. :return: Returns True if the description node is removed. Returns False if the node is not present. def remove_description(self): """ Removes the description node from the metadata node, if present. :return: Returns True...
Serialize the IOC to a .ioc file. :param output_dir: Directory to write the ioc out to. default is the current working directory. :param force: If specified, will not validate the root node of the IOC is 'OpenIOC'. :return: def write_ioc_to_file(self, output_dir=None, force=False): ""...
Get a string representation of an IOC. :param width: Width to print the description too. :param sep: Separator used for displaying the contents of the criteria nodes. :param params: Boolean, set to True in order to display node parameters. :return: def display_ioc(self, width=120, sep=...
Get a text represention of the links node. :return: def link_text(self): """ Get a text represention of the links node. :return: """ s = '' links_node = self.metadata.find('links') if links_node is None: return s links = links_node.g...