企業信息安全管理日趨完善,部分軟件項目須通過系統定級、備案,經過第三方等級保護測評,出具《信息安全等級保護測評報告》,才能符合驗收條件。html
就是通常所說的「入網安評」。linux
測評必定會發現漏洞和隱患,須要軟件廠商或者企業運維團隊針對已發現的問題清單逐一整改和加固。算法
通常來講,第三方安全廠商經過漏洞掃描和入侵探測,出具詳細的問題清單,每條清單也會有相應的整改措施或者加固建議,而後,咱們就照着清單,逐條解決。shell
都是些套路,本沒啥驚喜——昨天卻由於OpenSSH搞得一頭汗。centos
清單上有一項:安全
危險等級:中危bash
漏洞名稱:OpenSSH 用戶枚舉漏洞(CVE-2018-15919)服務器
詳細描述:OpenSSH 7.8及以前版本,
auth-gss2.c
文件存在安全漏洞。遠程攻擊者可利用該漏洞檢測其指定的用戶是否存在。運維解決辦法:ssh
廠商升級:新版本OpenSSH-7.9已經修復這個安全問題,請到廠商的主頁下載。
連接: http://www.openssh.com/ http://www.openssh.com/portable.html
目標服務器是CentOS7.4,起初我覺得萬能的RPM包再加上 yum install --downloadonly --downloaddir=<directory> <package>
和 yum localinstall <package>
就能輕鬆搞定……可是……
[root@localhost ~]# cat /etc/centos-release CentOS Linux release 7.4.1708 (Core) [root@localhost ~]# yum info openssh Loaded plugins: fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.cqu.edu.cn * updates: mirrors.aliyun.com Available Packages Name : openssh Arch : x86_64 Version : 7.4p1
目標機器與互聯網隔離,若是RPM包不可用,只能用源碼編譯,若是編譯遇到文件缺失等問題,會比較繁瑣。
多方尋找7.9p1+CentOS7的RPM資源,未果,只能編譯了。
# 卸載7.4 yum uninstall openssh # 安裝編譯所需的headers和libraries yum install zlib-devel yum install openssl-devel yum install pam-devel # 下載源碼包 wget https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-7.9p1.tar.gz # 解壓 tar zxvf openssh-7.9p1.tar.gz # 切目錄 cd openssh-7.9p1 # 配置 ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-pam # 編譯 make # 安裝 make install # 拷貝ssh-copy-id install -v -m755 contrib/ssh-copy-id /usr/bin # 拷貝幫助文件 install -v -m644 contrib/ssh-copy-id.1 /usr/share/man/man1 # 建立文檔目錄 install -v -m755 -d /usr/share/doc/openssh-7.9p1 # 拷貝文檔 install -v -m644 INSTALL LICENCE OVERVIEW README* /usr/share/doc/openssh-7.9p1 # 容許root登陸(7.9改變了PermitRootLogin的默認值) echo "PermitRootLogin yes" >> /etc/ssh/sshd_config # 使用PAM echo "UserPAM yes" >> /etc/ssh/sshd_config # 註冊服務 cp -p contrib/redhat/sshd.init /etc/init.d/sshd chmod +x /etc/init.d/sshd # 加入sshd到chkconfig管理 chkconfig --add sshd # 設置開機啓動 chkconfig sshd on # 檢查啓動項 chkconfig --list sshd # 驗證版本信息 ssh -V # 重啓ssh服務 service sshd restart
若是一切順利,客戶機可以經過ssh
登陸服務器。
在安裝過程當中我遇到過多個不一樣的錯誤,在總結這篇短文時,才發現那些都是彎路。
ssh
鏈接時出錯:error Could not get shadow information for <user>
服務啓動成功,用戶密碼也都對,就是沒法創建鏈接,多是UsePAM
和SELinux
的問題。
客戶端登陸時,即使輸入了正確的密碼,仍然提示:
[user@localhost~]# ssh user@192.168.171.128 user@192.168.171.128's password: Permission denied, please try again.
查看服務端日誌(/var/log/messages
),發現:
error: Could not get shadow information for <user> Failed password for <user> from <ip> port <port> ssh2
這多是由於UsePAM
沒有啓用,檢查/etc/ssh/sshd_config
:
# 檢查UsePAM,確認是否啓用了PAM # UseAPM no UsePAM yes
修改配置後,重啓sshd
服務後,服務恢復。若是編譯時缺了--with-pam
參數,UsePAM yes
會讓服務報錯。
若是不想修改PAM
選項,也能夠關閉Selinux
:
# 臨時關閉 setenforce 0 # 永久關閉 vi /etc/selinux/config # 而後將 SELINUX=enforcing 修改成 SELINUX=disabled
UsePAM yes
時,不管啓用或禁用selinux
,都不會引起Could not get shadow information
錯誤。
sshd
啓動報錯:Bad SSH2 cipher spec '...'
多是升級了openssl
但sshd_config
配置未更新,或者配置有錯,形成不一致。
能夠查詢當前被支持的加密方法:
[user@localhost ~]# ssh -Q cipher 3des-cbc aes128-cbc aes192-cbc aes256-cbc rijndael-cbc@lysator.liu.se aes128-ctr aes192-ctr aes256-ctr aes128-gcm@openssh.com aes256-gcm@openssh.com chacha20-poly1305@openssh.com
也能夠用paste -s -d,
直接將查詢結果串接並寫入配置文件:
echo 'Ciphers' `ssh -Q cipher | paste -d, -s` >> /etc/ssh/sshd_config
sshd
啓動報錯:Bad SSH2 mac spec '...'
查詢被支持的消息摘要算法:
[user@localhost ~]# ssh -Q mac hmac-sha1 hmac-sha1-96 hmac-sha2-256 hmac-sha2-512 hmac-md5 hmac-md5-96 umac-64@openssh.com umac-128@openssh.com hmac-sha1-etm@openssh.com hmac-sha1-96-etm@openssh.com hmac-sha2-256-etm@openssh.com hmac-sha2-512-etm@openssh.com hmac-md5-etm@openssh.com hmac-md5-96-etm@openssh.com umac-64-etm@openssh.com umac-128-etm@openssh.com
也能夠用paste -s -d,
直接將查詢結果串接並寫入配置文件:
echo 'MACs' `ssh -Q mac | paste -d, -s` >> /etc/ssh/sshd_config
sshd
啓動報錯:Bad SSH2 KexAlgorithms '...'
查詢支持的算法:
[user@localhost ~]# ssh -Q kex diffie-hellman-group1-sha1 diffie-hellman-group14-sha1 diffie-hellman-group14-sha256 diffie-hellman-group16-sha512 diffie-hellman-group18-sha512 diffie-hellman-group-exchange-sha1 diffie-hellman-group-exchange-sha256 ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 curve25519-sha256 curve25519-sha256@libssh.org
也能夠用paste -s -d,
直接將查詢結果串接並寫入配置文件:
echo 'KexAlgorithms' `ssh -Q kex | paste -d, -s` >> /etc/ssh/sshd_config
sshd -d
啓用debug
模式來排查問題。ssh -vvv
以便更快找到問題。