sshmitm.session module

Session Class

The Session class provides the ability to start, manage, and close an interactive session between a client and a server. It provides a convenient and exception-safe way to handle sessions in your application.

try:
    with Session(self, client, addr, self.authenticator, remoteaddr) as session:
        if session.start():
            while session.running:
                # session is running
                pass
        else:
            logging.warning("(%s) session not started", session)
except Exception:
    logging.exception("error handling session creation")

This code creates a session object using the session_class method, and wraps it in a with statement. The start method is then called on the session object. If the start method returns True, the session is considered running and the running property of the session is checked in a while loop. If the start method returns False, a warning message is logged indicating that the session was not started. If any exceptions are raised during session creation, they are logged using the logging.exception method.

class sshmitm.session.BaseSession

Bases: BaseModule

The BaseSession class serves as a base for session management in the system.

This class should be subclassed to provide custom session management functionality.

register_session_thread()
Return type:

None

class sshmitm.session.Session(proxyserver, client_socket, client_address, authenticator, remoteaddr, banner_name=None)

Bases: BaseSession

Session Handler to store and manage active SSH sessions.

Parameters:
  • proxyserver (SSHProxyServer) – Instance of ‘sshmitm.server.SSHProxyServer’ class

  • client_socket (socket) – A socket instance representing the connection from the client

  • client_address (Union[Tuple[str, int], Tuple[str, int, int, int]]) – Address information of the client

  • authenticator (Type[Authenticator]) – Type of the authentication class to be used

  • remoteaddr (Union[Tuple[str, int], Tuple[str, int, int, int]]) – Remote address information

  • banner_name (Optional[str], default: None)

CIPHERS = None
close()

Close the session and release the underlying resources.

Return type:

None

get_session_log_dir()

Returns the directory where the ssh session logs will be stored.

Return type:

Optional[str]

Returns:

The directory path where the ssh session logs will be stored, or None if the directory is not specified.

classmethod parser_arguments()

Add an argument to the command line parser for session plugin.

Return type:

None

property running: bool

Returns the running state of the current session.

Returns:

A boolean indicating whether the session is running or not

start()

Start the session and initialize the underlying transport.

Return type:

bool

property transport: Transport

Returns the type of transport being used by the current session.

Returns:

A string representing the transport type