The Terrapin Attack is the biggest SSH vulnerability that we have seen in decades. Terrapin splices TCP sequence numbers to truncate SSH extension negotiation. While this is a concern, effective exploitation of this vulnerability is very difficult, and mitigation is very easy! The paper notes that AES-GCM is not vulnerable to the attack:
AES-GCM (RFC5647) is not affected by Terrapin as it does not use the SSH sequence numbers. Instead, AES-GCM uses the IV obtained from key derivation as its nonce, incrementing it after sending a binary packet. In a healthy connection, this results in the nonce being at a fixed offset from the sequence number.
The original Encrypt-and-MAC paradigma from RFC4253 protects the integrity of the plaintext, thus thwarting our attack, which yields one pseudorandom block during decryption.
This means you can simply use the AES-GCM cipher in SSL communication by configuring your hosts to default to that protocol. The AES-GCM cipher has been supported in SSH since version 6.2 so pretty much all supported distributions going back to at least 2014 have an easy mitigation.
Mitigating on the server
Newer Servers that are using `update-crypto-policies` (RHEL, Alma, Rocky, Oracle, newer Ubuntu and Debian)
Newer operating systems that provide the command update-crypto-policies, create a new policy file and activate it. You can modify `DEFAULT` to something different if you are using a different policy, but “DEFAULT” works for most systems.
# cat /etc/crypto-policies/policies/modules/TERRAPIN.pmod cipher@ssh = -CHACHA20* ssh_etm = 0 # update-crypto-policies --set DEFAULT:TERRAPIN Setting system policy to DEFAULT:TERRAPIN Note: System-wide crypto policies are applied on application start-up. It is recommended to restart the system for the change of policies to fully take place.
Older Servers are not using `update-crypto-policies`
Simply add this to the bottom of /etc/ssh/sshd_config:
Match All Ciphers firstname.lastname@example.org
Match all is added in case you have other match blocks. Of course, if you prefer, you can exclude the
Match all line and insert the cipher above any match blocks so that it is a global option.
Forcing aes256-gcm is a bit of a hammer, it certainly works but may be more than you need. Ultimately only Chacha20 and ETM-based MACs need to be disabled, so modify this as you see fit.
Testing Server Mitigation
The Terrapin research team has published a scanning/test tool. There is GitHub page to compile it yourself, or pre-compiled binaries for the most common OS’s are available on the releases page. The result should look something like this. “Strict key exchange support” is unnecessary if the vulnerable ciphers are disabled. As you can see, it says “NOT VULNERABLE” in green:
Mitigating on the client
This can be done per user or system-wide. To configure it for all users on a system, add this to the bottom of /etc/ssh/ssh_config:
To configure it for a single user, add this to the top of the SSH configuration in your home directory (~/.ssh/config)
Mitigating Windows SSH Clients
Unfortunately, the following Windows packages do not support AES-GCM and cannot be mitigated in this way:
- PuTTY does not support AES-GCM
- Update: PuTTY now supports the
kex-strictextension, but your server needs to support it.
- Update: PuTTY now supports the
- WinSCP does not support AES-GCM
If you use any of these then it would be a good idea to switch to an SSH client that supports AES-GCM.
Windows clients that support AES-GCM
Here are a few Windows clients that do support AES-GCM, in alphabetical order, by second letter:
The Fine Print
The examples above are one (very simple) way of dealing with this. Ultimately you need to disable the ETM and ChaCha20 ciphers. You can see what is configured in ssh as follows:
]$ ssh -Q mac|grep etm email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org email@example.com firstname.lastname@example.org ]$ ssh -Q cipher|grep -i cha email@example.com