Skip to content

Overview

Nicolas Couture edited this page Apr 23, 2026 · 1 revision

Core Architecture

MockSSH is built on top of the Twisted networking engine, specifically using the Conch SSH implementation. It provides a high-level abstraction for simulating SSH servers and interactive shells.

Component Overview

1. The SSH Server (MockSSH.py)

The core of the library manages the SSH transport layer, authentication, and session handling.

  • SSHRealm: Manages the "realm" of the server, mapping authenticated users to their Avatar.
  • SSHAvatar: Represents the user session once authenticated. It provides the SSHUser with a shell or a subsystem.
  • SSHProtocol: Handles the terminal interaction, line buffering, and command dispatching.

2. The Command System

MockSSH uses a pluggable command system. Every command is a class that inherits from SSHCommand.

  • SSHCommand: The base class for all commands. It provides methods like writeln() and exit().
  • PromptingCommand: A specialized command for multi-step interactions (e.g., password prompts).
  • ArgumentValidatingCommand: A command that validates its arguments before execution.

3. The Interactive Shell (SSHShell)

The shell acts as the primary interface for users. It matches input strings against registered commands and handles the "fallback" behavior for unknown commands.

4. The Hy DSL (mocksshy/)

For users who prefer a declarative configuration style, MockSSH provides a DSL written in Hy (a LISP on Python). This allows defining complex server behaviors in a format that looks more like configuration than code.

State Management

  • Protocol State: The SSHProtocol instance maintains the current prompt and session-wide state.
  • Command State: Individual commands can maintain their own state during their lifecycle (from start() to exit()).

Security Model

MockSSH implements modern SSH security standards:

  • Host Keys: Supports Ed25519 and ECDSA by default.
  • Ciphers: Restricted to modern CTR mode ciphers.
  • Authentication: Uses twisted.cred for robust, pluggable authentication.

Clone this wiki locally