def main():
    infilename = ''
    outfilename = ''

    #Get the command-line arguments
    args = sys.argv[1:]
    
    if len(args) < 4:
        usage()
        sys.exit(1)
        
    for i in range(0,len(args)):
        if args[i] == '-i':
            infilename = args[i+1]
        elif args[i] == '-o':
            outfilename = args[i+1]
    if os.path.isfile(infilename): 
        try:
            # Perform the translation using the methods from the OpenIOC to CybOX Script
            openioc_indicators = openioc.parse(infilename)
            observables_obj = openioc_to_cybox.generate_cybox(openioc_indicators, infilename, True)
            observables_cls = Observables.from_obj(observables_obj)

            # Set the namespace to be used in the STIX Package
            stix.utils.set_id_namespace({"https://github.com/STIXProject/openioc-to-stix":"openiocToSTIX"})

            # Wrap the created Observables in a STIX Package/Indicator
            stix_package = STIXPackage()
            # Add the OpenIOC namespace
            input_namespaces = {"http://openioc.org/":"openioc"}
            stix_package.__input_namespaces__ = input_namespaces

            for observable in observables_cls.observables:
                indicator_dict = {}
                producer_dict = {}
                producer_dict['tools'] = [{'name':'OpenIOC to STIX Utility', 'version':str(__VERSION__)}]
                indicator_dict['producer'] = producer_dict
                indicator_dict['title'] = "CybOX-represented Indicator Created from OpenIOC File"
                indicator = Indicator.from_dict(indicator_dict)
                indicator.add_observable(observables_cls.observables[0])
                stix_package.add_indicator(indicator)

            # Create and write the STIX Header
            stix_header = STIXHeader()
            stix_header.package_intent = "Indicators - Malware Artifacts"
            stix_header.description = "CybOX-represented Indicators Translated from OpenIOC File"
            stix_package.stix_header = stix_header

            # Write the generated STIX Package as XML to the output file
            outfile = open(outfilename, 'w')
            # Ignore any warnings - temporary fix for no schemaLocation w/ namespace
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                outfile.write(stix_package.to_xml())
                warnings.resetwarnings()
            outfile.flush()
            outfile.close()
        except Exception, err:
            print('\nError: %s\n' % str(err))
            traceback.print_exc()
Beispiel #2
0
def to_stix(infile):
    """Converts the `infile` OpenIOC xml document into a STIX Package.

    Args:
        infile: OpenIOC xml filename to translate

    Returns:
       stix.core.STIXPackage object
    """
    observables = to_cybox(infile)

    # Build Indicators from the Observable objects
    indicators = [_observable_to_indicator_stix(o) for o in observables]

    # Wrap the created Observables in a STIX Package/Indicator
    stix_package = STIXPackage()

    # Set the Indicators collection
    stix_package.indicators = Indicators(indicators)

    # Create and write the STIX Header. Warning: these fields have been
    # deprecated in STIX v1.2!
    stix_header = STIXHeader()
    stix_header.package_intent = PackageIntent.TERM_INDICATORS_MALWARE_ARTIFACTS
    stix_header.description = "CybOX-represented Indicators Translated from OpenIOC File"
    stix_package.stix_header = stix_header

    return stix_package
Beispiel #3
0
def to_stix(infile):
    """Converts the `infile` OpenIOC xml document into a STIX Package.

    Args:
        infile: OpenIOC xml filename to translate

    Returns:
       stix.core.STIXPackage object
    """
    observables = to_cybox(infile)

    # Build Indicators from the Observable objects
    indicators = [_observable_to_indicator_stix(o) for o in observables]

    # Wrap the created Observables in a STIX Package/Indicator
    stix_package = STIXPackage()

    # Set the Indicators collection
    stix_package.indicators = indicators

    # Create and write the STIX Header. Warning: these fields have been
    # deprecated in STIX v1.2!
    stix_header = STIXHeader()
    stix_header.package_intent = PackageIntent.TERM_INDICATORS_MALWARE_ARTIFACTS
    stix_header.description = "CybOX-represented Indicators Translated from OpenIOC File"
    stix_package.stix_header = stix_header

    return stix_package
