
A lightweight Python scanner for CVE-2023-48795 — the SSH Terrapin Prefix Truncation vulnerability.
Terrapin is a protocol-level vulnerability in SSH that allows an attacker performing an active MitM to truncate the negotiated extension information, downgrading connection security — most critically disabling
ext-info(used for server signature algorithms) andping(used by OpenSSH'sno-authextension).
| Field | Detail |
|---|---|
| CVE | CVE-2023-48795 |
| CVSS | 5.9 (Medium) |
| Type | SSH Protocol — Prefix Truncation / Integrity Bypass |
| Disclosure | December 2023 |
| Affected | OpenSSH < 9.6, PuTTY < 0.80, libssh < 0.10.6, and many others |
| References | terrapin-attack.com |
The vulnerability exists because certain SSH cipher/MAC combinations — specifically chacha20-poly1305 and CBC-mode ciphers with Encrypt-then-MAC — allow an active MitM attacker to inject and remove SSH sequence numbers during the handshake, truncating the negotiated extension data without detection.
The fix introduced a strict KEX extension (kex-strict-*[email protected]) that both client and server must advertise to be immune.
The script performs a passive banner grab and KEXINIT parse only — no full SSH handshake, no authentication, no exploitation:
SSH_MSG_KEXINIT packetBecause the check occurs entirely within the key exchange phase, it is non-intrusive and leaves no meaningful trace beyond a normal TCP connection attempt.
socket, struct, argparse, concurrent.futures)git clone https://github.com/Mr-Whiskerss/terrapin_check
cd terrapin_check
chmod +x terrapin_check.py
python3 terrapin_check.py <host> [port]
python3 terrapin_check.py 192.168.1.10
python3 terrapin_check.py 192.168.1.10 2222
One target per line — accepts host or host:port format.
python3 terrapin_check.py -f targets.txt
python3 terrapin_check.py -f targets.txt --threads 20 --timeout 3
python3 terrapin_check.py -f targets.txt --summary
usage: terrapin_check.py [-h] [-f FILE] [-p PORT] [--threads THREADS] [--timeout TIMEOUT] [--summary] [host] [port]
positional arguments:
host Target host
port SSH port (default: 22)
options:
-h, --help Show this help message and exit
-f, --file FILE File containing hosts (host or host:port per line)
-p, --port-flag PORT Default port when using -f (default: 22)
--threads THREADS Concurrent threads for bulk scan (default: 10)
--timeout TIMEOUT Socket timeout in seconds (default: 5.0)
--summary Print one-line summary per host only
| Code | Meaning |
|---|---|
0 | No vulnerable hosts found |
1 | One or more vulnerable hosts detected |
This allows the script to be used cleanly in pipelines and automated workflows.
────────────────────────────────────────────────────────────
Target : 192.168.1.10:22
Banner : SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6
Status : VULNERABLE
Strict-KEX : No
✗ ChaCha20-Poly1305 advertised → prefix-truncation possible
✗ CBC+ETM combination advertised
CBC ciphers : aes128-cbc, aes256-cbc
ETM MACs : [email protected], [email protected]
KEX algorithms:
curve25519-sha256
ecdh-sha2-nistp256
diffie-hellman-group14-sha256
────────────────────────────────────────────────────────────
[VULN] 192.168.1.10:22 VULNERABLE (CVE-2023-48795)
[SAFE] 192.168.1.20:22 Not vulnerable
[MIT] 192.168.1.30:22 Algorithms present but strict-KEX mitigates
[?] 192.168.1.99:22 ERROR: Connection refused
The script flags a host as VULNERABLE if either of the following is true, and the strict-KEX extension is not advertised:
The server advertises [email protected] in either encryption direction.
The server advertises any CBC-mode cipher and any ETM MAC together:
CBC ciphers checked:
aes128-cbc, aes192-cbc, aes256-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, idea-cbc, arcfour, arcfour128, arcfour256, [email protected]
ETM MACs checked:
[email protected], [email protected], [email protected], [email protected], and variants
If the server advertises [email protected] in its KEX algorithm list, the connection is protected regardless of which ciphers and MACs are offered. The script will report MITIGATED rather than VULNERABLE in this case.
| Action |
|---|
# /etc/ssh/sshd_config
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
MACs hmac-sha2-256,hmac-sha2-512
Algorithm removal reduces cipher agility. Upgrading is always the preferred remediation.
This tool is intended for authorised security assessments only. Only use it against systems you own or have explicit written permission to test. The author accepts no liability for misuse.
Part of the Mr-Whiskerss pentesting toolkit.
| Detail |
|---|
| Upgrade OpenSSH | Upgrade to ≥ 9.6 on both client and server. Strict KEX is enabled by default. |
| Patch other implementations | PuTTY ≥ 0.80, libssh ≥ 0.10.6, Paramiko ≥ 3.4.0, AsyncSSH ≥ 2.14.2 |
| Remove vulnerable algorithms | If upgrading is not immediately possible, remove chacha20-poly1305 and CBC ciphers + ETM MACs from sshd_config: |