def applySession(self, session): # retrieve the automata automata = self.project.getGrammar().getAutomata() self.log.debug("automata: %s" % automata.getDotCode()) if automata is None: self.log.warn("Cannot apply a session on the current automata because it doesn't exist") return None difference = None # Configure the role-play environment # with : # - a memory memory = Memory() # memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) currentState = automata.getInitialState() # We execute the opening transition if len(currentState.getTransitions()) == 1 and currentState.getTransitions()[0].getType() == OpenChannelTransition.TYPE: currentState = currentState.getTransitions()[0].getOutputState() isInput = True for message in session.getMessages(): self.log.debug("Inject message: %s" % (message.getData())) # we abstract the message symbol = abstractionLayer.abstract(TypeConvertor.netzobRawToBitArray(str(message.getData()))) if isInput: # We simulate the reception of the message # - verify its a valid input symbol # - find out the associated transition currentTransition = None for transition in currentState.getTransitions(): if transition.getInputSymbol() == symbol: currentTransition = transition break if currentTransition is None: self.log.warn("Input symbol %s doesn't match any existing transition in current state %s" % (symbol.getName(), currentState.getName())) self.log.warn("We forget this message.") else: self.log.debug("Input symbol %s matchs the transition %s from state %s" % (symbol.getName(), currentTransition.getName(), currentState.getName())) isInput = False else: # We simulate emiting the message # - we just verify the symbol matches available output message in current transition found = False for (outputSymbol, probability, time) in currentTransition.getOutputSymbols(): if symbol.getID() == outputSymbol.getID(): found = True isInput = True currentState = currentTransition.getOutputState() break if not found: self.log.info("A difference has been found, symbol %s is not an output symbol of transition %s" % (symbol.getName(), currentTransition.getName())) return (currentTransition, symbol) return difference
def computeCurrentValue(self, strValue): if strValue != None: strCurrentValue = strValue binCurrentValue = TypeConvertor.netzobRawToBitArray(strValue) self.currentValue = (binCurrentValue, strCurrentValue) else: self.currentValue = None
def displaySession(self, session): memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) symbols = [] for message in session.getMessages(): symbols.append(abstractionLayer.abstract(TypeConvertor.netzobRawToBitArray(str(message.getData())))) for symbol in symbols: self.log.debug("- %s" % symbol.getName())
def computeCurrentValue(self, strValue): """computeCurrentValue: Compute a couple of binary and string values for the current variable. @type strValue: string @param strValue: a string value proposed as default value for this variable. """ if strValue is not None: strCurrentValue = strValue binCurrentValue = TypeConvertor.netzobRawToBitArray(strValue) self.currentValue = (binCurrentValue, strCurrentValue) else: self.currentValue = None
def displaySession(self, session): memory = Memory() # memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) symbols = [] for message in session.getMessages(): symbols.append( abstractionLayer.abstract( TypeConvertor.netzobRawToBitArray(str(message.getData())))) for symbol in symbols: self.log.debug("- %s" % symbol.getName())
def computeCurrentValue(self, strValue): if strValue != None: if self.format == Format.ASCII: strCurrentValue = str(strValue) binCurrentValue = TypeConvertor.string2bin(strValue, 'big') elif self.format == Format.HEX: hexVal = TypeConvertor.ipToNetzobRaw(strValue) if hexVal != None: strCurrentValue = str(strValue) binCurrentValue = TypeConvertor.netzobRawToBitArray(hexVal) else: strCurrentValue = str("None:Error") binCurrentValue = None self.currentValue = (binCurrentValue, strCurrentValue) else: self.currentValue = None
def computeCurrentValue(self, strValue): """computeCurrentValue: Compute a couple of binary and string values for the current variable. @type strValue: string @param strValue: a string value proposed as default value for this variable, must be a "real" ip address declared in ASCII like : "192.168.0.10". """ if strValue is not None: if self.format == Format.ASCII: strCurrentValue = str(strValue) binCurrentValue = TypeConvertor.string2bin(strValue, 'big') elif self.format == Format.HEX: hexVal = TypeConvertor.ipToNetzobRaw(strValue) if hexVal is not None: strCurrentValue = str(strValue) binCurrentValue = TypeConvertor.netzobRawToBitArray(hexVal) else: strCurrentValue = str("None:Error") binCurrentValue = None self.currentValue = (binCurrentValue, strCurrentValue) else: self.currentValue = None
def computeCurrentValue(self, strValue): """computeCurrentValue: Compute a couple of binary and string values for the current variable. @type strValue: string @param strValue: a string value proposed as default value for this variable, must be a "real" ip address declared in ASCII like : "192.168.0.10". """ if strValue is not None: if self.format == Format.ASCII: strCurrentValue = str(strValue) binCurrentValue = TypeConvertor.string2bin(strValue, "big") elif self.format == Format.HEX: hexVal = TypeConvertor.ipToNetzobRaw(strValue) if hexVal is not None: strCurrentValue = str(strValue) binCurrentValue = TypeConvertor.netzobRawToBitArray(hexVal) else: strCurrentValue = str("None:Error") binCurrentValue = None self.currentValue = (binCurrentValue, strCurrentValue) else: self.currentValue = None
def applySession(self, session): # retrieve the automata automata = self.project.getGrammar().getAutomata() self.log.debug("automata: %s" % automata.getDotCode()) if automata is None: self.log.warn( "Cannot apply a session on the current automata because it doesn't exist" ) return None difference = None # Configure the role-play environment # with : # - a memory memory = Memory() # memory = Memory(None) # - an abstraction layer abstractionLayer = AbstractionLayer(None, self.project.getVocabulary(), memory, None, None) currentState = automata.getInitialState() # We execute the opening transition if len(currentState.getTransitions() ) == 1 and currentState.getTransitions()[0].getType( ) == OpenChannelTransition.TYPE: currentState = currentState.getTransitions()[0].getOutputState() isInput = True for message in session.getMessages(): self.log.debug("Inject message: %s" % (message.getData())) # we abstract the message symbol = abstractionLayer.abstract( TypeConvertor.netzobRawToBitArray(str(message.getData()))) if isInput: # We simulate the reception of the message # - verify its a valid input symbol # - find out the associated transition currentTransition = None for transition in currentState.getTransitions(): if transition.getInputSymbol() == symbol: currentTransition = transition break if currentTransition is None: self.log.warn( "Input symbol %s doesn't match any existing transition in current state %s" % (symbol.getName(), currentState.getName())) self.log.warn("We forget this message.") else: self.log.debug( "Input symbol %s matchs the transition %s from state %s" % (symbol.getName(), currentTransition.getName(), currentState.getName())) isInput = False else: # We simulate emiting the message # - we just verify the symbol matches available output message in current transition found = False for (outputSymbol, probability, time) in currentTransition.getOutputSymbols(): if symbol.getID() == outputSymbol.getID(): found = True isInput = True currentState = currentTransition.getOutputState() break if not found: self.log.info( "A difference has been found, symbol %s is not an output symbol of transition %s" % (symbol.getName(), currentTransition.getName())) return (currentTransition, symbol) return difference