SSH Terrapin Prefix Truncation (CVE-2023-48795)
The SSH server is vulnerable to the Terrapin attack, which lets an attacker in the network path delete messages at the start of a session and weaken its security extensions.
| Severity | Medium |
| CVSS 3.1 | 5.9 CVSS:3.1/AV:N/AC:H/PR:N/UI:N/S:U/C:N/I:H/A:N Open in the calculator |
| CVSS 4.0 | 8.2 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:N/VC:N/VI:H/VA:N/SC:N/SI:N/SA:N Open in the calculator |
| CWE | CWE-354: Improper Validation of Integrity Check Value |
| MITRE ATT&CK | T1557 Adversary-in-the-Middle |
| CVE | CVE-2023-48795 |
| Category | Cryptographic Failures |
Description
The SSH server supports a cipher or MAC mode affected by the Terrapin prefix truncation attack (CVE-2023-48795) and does not support the strict key exchange countermeasure. During the handshake, an attacker who can intercept and modify traffic between the client and the server can add messages before encryption starts and delete the same number of messages after it starts, without either side noticing, because the packet sequence numbers still line up. The attack is practical against the chacha20-poly1305@openssh.com cipher, and, with a lower success rate, against CBC ciphers combined with Encrypt-then-MAC (EtM) MACs; AES-GCM, and MACs that are not EtM, are not affected.
The attack works only when both ends use an affected mode without strict key exchange, and against OpenSSH its practical effect is limited: the attacker can delete the extension negotiation message sent at the start of the session, which can downgrade the signature algorithms used for public key authentication and turn off the keystroke timing obfuscation in recent OpenSSH releases, but Terrapin alone does not let the attacker read the traffic or inject arbitrary data into an OpenSSH session. Some other implementations had flaws that the attack made far more serious, such as AsyncSSH, where it could log the client in to an account the attacker controls, so the impact depends on the software at both ends.
The countermeasure, strict key exchange, resets the sequence numbers when encryption starts and rejects unexpected messages during the handshake. A server advertises it as kex-strict-s-v00@openssh.com in its key exchange list, and it only takes effect when the client supports it too. It was added in OpenSSH 9.6 and in many other SSH implementations at the end of 2023, and many distributions have backported it, so the version in the banner is not a reliable guide. The issue is confirmed by checking the algorithms offered and whether strict key exchange is advertised, which the researchers' Terrapin scanner and ssh-audit both do.
Remediation
Update both ends so that strict key exchange is used:
- Install the SSH server update that adds strict key exchange: OpenSSH 9.6 or later, the distribution's patched package, or the vendor's fixed firmware for network devices and appliances.
- Update SSH clients and libraries as well, such as PuTTY, WinSCP, libssh, Paramiko and the Go SSH package where they are used, because the countermeasure only applies when both sides support it.
Where the server cannot be updated straight away, stop offering the affected modes. On OpenSSH, remove chacha20-poly1305@openssh.com from Ciphers, and either remove the CBC ciphers or remove the EtM MACs (names ending -etm@openssh.com) from MACs. This example removes ChaCha20-Poly1305 and the CBC ciphers:
Check that clients can still connect with the remaining algorithms, as some older clients support only the removed ones. Confirm the fix by repeating the scan, which should show strict key exchange supported or no affected mode offered.
References
Add This Finding to Your Library
In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.
Free trialYour trial starts when your portal goes live, not when you sign up, so the time you spend setting up does not count. · No card required
Only need the reporting? Our reporting tool is free and open source, with the same library.