5 ms·
For anyone who wants to disable the vulnerable primitives, I just made a bash function: #!/bin/bash # Function to apply Terrapin Mitigation to SSH configu
by keepamovin 3y ago
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! :)
- throw0101b 3y ago# Ensure .d directories exist sudo mkdir -p /etc/ssh/sshd_config.d sudo mkdir -p /etc/ssh/ssh_config.d Note that this was added in OpenSSH 8.2, released 2020-02-14: * https://bugzilla.mindrot.org/show_bug.cgi?id=2468 https://bugzilla.mindrot.org/show_bug.cgi?id=2468 * https://www.openssh.com/txt/release-8.2 https://www.openssh.com/txt/release-8.2 If you have an older version this will not work.
- keepamovin 3y agoCool. Might be good to add a workaround in that case, maybe appending to the actual user local client config, and global daemon config with grep for a comment block to check if it's already been added.
- dmd 3y agoNote that if you're using Red Hat, you probably should not do this; you should instead make the temporary change through the crypto-policies tool (see https://access.redhat.com/security/cve/cve-2023-48795 https://access.redhat.com/security/cve/cve-2023-48795 ).
- micah94 3y agoThese files had to be named terrapin-mitigation.conf to work for me.
- keepamovin 3y agoThanks! Yeah, I think that's right.