ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

CentOS7.9升级OpenSSH7.4到OpenSSL-8.8p1总结

2022-01-22 17:02:26  阅读:228  来源: 互联网

标签:sshd p1 8.8 OpenSSL usr 0.0 root localhost LISTEN


CentOS7.9升级OpenSSH7.4到OpenSSL-8.8p1总结

 升级方法参考:https://www.cnblogs.com/nmap/p/10779658.html

 

本次测试所用系统环境:

  

系统当前OpenSSH和OpenSSL版本:

 

 

 

通过第三方漏洞扫描,检测出OpenSSH存在漏洞,以下是扫描报告中高危漏洞列表:

 

 

但是升级OpenSSH后做漏扫,漏洞仍然存在。当时的升级方法参照的是B站视频。

(升级方法基本参照B站视频:https://www.bilibili.com/video/BV1Fr4y1Q7L4),于是升级OpenSSL.

 

下载OpenSSH和OpenSSL:

OpenSSL官网:https://www.openssl.org/

OpenSSH官网:http://www.openssh.com/

https://ftp.openssl.org/source/

https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/

本次升级测试使用的是以下版本:

openssh-8.8p1.tar

openssl-1.1.1m.tar

 

升级之前请自行配置好yum源,通过yum源安装可以自动处理一些软件包之间的依赖关系,个人建议通过yum安装。

 

1、安装telnet(如果升级失败ssh中断会导致升级失败,以telnet方式登录,协议为telnet,端口23)

[root@localhost ~]# yum install xinetd -y

[root@localhost ~]#

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

[root@localhost ~]#

[root@localhost ~]# yum install telnet -y

[root@localhost ~]#

以上配置telent服务端和xinetd必须安装,至于telnet客户端根据自己需要安装即可,如果本地想要使用telnet命令连接其他机器就需要安装,如果只作为服务端需要别人连接自己既可以不用安装客户端。

 

2、配置telnet

以下表格中的配置仅供参考,本次测试使用的环境该目录下没有此文件,故跳过该步骤。

参考:https://www.cnblogs.com/nmap/p/10779658.html

 

3、配置telnet登录的终端类型,在/etc/securetty文件末尾增加一些pts终端,这样通过telnet方式使用rootz才能登录

[root@localhost ~]# vi /etc/securetty

[root@localhost ~]#

[root@localhost ~]# tail -5 /etc/securetty

xvc0

pts/0

pts/1

pts/2

pts/3

[root@localhost ~]#

 

4、启动telnet服务,并设置开机自动启动

[root@localhost ~]# systemctl enable xinetd

[root@localhost ~]#

[root@localhost ~]# systemctl enable telnet.socket

Created symlink from /etc/systemd/system/sockets.target.wants/telnet.socket to /usr/lib/sys                                   temd/system/telnet.socket.

[root@localhost ~]#

[root@localhost ~]# systemctl start telnet.socket

[root@localhost ~]#

[root@localhost ~]# systemctl start xinetd

[root@localhost ~]#

 

另:查看防火墙状态,防火墙开启的话,也无法通过telnet方式登录

(1)设置开机启用防火墙:systemctl enable firewalld.service

(2)设置开机禁用防火墙:systemctl disable firewalld.service

(3)启动防火墙:systemctl start firewalld

(4)关闭防火墙:systemctl stop firewalld

(5)检查防火墙状态:systemctl status firewalld 

 

5、查看端口状态,端口是否打开

[root@localhost ~]# netstat -lntp | grep 23

tcp6       0      0 :::23                   :::*              LISTEN      1/systemd                                    

[root@localhost ~]#

 

6、使用telnet方式登录测试,能正常登录后再开始下一步操作

 

7、安装依赖包

升级需要几个组件,有些是和编译相关的

[root@localhost ~]# yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel            

[root@localhost ~]#

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

[root@localhost ~]#

 

8、上传openssh-8.8p1.tar.gz  openssl-1.1.1m.tar.gz到指定目录,根据个人喜好随便放,不影响安装

新建文件夹存放安装包:

[root@localhost ~]# mkdir /home/itc/update

[root@localhost update]# ls

openssh-8.8p1.tar.gz  openssl-1.1.1m.tar.gz

 

解压文件:

[root@localhost update]# tar -zxvf openssl-1.1.1m.tar.gz

 

查看当前系统默认的版本,等会升级完毕对比下:

[root@localhost ~]# openssl version

OpenSSL 1.0.2k-fips  26 Jan 2017

[root@localhost ~]#

 

9、安装升级OpenSSL

备份下面两个文件或目录:

[root@localhost ~]# mv /usr/bin/openssl /usr/bin/openssl_bak

[root@localhost ~]# mv /usr/include/openssl /usr/include/openssl_bak

 

/usr/bin/openssl和/usr/include/openssl是当前系统默认版本的安装文件

 

10、编译安装新版本的OpenSSL

 

[root@localhost ~]# cd /home/itc/update/openssl-1.1.1m/

 

配置、编译、安装3个命令一起执行:

[root@localhost openssl-1.1.1m]# ./config shared && make && make install

 

注:Configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure–help输出详细的选项列表。

其中,prefix选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr/local/bin,库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr/local/share。

 

下面两个文件或目录做软连接:

[root@localhost ~]# ln -s /usr/local/bin/openssl /usr/bin/openssl

[root@localhost ~]# ln -s /usr/local/inclued/openssl /usr/include/openssl

 

更新动态链接库数据,加载新配置:

[root@localhost lib]# echo "/usr/local/lib64" >> /etc/ld.so.conf

 

注:此目录/usr/local/lib64,在测试的时候参考网上的文章该目录是/usr/local/ssl/lib,但是在我当前环境下查看该目录为空,该命令如果未执行成功的话,查看版本号仍然是原版本。

 

重新加载动态链接库:

[root@localhost lib]# /sbin/ldconfig

 

查看版本号:

[root@localhost lib]# openssl version

OpenSSL 1.1.1m  14 Dec 2021

 

11、安装OpenSSH

进入安装包存放目录并解压

[root@localhost lib]# cd /home/itc/update

[root@localhost update]# ls

openssh-8.8p1.tar.gz  openssl-1.1.1m  openssl-1.1.1m.tar.gz

[root@localhost update]#

[root@localhost update]# tar -zvxf openssh-8.8p1.tar.gz

 

删除原先ssh的配置文件和目录:

[root@localhost openssh-8.8p1]# rm -rf /etc/ssh/*

 

配置、编译、安装:

[root@localhost openssh-8.8p1]# ./configure --prefix=/usr/ --sysconfdir=/etc/ssh  --with-ssl-dir=/usr/local/lib64 --with-zlib --with-md5-passwords --with-pam && make && make install

 

注意:/usr/local/lib64此目录对应动态链接库的目录,目录不对的话,命令执行中会报错。

 

从解压包中拷贝以下文件到目标位置:

(/etc/init.d/sshd和/etc/pam.d/sshd.pam应该是用新文件替换原文件,升级之前为查看该目录,请自行测试)

[root@localhost openssh-8.8p1]# cp -a contrib/redhat/sshd.init /etc/init.d/sshd

[root@localhost openssh-8.8p1]# cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam

[root@localhost openssh-8.8p1]#

[root@localhost openssh-8.8p1]# chmod +x /etc/init.d/sshd

[root@localhost openssh-8.8p1]#

[root@localhost openssh-8.8p1]# chkconfig --add sshd

[root@localhost openssh-8.8p1]#

[root@localhost openssh-8.8p1]# systemctl enable sshd

[root@localhost openssh-8.8p1]#

 

把原先的systemd管理的sshd文件删除或者移走或删除,不移走的话影响重启sshd服务

[root@localhost ~]# mv /usr/lib/systemd/system/sshd.service /home/itc/update

 

设置sshd服务开机启动

[root@localhost ~]# chkconfig sshd on

 

测试启停服务:

[root@localhost ~]# /etc/init.d/sshd restart

Restarting sshd (via systemctl):                           [  OK  ]

 

[root@localhost ~]# netstat -lntp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2666/dnsmasq

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      103157/sshd: /usr/s

tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1206/cupsd

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1821/master

tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      10334/sshd: root@pt

tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      718/rpcbind

tcp6       0      0 :::22                   :::*                    LISTEN      103157/sshd: /usr/s

tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd

tcp6       0      0 ::1:631                 :::*                    LISTEN      1206/cupsd

tcp6       0      0 ::1:25                  :::*                    LISTEN      1821/master

tcp6       0      0 ::1:6010                :::*                    LISTEN      10334/sshd: root@pt

tcp6       0      0 :::111                  :::*                    LISTEN      718/rpcbind

[root@localhost ~]#

 

[root@localhost ~]# /etc/init.d/sshd stop

Stopping sshd (via systemctl):                             [  OK ]

[root@localhost ~]#

[root@localhost ~]# netstat -lntp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2666/dnsmasq

tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1206/cupsd

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1821/master

tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      10334/sshd: root@pt

tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      718/rpcbind

tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd

tcp6       0      0 ::1:631                 :::*                    LISTEN      1206/cupsd

tcp6       0      0 ::1:25                  :::*                    LISTEN      1821/master

tcp6       0      0 ::1:6010                :::*                    LISTEN      10334/sshd: root@pt

tcp6       0      0 :::111                  :::*                    LISTEN      718/rpcbind

 

[root@localhost ~]# /etc/init.d/sshd start

Starting sshd (via systemctl):                             [  OK  ]

[root@localhost ~]#

[root@localhost ~]# netstat -lntp

Active Internet connections (only servers)

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name

tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      2666/dnsmasq

tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      103242/sshd: /usr/s

tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1206/cupsd

tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN      1821/master

tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      10334/sshd: root@pt

tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      718/rpcbind

tcp6       0      0 :::22                   :::*                    LISTEN      103242/sshd: /usr/s

tcp6       0      0 :::23                   :::*                    LISTEN      1/systemd

tcp6       0      0 ::1:631                 :::*                    LISTEN      1206/cupsd

tcp6       0      0 ::1:25                  :::*                    LISTEN      1821/master

tcp6       0      0 ::1:6010                :::*                    LISTEN      10334/sshd: root@pt

tcp6       0      0 :::111                  :::*                    LISTEN      718/rpcbind

[root@localhost ~]#

 

查看版本:

[root@localhost ~]# ssh -V

OpenSSH_8.8p1, OpenSSL 1.1.1m  14 Dec 2021

[root@localhost ~]#

 

至此,升级顺利完成,再次做漏洞扫描,未发现漏洞。但是再次用root用户通过SSH登录提示Access denied,该问题正在处理中,暂未解决。

标签:sshd,p1,8.8,OpenSSL,usr,0.0,root,localhost,LISTEN
来源: https://www.cnblogs.com/heyaping/p/15834424.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有