netzob.Simulator.Channels package¶
Submodules¶
netzob.Simulator.Channels.AbstractChannel module¶
-
class
AbstractChannel
(isServer, _id=UUID('a44ac076-ca41-4bcc-83fd-3d834c9e66fc'))[source]¶ Bases:
object
-
DEFAULT_WRITE_COUNTER_MAX
= -1¶
-
TYPE_IPCLIENT
= 2¶
-
TYPE_RAWETHERNETCLIENT
= 3¶
-
TYPE_RAWIPCLIENT
= 1¶
-
TYPE_SSLCLIENT
= 4¶
-
TYPE_TCPCLIENT
= 5¶
-
TYPE_TCPSERVER
= 6¶
-
TYPE_UDPCLIENT
= 7¶
-
TYPE_UDPSERVER
= 8¶
-
TYPE_UNDEFINED
= 0¶
-
channelType
¶ Returns if the communication channel type
Returns: the type of the communication channel Type: int
-
static
getLocalIP
(remoteIP)[source]¶ Retrieve the source IP address which will be used to connect to the destination IP address.
-
static
getLocalInterface
(localIP)[source]¶ Retrieve the network interface name associated with a specific IP address.
-
id
¶ the unique identifier of the channel
Type: uuid.UUID
-
isOpen
¶ Returns if the communication channel is open
Returns: the status of the communication channel Type: bool
-
isServer
¶ isServer indicates if this side of the channel plays the role of a server.
Type: bool
-
open
(timeout=None)[source]¶ Open the communication channel. If the channel is a server, it starts to listen and will create an instance for each different client.
Parameters: timeout – the maximum time to wait for a client to connect
-
read
(timeout=None)[source]¶ Read the next message on the communication channel.
@keyword timeout: the maximum time in millisecond to wait before a message can be reached @type timeout:
int
-
sendReceive
(data, timeout=None)[source]¶ Write on the communication channel the specified data and returns the corresponding response
Parameters: data (binary object) – the data to write on the channel @type timeout:
int
-
setWriteCounterMax
(maxValue)[source]¶ Change the max number of writings. When it is reached, no packet can be sent anymore until clearWriteCounter() is called. if maxValue==-1, the sending limit is deactivated.
Parameters: maxValue (int) – the new max value
-
write
(data, rate=None, duration=None)[source]¶ Write on the communication channel the specified data
Parameters: - data (bytes object) – the data to write on the channel
- rate (int) – specifies the bandwidth in octets to respect during traffic emission (should be used with duration= parameter)
- duration (int) – tells how much seconds the symbol is continuously written on the channel
- duration – tells how much time the symbol is written on the channel
-
netzob.Simulator.Channels.IPClient module¶
netzob.Simulator.Channels.RawEthernetClient module¶
netzob.Simulator.Channels.RawIPClient module¶
netzob.Simulator.Channels.SSLClient module¶
-
class
SSLClient
(remoteIP, remotePort, localIP=None, localPort=None, timeout=2, server_cert_file=None, alpn_protocols=None)[source]¶ Bases:
netzob.Simulator.Channels.AbstractChannel.AbstractChannel
An SSLClient is a communication channel that relies on SSL. It allows to create client connecting to a specific IP:Port server over a TCP/SSL socket.
When the actor execute an OpenChannelTransition, it calls the open method on the ssl client which connects to the server.
-
localIP
¶ IP on which the server will listen.
Type: str
-
localPort
¶ TCP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
open
(timeout=None)[source]¶ Open the communication channel. If the channel is a client, it starts to connect to the specified server.
-
read
(timeout=None)[source]¶ Read the next message on the communication channel.
@keyword timeout: the maximum time in millisecond to wait before a message can be reached @type timeout:
int
-
remoteIP
¶ IP on which the server will listen.
Type: str
-
remotePort
¶ TCP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
sendReceive
(data, timeout=None)[source]¶ Write on the communication channel the specified data and returns the corresponding response.
-
timeout
¶
-
netzob.Simulator.Channels.TCPClient module¶
-
class
TCPClient
(remoteIP, remotePort, localIP=None, localPort=None, timeout=5)[source]¶ Bases:
netzob.Simulator.Channels.AbstractChannel.AbstractChannel
A TCPClient is a communication channel. It allows to create client connecting to a specific IP:Port server over a TCP socket.
When the actor execute an OpenChannelTransition, it calls the open method on the tcp client which connects to the server.
>>> from netzob.all import * >>> import time >>> client = TCPClient(remoteIP='127.0.0.1', remotePort=9999)
>>> symbol = Symbol([Field("Hello everyone!")]) >>> s0 = State() >>> s1 = State() >>> s2 = State() >>> openTransition = OpenChannelTransition(startState=s0, endState=s1) >>> mainTransition = Transition(startState=s1, endState=s1, inputSymbol=symbol, outputSymbols=[symbol]) >>> closeTransition = CloseChannelTransition(startState=s1, endState=s2) >>> automata = Automata(s0, [symbol])
>>> channel = TCPServer(localIP="127.0.0.1", localPort=8885) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> server = Actor(automata = automata, initiator = False, abstractionLayer=abstractionLayer)
>>> channel = TCPClient(remoteIP="127.0.0.1", remotePort=8885) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> client = Actor(automata = automata, initiator = True, abstractionLayer=abstractionLayer)
>>> server.start() >>> client.start()
>>> time.sleep(1) >>> client.stop() >>> server.stop()
-
localIP
¶ IP on which the server will listen.
Type: str
-
localPort
¶ TCP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
open
(timeout=None)[source]¶ Open the communication channel. If the channel is a client, it starts to connect to the specified server.
-
read
(timeout=None)[source]¶ Reads the next message on the communication channel. Continues to read while it receives something.
@keyword timeout: the maximum time in millisecond to wait before a message can be reached @type timeout:
int
-
remoteIP
¶ IP on which the server will listen.
Type: str
-
remotePort
¶ TCP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
sendReceive
(data, timeout=None)[source]¶ Write on the communication channel the specified data and returns the corresponding response.
-
timeout
¶
-
netzob.Simulator.Channels.TCPServer module¶
-
class
TCPServer
(localIP, localPort, timeout=5)[source]¶ Bases:
netzob.Simulator.Channels.AbstractChannel.AbstractChannel
A TCPServer is a communication channel. It allows to create server listening on a specified IP:Port over a TCP socket.
When the actor execute an OpenChannelTransition, it calls the open method on the tcp server which starts the server. The objective of the server is to wait for the client to connect.
>>> from netzob.all import * >>> import time >>> server = TCPServer(localIP='127.0.0.1', localPort=9999)
>>> symbol = Symbol([Field("Hello everyone!")]) >>> s0 = State() >>> s1 = State() >>> s2 = State() >>> openTransition = OpenChannelTransition(startState=s0, endState=s1) >>> mainTransition = Transition(startState=s1, endState=s1, inputSymbol=symbol, outputSymbols=[symbol]) >>> closeTransition = CloseChannelTransition(startState=s1, endState=s2) >>> automata = Automata(s0, [symbol])
>>> channel = TCPServer(localIP="127.0.0.1", localPort=8886) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> server = Actor(automata = automata, initiator = False, abstractionLayer=abstractionLayer)
>>> channel = TCPClient(remoteIP="127.0.0.1", remotePort=8886) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> client = Actor(automata = automata, initiator = True, abstractionLayer=abstractionLayer)
>>> server.start() >>> client.start()
>>> time.sleep(1) >>> client.stop() >>> server.stop()
-
localIP
¶ IP on which the server will listen.
Type: str
-
localPort
¶ TCP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
open
(timeout=None)[source]¶ Open the communication channel. If the channel is a server, it starts to listen and will create an instance for each different client
-
read
(timeout=None)[source]¶ Read the next message on the communication channel.
@keyword timeout: the maximum time in millisecond to wait before a message can be reached @type timeout:
int
-
sendReceive
(data, timeout=None)[source]¶ Write on the communication channel the specified data and returns the corresponding response.
-
timeout
¶
-
netzob.Simulator.Channels.UDPClient module¶
-
class
UDPClient
(remoteIP, remotePort, localIP=None, localPort=None, timeout=5)[source]¶ Bases:
netzob.Simulator.Channels.AbstractChannel.AbstractChannel
A UDPClient is a communication channel. It allows to create client connecting to a specific IP:Port server over a UDP socket.
When the actor executes an OpenChannelTransition, it calls the open method on the UDP client which connects to the server.
>>> from netzob.all import * >>> import time >>> client = UDPClient(remoteIP='127.0.0.1', remotePort=9999) >>> client.open() >>> client.close()
>>> symbol = Symbol([Field("Hello everyone!")]) >>> s0 = State() >>> s1 = State() >>> s2 = State() >>> openTransition = OpenChannelTransition(startState=s0, endState=s1) >>> mainTransition = Transition(startState=s1, endState=s1, inputSymbol=symbol, outputSymbols=[symbol]) >>> closeTransition = CloseChannelTransition(startState=s1, endState=s2) >>> automata = Automata(s0, [symbol])
>>> channel = UDPServer(localIP="127.0.0.1", localPort=8883) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> server = Actor(automata = automata, initiator = False, abstractionLayer=abstractionLayer)
>>> channel = UDPClient(remoteIP="127.0.0.1", remotePort=8883) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> client = Actor(automata = automata, initiator = True, abstractionLayer=abstractionLayer)
>>> server.start() >>> client.start()
>>> time.sleep(2) >>> client.stop() >>> server.stop()
-
localIP
¶ IP on which the server will listen.
Type: str
-
localPort
¶ UDP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
open
(timeout=None)[source]¶ Open the communication channel. If the channel is a client, it starts to connect to the specified server.
-
read
(timeout=None)[source]¶ Read the next message on the communication channel.
@keyword timeout: the maximum time in millisecond to wait before a message can be reached @type timeout:
int
-
remoteIP
¶ IP on which the server will listen.
Type: str
-
remotePort
¶ UDP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
sendReceive
(data, timeout=None)[source]¶ Write on the communication channel the specified data and returns the corresponding response.
-
timeout
¶
-
netzob.Simulator.Channels.UDPServer module¶
-
class
UDPServer
(localIP, localPort, timeout=5)[source]¶ Bases:
netzob.Simulator.Channels.AbstractChannel.AbstractChannel
A UDPServer is a communication channel. It allows to create a server that listen to a specific IP:Port over a UDP socket.
When the actor executes an OpenChannelTransition, it calls the open method on the UDP server which makes it to listen for incomming messages.
>>> from netzob.all import * >>> import time >>> server = UDPServer(localIP='127.0.0.1', localPort=9999) >>> server.open() >>> server.close()
>>> symbol = Symbol([Field("Hello everyone!")]) >>> s0 = State() >>> s1 = State() >>> s2 = State() >>> openTransition = OpenChannelTransition(startState=s0, endState=s1) >>> mainTransition = Transition(startState=s1, endState=s1, inputSymbol=symbol, outputSymbols=[symbol]) >>> closeTransition = CloseChannelTransition(startState=s1, endState=s2) >>> automata = Automata(s0, [symbol])
>>> channel = UDPServer(localIP="127.0.0.1", localPort=8884) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> server = Actor(automata = automata, initiator = False, abstractionLayer=abstractionLayer)
>>> channel = UDPClient(remoteIP="127.0.0.1", remotePort=8884) >>> abstractionLayer = AbstractionLayer(channel, [symbol]) >>> client = Actor(automata = automata, initiator = True, abstractionLayer=abstractionLayer)
>>> server.start() >>> client.start()
>>> time.sleep(1) >>> client.stop() >>> server.stop()
-
localIP
¶ IP on which the server will listen.
Type: str
-
localPort
¶ UDP Port on which the server will listen. Its value must be above 0 and under 65535.
Type: int
-
open
(timeout=None)[source]¶ Open the communication channel. This will open a UDP socket that listen for incomming messages.
-
read
(timeout=None)[source]¶ Read the next message on the communication channel.
@keyword timeout: the maximum time in millisecond to wait before a message can be reached @type timeout:
int
-
sendReceive
(data, timeout=None)[source]¶ Write on the communication channel the specified data and returns the corresponding response.
-
timeout
¶
-