华域联盟 漏洞资讯 OpenSSH和OpenSSL升级之路(可升级openssh-8.6p1,应对CVE-2021-28041漏洞)

OpenSSH和OpenSSL升级之路(可升级openssh-8.6p1,应对CVE-2021-28041漏洞)

 

 


前言

升级到Centos 7.9.2009后,又要升级OpenSSH和OpenSSL,进了太多坑后,终于摸索出了一点心得。顺便说下我跳过的坑

1.先升级了OpenSSH再升级了OpenSSL后,ssh -V出来的还是旧版本,导致漏扫不过

2.有些文章给的地方缺字或缺失步骤导致失败,如防火墙启动的系统是要开telnet的23端口的,而且把firewal写成firwall了

3.做了软连接后一直报 /lib64/libssl.so.10: version `libssl.so.10’ not found 错误


2021年5月19日补充:因应对 CVE 2021 28041 的漏洞(CVE-2021-28041 / CNNVD-202103-527的OpenSSH before 安全漏洞),紧急对OpenSSH和OpenSSL进行升级,使用以下命令可升级至OpenSSH 8.6p1, OpenSSL 1.1.1k ,且可以正常登入使用 因本人没有系统学习过红帽系统,对如此升级的后遗症无法确定,请升级前一定做好备份或快照,以防意外发生。


一、检查版本

[root@localhost ~]# cat /etc/redhat-release    #查看系统版本
CentOS Linux release 7.9.2009 (Core)
[root@localhost ~]# ssh -V  #其中V是大写的
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips  26 Jan 2017
 
  • 1
  • 2
  • 3
  • 4

两个最新的是OpenSSH8.4, OpenSSL 1.1.1(3.0.0的版本没研究)

二、升级前准备

1.备份文件

[root@localhost ~]# cp -r /etc/pam.d /etc/pam.d.bak
[root@localhost ~]# cp -af  /usr/bin/openssl  /usr/bin/openssl.old
[root@localhost ~]# cp -af  /etc/pki/ca-trust/extracted/openssl  /etc/pki/ca-trust/extracted/openssl.old
[root@localhost ~]# cp -af  /usr/lib64/openssl /usr/lib64/openssl.old
[root@localhost ~]# cp -af  /usr/lib64/libcrypto.so.10  /usr/lib64/libcrypto.so.10.old
[root@localhost ~]# cp -af  /usr/lib64/libssl.so.10  /usr/lib64/libssl.so.10.old 
[root@localhost ~]# cp -arf /etc/ssh/ /etc/ssh_old

 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

2.安装和配置telnet-server以及xinetd(万一失败了telnet也能连接)

使用yum命令报错或提示没有连接上的,先ping下外网通不,这是在线更新的,还有DNS没配置也可能报错,其他问题请自行查找文档

[root@localhost ~]#yum install xinetd telnet-server -y
 
  • 1

根据其他文档写的老版本升级上来的需要修改配置文件让root登入,反正我是新装telnet没看到这个

[root@localhost ~]# ll /etc/xinetd.d/telnet
ls: cannot access /etc/xinetd.d/telnet: No such file or directory
 
  • 1
  • 2

如果该文档存在就按如下操作,更改配置使root可以telnet登录,把disable = no改成disable = yes #修改文件的命令是vi,但有些系统可以用vim来,两个区别是vim功能更强大 #vim xxxxx 打开某个文件,打开后需要编辑的话按i键进入编辑模式,编辑完毕后按ESC键退出编辑模式,直接输入:wq是保持并退出,:q!是不保存并强制退出

[root@localhost ~]# cat /etc/xinetd.d/telnet
# default: on
# description: The telnet server serves telnet sessions; it uses \
#   unencrypted username/password pairs for authentication.
service telnet
{
    disable = no
    flags       = REUSE
    socket_type = stream       
    wait        = no
    user        = root
    server      = /usr/sbin/in.telnetd
    log_on_failure  += USERID
}
 
[root@localhost ~]# vim /etc/xinetd.d/telnet
[root@localhost ~]# cat /etc/xinetd.d/telnet
# default: on
# description: The telnet server serves telnet sessions; it uses \
#   unencrypted username/password pairs for authentication.
service telnet
{
    disable = yes
    flags       = REUSE
    socket_type = stream       
    wait        = no
    user        = root
    server      = /usr/sbin/in.telnetd
    log_on_failure  += USERID
}
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30

配置telnet登录的终端类型,编辑/etc/securetty文件并在末尾增加一些pts终端

[root@localhost ~]# vim /etc/securetty
 
  • 1

然后在文末添加如下信息

pts/0
pts/1
pts/2
pts/3
 
  • 1
  • 2
  • 3
  • 4

配置后显示如下

[root@localhost ~]# tail -5 /etc/securetty
xvc0
pts/0
pts/1
pts/2
pts/3
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

接着启动telnet服务,并设置开机自动启动和检查端口状态

[root@localhost ~]# systemctl enable xinetd
[root@localhost ~]# systemctl enable telnet.socket
[root@localhost ~]# systemctl start telnet.socket
[root@localhost ~]# systemctl start xinetd
[root@localhost ~]# netstat -lntp|grep 23
tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd        
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

很多文章到这边就让你使用telnet登入系统查看了,但还有防火墙端口没有打开,小白的我研究了很久才知道,这还涉及到一个错字的坑,一些文章把firewal写成firwall了,导致我命令不过,然后去查别的原因了

[root@localhost ~]# firewall-cmd --query-port=23/tcp
no
[root@localhost ~]# firewall-cmd --zone=public --add-port=23/tcp --permanent
success
[root@localhost ~]# firewall-cmd --reload
success
[root@localhost ~]# firewall-cmd --query-port=23/tcp
yes
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

利用telnet远程登录进行升级(避免升级失败,一定要telnet登录操作,且建议重启试试,以防意外重启无法登入 ),还有别看连上就好了,一定要登入成功,不然会像我第一次时候一样,一直提示账号或密码错误

三、开始升级

1.清理旧文件并安装依赖包

以下操作全部在telnet下进行,这些是升级时候会需要用到的组件

[root@localhost ~]# yum remove -y openssl
[root@localhost ~]# yum remove -y openssh
[root@localhost ~]# yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel  pam-devel cpan
 
  • 1
  • 2
  • 3

再安装pam和zlib等(后面的升级操作可能没用到pam,安装上也没啥影响,如果不想安装pam请自行测试)

[root@localhost ~]# yum install -y pam* zlib* perl*
 
  • 1

2.下载升级包

下载openssh包和openssl的包 https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/ https://ftp.openssl.org/source/ 得到文件地址后可直接在系统内下载

[root@localhost ~]# wget https://ftp.openssl.org/source/openssl-1.1.1h.tar.gz
[root@localhost ~]# wget https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.4p1.tar.gz
 
  • 1
  • 2

3.Openssl的解压和编译

解压文件, 进入解压后文件夹,不同版本名字不一样openssl-1.1.1k是 cd openssl-1.1.1k

[root@localhost ~]# tar -zxvf openssl-1.1.1h.tar.gz
[root@localhost ~]# cd  openssl-1.1.1h     
 
  • 1
  • 2

检查文件是否存在,如果存在提前备份

[root@localhost openssl-1.1.1h]# ll /usr/bin/openssl
-rwxr-xr-x. 1 root root 555288 Aug  9  2019 /usr/bin/openssl
[root@localhost openssl-1.1.1h]# mv /usr/bin/openssl /usr/bin/openssl_bak
[root@localhost openssl-1.1.1h]# ll /usr/include/openssl
[root@localhost openssl-1.1.1h]# mv /usr/include/openssl /usr/include/openssl_bak
 
  • 1
  • 2
  • 3
  • 4
  • 5

开始编译文件

[root@localhost openssl-1.1.1h]# ./config --prefix=/usr/local --openssldir=/usr/local/openssl && make && make install
 #./config shared && make && make install
 
  • 1
  • 2

编译完成后检查下结果,输出为0就是正常的

[root@localhost openssl-1.1.1h]# echo $?
0
 
  • 1
  • 2

重建软连接并检查,有提示确认就输入y并回车

[root@localhost openssl-1.1.1h]# ln -s /usr/local/bin/openssl /usr/bin/openssl
[root@localhost openssl-1.1.1h]# ln -s /usr/local/include/openssl /usr/include/openssl
[root@localhost openssl-1.1.1h]# ll /usr/bin/openssl
lrwxrwxrwx. 1 root root 22 Dec  5 16:01 /usr/bin/openssl -> /usr/local/bin/openssl
[root@localhost openssl-1.1.1h]# ll /usr/include/openssl -ld
lrwxrwxrwx. 1 root root 26 Dec  5 16:02 /usr/include/openssl -> /usr/local/include/openssl
[root@localhost openssl-1.1.1h]# echo "/usr/local/lib" >> /etc/ld.so.conf
[root@localhost openssl-1.1.1h]# echo "/usr/local/lib64/" >> /etc/ld.so.conf
[root@localhost openssl-1.1.1h]# /sbin/ldconfig
[root@localhost openssl-1.1.1h]#  cp  libcrypto.so.1.1  libssl.so.1.1 /usr/lib64  
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

确认版本

[root@localhost openssl-1.1.1h]# openssl version                        OpenSSL 1.1.1h  22 Sep 2020
 
  • 1

4.Openssh的解压和编译

回到下载目录并解压openssh-8.4p1.tar.gz, 进入解压后文件夹,不同版本名字不一样openssh-8.6p1是 cd openssh-8.6p1

[root@localhost openssl-1.1.1h]# cd
[root@localhost ~]# tar -zxvf openssh-8.4p1.tar.gz
[root@localhost ~]# cd openssh-8.4p1
 
  • 1
  • 2
  • 3

开始编译文件

[root@localhost openssh-8.4p1]# ./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
 
  • 1

编译完成后检查下结果,输出为0就是正常的

[root@localhost openssh-8.4p1]# echo $?
0
 
  • 1
  • 2

继续安装并检查结果和修改权限

[root@localhost openssh-8.4p1]# make
[root@localhost openssh-8.4p1]# echo $?
0
[root@localhost openssh-8.4p1]# chmod 600 /etc/ssh/ssh_host*
[root@localhost openssh-8.4p1]# make install
[root@localhost openssh-8.4p1]# echo $?
0
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

配置SSH文件

[root@localhost openssh-8.4p1]# echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
[root@localhost openssh-8.4p1]# grep "^PermitRootLogin"  /etc/ssh/sshd_config      
PermitRootLogin yes
[root@localhost openssh-8.4p1]# echo "UseDNS no" >> /etc/ssh/sshd_config
[root@localhost openssh-8.4p1]# grep  "UseDNS"  /etc/ssh/sshd_config    
UseDNS no
[root@localhost openssh-8.4p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd
[root@localhost openssh-8.4p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam
[root@localhost openssh-8.4p1]# chmod +x /etc/init.d/sshd
[root@localhost openssh-8.4p1]# chkconfig --add sshd
[root@localhost openssh-8.4p1]# systemctl enable sshd
[root@localhost openssh-8.4p1]# chkconfig sshd on
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12

有些主机需要移走原先服务,否则重启后服务会不起来,有报错也无所谓

[root@localhost openssh-8.4p1]# mv /usr/lib/systemd/system/sshd.service  /home/
 
  • 1

在测试下服务是否正常

[root@localhost openssh-8.4p1]# /etc/init.d/sshd restart
Restarting sshd (via systemctl):                           [  OK  ]
[root@localhost openssh-8.4p1]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name                  
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1881/sshd: /usr/sbi                      
tcp6       0      0 :::22                   :::*                    LISTEN      1881/sshd: /usr/sbi         
tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd    
[root@localhost openssh-8.4p1]# /etc/init.d/sshd stop
Stopping sshd (via systemctl):                             [  OK  ]
[root@localhost openssh-8.4p1]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name            
tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd 
[root@localhost openssh-8.4p1]# /etc/init.d/sshd start
Starting sshd (via systemctl):                             [  OK  ]  
[root@localhost openssh-8.4p1]# ssh -V
OpenSSH_8.4p1, OpenSSL 1.1.1h  22 Sep 2020
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18

测试到这里都正常后别退出telnet的登入,切换到ssh登入试试,如果没问题再退出!!! 我在这里遇见一个问题,是SELinux的问题,导致我所有账号和密码都会报错:password authentication failed .please verfy that the username and password are correct . 在这里插入图片描述 处理方法如下:

[root@localhost openssh-8.4p1]# getenforce   
Enforcing
[root@localhost openssh-8.4p1]# setenforce 0
[root@localhost openssh-8.4p1]# getenforce   
Permissive
[root@localhost openssh-8.4p1]#  sed -i s#SELINUX=enforcing#SELINUX=disabled# /etc/selinux/config
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

测试完可以登入后,建议再重启测试下,如果没问题就可以关闭telnet的相关服务提高安全性。


总结

以上只能说在我这个环境下已经没问题,不代表你环境中就是完美的,升级的路总是有很多坑的,记得先搞个测试环境,不然崩了就很尴尬了。

本文由 华域联盟 原创撰写:华域联盟 » OpenSSH和OpenSSL升级之路(可升级openssh-8.6p1,应对CVE-2021-28041漏洞)

转载请保留出处和原文链接:https://www.cnhackhy.com/157368.htm

本文来自网络,不代表华域联盟立场,转载请注明出处。

作者: sterben

发表回复

联系我们

联系我们

2551209778

在线咨询: QQ交谈

邮箱: [email protected]

工作时间:周一至周五,9:00-17:30,节假日休息

关注微信
微信扫一扫关注我们

微信扫一扫关注我们

关注微博
返回顶部