def load_event(self, filename): try: return STIXPackage.from_xml(filename) except Exception as ns_error: if ns_error.__str__().startswith('Namespace not found:'): ns_value = ns_error.ns_uri prefix = ns_value.split('/')[-1] ns = mixbox_ns.Namespace(ns_value, prefix, '') mixbox_ns.register_namespace(ns) return self.load_event(filename) else: return None
def _get_stix_package(ioc_xml): if ioc_xml is not None and len(ioc_xml) > 0: ns = namespaces.Namespace("http://openioc.org/openioc", "openioc", "") idgen.set_id_namespace(ns) stix_obj = to_stix(BytesIO(ioc_xml)) stix_package = STIXPackage_v1.from_xml(etree.fromstring(stix_obj.to_xml())) return stix_package else: raise RuntimeError('request body is empty.')
def main(): # Parse command line arguments argparser = get_arg_parser() args = argparser.parse_args() # initialize logging init_logging(args.verbose) # Set the namespace to be used in the STIX Package ns = namespaces.Namespace("http://openioc.org/openioc", "openioc", "") idgen.set_id_namespace(ns) # Create Observables from binding object stix_package = translate.to_stix(args.infile) # Write the STIXPackage to a output file write_package(stix_package, outfn=args.outfile)
def ioc2stix(): try: data_dir = os.path.abspath( os.path.join(os.path.dirname(os.path.abspath(__file__)), '../data')) in_xml = read2str(data_dir + '/stuxnet.ioc.xml') # Set the namespace to be used in the STIX Package ns = namespaces.Namespace("http://openioc.org/openioc", "openioc", "") idgen.set_id_namespace(ns) stix_package = to_stix(BytesIO(in_xml)) # print stix_package.to_xml() out_fname = './stuxnet.xml' write2file(out_fname, stix_package.to_xml()) except: print traceback.format_exc().decode('utf-8')
def set_default_namespace(prefix, ns_uri, schemaLocation=None): """Method to override the mixbox and slider 'example' namespace.""" new_namespace = namespaces.Namespace(ns_uri, prefix, schemaLocation) idgen.set_id_namespace(new_namespace)