Sending and Receiving Messages
Contents
Sending and Receiving Messages#
Underlying Concepts#
In the Netzob library, a communication channel is an element allowing a connection to a remote device. Generally, if the device is connected with an Ethernet network, the channel includes a socket object and all the properties used to configure it. The channel also provides the connection status and send/receive APIs.
Some specific channels make it possible to access and manipulate the underlying protocol header. These channels are prefixed with the term Custom
. The underlying protocol header takes the form of a Symbol
for which we can specify a Preset
configuration.
These elements are described in this chapter.
Communication Channel API#
Each communication channel provides the following API:
- class AbstractChannel[source]#
A communication channel is an element allowing the establishment of a connection to or from a remote device.
The AbstractChannel defines the API of a communication channel.
A communication channel provides the following public variables:
- Variables
isOpen (
bool
) – The status of the communication channel.timeout (
int
) – The default timeout in seconds for opening a connection (only effective in the context of a client), as well as for waiting a message when calling theread()
method.header (
Symbol
) – A Symbol that makes it possible to access the underlying protocol header for the channels prefixed with the term Custom.header_preset (
Preset
) – A Preset used to preset (parameterize) the fields of the underlying protocol header during symbol specialization. SeeSymbol.specialize()
for more information.
- __enter__()[source]#
Enter the runtime channel context by opening the channel. This methods is implied in the with statement.
- __exit__(exc_type, exc_value, traceback)[source]#
Exit the runtime channel context by closing the channel. This methods is implied in the with statement.
This method should not be called explicitly. However, the following arguments are accepted:
- Parameters
exc_type (Exception, required) – the potential exception type caught in context
exc_value (object, required) – the potential exception value caught in context
traceback (object, required) – the traceback of the potential exception caught in context
- abstract close()#
Close the communication channel.
- abstract open(timeout=None)#
Open the communication channel. If the channel is a server, it starts to listen for incoming data. If the channel is a client, it connects to the remote peer.
- Parameters
timeout (
float
, optional) – The timeout of the channel for opening a connection with a remote peer. This parameter overrides the channeltimeout
attribute and is only effective in the context of a client. Default value (None) corresponds to no timeout.
- abstract read()#
Read the next message from the communication channel.
- Returns
The received data.
- Return type
bytes
- abstract sendReceive(data)#
Write on the communication channel the specified data, wait for a response and return the received data.
- Parameters
data (
bytes
, required) – The data to write on the channel.- Returns
The received data.
- Return type
bytes
- setSendLimit(maxValue)[source]#
Change the max number of writings.
When it is reached, no more packets can be sent until
clearSendLimit()
is called.If maxValue is -1, the sending limit is deactivated.
- Parameters
maxValue (
int
, required) – the new max value
- abstract set_rate(rate)[source]#
This method set the given transmission rate to the channel. Used in testing network under high load
- Parameters
rate (
int
, required) – This specifies the bandwidth in bytes per second to respect during traffic emission. Default value isNone
, which means that the bandwidth is only limited by the underlying physical layer.
- write(data, duration=None)[source]#
Write to the communication channel the specified data, either once, or in a loop according to the duration parameter.
- Parameters
data (bytes, required) – The data to write on the channel.
duration (int, optional) – This indicates for how many seconds the data is continuously written on the channel. Default value is
None
, which means that the data is sent only once.
- Returns
The amount of written data, in bytes.
- Return type
int
- write_map(data_iterator, duration=None)[source]#
Write to the communication channel the successive data values, either once, or in a loop according to the duration parameter.
- Parameters
data_iterator (Iterator[bytes], required) – data iterator used to write on the channel.
duration (int, optional) – This indicates for how many seconds the data is continuously written on the channel. Default value is
None
, which means that the data is sent only once.
- Returns
The amount of written data, count in bytes.
- Return type
int
Note
There are two ways to open and close a channel. Both methods provide the same behavior.
either by using the related methods:
open()
andclose()
. Example:channel.open() try: channel.write(b'abcd') finally: channel.close()
or by using Python contexts capability provided by the
with
statement and following methods:__enter__()
and__exit__()
. Example:with channel: channel.write(b'abcd')
Builder classes (see Build pattern) are also available for each communication channel. They could be used to create an instance of the channel class using generic keys.
This API is available through the following class:
- class ChannelBuilder(kind)[source]#
This builder pattern enables the creation of any kind of
AbstractChannel
.Initialize the builder context by providing the kind of object to build.
Sub classes should use specific setter methods (i.e.
set_key
to setkey
attribute in final object) to handle the setting of attributes in a specific way. Otherwise, the named attribute ofset()
will be used.Two data-stores are available in a
ChannelBuilder
instance:attrs
: a map between argument name in __init__ method of the channel,after_init_callbacks
: a list of callback to be called after __init__ method call.
- Parameters
kind (an AbstractChannel class) – the kind of object to build
- set(key, value)[source]#
Set a named parameter that will be passed to
build()
.- Parameters
key (str, required) – a named parameter expected by
self.kind.__init__()
value (object, required) – any object
- set_map(mapping: Mapping) netzob.Simulator.ChannelBuilder.ChannelBuilder [source]#
Set a mapping of key-value named parameters.
It is a shortcut method to address multiple key-value pairs successively. See
set()
for details.- Parameters
mapping (Mapping[str, Any], required) – A key-value parameter mapping
Available Communication Channels#
The available communication channels are as follows:
RawEthernetChannel
: this channel sends/receives Raw Ethernet frames.CustomEthernetChannel
: this channel sends/receives Ethernet frames (with Ethernet header computed by this channel).CustomIPChannel
: this channel sends/receives IP payloads (with IP header computed by this channel).IPChannel
: this channel sends/receives IP payloads (with IP header computed by the OS kernel).UDPClient
: this channel provides the connection of a client to a specific IP:Port server over a UDP socket.TCPClient
: this channel provides the connection of a client to a specific IP:Port server over a TCP socket.UDPServer
: this channel provides a server listening to a specific IP:Port over a UDP socket.TCPServer
: this channel provides a server listening to a specific IP:Port over a TCP socket.SSLClient
: this channel provides the connection of a client to a specific IP:Port server over a TCP/SSL socket.DebugChannel
: this channel provides a way to log I/Os into a specific stream.
Each communication channel, with their associated builder class, is described in the following sub-chapters.
RawEthernetChannel channel#
- class RawEthernetChannel(interface, timeout=None)[source]#
A RawEthernetChannel is a communication channel to send Raw Ethernet frames.
The RawEthernetChannel constructor expects some parameters:
- Parameters
interface (
str
, required) – The local network interface name (such as ‘eth0’, ‘lo’).timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the RawEthernetChannel class provides the following public variables:
- Variables
interface (
str
) – The network Interface name such as ‘eth0’, ‘lo’, determined with the local MAC address. Read only variable.
>>> from netzob.all import * >>> from binascii import hexlify >>> client = RawEthernetChannel(interface="lo") >>> client.open() >>> symbol = Symbol([Field(Raw(b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x08\x00"))]) >>> client.write(next(symbol.specialize())) 14 >>> client.close()
- class RawEthernetChannelBuilder[source]#
This builder is used to create a
RawEthernetChannel
instance.>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(interface="eth0") >>> builder = RawEthernetChannelBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.RawEthernetChannel.RawEthernetChannel'> >>> chan.interface # interface key has been mapped to interface attribute 'eth0'
CustomEthernetChannel channel#
- class CustomEthernetChannel(remoteMac, localMac, timeout=None)[source]#
A CustomEthernetChannel is a communication channel to send Ethernet frames. This channel is responsible for building the Ethernet layer.
The CustomEthernetChannel constructor expects some parameters:
- Parameters
remoteMac (
str
ornetaddr.EUI
, required) – This parameter is the remote MAC address to connect to.localMac (
str
ornetaddr.EUI
, required) – This parameter is the local MAC address.timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the CustomEthernetChannel class provides the following public variables:
- Variables
remoteMac (
str
) – The remote MAC address to connect to.localMac (
str
) – The local MAC address.interface (
str
) – The network Interface name such as ‘eth0’, ‘lo’, determined with the local MAC address. Read only variable.
The following example shows how to instantiate a CustomEthernetChannel.
>>> from netzob.all import * >>> from binascii import hexlify >>> def example_channel(): ... client = CustomEthernetChannel( ... remoteMac="00:01:02:03:04:05", ... localMac="00:06:07:08:09:10") ... client.open() ... symbol = Symbol([Field("ABC")]) ... client.write(next(symbol.specialize())) ... client.close()
- class CustomEthernetChannelBuilder[source]#
This builder is used to create an
CustomEthernetChannel
instance>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(dst_addr="00:00:00:00:00:00", ... src_addr="00:00:00:00:00:00", ... protocol=0x0800, ... interface="lo") >>> builder = CustomEthernetChannelBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.CustomEthernetChannel.CustomEthernetChannel'> >>> chan.localMac # src_addr key has been mapped to localMac attribute '00:00:00:00:00:00'
CustomIPChannel channel#
- class CustomIPChannel(remoteIP, localIP=None, upperProtocol=6, timeout=None)[source]#
A CustomIPChannel is a communication channel that is used to send IP payloads. This channel is responsible for building the IP header. It is similar to the
IPChannel
channel, except that withIPChannel
the OS kernel builds the IP header. Therefore, with CustomIPChannel, we can modify or fuzz the IP header fields.The CustomIPChannel constructor expects some parameters:
- Parameters
remoteIP (
str
ornetaddr.IPAddress
, required) – This parameter is the remote IP address to connect to.localIP (
str
ornetaddr.IPAddress
, optional) – The local IP address. Default value is the local IP address corresponding to the network interface that will be used to send the packet.upperProtocol (
int
, optional) – The protocol following IP in the stack. Default value issocket.IPPROTO_TCP
(6).timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the CustomIPChannel class provides the following public variables:
- Variables
remoteIP (
str
) – The remote IP address to connect to.localIP (
str
) – The local IP address.upperProtocol (
int
) – The protocol following the IP header.
The following code shows the use of a
CustomIPChannel
channel:>>> from netzob.all import * >>> client = CustomIPChannel(remoteIP='127.0.0.1', timeout=1.) >>> client.open() >>> symbol = Symbol([Field("Hello everyone!")]) >>> client.write(next(symbol.specialize())) 35 >>> client.close()
- class CustomIPChannelBuilder[source]#
This builder is used to create an
CustomIPChannel
instance>>> import socket >>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(dst_addr="1.2.3.4", ... src_addr="4.3.2.1", ... protocol=socket.IPPROTO_TCP) >>> builder = CustomIPChannelBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.CustomIPChannel.CustomIPChannel'> >>> chan.localIP # src_addr key has been mapped to localIP attribute '4.3.2.1'
IPChannel channel#
- class IPChannel(remoteIP, localIP=None, upperProtocol=6, timeout=None)[source]#
An IPChannel is a communication channel that is used to send IP payloads. The kernel is responsible for building the IP header. It is similar to the CustomIPChannel channel, except that with CustomIPChannel the channel builds the IP header. Therefore, with
IPChannel
, we cannot modify or fuzz the IP header fields.The IPChannel constructor expects some parameters:
- Parameters
remoteIP (
str
, required) – This parameter is the remote IP address to connect to.localIP (
str
, optional) – The local IP address. Default value is the local IP address corresponding to the interface that will be used to send the packet.upperProtocol (
int
, optional) – The protocol following the IP header. Default value is socket.IPPROTO_TCP.timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the IPChannel class provides the following public variables:
- Variables
remoteIP (
str
) – The remote IP address to connect to.localIP (
str
) – The local IP address.upperProtocol (
int
) – The protocol following the IP header.
The following code shows the use of an IPChannel channel:
>>> from netzob.all import * >>> client = IPChannel(remoteIP='127.0.0.1', timeout=1.) >>> client.open() >>> symbol = Symbol([Field("Hello everyone!")]) >>> client.write(next(symbol.specialize())) 15 >>> client.close()
- class IPChannelBuilder[source]#
This builder is used to create an
IPChannel
instance>>> import socket >>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(dst_addr="1.2.3.4", ... src_addr="4.3.2.1", ... protocol=socket.IPPROTO_TCP) >>> builder = IPChannelBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.IPChannel.IPChannel'> >>> chan.remoteIP # dst_addr key has been mapped to remoteIP attribute '1.2.3.4'
UDPClient channel#
- class UDPClient(remoteIP, remotePort, localIP=None, localPort=None, timeout=None)[source]#
A UDPClient is a communication channel. It provides the connection of a client to a specific IP:Port server over a UDP socket.
The UDPClient constructor expects some parameters:
- Parameters
remoteIP (
str
, required) – This parameter is the remote IP address to connect to.remotePort (
int
, required) – This parameter is the remote IP port.localIP (
str
, optional) – The local IP address. Default value is the local IP address corresponding to the network interface that will be used to send the packet.localPort (
int
, optional) – The local IP port. Default value in a random valid integer chosen by the kernel.timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the UDPClient class provides the following public variables:
- Variables
remoteIP (
str
) – The remote IP address to connect to.remotePort (
int
) – The remote IP port.localIP (
str
) – The local IP address.localPort (
int
) – The local IP port.
The following code shows the use of a UDPClient channel:
>>> from netzob.all import * >>> client = UDPClient(remoteIP='127.0.0.1', remotePort=9999, timeout=1.) >>> client.open() >>> symbol = Symbol([Field("Hello everyone!")]) >>> client.write(next(symbol.specialize())) 15 >>> client.close()
Complete example with the use of an actor.
>>> from netzob.all import * >>> import time >>> 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, timeout=1.) >>> server = Actor(automata = automata, channel=channel) >>> server.initiator = False
>>> channel = UDPClient(remoteIP="127.0.0.1", remotePort=8883, timeout=1.) >>> client = Actor(automata = automata, channel=channel)
>>> server.start() >>> client.start()
>>> time.sleep(2) >>> client.stop() >>> server.stop()
- class UDPClientBuilder[source]#
This builder is used to create an
UDPClient
instance>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(dst_addr="1.2.3.4", dst_port=1024, ... src_addr="4.3.2.1", src_port=32000) >>> builder = UDPClientBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.UDPClient.UDPClient'> >>> chan.localPort # src_port key has been mapped to localPort attribute 32000
TCPClient channel#
- class TCPClient(remoteIP, remotePort, localIP=None, localPort=None, timeout=None)[source]#
A TCPClient is a communication channel. It provides the connection of a client to a specific IP:Port server over a TCP socket.
The TCPClient constructor expects some parameters:
- Parameters
remoteIP (
str
, required) – This parameter is the remote IP address to connect to.remotePort (
int
, required) – This parameter is the remote IP port.localIP (
str
, optional) – The local IP address. Default value is the local IP address corresponding to the network interface that will be used to send the packet.localPort (
int
, optional) – The local IP port. Default value in a random valid integer chosen by the kernel.timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the TCPClient class provides the following public variables:
- Variables
remoteIP (
str
) – The remote IP address to connect to.remotePort (
int
) – The remote IP port.localIP (
str
) – The local IP address.localPort (
int
) – The local IP port.
The following code shows the creation of a TCPClient channel:
>>> from netzob.all import * >>> client = TCPClient(remoteIP='127.0.0.1', remotePort=9999, timeout=1.)
Complete example with the use of an actor.
>>> from netzob.all import * >>> import time >>> 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_server = TCPServer(localIP="127.0.0.1", localPort=8885, timeout=1.) >>> server = Actor(automata = automata, channel=channel_server) >>> server.initiator = False
>>> channel_client = TCPClient(remoteIP="127.0.0.1", remotePort=8885, timeout=1.) >>> client = Actor(automata = automata, channel=channel_client)
>>> server.start() >>> client.start()
>>> time.sleep(1) >>> client.stop() >>> server.stop() >>> channel_client.close() >>> channel_server.close()
- class TCPClientBuilder[source]#
This builder is used to create an
TCPClient
instance>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(dst_addr="1.2.3.4", dst_port=1024, ... src_addr="4.3.2.1", src_port=32000) >>> builder = TCPClientBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.TCPClient.TCPClient'> >>> chan.remotePort # dst_port key has been mapped to remotePort attribute 1024
UDPServer channel#
- class UDPServer(localIP, localPort, timeout=None)[source]#
A UDPServer is a communication channel. It provides a server listening to a specific IP:Port over a UDP socket.
The UDPServer constructor expects some parameters:
- Parameters
localIP (
str
, required) – This parameter is the local IP address.localPort (
int
, required) – This parameter is the local IP port.timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the UDPServer class provides the following public variables:
- Variables
localIP (
str
) – The local IP address.localPort (
int
) – The local IP port.
The following code shows the use of a UDPServer channel:
>>> from netzob.all import * >>> server = UDPServer(localIP='127.0.0.1', localPort=9999, timeout=1.) >>> server.open() >>> server.close()
The following code shows a complete example of a communication between a client and a server in UDP:
>>> from netzob.all import * >>> import time >>> 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, timeout=1.) >>> server = Actor(automata = automata, channel=channel) >>> server.initiator = False >>> >>> channel = UDPClient(remoteIP="127.0.0.1", remotePort=8884, timeout=1.) >>> client = Actor(automata = automata, channel=channel) >>> >>> server.start() >>> client.start() >>> >>> time.sleep(1) >>> client.stop() >>> server.stop()
- class UDPServerBuilder[source]#
This builder is used to create an
UDPServer
instance>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(src_addr="4.3.2.1", src_port=32000) >>> builder = UDPServerBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.UDPServer.UDPServer'> >>> chan.localPort # src_port key has been mapped to localPort attribute 32000
TCPServer channel#
- class TCPServer(localIP, localPort, timeout=None)[source]#
A TCPServer is a communication channel. It provides a server listening to a specified IP:Port over a TCP socket.
The TCPServer constructor expects some parameters:
- Parameters
localIP (
str
, required) – This parameter is the local IP address.localPort (
int
, required) – This parameter is the local IP port.timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel variables, the TCPServer class provides the following public variables:
- Variables
localIP (
str
) – The local IP address.localPort (
int
) – The local IP port.
The following code shows the creation of a TCPServer channel:
>>> from netzob.all import * >>> server = TCPServer(localIP='127.0.0.1', localPort=9999, timeout=1.)
The following code shows a complete example of a communication between a client and a server in TCP:
>>> from netzob.all import * >>> import time >>> 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, timeout=1.) >>> server = Actor(automata = automata, channel=channel) >>> server.initiator = False
>>> channel = TCPClient(remoteIP="127.0.0.1", remotePort=8886, timeout=1.) >>> client = Actor(automata = automata, channel=channel)
>>> server.start() >>> client.start()
>>> time.sleep(1) >>> client.stop() >>> server.stop()
- class TCPServerBuilder[source]#
This builder is used to create an
TCPServer
instance>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(src_addr="4.3.2.1", src_port=32000) >>> builder = TCPServerBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.TCPServer.TCPServer'> >>> chan.localIP # src_addr key has been mapped to localIP attribute '4.3.2.1'
SSLClient channel#
- class SSLClient(remoteIP, remotePort, localIP=None, localPort=None, server_cert_file=None, alpn_protocols=None, timeout=None)[source]#
An SSLClient is a communication channel that relies on SSL. It provides the connection of a client to a specific IP:Port server over a TCP/SSL socket.
The SSLClient constructor expects some parameters:
- Parameters
remoteIP (
str
, required) – This parameter is the remote IP address to connect to.remotePort (
int
, required) – This parameter is the remote IP port.localIP (
str
, optional) – The local IP address. Default value is the local IP address corresponding to the network interface that will be used to send the packet.localPort (
int
, optional) – The local IP port. Default value in a random valid integer chosen by the kernel.server_cert_file (
str
, optional) – The path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate’s authenticity. Default value is None, meaning that no verification is made on the certificate given by the peer.alpn_protocols (
list
, optional) – Specify which protocols the socket should advertise during the SSL/TLS handshake. It should be a list of strings, like [‘http/1.1’, ‘spdy/2’], ordered by preference. Default value is None.timeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
Adding to AbstractChannel public variables, the SSLClient class provides the following public variables:
- Variables
remoteIP (
str
) – The remote IP address to connect to.remotePort (
int
) – The remote IP port.localIP (
str
) – The local IP address.localPort (
int
) – The local IP port.server_cert_file (
str
) – The path to a single file in PEM format containing the certificate as well as any number of CA certificates needed to establish the certificate’s authenticity.alpn_protocols (
list
) – Specify which protocols the socket should advertise during the SSL/TLS handshake. It should be a list of strings, like [‘http/1.1’, ‘spdy/2’], ordered by preference.
The following code shows the creation of a SSLClient channel:
>>> from netzob.all import * >>> server = SSLClient(remoteIP='127.0.0.1', remotePort=9999)
- class SSLClientBuilder[source]#
This builder is used to create an
SSLClient
instance>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> netinfo = NetInfo(dst_addr="1.2.3.4", dst_port=1024, ... src_addr="4.3.2.1", src_port=32000) >>> builder = SSLClientBuilder().set_map(netinfo.getDict()) >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.SSLClient.SSLClient'> >>> chan.remotePort # dst_port key has been mapped to remotePort attribute 1024
DebugChannel channel#
- class DebugChannel(stream: Union[str, io.IOBase], timeout=None)[source]#
A DebugChannel is a file-like channel that handles writing of output data.
The DebugChannel constructor expects some parameters:
- Parameters
stream (
str
or a file-like object, required) – The output streamtimeout (
float
, optional) – The default timeout of the channel for global connection. Default value is blocking (None).
The following code shows the use of a DebugChannel channel:
>>> from netzob.all import * >>> client = DebugChannel("/dev/null") >>> symbol = Symbol([Field("Hello everyone!")]) >>> with client: ... client.write(next(symbol.specialize())) 18
- class DebugChannelBuilder[source]#
This builder is used to create an
DebugChannel
instance>>> from netzob.Simulator.Channels.NetInfo import NetInfo >>> builder = DebugChannelBuilder().set("stream", "stderr") >>> chan = builder.build() >>> type(chan) <class 'netzob.Simulator.Channels.DebugChannel.DebugChannel'>