sshmitm.clients.ssh module

The module provides a set of classes for implementing SSH-MITM clients in Python.

The AuthenticationMethod class is a helper class that provides different methods for authentication to a remote ssh server. It provides methods for authentication using passwords, private key files, and key-pair certificates. This class makes it easy to use different authentication methods in a consistent manner.

The BaseSSHClient class is an abstract class that provides the basic functionality for an ssh client. This class provides methods to connect to a remote server, create and use secure shell channels, and execute commands on the remote server. It is designed to be extended and customized for specific use cases.

The SSHClient class is a concrete implementation of the BaseSSHClient class. This class provides a high-level API for connecting to remote servers and performing operations over ssh. It uses the Paramiko library under the hood to handle the underlying ssh connectivity. This class makes it easy to connect to remote servers, execute commands, and transfer files.

class sshmitm.clients.ssh.AuthenticationMethod(value)

Bases: Enum

An enumeration of possible authentication methods that can be used to connect to a remote host.

AGENT = 'agent'
PASSWORD = 'password'
PUBLICKEY = 'publickey'
class sshmitm.clients.ssh.BaseSSHClient(args=None, namespace=None, **kwargs)

Bases: BaseModule

” The base class for an SSH client module.

Parameters:
  • args (Optional[Sequence[str]], default: None)

  • namespace (Optional[Namespace], default: None)

  • kwargs (Any)

class sshmitm.clients.ssh.SSHClient(host, port, method, password, user, key, session)

Bases: BaseSSHClient

The SSH client class, used to connect to a remote host.

Parameters:
  • host (str) – the hostname or IP address of the remote host

  • port (int) – the port number to connect to on the remote host

  • method (AuthenticationMethod) – the authentication method to use when connecting

  • password (Optional[str]) – the password to use for authentication (if method is password)

  • user (str) – the username to use for authentication

  • key (Optional[PKey]) – the public key to use for authentication (if method is publickey)

  • session (Session) – the session instance

CIPHERS = None
check_host_key(hostname, keytype, key)

Check the host key.

Parameters:
  • hostname (str) – Hostname of the remote server.

  • keytype (str) – Type of the key.

  • key (PKey) – Key of the remote server.

Return type:

bool

Returns:

True if the host key is valid, False otherwise.

connect()

Connects to the remote host using the specified authentication method.

Return type:

bool

Returns:

True if the connection was successful, False otherwise