Beispiel #4
0
def main():
    infilename = ''
    outfilename = ''

    #Get the command-line arguments
    args = sys.argv[1:]

    if len(args) < 4:
        usage()
        sys.exit(1)

    for i in range(0, len(args)):
        if args[i] == '-i':
            infilename = args[i + 1]
        elif args[i] == '-o':
            outfilename = args[i + 1]
    if os.path.isfile(infilename):
        try:
            # Perform the translation using the methods from the OpenIOC to CybOX Script
            openioc_indicators = openioc.parse(infilename)
            observables_obj = openioc_to_cybox.generate_cybox(
                openioc_indicators, infilename, True)
            observables_cls = Observables.from_obj(observables_obj)

            # Wrap the created Observables in a STIX Package/Indicator
            stix_package = STIXPackage()

            for observable in observables_cls.observables:
                indicator_dict = {}
                producer_dict = {}
                producer_dict['tools'] = [{
                    'name': 'OpenIOC to STIX Utility',
                    'version': str(__VERSION__)
                }]
                indicator_dict['producer'] = producer_dict
                indicator_dict[
                    'title'] = "CybOX-represented Indicator Created from OpenIOC File"
                indicator = Indicator.from_dict(indicator_dict)
                indicator.add_observable(observables_cls.observables[0])
                stix_package.add_indicator(indicator)

            # Create and write the STIX Header
            stix_header = STIXHeader()
            stix_header.package_intent = "Indicators - Malware Artifacts"
            stix_header.description = "CybOX-represented Indicators Translated from OpenIOC File"
            stix_package.stix_header = stix_header

            # Write the generated STIX Package as XML to the output file
            outfile = open(outfilename, 'w')
            outfile.write(stix_package.to_xml())
            outfile.flush()
            outfile.close()
        except Exception, err:
            print('\nError: %s\n' % str(err))
            traceback.print_exc()
def _export_multi_json():
    from stix.core import STIXPackage, STIXHeader
    
    if jsonPattern is None:
        if streamFlag: #stream
            fullFileName = "cifStream"
        else: 
            fullFileName = myJsonFile
            xmlFileName = outputFile
    else:
        fullFileName = jsonPath + myJsonFile + '.json'
        fileName = "stix_" + str(myJsonFile)
        xmlFileName = stixPath + fileName + '.xml'
        
    if testMode:
        print "-----------------File Name: -------- " + fullFileName
        print "xmlFileName: " + xmlFileName
        
    global log_string
    log_string = log_string + "\n\n" + str(datetime.datetime.now().time()) + ": fullFileName: " + fullFileName + "\n"
    log_string = log_string + str(datetime.datetime.now().time()) + ": xmlFileName: " + xmlFileName + "\n"

    wholeJson = _prepare_json(fullFileName)
    
    stix_package = STIXPackage()
    stix_header = STIXHeader()

    stix_header.description = "Search result from CIF with search parameter " + str(mySearchParam)
    stix_header.title = "Indicators from search by " + str(mySearchParam)

    stix_package.stix_header = stix_header
    stix_header.package_intent = "Purpose: mitigation"
    
    for x in wholeJson:
        indicatorIns = _export_from_json_to_xml(json.loads(x))
        stix_package.add_indicator(indicatorIns)
        
    if streamFlag is False:
        f = open(xmlFileName, 'w')
        try:
            f.write(stix_package.to_xml())
        finally:
            f.close()
   
    #if testMode:
    #    print stix_package.to_xml()
   
    log_string = log_string + str(datetime.datetime.now().time()) + ": -------------- STIX----------- \n\n" + stix_package.to_xml()

    return stix_package.to_xml()        
def main():
    infilename = ''
    outfilename = ''

    #Get the command-line arguments
    args = sys.argv[1:]
    
    if len(args) < 4:
        usage()
        sys.exit(1)
        
    for i in range(0,len(args)):
        if args[i] == '-i':
            infilename = args[i+1]
        elif args[i] == '-o':
            outfilename = args[i+1]
    if os.path.isfile(infilename): 
        try:
            # Perform the translation using the methods from the OpenIOC to CybOX Script
            openioc_indicators = openioc.parse(infilename)
            observables_obj = openioc_to_cybox.generate_cybox(openioc_indicators, infilename, True)
            observables_cls = Observables.from_obj(observables_obj)

            # Wrap the created Observables in a STIX Package/Indicator
            stix_package = STIXPackage()

            for observable in observables_cls.observables:
                indicator_dict = {}
                producer_dict = {}
                producer_dict['tools'] = [{'name':'OpenIOC to STIX Utility', 'version':str(__VERSION__)}]
                indicator_dict['producer'] = producer_dict
                indicator_dict['title'] = "CybOX-represented Indicator Created from OpenIOC File"
                indicator = Indicator.from_dict(indicator_dict)
                indicator.add_observable(observables_cls.observables[0])
                stix_package.add_indicator(indicator)

            # Create and write the STIX Header
            stix_header = STIXHeader()
            stix_header.package_intent = "Indicators - Malware Artifacts"
            stix_header.description = "CybOX-represented Indicators Translated from OpenIOC File"
            stix_package.stix_header = stix_header

            # Write the generated STIX Package as XML to the output file
            outfile = open(outfilename, 'w')
            outfile.write(stix_package.to_xml())
            outfile.flush()
            outfile.close()
        except Exception, err:
            print('\nError: %s\n' % str(err))
            traceback.print_exc()
