def convert_maec(self): #Parse the input file and get the MAEC Bundle try: self.__maec21_bundle = maec_2_1.parse(self.infilename) except: print 'Error occurred when parsing the input MAEC v2.1 XML file' if self.verbose_mode: traceback.print_exc() try: #Find the namespace based on the bundle ID self.__get_namespace() #Handle any analyses embedded in the Bundle self.__handle_analyses() #Handle any behaviors embedded in the Bundle self.__handle_behaviors() #Handle any actions embedded in the Bundle self.__handle_actions() #Handle any objects embedded in the Bundle self.__handle_objects() #Create the corresponding MAEC Bundle to be embedded in the Malware Subject in the Package self.__create_bundle() #Create the corresponding MAEC Package with a single embedded Malware Subject self.__create_package() except: if self.verbose_mode: traceback.print_exc() try: #Export the Package or Bundle to the output file outfile = file(self.outfilename, 'w') self.__export_to_file(outfile) except: if self.verbose_mode: traceback.print_exc()
def generate_oval(self): #Basic input file checking if os.path.isfile(self.infilename): #Parse the MAEC file maec_bundle = maec.parse(self.infilename) try: sys.stdout.write('Generating ' + self.outfilename + ' from ' + self.infilename + '...') self.process_bundle(maec_bundle) #Build up the OVAL document from the parsed data and corresponding objects self.__build_oval_document() if len(self.converted_ids) > 0: #Export to the output file outfile = open(self.outfilename, 'w') self.ovaldefroot.export( outfile, 0, namespacedef_= 'xmlns="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:oval-def="http://oval.mitre.org/XMLSchema/oval-definitions-5" xmlns:win-def="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows" xmlns:oval="http://oval.mitre.org/XMLSchema/oval-common-5" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://oval.mitre.org/XMLSchema/oval-definitions-5#windows http://oval.mitre.org/language/version5.7/ovaldefinition/complete/windows-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-definitions-5 http://oval.mitre.org/language/version5.7/ovaldefinition/complete/oval-definitions-schema.xsd http://oval.mitre.org/XMLSchema/oval-common-5 http://oval.mitre.org/language/version5.7/ovaldefinition/complete/oval-common-schema.xsd"' ) sys.stdout.write('Done\n') else: sys.stdout.write( 'no OVAL output written; 0 actions were converted.\n') if self.stat_mode: print '\n**Converted Actions**' for action_id in self.converted_ids: print 'Action ' + action_id + ' converted successfully' print '**Skipped Actions**' for action_id in self.skipped_actions: print 'Action ' + action_id + ' skipped; incompatible action/object type or missing object attributes' except Exception, err: print('\nError: %s\n' % str(err)) if self.verbose_mode: traceback.print_exc()