import abc
# abc.ABCMeta is the metaclass in both python 2 and 3
[docs]
class ITargetConnection(metaclass=abc.ABCMeta):
"""
Interface for connections to fuzzing targets.
Target connections may be opened and closed multiple times. You must open before using send/recv and close
afterwards.
.. versionchanged:: 0.2.0
ITargetConnection has been moved into the connections subpackage.
The full path is now boofuzz.connections.itarget_connection.ITargetConnection
"""
[docs]
@abc.abstractmethod
def close(self):
"""
Close connection.
:return: None
"""
raise NotImplementedError
[docs]
@abc.abstractmethod
def open(self):
"""
Opens connection to the target. Make sure to call close!
:return: None
"""
raise NotImplementedError
[docs]
@abc.abstractmethod
def recv(self, max_bytes):
"""
Receive up to max_bytes data.
:param max_bytes: Maximum number of bytes to receive.
:type max_bytes: int
:return: Received data. bytes('') if no data is received.
:rtype: bytes
"""
raise NotImplementedError
[docs]
@abc.abstractmethod
def send(self, data):
"""
Send data to the target.
:param data: Data to send.
:return: Number of bytes actually sent.
:rtype: int
"""
raise NotImplementedError
@property
@abc.abstractmethod
def info(self):
"""Return description of connection info.
E.g., "127.0.0.1:2121"
Returns:
str: Connection info descrption
"""
raise NotImplementedError