def export_stix(iocs):
    '''Export to STIX. Adapted from:
        github.com/STIXProject/openioc-to-stix/blob/master/openioc_to_stix.py
    '''
    cybox_observables = export_cybox(iocs)
    stix_package = STIXPackage()
    for obs in cybox_observables:
        indicator_dict = {}
        producer_dict = {}
        producer_dict['tools'] = [{'name':'extract_iocs'}]
        indicator_dict['producer'] = producer_dict
        indicator_dict['title'] = "extract_iocs STIX export"
        indicator = Indicator.from_dict(indicator_dict)
        indicator.add_observable(obs)
        stix_package.add_indicator(indicator)
    # Create and write the STIX Header
    stix_header = STIXHeader()
    stix_header.package_intent = "Indicators - Malware Artifacts"
    stix_header.description = "CybOX-represented Indicators extracted with extract_iocs"
    stix_package.stix_header = stix_header
    return stix_package.to_xml()
def export_stix(iocs):
    '''Export to STIX. Adapted from:
        github.com/STIXProject/openioc-to-stix/blob/master/openioc_to_stix.py
    '''
    cybox_observables = export_cybox(iocs)
    stix_package = STIXPackage()
    for obs in cybox_observables:
        indicator_dict = {}
        producer_dict = {}
        producer_dict['tools'] = [{'name': 'export_iocs'}]
        indicator_dict['producer'] = producer_dict
        indicator_dict['title'] = "export_iocs STIX export"
        indicator = Indicator.from_dict(indicator_dict)
        indicator.add_observable(obs)
        stix_package.add_indicator(indicator)
    # Create and write the STIX Header
    stix_header = STIXHeader()
    stix_header.package_intent = "Indicators - Malware Artifacts"
    stix_header.description = "CybOX-represented Indicators extracted with export_iocs"
    stix_package.stix_header = stix_header
    return stix_package.to_xml()
Beispiel #9
0
    def __make_stix_xml_string(self, filename, open_ioc_xml):
        # This is actually an adapted version of the openioc_to_stix.py to be compatible with ce1sus
        try:

            # save the file
            base_dir = self.get_dest_folder()
            open_ioc_filename = base_dir + '/' + filename
            open_stix_filename = base_dir + '/STIX_of_' + filename
            open_ioc_file = open(open_ioc_filename, 'w+')
            open_ioc_file.write(open_ioc_xml)
            open_ioc_file.close()

            openioc_indicators = openioc.parse(open_ioc_filename)
            observables_obj = openioc_to_cybox.generate_cybox(
                openioc_indicators, open_ioc_filename, True)
            observables_cls = Observables.from_obj(observables_obj)
            stix.utils.set_id_namespace({
                "https://github.com/STIXProject/openioc-to-stix":
                "openiocToSTIX"
            })
            stix_package = STIXPackage()
            stix_package.version = '1.1.1'
            input_namespaces = {"openioc": "http://openioc.org/"}

            stix_package.__input_namespaces__ = input_namespaces

            for observable in observables_cls.observables:
                indicator_dict = {}
                producer_dict = {}
                producer_dict['tools'] = [{
                    'name': 'OpenIOC to STIX Utility',
                    'version': str(__VERSION__)
                }]
                indicator_dict['producer'] = producer_dict
                indicator_dict[
                    'title'] = "CybOX-represented Indicator Created from OpenIOC File"
                indicator = Indicator.from_dict(indicator_dict)
                indicator.add_observable(observables_cls.observables[0])
                stix_package.add_indicator(indicator)

            stix_header = STIXHeader()
            # set the correct header
            file_obj = open(open_ioc_filename, 'rb')
            file_contents = file_obj.read()
            print file_contents
            file_obj.close()
            root = etree.fromstring(file_contents)
            for child in root:

                if child.tag.endswith('short_description'):
                    stix_header.short_description = child.text
                elif child.tag.endswith('description'):
                    stix_header.description = child.text
                else:
                    if stix_header.description and stix_header.short_description:
                        break

            stix_header.package_intent = "Indicators - Malware Artifacts"
            stix_header.description = '{0}\n\n CybOX-represented Indicators Translated from OpenIOC File'.format(
                stix_header.description)
            stix_package.stix_header = stix_header

            # Write the generated STIX Package as XML to the output file
            outfile = open(open_stix_filename, 'w')
            # Ignore any warnings - temporary fix for no schemaLocation w/ namespace
            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                outfile.write(stix_package.to_xml())
                warnings.resetwarnings()
            outfile.flush()
            outfile.close()
            return base_dir, open_stix_filename
        except Exception as error:
            self.logger.error(error)
            raise cherrypy.HTTPError(500, '{0}'.format(error.message))