netzob.Inference.Grammar package¶
Subpackages¶
- netzob.Inference.Grammar.AutomataFactories package
- Submodules
- netzob.Inference.Grammar.AutomataFactories.ChainedStatesAutomataFactory module
- netzob.Inference.Grammar.AutomataFactories.OneStateAutomataFactory module
- netzob.Inference.Grammar.AutomataFactories.PTAAutomataFactory module
- netzob.Inference.Grammar.AutomataFactories.all module
- Module contents
- netzob.Inference.Grammar.EquivalenceOracles package
- netzob.Inference.Grammar.Oracles package
- netzob.Inference.Grammar.Queries package
- netzob.Inference.Grammar.lstar package
Submodules¶
netzob.Inference.Grammar.Angluin module¶
-
class
MealyLSTAR
(inputVocabulary, membershipOracle)[source]¶ Bases:
object
This class is an implementation of the Angluin L* Algorithm as detailled in “Learning regular sets from queries and counterexamples” [Ang87].
This active grammatical inference algorithm infers state machine. It communicates with a target by sending membership queries which requires to have access to an implementation of the protocol.
To illustrate its usage, we will infer the grammar of a fake simple protocol.
>>> from netzob.all import * >>> import time
We first create a fake server which requires a vocabulary of input (I) and output (O) symbols:
>>> i0 = Symbol(name="a", fields=[Field("a\n")]) >>> i1 = Symbol(name="b", fields=[Field("b\n")]) >>> i2 = Symbol(name="c", fields=[Field("c\n")]) >>> i3 = Symbol(name="d", fields=[Field("d\n")]) >>> # List of Client > Server messages >>> I = [i0, i1, i2, i3]
>>> o0 = Symbol(name="0", fields=[Field("0")]) >>> o1 = Symbol(name="1", fields=[Field("1")]) >>> o2 = Symbol(name="2", fields=[Field("2")]) >>> o3 = Symbol(name="3", fields=[Field("3")]) >>> # List of Server > Client messages >>> O = [o0, o1, o2, o3]
>>> symbolList = I + O
Now we can create the grammar which includes 5 states
>>> s0 = State(name="S0") >>> s1 = State(name="S1") >>> s2 = State(name="S2") >>> s3 = State(name="S3") >>> s4 = State(name="S4")
and their transitions
>>> t0 = Transition(s0, s1, i0, [o0]) >>> t1 = Transition(s1, s1, i1, [o1]) >>> t2 = Transition(s1, s2, i2, [o2]) >>> t3 = Transition(s2, s1, i1, [o1]) >>> t4 = Transition(s2, s3, i0, [o0]) >>> t5 = Transition(s3, s1, i1, [o1]) >>> t6 = Transition(s3, s4, i2, [o2]) >>> t7 = Transition(s1, s4, i0, [o1])
we add an initial state and an ending state with open and close channel transitions
>>> initialState = State(name="Initial") >>> endingState = State(name="End") >>> openTransition = OpenChannelTransition(initialState, s0) >>> closeTransition = CloseChannelTransition(s4, endingState) >>> automata = Automata(initialState, symbolList)
>>> # Create an actor: Alice (a server) >>> channel = UDPServer(localIP="127.0.0.1", localPort=8887) >>> abstractionLayer = AbstractionLayer(channel, symbolList) >>> alice = Actor(automata = automata, initiator = False, abstractionLayer=abstractionLayer) >>> alice.start()
We finaly create an angluin-based grammar learner
>>> # Creates an inference channel >>> angluinChannel = UDPClient(remoteIP="127.0.0.1", remotePort=8887) # >>> angluin = MealyLSTAR(inputSymbols = I, outputSymbols = O, channel=angluinChannel) # >>> angluin.start()
# We wait for the results
>>> time.sleep(10)
# >>> while (angluin.alive): time.sleep(5) >>> print(“Inference finish”) Inference finish
>>> alice.stop()
>>> print(angluin.initialStateOfInferedGrammar) State
[Ang87] @article{Ang87, author = {Angluin, Dana}, title = {Learning regular sets from queries and counterexamples}, journal = {Inf. Comput.}, year = {1987}, volume = {75}, pages = {87–106}, month = {November} }
-
hypothesisModel
¶
-
inputVocabulary
¶
-
membershipOracle
¶
-