networking, updated

SSH

Secure Shell gives encrypted remote logins, command execution, file transfer (SFTP, SCP) and port forwarding over a single TCP connection. After the key exchange, almost nothing is visible.

OSI layer
7 Application
Carried in
TCP
Ports
22/tcp
Specs
RFC 4251, RFC 4252, RFC 4253, RFC 4254
Wireshark filter
ssh
Encrypted
yes

Packet structure

SSH binary packet5 bytes + variable

Select a field to see what it does.

RFC 4253. After key exchange everything except (with etm/AEAD modes) the length is encrypted, and the MAC follows the packet.

Before the binary packets, both sides send a plain-text version banner, e.g. SSH-2.0-OpenSSH_9.6p1 Ubuntu-3ubuntu13. It reveals the software and often the OS version.

How it works

sequenceDiagram
    participant C as Client
    participant S as Server :22
    C->>S: Banner SSH-2.0-OpenSSH_9.7
    S->>C: Banner SSH-2.0-OpenSSH_9.6p1 Ubuntu
    C->>S: KEXINIT (algorithm lists, clear text)
    S->>C: KEXINIT
    C->>S: KEX ECDH init (client public key)
    S->>C: KEX ECDH reply (server public key, host key, signature)
    Note over C: Verifies the host key (known_hosts)
    C->>S: NEWKEYS
    S->>C: NEWKEYS
    Note over C,S: Encrypted from here
    C->>S: User authentication (publickey, password, keyboard-interactive)
    C->>S: Channel open: session, then shell / exec / subsystem sftp

The protocol has three layers: transport (key exchange, encryption, host authentication), user authentication, and connection (multiplexed channels: shells, commands, SFTP, forwarded ports, X11, agent).

Port forwarding: -L (local: reach a remote service through the server), -R (remote: expose a local service on the server, popular for reverse shells), -D (dynamic: SOCKS proxy).

In Wireshark

FilterShows
sshAll SSH (port 22, or “Decode As”)
ssh.protocolVersion banners (software and version)
ssh.message_code == 20KEXINIT: algorithms offered
ssh.kex_algorithms contains "sha1"Weak key exchange offered
ssh.kex.hassh / ssh.kex.hasshserverHASSH client/server fingerprints
tcp.port == 22 && tcp.flags.syn == 1 && tcp.flags.ack == 0Connection attempts (brute force when many)
ssh && !(tcp.port == 22)SSH on unusual ports

What normal looks like: short handshake, then interactive sessions (many small packets, one per keystroke) or bulk transfers (SFTP, SCP). Many short connections that end right after authentication from one source = brute force. A long-lived SSH connection to the internet with steady traffic can be a tunnel.

Security notes

References

§ home
~/knubertus/home/
1,1 Top