1.漏洞介绍
Diffie-Hellman Key Agreement Protocol是一种密钥协商协议。它最初在 Diffie 和 Hellman 关于公钥密码学的开创性论文中有所描述。该密钥协商协议允许 Alice 和 Bob 交换公钥值,并根据这些值和他们自己对应的私钥的知识,安全地计算共享密钥K,从而实现进一步的安全通信。仅知道交换的公钥值,窃听者无法计算共享密钥。Diffie-Hellman Key Agreement Protocol 存在安全漏洞,远程攻击者可以发送实际上不是公钥的任意数字,并触发服务器端DHE模幂计算。
2.修复方法:
- 查看服务端支持的kexalgorithms
bash
root@test:/home/dev# sshd -T | grep -w kexalgorithms
kexalgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
- 查看可用的算法
bash
man sshd_config |grep -A 40 -w KexAlgorithms

bash
当前 OpenSSH 支持的密钥交换算法列表
默认启用的算法(按优先级排序):
curve25519-sha256
curve25519-sha256@libssh.org
ecdh-sha2-nistp256
ecdh-sha2-nistp384
ecdh-sha2-nistp521
sntrup761x25519-sha512@openssh.com(量子安全算法)
diffie-hellman-group-exchange-sha256
diffie-hellman-group16-sha512
diffie-hellman-group18-sha512
diffie-hellman-group14-sha256
- 通过在sshd_config指定使用的算法,来完全禁用diffie-hellman算法,只使用椭圆曲线算法
bash
# 1. 备份配置文件(重要!)
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
# 2. 添加新的配置(完全禁用所有 DH 算法)
echo "KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521" >> /etc/ssh/sshd_config
# 3. 测试配置语法
sudo sshd -t
# 4. 重启 SSH 服务
sudo systemctl restart sshd
# 5. 验证配置是否生效
sudo sshd -T | grep -w kexalgorithms

3.参考文档