For anyone who wants to disable the vulnerable primitives, I just made a bash function:
#!/bin/bash
# Function to apply Terrapin Mitigation to SSH configurations
terrapin_mitigation() {
echo "Applying Terrapin mitigation to SSH client and daemon config..."
# Function to filter algorithms, reading from stdin
filter_algorithms() {
while read -r alg; do
if [[ "$alg" != *"chacha20-poly1305@openssh.com"* ]] && [[ "$alg" != *"-cbc"* ]] && [[ "$alg" != *"-etm@openssh.com"* ]]; then
echo "$alg"
else
echo "Removing vulnerable $alg" >&2
fi
done
}
# Ensure .d directories exist
sudo mkdir -p /etc/ssh/sshd_config.d
sudo mkdir -p /etc/ssh/ssh_config.d
# Get and filter algorithms
kex_algorithms=$(ssh -Q kex | filter_algorithms)
ciphers=$(ssh -Q cipher | filter_algorithms)
macs=$(ssh -Q mac | filter_algorithms)
# Create configuration lines
kex_line="KexAlgorithms $(echo "$kex_algorithms" | tr '\n' ',')"
cipher_line="Ciphers $(echo "$ciphers" | tr '\n' ',')"
mac_line="MACs $(echo "$macs" | tr '\n' ',')"
# Remove trailing commas
kex_line=${kex_line%,}
cipher_line=${cipher_line%,}
mac_line=${mac_line%,}
# Output to sshd.d and ssh.d files
echo ""
echo "*** /etc/ssh/sshd_config.d/terrapin-mitigation: ***"
{ echo "$kex_line"; echo "$cipher_line"; echo "$mac_line"; } | sudo tee /etc/ssh/sshd_config.d/terrapin-mitigation
echo ""
echo "*** /etc/ssh/ssh_config.d/terrapin-mitigation: ***"
{ echo "$kex_line"; echo "$cipher_line"; echo "$mac_line"; } | sudo tee /etc/ssh/ssh_config.d/terrapin-mitigation
echo ""
echo "Terrapin mitigation configuration updated!"
}
terrapin_mitigation
Because of the way SSH resolves its config (first of CLI, user local, system wide), in some cases you may prefer to alias ssh to configure this at the command line.Also disabling some algorithms might bar you from connections that are limited to those. I'm not an expert, this is just what I threw together now. You're welcome to use it unless you know a better way. Please suggest improvements if you see them and use at your own discretion otherwise! :)