sshmitm.forwarders.tunnel module

class sshmitm.forwarders.tunnel.LocalPortForwardingBaseForwarder(args=None, namespace=None, **kwargs)

Bases: SSHMITMBaseModule

Sets the interface for handling client-side tunnel operations, such as local port forwarding.

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

  • namespace (Namespace | None, default: None)

  • kwargs (Any)

class sshmitm.forwarders.tunnel.LocalPortForwardingForwarder(session, chanid, origin, destination)

Bases: TunnelForwarder, LocalPortForwardingBaseForwarder

Handles tunnel forwarding when the client is requesting a tunnel connection

Then forward data between direct-tcpip channels connecting to local and to remote through the ssh-mitm
  • implements Proxyjump (-W / -J) feature, client side port forwarding (-L)

Parameters:
  • session (Session)

  • chanid (int)

  • origin (tuple[str, int] | None)

  • destination (tuple[str, int] | None)

__init__(session, chanid, origin, destination)

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

Parameters:
  • session (Session)

  • chanid (int)

  • origin (tuple[str, int] | None)

  • destination (tuple[str, int] | None)

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

Return type:

None

classmethod setup(session)
Parameters:

session (Session)

Return type:

None

class sshmitm.forwarders.tunnel.RemotePortForwardingBaseForwarder(args=None, namespace=None, **kwargs)

Bases: SSHMITMBaseModule

Configures the interface for managing server-side tunnel operations, such as remote port forwarding.

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

  • namespace (Namespace | None, default: None)

  • kwargs (Any)

class sshmitm.forwarders.tunnel.RemotePortForwardingForwarder(session, server_interface, destination)

Bases: RemotePortForwardingBaseForwarder

Handles Tunnel forwarding when the server is requesting a tunnel connection

Actually just used to wrap data around a handler to parse to the transport.request_port_forward -> that is why it does not inherit the TunnelForwarder; it just uses it in the handler

Parameters:
__init__(session, server_interface, destination)
Parameters:
close()
Return type:

None

handler(channel, origin, destination)
Parameters:
  • channel (Channel)

  • origin (tuple[str, int] | None)

  • destination (tuple[str, int] | None)

Return type:

None

join()
Return type:

None

class sshmitm.forwarders.tunnel.TunnelForwarder(local_ch, remote_ch)

Bases: Thread

Parameters:
  • local_ch (socket | Channel | None)

  • remote_ch (socket | Channel | None)

__init__(local_ch, remote_ch)

This constructor should always be called with keyword arguments. Arguments are:

group should be None; reserved for future extension when a ThreadGroup class is implemented.

target is the callable object to be invoked by the run() method. Defaults to None, meaning nothing is called.

name is the thread name. By default, a unique name is constructed of the form “Thread-N” where N is a small decimal number.

args is a list or tuple of arguments for the target invocation. Defaults to ().

kwargs is a dictionary of keyword arguments for the target invocation. Defaults to {}.

If a subclass overrides the constructor, it must make sure to invoke the base class constructor (Thread.__init__()) before doing anything else to the thread.

Parameters:
  • local_ch (socket | Channel | None)

  • remote_ch (socket | Channel | None)

close()

Comparable with Channels and Sockets

Return type:

None

close_channel(channel)
Parameters:

channel (socket | Channel)

Return type:

None

handle_client_data(data)
Parameters:

data (bytes)

Return type:

bytes

handle_data(data)
Parameters:

data (bytes)

Return type:

bytes

handle_server_data(data)
Parameters:

data (bytes)

Return type:

bytes

run()

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

Return type:

None

tunnel(chunk_size=1024)

Connect two SSH channels (socket like objects).

Parameters:

chunk_size (int, default: 1024)

Return type:

None