文章目录
问题
某个我们对某个服务进行了漏洞扫描,在扫描报告中发现了一个低微漏洞
[ 低风险 ] OpenSSH CBC模式信息泄露漏洞
该漏洞描述为:
OpenSSH是一种开放源码的SSH协议的实现,初始版本用于OpenBSD平台,现在已经被移植到多种Unix/Linux类操作系统下。
如果配置为CBC模式的话,OpenSSH没有正确地处理分组密码算法加密的SSH会话中所出现的错误,导致可能泄露密文中任意块最多32位纯文本。在以标准配置使用OpenSSH时,攻击者恢复32位纯文本的成功概率为2^{-18}, 此外另一种攻击变种恢复14位纯文本的成功概率为2^{-14}。
解决
修改ssh配置文件
/etc/ssh/sshd_config
,首先查找该文件中是否有下面关键字的配置项
# Ciphers and keying
Ciphers ....
如果存在则修改为下面这段,不存在则在这个文件的末尾加上下面这段
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,arcfour
除
Ciphers
你可能还需要关心
KexAlgorithms
、
MACs
参数。
验证
使用下面命令检测配置文件配置是否存在错误。
sshd -t
若文件中配置存在错误,则会弹出错误提示,若没有继续下面流程
重启SSH服务就可以完成配置
CentOS 7 以上的SSH服务重启命令
systemctl restart sshd
CentOS 7 以下的SSH服务重启命令
service sshd restart
使用SSH针对CBC分组类型的加密算法进行检查
ssh -vv -oCiphers=aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc <你的主机名>
如:
ssh -vv -oCiphers=aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc 127.0.0.1
屏幕打印的日志的最后一行:
....
no matching cipher found: client aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc server aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,arcfour
出现
no matching cipher found: client aes128-cbc,3des-cbc …
说明配置生效。(此时的SSH登录并未成功)
如果有兴趣可以阅读下面的解决思路
解决思路
导致该问题的原因是SSH CBC的加密模式可能存在风险,所以只要关闭CBC模式的分组加密就可以。
如何查看默认SSH支持加密算法分组类型
man sshd_config
打开手册,通过
PageDown
按键翻页,我们可以找到
Ciphers
的配置项
按
q
退出,
Enter
下一行。
Ciphers算法更新
从这个描述中我们可以得到,默认情况下支持的加密算法如下:
The default is:
aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,
aes128-gcm@openssh.com,aes256-gcm@openssh.com,
chacha20-poly1305@openssh.com,
aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,
aes256-cbc,arcfour
其中包括了包含CBC分组类型的加密算法如下:
aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc
所以只需要把这些算法去掉就可以得到一个新的配置信息,然后写入
/etc/ssh/sshd_config
文件中
Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,arcfour
MAC算法更新
默认为:
The default is:
umac-64-etm@openssh.com,umac-128-etm@openssh.com,
hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,
hmac-sha1-etm@openssh.com,
umac-64@openssh.com,umac-128@openssh.com,
hmac-sha2-256,hmac-sha2-512,hmac-sha1,
hmac-sha1-etm@openssh.com
特别的由于SHA-1 目前也被认为是不安全,因此我们需要移除SHA-1的所有HMAC
移除后配置如下:
MACs umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512
KeyAlgorithms更新
默认为:
The default is:
curve25519-sha256,curve25519-sha256@libssh.org,
ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,
diffie-hellman-group-exchange-sha256,
diffie-hellman-group14-sha1,
diffie-hellman-group1-sha1
同样的SHA-1系列算法被人为不安全。
因此移除后配置如下:
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256
参考文献
[1]
努力改个网名 . 低微漏洞处理办法记录 . https://www.cnblogs.com/lsdb/p/8204578.html
[2].
Disable Weak Key Exchange Algorithm, CBC Mode in SSH . techglimpse . 2022.03 . https://techglimpse.com/disable-weak-key-exchange-algorithm-cbc-ssh/