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,該問題正在處理中,暫未解決。