TExcelTAD

SSH versus Telnet

Telnet and SSH do the same job: give you a remote shell. Telnet (1969, RFC 854) sends every keystroke, including the password, as plain bytes. SSH (1995, RFC 4251–4254) encrypts and authenticates the whole session and lets the client verify that it is talking to the right server. The difference is easy to state and easy to see in a capture, which is exactly how audits find the Telnet servers that are still running on routers, switches, printers and industrial devices. This lesson reads a Telnet login from a synthetic capture, looks at what an observer can still learn from SSH, and covers the SSH practices that matter more than encryption: host-key verification and how users authenticate.

A Telnet login, as an observer sees it

The session builds a small capture of a lab client logging in to a lab router over Telnet (port 23), then follows the stream as Wireshark would.

bash · try it yourself
python3 - <<'PY'
from scapy.all import Ether, IP, TCP, Raw, wrpcap
t0, pkts = 1768471200.0, []
C, S = ("10.10.0.5", 50500, "02:00:00:0a:0a:05"), ("10.10.0.23", 23, "02:00:00:0a:0a:17")
seq = {C: 1000, S: 7000}
def send(a, b, flags, data=b"", dt=0.0):
    p = Ether(src=a[2], dst=b[2])/IP(src=a[0], dst=b[0])/TCP(sport=a[1], dport=b[1], flags=flags,
                                                              seq=seq[a], ack=seq[b] if "A" in flags else 0)
    if data:
        p = p/Raw(data)
    p.time = t0 + dt; pkts.append(p)
    seq[a] += len(data) + (1 if "S" in flags or "F" in flags else 0)
send(C, S, "S", dt=0); send(S, C, "SA", dt=0.001); send(C, S, "A", dt=0.002)
send(S, C, "PA", b"lab-router login: ", 0.1)
send(C, S, "PA", b"lab-user\r\n", 1.5)
send(S, C, "PA", b"Password: ", 1.6)
send(C, S, "PA", b"lab-only-pw\r\n", 3.0)
send(S, C, "PA", b"Welcome to lab-router\r\n$ ", 3.1)
wrpcap("telnet.pcap", pkts)
PY
tshark -r telnet.pcap -Y telnet -T fields -e frame.number -e ip.src -e telnet.data
4	10.10.0.23	lab-router login:
5	10.10.0.5	lab-user\r\n
6	10.10.0.23	Password:
7	10.10.0.5	lab-only-pw\r\n
8	10.10.0.23	Welcome to lab-router\r\n,$

The username and password are in frames 5 and 7, readable by anyone who can capture on the path, and so is every command typed afterwards. Real Telnet clients often send one character per packet in character mode, which changes the packet count, not the exposure.

What an observer sees of SSH

An SSH connection starts with two cleartext lines, the identification strings (SSH-2.0-…), then a cleartext key-exchange negotiation (KEXINIT: the lists of key-exchange, host-key, cipher and MAC algorithms each side supports). Everything after the key exchange is encrypted and authenticated. So an observer learns:

  • the client and server software and version from the banners (useful for attackers looking for outdated servers, and for defenders doing inventory),
  • the algorithm lists, which fingerprint the implementation (the HASSH method hashes them, like JA3 for TLS),
  • packet sizes and timing (interactive typing produces many small packets),

but not the username, the password, the commands or their output.

Verifying the server: host keys

Encryption alone doesn't help if you are talking to the wrong server. During key exchange the server signs the exchange with its host key; the client checks that key against ~/.ssh/known_hosts. On first contact there is nothing to compare with, so the client shows a fingerprint and asks: this is "trust on first use" (TOFU). The program computes a fingerprint exactly as OpenSSH does (SHA-256 over the public-key blob, Base64 without padding) for a lab Ed25519 key derived from a fixed seed (real host keys are generated randomly at installation).

python · try it yourself
import base64, hashlib, struct
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PrivateKey
from cryptography.hazmat.primitives import serialization

def ssh_string(b):
    return struct.pack("!I", len(b)) + b

def host_key(seed_text):
    key = Ed25519PrivateKey.from_private_bytes(hashlib.sha256(seed_text).digest())
    raw = key.public_key().public_bytes(serialization.Encoding.Raw, serialization.PublicFormat.Raw)
    return ssh_string(b"ssh-ed25519") + ssh_string(raw)

def fingerprint(blob):
    return "SHA256:" + base64.b64encode(hashlib.sha256(blob).digest()).decode().rstrip("=")

