一、项目背景
客户新系统上线,因为行业网络安全要求,需要做等保测评,通过第三方漏扫工具扫描系统,漏扫报告显示OpenSSH服务拥有一个高危漏洞,两个中危漏洞,具体结果如下:
1、OpenSSH 命令注入漏洞(CVE-2020-15778)
2、OpenSSH 用户枚举漏洞(CVE-2018-15919)
3、OpenSSH 安全漏洞(CVE-2017-15906)
最好的解决方案是将OpenSSH升级到最新版本
二、工具准备
所需软件链接:
官网:https://www.openssh.com/portable.html
安装说明:https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/INSTALL
下载:
FTP:https://www.openssh.com/portable.html#ftp
RSYNC:https://www.openssh.com/portable.html#rsync
HTTP:https://www.openssh.com/portable.html#http
三、补漏步骤
1、执行脚本ssh.sh
bash
chmod +x ssh.sh
sh ssh.sh
脚本具体的内容如下:
bash
##SSH升级
## 安装启动并配置telnet服务 | 防止ssh升级失败无法访问服务器
yum install -y telnet-server* telnet xinetd
systemctl enable xinetd.service
systemctl enable telnet.socket
systemctl start telnet.socket
systemctl start xinetd.service
echo 'pts/0' >>/etc/securetty
echo 'pts/1' >>/etc/securetty
echo 'pts/2' >>/etc/securetty
echo "************************************备份开始************************************"
cp /usr/bin/ssh /usr/bin/ssh.bak || echo "已备份"
cp /usr/sbin/sshd /usr/sbin/sshd.bak || echo "已备份"
mv /usr/bin/openssl /usr/bin/openssl.bak || echo "已备份"
mv /etc/ssh /etc/ssh.bak || echo "已备份"
echo "************************************备份结束****************************************"
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel
yum install -y pam* zlib*
ls /root | grep openssh-8.5p1 || wget -c https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-8.5p1.tar.gz
ls /root | grep openssl-1.1.1g || wget -c https://ftp.openssl.org/source/openssl-1.1.1g.tar.gz
tar -zxvf openssl-1.1.1g.tar.gz
cd openssl-1.1.1g
./config shared && make && make install
\cp -rvf include/openssl /usr/include/
ln -s /usr/local/bin/openssl /usr/bin/openssl
ln -snf /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so
ln -snf /usr/local/lib64/libssl.so.1.1 /usr/lib64/libssl.so.1.1
ln -snf /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so
ln -snf /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1
ldconfig
openssl version
echo $?
cd /root
tar -zxvf openssh-8.5p1.tar.gz
cd openssh-8.5p1
./configure --prefix=/usr/ --sysconfdir=/etc/ssh --with-ssl-dir=/usr/local/ssl --with-zlib --with-md5-passwords
make && make install
# 修改启动文件和pam
cp ./contrib/redhat/sshd.init /etc/init.d/sshd || echo "已执行"
cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam || echo "已执行"
mv /usr/lib/systemd/system/sshd.service /usr/lib/systemd/system/sshd.service_bak || echo "已执行"
cat >> /etc/ssh/sshd_config <<EOF
#启用允许root远程登录
PermitRootLogin yes
#启用公钥身份验证
PubkeyAuthentication yes
#启用隧道明文密码
PasswordAuthentication yes
EOF
systemctl daemon-reload
systemctl restart sshd
systemctl status sshd
ssh -V
rm -rf /root/.ssh/known_hosts
echo -e "\033[33m升级成功 测试如果没有问题 记得关闭telnet服务\033[0m"
2、关闭telnet服务
自测后如果没有问题的话,自行把telnet服务关闭
bash
systemctl disable xinetd
systemctl disable telnet.socket
systemctl stop xinetd.service
systemctl stop telnet.socket