Module sysbot.connectors.socket

Socket Connector Module

This module provides TCP and UDP socket connectors with support for SSL/TLS encryption. It enables raw network communication for protocols not covered by other specialized connectors.

Classes

class Tcp (port=80)

TCP connector with optional SSL/TLS support for secure communication.

Initialize TCP connector with default port.

Args

port : int
Default TCP port (default: 80).

Ancestors

Methods

def close_session(self, session)

Closes the SSL/TCP socket connection.

Args

session : ssl.SSLSocket
The SSL-wrapped TCP socket object to close.

Raises

Exception
If there is an error closing the session.
def execute_command(self,
session,
command,
expect_response=True,
timeout=30,
buffer_size=4096,
encoding='utf-8')

Send data through the TCP socket and optionally receive a response.

Args

session : socket.socket or ssl.SSLSocket
The socket object.
command : str or bytes
The data to send through the socket.
expect_response : bool
Whether to wait for a response (default: True).
timeout : int
Custom timeout for this operation (default: 30).
buffer_size : int
Custom buffer size for receiving data (default: 4096).
encoding : str
Encoding to use for string data (default: 'utf-8').

Returns

dict
Dictionary containing: - 'sent': The data that was sent - 'bytes_sent': Number of bytes sent - 'received': The data received (if expect_response is True) - 'bytes_received': Number of bytes received - 'success': Boolean indicating if operation was successful - 'timeout': Boolean indicating if timeout occurred during receive

Raises

Exception
If there is an error during communication.
def open_session(self, host, port=None, login=None, password=None, use_ssl=True)

Opens a TCP socket connection with optional SSL/TLS encryption.

Args

host : str
Hostname or IP address of the target system.
port : int
Port to connect to. If None, uses default_port.
login : str
Username for authentication (optional for raw TCP).
password : str
Password for authentication (optional for raw TCP).
use_ssl : bool
Whether to use SSL/TLS encryption (default: True).

Returns

socket.socket or ssl.SSLSocket
Socket object for communication.

Raises

Exception
If there is an error opening the connection.
class Udp (port=53)

UDP connector for connectionless communication.

Initialize UDP connector with default port.

Args

port : int
Default UDP port (default: 53).

Ancestors

Methods

def close_session(self, session)

Closes the UDP socket.

Args

session : dict
The session dictionary containing the socket.

Raises

Exception
If there is an error closing the session.
def execute_command(self,
session,
command,
expect_response=True,
timeout=30,
buffer_size=4096,
encoding='utf-8')

Send data through the UDP socket and optionally receive a response.

Args

session : dict
The session dictionary containing socket and target info.
command : str or bytes
The data to send through the socket.
expect_response : bool
Whether to wait for a response (default: True).
timeout : int
Custom timeout for this operation (default: 30).
buffer_size : int
Custom buffer size for receiving data (default: 4096).
encoding : str
Encoding to use for string data (default: 'utf-8').

Returns

dict
Dictionary containing: - 'sent': The data that was sent - 'bytes_sent': Number of bytes sent - 'received': The data received (if expect_response is True) - 'bytes_received': Number of bytes received - 'success': Boolean indicating if operation was successful - 'timeout': Boolean indicating if timeout occurred during receive - 'source_address': Address that sent the response (if received)

Raises

Exception
If there is an error during communication.
def open_session(self, host, port=None, login=None, password=None)

Creates a UDP socket for communication.

Args

host : str
Hostname or IP address of the target system.
port : int
Port to communicate with. If None, uses default_port.
login : str
Username for authentication (not used in UDP).
password : str
Password for authentication (not used in UDP).

Returns

dict
Dictionary containing socket and target information.

Raises

Exception
If there is an error creating the socket.