real = host_key(b"lab-router host key, lab only")
known_hosts = {"lab-router.lab.test": fingerprint(real)}
print("known_hosts entry:", "ssh-ed25519", base64.b64encode(real).decode()[:24] + "...")
print("stored fingerprint:", known_hosts["lab-router.lab.test"])

for label, presented in [("the real server", real), ("a man-in-the-middle", host_key(b"some other machine"))]:
    fp = fingerprint(presented)
    ok = fp == known_hosts["lab-router.lab.test"]
    print(f"{label:<20} presents {fp[:22]}...  ->", "OK" if ok else "WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!")
known_hosts entry: ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...
stored fingerprint: SHA256:c4JtaRcdbTB+CObb1zQUUEIFuHryCdL5uZxl959e5F0
the real server      presents SHA256:c4JtaRcdbTB+COb...  -> OK
a man-in-the-middle  presents SHA256:6kJvtv0Sk1RD4YL...  -> WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!

The warning in the last line is the one OpenSSH prints when a host key changes. It is the only thing that stands between a user and a man-in-the-middle who has redirected the connection, which is why "just remove the old line from known_hosts" is a dangerous habit.

Security properties side by side

Telnet SSH
confidentiality none encrypted (e.g. ChaCha20-Poly1305, AES-GCM)
integrity none: an on-path attacker can inject commands every packet authenticated
server authentication none host key, checked against known_hosts, SSHFP DNS records or an SSH CA
user authentication password in cleartext password inside the tunnel, public keys, certificates, FIDO security keys
default port 23 22

How problems are detected

  • Any Telnet at all: flows to TCP 23 (and 2323, common on IoT devices) in NetFlow, IDS rules for Telnet login prompts, scans of your own ranges for open 23.
  • SSH brute force and spraying: many failed logins in /var/log/auth.log or the journal (Failed password for invalid user …), many short connections to port 22 from one source.
  • Host-key changes reported by users or by monitoring that records fingerprints of your servers.
  • Outdated SSH servers and weak algorithms in banners and KEXINIT (SSH-1, diffie-hellman-group1-sha1, ssh-dss, CBC ciphers).

How it is fixed

  1. Turn Telnet off everywhere; for network devices, enable SSH (and use an out-of-band management network). Where a legacy device can only do Telnet, isolate it and reach it through a jump host.
  2. Key-based authentication: PasswordAuthentication no, PermitRootLogin no (or prohibit-password), keys protected by passphrases or hardware tokens (sk-ssh-ed25519@openssh.com).
  3. Verify host keys properly: distribute known_hosts centrally, publish SSHFP records in a DNSSEC-signed zone, or use an SSH certificate authority for host certificates.
  4. Limit exposure: SSH reachable only from admin networks or through a bastion; rate limiting and tools like fail2ban against guessing; MFA for privileged access.
  5. Keep algorithms modern (current OpenSSH defaults) and the software patched.

Pitfalls

  • Moving SSH to port 2222 and calling it secure. It reduces log noise from bots, nothing else.
  • Accepting host keys blindly in scripts (StrictHostKeyChecking=no), which turns every automated connection into a TOFU with no T.
  • Forgetting agent forwarding: ssh -A to a compromised host lets that host use your keys while you are connected. Prefer ProxyJump.

Practice

1. In the Telnet capture, which side sent the password, and in which frame?

The client 10.10.0.5, in frame 7 (lab-only-pw\r\n), right after the server's Password: prompt in frame 6.

2. Why does SSH still reveal the software version, and does that matter?

The identification string is exchanged before encryption so both sides can pick the protocol version and work around known bugs. It lets anyone fingerprint outdated servers, which is a reason to patch, not to hide the banner.

3. A user reports the "REMOTE HOST IDENTIFICATION HAS CHANGED" warning after a server was reinstalled. What is the right response?

Confirm out of band that the server was reinstalled and obtain its new fingerprint from a trusted source (the admin, the configuration system, SSHFP with DNSSEC), compare, and only then replace the known_hosts entry. If nobody reinstalled it, treat it as a possible man-in-the-middle.

Test yourself

What can a passive observer read in a Telnet session?

  1. Only the IP addresses
  2. Everything, including username, password and commands
  3. Only the banner
  4. Nothing; Telnet is encrypted

Which parts of an SSH connection are sent in the clear?

  1. The password
  2. The identification strings and the key-exchange algorithm lists
  3. The commands
  4. The private key

What protects an SSH client against a man-in-the-middle?

  1. The port number
  2. Checking the server's host key against a known fingerprint
  3. The client's IP address
  4. Compression

Which sshd setting disables password logins?

  1. PermitRootLogin no
  2. PasswordAuthentication no
  3. Port 2222
  4. X11Forwarding no