sshmitm.apps.mosh.proxy module

class sshmitm.apps.mosh.proxy.MonitorServer(listen_port=0, listen_ip='127.0.0.1')

Bases: object

TCP server that streams raw MOSH server output to connected clients (e.g. netcat).

All host bytes are buffered from the start of the session. Clients connecting later receive the full history first, then live updates. Multiple clients can connect simultaneously.

Parameters:
  • listen_port (int, default: 0) – TCP port to listen on (0 = random free port)

  • listen_ip (str, default: '127.0.0.1') – IP to bind to (default ‘127.0.0.1’)

get_port()
Return type:

int

send(data)

Broadcast data to all connected clients and buffer for late-connecting clients.

Parameters:

data (bytes)

Return type:

None

start()
Return type:

None

class sshmitm.apps.mosh.proxy.UdpProxy(key, target_ip, target_port, listen_ip='', listen_port=0, buf_size=65535, monitor_port=0, log_heartbeats=False, show_debug=False, sessionlog=None)

Bases: object

UdpProxy is a class to act as a proxy server for MOSH (Mobile shell) protocol

This class provides the functionality of a proxy server for the MOSH protocol. MOSH is a protocol for mobile shell sessions, which helps maintain shell sessions when network connection is disrupted.

Parameters:
  • key (str) – Base64 encoded key to be used for decryption of incoming messages

  • target_ip (str) – IP of target server

  • target_port (int) – Port number of target server

  • listen_ip (str, default: '') – IP to bind the proxy server (default ‘’)

  • listen_port (int, default: 0) – Port number to bind the proxy server (default 0)

  • buf_size (int, default: 65535) – buffer size for incoming UDP datagrams (default 65535, the maximum UDP payload size)

  • monitor_port (int | None, default: 0) – TCP port for the netcat monitor socket (0 = random, None = disabled)

  • log_heartbeats (bool, default: False) – log packets that carry no terminal data (default False)

  • show_debug (bool, default: False) – show low-level hex dump fields in log output (default False)

  • sessionlog (TerminalLogFormat | None, default: None)

check_pairing(addr)

Get the destination address to forward incoming messages to.

Parameters:

addr (tuple[str, int]) – Address of incoming message

Return type:

tuple[str, int]

Returns:

Destination address

get_bind_port()

Get the port number that the proxy server is bound to.

Return type:

int

Returns:

Port number

receive(buff_size)

Receive incoming messages, decrypt and log the data, and forward it to the target server.

Parameters:

buff_size (int) – buffer size for incoming data

Return type:

None

start()

Start the proxy server.

Return type:

None

thread_receive()

Start a separate thread to receive incoming messages.

Return type:

None

sshmitm.apps.mosh.proxy.handle_mosh(session, data, isclient, sessionlog=None)

Handle encrypted data from Mosh, a mobile shell that serves as a replacement for ssh.

Parameters:
  • session (Session) – A Session object representing the Mosh connection.

  • data (bytes) – Encrypted data from Mosh.

  • isclient (bool) – A boolean value indicating whether the current session is a client session.

  • sessionlog (TerminalLogFormat | None, default: None) – Optional terminal session recorder.

Return type:

bytes

Returns:

The processed data.