本文已参与「新人创作礼」活动,一起开启掘金创作之路
CVE-2021-28041漏洞描述:
OpenSSH(OpenBSD Secure Shell)是Openbsd计划组的一套用于安全访问远程计算机的连接工具。该工具是SSH协议的开源实现,支持对所有的传输进行加密,可有效阻止窃听、连接劫持以及其他网络级的攻击。 OpenSSH before 8.5 存在安全漏洞,攻击者可利用该漏洞在遗留操作系统上不受约束的代理套接字访问。
解决办法:
- 升级OpenSSH至最新版本(8.6p1)(本次使用)
- 将22端口进行防火墙控制(特定客户端地址可以访问),这种方式不算真的没有漏洞,不过爽的地方在于,漏送再也扫不出来了
**注意:升级OpenSSH前,需要先升级OpenSSL版本。升级方法见: SSL/TLS协议信息泄露漏洞(CVE-2016-2183)处理采坑历程(升级SSL至 1.1.1h版本)
**准备工作,安装telnet,避免升级失败后无法ssh登录.telnet开启及关闭办法:CentOS7开启telnet服务端,配合进行ssh升级 **
1. 下载OpenSSH
下载地址: openbsd.hk/pub/OpenBSD…
#进入要下载的目录
[root@localhost ~]# cd /usr/local/src/
#下载源码
[root@localhost src]# wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz
*注意:如果提示ssl证书相关问题,根据提示在上述语句后面加上 --no-check-certificate 即可。 即:wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz --no-check-certificate*
#解压
[root@localhost src]# tar -zxvf openssh-8.6p1.tar.gz
2. 编译安装
#进入目录
[root@172-15-4-5 src]# cd openssh-8.6p1
#编译
[root@172-15-4-5 openssh-8.6p1]# ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/lib64 --without-hardening
#查看结果,输出为0代表正常
[root@172-15-4-5 openssh-8.6p1]# echo $?
0
安装
[root@172-15-4-5 openssh-8.6p1]# make
#查看结果,输出为0代表正常
[root@172-15-4-5 openssh-8.6p1]# echo $?
0
[root@172-15-4-5 openssh-8.6p1]# make install
#查看结果,输出为0代表正常
[root@172-15-4-5 openssh-8.6p1]# echo $?
0
3. 配置SSH文件
#允许root账户登录
[root@localhost openssh-8.6p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# grep "^PermitRootLogin" /etc/ssh/sshd_config
PermitRootLogin yes
[root@localhost openssh-8.6p1]# echo "UseDNS no" >> /etc/ssh/sshd_config
[root@localhost openssh-8.6p1]# grep "UseDNS" /etc/ssh/sshd_config
UseDNS no
#复制文件到系统服务目录
[root@localhost openssh-8.6p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-8.6p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
#添加执行权限
[root@localhost openssh-8.6p1]# chmod +x /etc/init.d/sshd
#添加服务,配置开机启动
[root@localhost openssh-8.6p1]# chkconfig --add sshd
[root@localhost openssh-8.6p1]# systemctl enable sshd
[root@localhost openssh-8.6p1]# chkconfig sshd on
#原来的服务移走,否走有时重启后ssh服务起不来
[root@localhost openssh-8.6p1]# mv /usr/lib/systemd/system/sshd.service /home/
4. 测试验证
测试服务是否正常:
[root@localhost openssh-8.4p1]# /etc/init.d/sshd restart
Restarting sshd (via systemctl): [ OK ]
#查看端口
[root@localhost openssh-8.4p1]# netstat -ntlp
#22端口正常即可
#可以通过systemctl start/stop/restart 启动/停止/重启sshd服务
#查看版本
[root@localhost openssh-8.4p1]# ssh -V
OpenSSH_8.6p1, OpenSSL 1.1.1h 22 Sep 2020
5. 关闭telnet
最后记得根据telnet操作文档关闭telnet,避免又产生新的漏洞
再次使用telnet就不能再登录了。
再次漏扫,漏洞消除!