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
- Wireshark filter
ssh- Encrypted
- yes
Packet structure
Select a field to see what it does.
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
| Filter | Shows |
|---|---|
ssh | All SSH (port 22, or “Decode As”) |
ssh.protocol | Version banners (software and version) |
ssh.message_code == 20 | KEXINIT: algorithms offered |
ssh.kex_algorithms contains "sha1" | Weak key exchange offered |
ssh.kex.hassh / ssh.kex.hasshserver | HASSH client/server fingerprints |
tcp.port == 22 && tcp.flags.syn == 1 && tcp.flags.ack == 0 | Connection 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
- Brute force and credential stuffing on port 22. Fix: keys only (
PasswordAuthentication no), fail2ban, allow-lists, no root login. - Host key verification: clients that accept unknown or changed host keys (
StrictHostKeyChecking no) are open to man-in-the-middle. - Tunnelling and pivoting:
-L,-Rand-Dmove traffic past firewalls; reverse tunnels (ssh -R) are a classic C2 and persistence trick. Restrict withAllowTcpForwarding nowhere not needed. - Stolen keys and agent forwarding: private keys without a passphrase, and forwarded agents on a compromised jump host.
- Weak algorithms:
diffie-hellman-group1-sha1,ssh-rsa(SHA-1), CBC ciphers,hmac-md5. Check withssh-audit. - Terrapin (CVE-2023-48795): prefix truncation against chacha20-poly1305 and
-etmmodes; fixed with “strict kex” in current versions. - Fingerprinting: banners and HASSH identify client tools (OpenSSH, PuTTY, Paramiko-based malware).
Versions and related
- SSH-1 is broken and gone; everything today is SSH-2 (
SSH-2.0-banner). - SFTP and SCP run inside SSH. FTP is unrelated.
- TLS solves the same problem for other protocols, with certificates instead of host keys and known_hosts.
- Runs over TCP. See also SSH key management.