sshmitm.apps.mosh module
- class sshmitm.apps.mosh.UdpProxy(key: str, target_ip: str, target_port: int, listen_ip: str = '', listen_port: int = 0, buf_size: int = 1024)
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) – IP to bind the proxy server (default ‘’)
listen_port (int) – Port number to bind the proxy server (default 0)
buf_size (int) – buffer size for incoming data (default 1024)
- check_pairing(addr: Tuple[str, int]) Tuple[str, int]
Get the destination address to forward incoming messages to.
- Parameters:
addr (Tuple[str, int]) – Address of incoming message
- Returns:
Destination address
- Return type:
Tuple[str, int]
- static format_hex(data: bytes, hexwidth: int = 19) str
Format the data in hexadecimal format.
- Parameters:
data (bytes) – Data to be formatted
hexwidth (int) – Width of hexadecimal data (default 19)
- Returns:
Formatted hexadecimal data
- Return type:
str
- get_bind_port() int
Get the port number that the proxy server is bound to.
- Returns:
Port number
- Return type:
int
- receive(buff_size: int) None
Receive incoming messages, decrypt and log the data, and forward it to the target server.
- Parameters:
buff_size (int) – buffer size for incoming data
- Returns:
None
- start() None
Start the proxy server.
- Returns:
None
- thread_receive() None
Start a separate thread to receive incoming messages.
- Returns:
None
- sshmitm.apps.mosh.handle_mosh(session: Session, traffic: bytes, isclient: bool) bytes
Handle encrypted traffic from Mosh, a mobile shell that serves as a replacement for ssh.
- Parameters:
session (Session) – A Session object representing the Mosh connection.
traffic (bytes) – Encrypted traffic from Mosh.
isclient (bool) – A boolean value indicating whether the current session is a client session.
- Returns:
The processed traffic.
- Return type:
bytes