def __init__(self, session): Proxy.__init__(self, session) log(self.session.session_id, CORE_SESSION, 5, "Proxy start") self._detector_config = OrderedDict(session.service.detector_config) self._detector_default_service_name = session.service.detector_default_service_name self.results = {}
def cleartable(self, identifier): lock = thread.allocate_lock() lock.acquire() temp = Template('DROP TABLE IF EXISTS $tablename;') self.cursor.execute(temp.substitute(tablename=identifier)) self.connection.commit() log("delete table: " + identifier) lock.release()
def _open_lockfile(self, filename): try: try: fd = open(filename, 'r+') except IOError: fd = open(filename, 'w') return fd except IOError, e: log(None, CORE_ERROR, 3, "Error opening lock file; file='%s', error='%s'", (e.filename, e.strerror))
def __init__(self, n, rows): dict = [] self.threads = [] #sequence of threads noofthreads = Config().readConfigEntry('noofthreads') for i in range(noofthreads): dict.append([]) for i in range(n): y = i % noofthreads dict[y].append(self.ThreadParameter(i, rows[i]["model"], rows[i]["appparameters"], rows[i]["ordering"], rows[i]["md5"], rows[i]["sha1"])) #append ThreadParameter instance for i in range(noofthreads): thread = self.AppValidationThread(dict[i]) #create thread self.threads.append(thread) thread.start() for t in self.threads: t.join() #wait for threads to finish n = 0 for t in self.threads: if len(t.ReturnValue) > 0: #thread object reported errors for x in t.ReturnValue: log("\nerror. different hashes with these parameters: \n" + x) n += 1 if n > 0: log(str(n) + " errors.") raise Exception("different hashes") else: log("success. hashes are identical.")
def __init__(self, n, md5, sha1): dict = {} md5dict = {} #md5 hashes to check against sha1dict = {} #sha1 hashes to check against self.threads = [] #sequence of threads noofthreads = Config().readConfigEntry('noofthreads') for i in range(noofthreads): dict[i] = [] md5dict[i] = [] sha1dict[i] = [] for i in range(n): y = i % noofthreads dict[y].append(i) md5dict[y].append(md5[i]) sha1dict[y].append(sha1[i]) for i in range(noofthreads): thread = self.ModelValidationThread(dict[i], md5dict[i], sha1dict[i]) #create thread self.threads.append(thread) thread.start() for t in self.threads: t.join() #wait for threads to finish self.cleanup() n = 0 for t in self.threads: if len(t.ReturnValue) > 0: #thread object reported errors for x in t.ReturnValue: log("error. different hashes with these parameters:" + x) n += 1 if n > 0: log(str(n) + " errors.") raise Exception("different hashes") else: log("success. hashes are identical.")
def __init__(self, n, md5, sha1): dict = {} md5dict = {} #md5 hashes to check against sha1dict = {} #sha1 hashes to check against self.threads = [] #sequence of threads noofthreads = Config().readConfigEntry('noofthreads') for i in range(noofthreads): dict[i] = [] md5dict[i] = [] sha1dict[i] = [] for i in range(n): y = i % noofthreads dict[y].append(i) md5dict[y].append(md5[i]) sha1dict[y].append(sha1[i]) for i in range(noofthreads): thread = self.ModelValidationThread(dict[i],md5dict[i], sha1dict[i]) #create thread self.threads.append(thread) thread.start() for t in self.threads: t.join() #wait for threads to finish self.cleanup() n = 0 for t in self.threads: if len(t.ReturnValue) > 0: #thread object reported errors for x in t.ReturnValue: log("error. different hashes with these parameters:" + x) n += 1 if n > 0: log(str(n) + " errors.") raise Exception("different hashes") else: log("success. hashes are identical.")
def detect(self, side, data): service = None count_nomatch_detectors = 0 for detector_name, service_name in self._detector_config.iteritems(): if (self.results[detector_name] == DetectResultType.NOMATCH): count_nomatch_detectors += 1 continue detector = Globals.detectors.get(detector_name, None) if not detector: raise ValueError, "No such detector defined; detector='%s'" % (detector_name,) res = detector.detect(side, data) self.results[detector_name] = res.result if res.result == DetectResultType.MATCH: service = Globals.services.get(service_name, None) if not service: raise ValueError, "No such service defined; service='%s'" % (service_name,) log(self.session.session_id, CORE_SESSION, 3, "Detector starting service; service='%s'" % service) return service elif res.result == DetectResultType.NOMATCH: count_nomatch_detectors += 1 elif res.result == DetectResultType.COPY_CLIENT: self.need_server_connect = TRUE self.copy_client_data = res.bytes_to_copy if len(self._detector_config) == count_nomatch_detectors: service = Globals.services.get(self._detector_default_service_name, None) self.quit = TRUE if not service: raise ValueError, "Could not find default service; service='%s'" % (self._detector_default_service_name,) else: log(self.session.session_id, CORE_SESSION, 3, "Detector starting default service; service='%s'" % service) else: log(self.session.session_id, CORE_DEBUG, 6, "Detector still undecided;") return service
def __init__(self, n, rows): dict = [] self.threads = [] #sequence of threads noofthreads = Config().readConfigEntry('noofthreads') for i in range(noofthreads): dict.append([]) for i in range(n): y = i % noofthreads dict[y].append( self.ThreadParameter( i, rows[i]["model"], rows[i]["appparameters"], rows[i]["ordering"], rows[i]["md5"], rows[i]["sha1"])) #append ThreadParameter instance for i in range(noofthreads): thread = self.AppValidationThread(dict[i]) #create thread self.threads.append(thread) thread.start() for t in self.threads: t.join() #wait for threads to finish n = 0 for t in self.threads: if len(t.ReturnValue) > 0: #thread object reported errors for x in t.ReturnValue: log("\nerror. different hashes with these parameters: \n" + x) n += 1 if n > 0: log(str(n) + " errors.") raise Exception("different hashes") else: log("success. hashes are identical.")
def main(): config = Config() config.setArgsConfig(parseScriptArguments(sys.argv[1:])) if config.argsconfig['task'] is Task.DETERMINEMODEL: for filename in listOfModelTestFiles(Config().argsconfig['inputDirOrFile']): generator = BonnmotionParamsGenerator() generator.setModeltestFilename(filename) generator.createBonnmotionParamsFiles() if config.argsconfig['delete'] == True: DataAccess().cleartable(generator.modelname) log("starting model-determination of " + generator.modelname) md = ModelDeterminationDispatcher(generator.noOfFilesCreated) log("done. " + str(generator.noOfFilesCreated) + " hashes saved.") md.cleanup() elif config.argsconfig['task'] is Task.VALIDATEMODEL: md5 = [] sha1 = [] result = [] if config.argsconfig.has_key('arg'): DataAccess().get(config.argsconfig['arg'], result, md5, sha1) #get parameters and hashes from database log("starting model-validation of " + config.argsconfig['arg']) else: DataAccess().get4(result, md5, sha1) n = 0 for x in result: f = open(config.readConfigEntry('tempoutputparamsfile').replace('INDEX', str(n)), 'w') f.write(x['bmparamsfile']) f.close() n += 1 mv = ModelValidationDispatcher(n,md5,sha1) log("done. " + str(n) + " hashes checked.") elif config.argsconfig['task'] is Task.DETERMINEAPP: for filename in listOfAppTestFiles(config.argsconfig['inputDirOrFile']): generator = BonnmotionParamsGenerator() generator.setApptestFilename(filename) params = generator.parseApptestFile() if config.argsconfig['delete'] == True: DataAccess().cleartable(params['app']) ##APP-DATATABLE if params['inputDirOrFile'] is InputDirOrFile.FILE: generator2 = BonnmotionParamsGenerator() generator2.setModeltestFilename(params['paramsfile']) generator2.createBonnmotionParamsFiles() log("starting app determination: " + filename + ", modeltest: " + params['paramsfile']) bmd = BonnmotionDispatcher(generator2.noOfFilesCreated, config.readConfigEntry('bonnmotionpath')) add = AppDeterminationDispatcher(generator2.noOfFilesCreated, params) log("done") add.cleanup() elif params['inputDirOrFile'] is InputDirOrFile.DIRECTORY: for file in os.listdir(params['paramsfile']): if file.endswith('.modeltest'): generator2 = BonnmotionParamsGenerator() generator2.setModeltestFilename(os.path.join(params['paramsfile'], file)) generator2.createBonnmotionParamsFiles() log("starting app determination: " + filename + ", modeltest: " + file) bmd = BonnmotionDispatcher(generator2.noOfFilesCreated, config.readConfigEntry('bonnmotionpath')) add = AppDeterminationDispatcher(generator2.noOfFilesCreated, params) add.cleanup() log("done") elif config.argsconfig['task'] is Task.VALIDATEAPP: result = [] if config.argsconfig.has_key('arg'): DataAccess().get2(config.argsconfig['arg'], result) #get parameters and hashes from database log("starting app-validation of " + config.argsconfig['arg']) else: DataAccess().get3(result) n = 0 for x in result: f = open(config.readConfigEntry('tempoutputparamsfile').replace('INDEX', str(n)), 'w') f.write(x['bmparamsfile']) f.close() n += 1 bmd = BonnmotionDispatcher(n, config.readConfigEntry('bonnmotionvalidatepath')) AppValidationDispatcher(n, result).cleanup() log("done. " + str(n) + " hashes checked.")
def main(): config = Config() config.setArgsConfig(parseScriptArguments(sys.argv[1:])) if config.argsconfig['task'] is Task.DETERMINEMODEL: for filename in listOfModelTestFiles( Config().argsconfig['inputDirOrFile']): generator = BonnmotionParamsGenerator() generator.setModeltestFilename(filename) generator.createBonnmotionParamsFiles() if config.argsconfig['delete'] == True: DataAccess().cleartable(generator.modelname) log("starting model-determination of " + generator.modelname) md = ModelDeterminationDispatcher(generator.noOfFilesCreated) log("done. " + str(generator.noOfFilesCreated) + " hashes saved.") md.cleanup() elif config.argsconfig['task'] is Task.VALIDATEMODEL: md5 = [] sha1 = [] result = [] if config.argsconfig.has_key('arg'): DataAccess().get(config.argsconfig['arg'], result, md5, sha1) #get parameters and hashes from database log("starting model-validation of " + config.argsconfig['arg']) else: DataAccess().get4(result, md5, sha1) n = 0 for x in result: f = open( os.path.join( Config().readConfigEntry('bonnmotionvalidatepath'), config.readConfigEntry('tempoutputparamsfile').replace( 'INDEX', str(n))), 'w') f.write(x['bmparamsfile']) f.close() n += 1 mv = ModelValidationDispatcher(n, md5, sha1) log("done. " + str(n) + " hashes checked.") elif config.argsconfig['task'] is Task.DETERMINEAPP: for filename in listOfAppTestFiles( config.argsconfig['inputDirOrFile']): generator = BonnmotionParamsGenerator() generator.setApptestFilename(filename) params = generator.parseApptestFile() if config.argsconfig['delete'] == True: DataAccess().cleartable(params['app']) ##APP-DATATABLE if params['inputDirOrFile'] is InputDirOrFile.FILE: generator2 = BonnmotionParamsGenerator() generator2.setModeltestFilename(params['paramsfile']) generator2.createBonnmotionParamsFiles() log("starting app determination: " + filename + ", modeltest: " + params['paramsfile']) bmd = BonnmotionDispatcher( generator2.noOfFilesCreated, config.readConfigEntry('bonnmotionvalidatepath')) add = AppDeterminationDispatcher(generator2.noOfFilesCreated, params) log("done") add.cleanup() elif params['inputDirOrFile'] is InputDirOrFile.DIRECTORY: for file in os.listdir(params['paramsfile']): if file.endswith('.modeltest'): generator2 = BonnmotionParamsGenerator() generator2.setModeltestFilename( os.path.join(params['paramsfile'], file)) generator2.createBonnmotionParamsFiles() log("starting app determination: " + filename + ", modeltest: " + file) bmd = BonnmotionDispatcher( generator2.noOfFilesCreated, config.readConfigEntry('bonnmotionvalidatepath')) add = AppDeterminationDispatcher( generator2.noOfFilesCreated, params) add.cleanup() log("done") elif config.argsconfig['task'] is Task.VALIDATEAPP: result = [] if config.argsconfig.has_key('arg'): DataAccess().get2(config.argsconfig['arg'], result) #get parameters and hashes from database log("starting app-validation of " + config.argsconfig['arg']) else: DataAccess().get3(result) n = 0 for x in result: f = open( os.path.join( Config().readConfigEntry('bonnmotionvalidatepath'), config.readConfigEntry('tempoutputparamsfile').replace( 'INDEX', str(n))), 'w') f.write(x['bmparamsfile']) f.close() n += 1 bmd = BonnmotionDispatcher( n, config.readConfigEntry('bonnmotionvalidatepath')) AppValidationDispatcher(n, result).cleanup() log("done. " + str(n) + " hashes checked.")