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() None
- class sshmitm.session.Session(proxyserver: SSHProxyServer, client_socket: socket, client_address: Union[Tuple[str, int], Tuple[str, int, int, int]], authenticator: Type[Authenticator], remoteaddr: Union[Tuple[str, int], Tuple[str, int, int, int]], banner_name: Optional[str] = None)
Bases:
BaseSession
A class that holds the information and methods for the ssh session.
- Parameters:
proxyserver (sshmitm.server.SSHProxyServer) – Instance of ‘sshmitm.server.SSHProxyServer’ class
client_socket (socket.socket) – A socket instance representing the connection from the client
client_address (Tuple[str, int] or Tuple[str, int, int, int]) – Address information of the client
authenticator (Type[sshmitm.authentication.Authenticator]) – Type of the authentication class to be used
remoteaddr (Tuple[str, int] or Tuple[str, int, int, int]) – Remote address information
- CIPHERS = None
- close() None
Close the session and release the underlying resources.
- Returns:
None
- get_session_log_dir() Optional[str]
Returns the directory where the ssh session logs will be stored.
- Returns:
The directory path where the ssh session logs will be stored, or None if the directory is not specified.
- Return type:
Optional[str]
- classmethod parser_arguments() None
Add an argument to the command line parser for session plugin.
- Returns:
None
- 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
- Return type:
bool
- start() bool
Start the session and initialize the underlying transport.
- Returns:
None
- property transport: Transport
Returns the type of transport being used by the current session.
- Returns:
A string representing the transport type
- Return type:
str