CVE-2021-28041漏洞描述:

OpenSSH(OpenBSD Secure Shell)是Openbsd计划组的一套用于安全访问远程计算机的连接工具。该工具是SSH协议的开源实现,支持对所有的传输进行加密,可有效阻止窃听、连接劫持以及其他网络级的攻击。 OpenSSH before 8.5 存在安全漏洞,攻击者可利用该漏洞在遗留操作系统上不受约束的代理套接字访问。

解决办法:

升级OpenSSH至最新版本(8.6p1)

注意:升级OpenSSH前,需要先升级OpenSSL版本。升级方法见:https://blog.csdn.net/lhrm0213/article/details/117561734

准备工作,安装telnet,避免升级失败后无法ssh登录.

yum -y install telnet-server.x86_64  //telnet服务器
yum list | grep telnet-server  //telnet客户端(可不安装)
yum list | grep xinetd //xinetd守护进程

#配置开机启动
systemctl enable xinetd.service
systemctl enable telnet.socket

#启动服务
systemctl start telnet.socket
systemctl start xinetd

#查看端口,看到23端口已打开
netstat -ntlp

#开启防火墙允许访问23端口(没开防火墙跳过此步骤)
firewall-cmd --add-port=23/tcp --permanent
firewall-cmd --reload

#默认root无法远程访问,修改/etc/securetty
vi /etc/securetty
在末尾添加
pts/0
pts/1

测试使用telnet登录服务器

1. 下载OpenSSH

下载地址: https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

#进入要下载的目录
[root@localhost ~]# cd /usr/local/src/

#下载源码
[root@localhost src]# wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.6p1.tar.gz

#解压
[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

[root@172-15-4-5 src]# systemctl disable xinetd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/xinetd.service.
[root@172-15-4-5 src]# systemctl stop xinetd.service
[root@172-15-4-5 src]# systemctl disable telnet.socket
Removed symlink /etc/systemd/system/sockets.target.wants/telnet.socket.
[root@172-15-4-5 src]# systemctl stop telnet.socket

再次使用telnet就不能再登录了。
再次漏扫,漏洞消除!

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