环境:CentOS 6.7
安全加固需求,因为某盟扫描系统主机有SSL系列漏洞,客户要求必须修复;
解决方案:将SSH/SSL升级到最新版本,删除SSL旧版本(实测不删除旧版本某盟扫描没法经过)。
当前版本:OpenSSH_5.3p1, OpenSSL 1.0.1e-fips
当前最新版本:OpenSSH_7.3p1, OpenSSL 1.0.2hhtml
查看SSH/SSL当前版本:
ssh -V
openssl versionnode
[root@test0823 ~]# ssh -V OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013 [root@test0823 ssh]# openssl version OpenSSL 1.0.1e-fips 11 Feb 2013
备份ssh配置文件:
tar zcvf /etc/ssh.tar.gz /etc/ssh/python
[root@test0823 ~]# tar zcvf /etc/ssh.tar.gz /etc/ssh/ ssh/ ssh/ssh_host_dsa_key.pub ssh/ssh_host_rsa_key.pub ssh/ssh_host_rsa_key ssh/sshd_config ssh/ssh_config ssh/moduli ssh/ssh_host_dsa_key ssh/ssh_host_key.pub ssh/ssh_host_key
目前最新版本:
OpenSSH_7.3p1, OpenSSL 1.0.2h
本次安装介质:
连接: http://pan.baidu.com/s/1eRW3ytc 密码: 46sy
SSH/SSL安装配置参考:
SSL安装:
参考 http://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssl.html
SSH安装:
参考 http://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssh.htmlmysql
本次测试全部源码包均默认上传到服务器的/root目录下。
须要先安装SSL,再安装SSHlinux
[root@test0823 ~]# tar -zxvf openssl-1.0.2h.tar.gz [root@test0823 ~]# cd openssl-1.0.2h
复制下面的命令执行:git
./config --prefix=/usr \ --openssldir=/etc/ssl \ --libdir=lib \ shared \ zlib-dynamic && make depend && make
操做以下:sql
[root@test0823 openssl-1.0.2h]# ./config --prefix=/usr \ > --openssldir=/etc/ssl \ > --libdir=lib \ > shared \ > zlib-dynamic && > make depend && > make
复制下面的命令执行:centos
make MANDIR=/usr/share/man MANSUFFIX=ssl install && install -dv -m755 /usr/share/doc/openssl-1.0.2h && cp -vfr doc/* /usr/share/doc/openssl-1.0.2h
操做以下:安全
[root@test0823 openssl-1.0.2h]# make MANDIR=/usr/share/man MANSUFFIX=ssl install && > install -dv -m755 /usr/share/doc/openssl-1.0.2h && > cp -vfr doc/* /usr/share/doc/openssl-1.0.2h
openssl version服务器
操做以下:
[root@test0823 openssl-1.0.2h]# openssl version OpenSSL 1.0.2h 3 May 2016 [root@test0823 openssl-1.0.2h]# ssh -V OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
[root@test0823 ~]# tar -zxvf openssh-7.3p1.tar.gz [root@test0823 ~]# cd openssh-7.3p1
复制下面的命令执行:
install -v -m700 -d /var/lib/sshd && chown -v root:sys /var/lib/sshd && groupadd -g 50 sshd && useradd -c 'sshd PrivSep' \ -d /var/lib/sshd \ -g sshd \ -s /bin/false \ -u 50 sshd
操做以下:
[root@test0823 openssh-7.3p1]# install -v -m700 -d /var/lib/sshd && > chown -v root:sys /var/lib/sshd && > > groupadd -g 50 sshd && > useradd -c 'sshd PrivSep' \ > -d /var/lib/sshd \ > -g sshd \ > -s /bin/false \ > -u 50 sshd
复制下面的命令执行:
./configure --prefix=/usr \ --sysconfdir=/etc/ssh \ --with-md5-passwords \ --with-privsep-path=/var/lib/sshd && make
操做以下:
[root@test0823 openssh-7.3p1]# ./configure --prefix=/usr \ > --sysconfdir=/etc/ssh \ > --with-md5-passwords \ > --with-privsep-path=/var/lib/sshd && > make
复制下面的命令执行:
make install && 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.3p1 && install -v -m644 INSTALL LICENCE OVERVIEW README* \ /usr/share/doc/openssh-7.3p1
操做以下:
[root@test0823 openssh-7.3p1]# make install && > 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.3p1 && > install -v -m644 INSTALL LICENCE OVERVIEW README* \ > /usr/share/doc/openssh-7.3p1
[root@test0823 openssh-7.3p1]# ssh -V OpenSSH_7.3p1, OpenSSL 1.0.2h 3 May 2016
将以前的sshd重命名备份,作一个sshd的软链接:
mv /usr/sbin/sshd /usr/sbin/sshd.OFF ln -s /root/openssh-7.3p1/sshd /usr/sbin/sshd
使用 service sshd restart 重启一下服务
[root@test0823 openssh-7.3p1]# service sshd restart Stopping sshd: [ OK ] Starting sshd: /etc/ssh/sshd_config line 81: Unsupported option GSSAPIAuthentication /etc/ssh/sshd_config line 83: Unsupported option GSSAPICleanupCredentials /etc/ssh/sshd_config line 97: Unsupported option UsePAM [ OK ]
上面的报错并不影响sshd正常启动,为了避免再显示上述提示,能够注释掉相关配置行:
vi /etc/ssh/sshd_config
注释掉 81,83,97 三行。
再次重启sshd服务就不会有那三行的提示报错。
容许root用户ssh登陆(默承认能就是容许,若是不容许,能够在文件末尾追加下面的一行配置到配置文件,或者直接vi编辑修改)
echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
以前没有删除旧版本的SSL,SSH是由于不了解相关联的程序,
可是最后扫描发现若是不删除旧版本的SSL,某盟的扫描依然会扫出SSL的系列漏洞。
查看rpm安装的openssl相关包:
rpm -qa|grep openssl
对旧版本的SSL(这里是openssl-1.0.1e-42.el6.x86_64)进行删除:
rpm -e openssl-1.0.1e-42.el6.x86_64
直接尝试删除会提示以下库文件的依赖:
[root@test0823 ~]# rpm -e openssl-1.0.1e-42.el6.x86_64 error: Failed dependencies: libcrypto.so.10()(64bit) is needed by (installed) qt-1:4.6.2-28.el6_5.x86_64 libcrypto.so.10()(64bit) is needed by (installed) libarchive-2.8.3-4.el6_2.x86_64 libcrypto.so.10()(64bit) is needed by (installed) libssh2-1.4.2-1.el6_6.1.x86_64 libcrypto.so.10()(64bit) is needed by (installed) wget-1.12-5.el6_6.1.x86_64 libcrypto.so.10()(64bit) is needed by (installed) wpa_supplicant-1:0.7.3-6.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) bind-libs-32:9.8.2-0.37.rc1.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) bind-utils-32:9.8.2-0.37.rc1.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) mysql-libs-5.1.73-5.el6_6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) fipscheck-1.2.0-7.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) httpd-tools-2.2.15-45.el6.centos.x86_64 libcrypto.so.10()(64bit) is needed by (installed) cyrus-sasl-md5-2.1.23-15.el6_6.2.x86_64 libcrypto.so.10()(64bit) is needed by (installed) gnome-vfs2-2.24.2-6.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) ptlib-2.6.5-3.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) opal-3.6.6-4.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) python-libs-2.6.6-64.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) python-ldap-0:2.3.10-1.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) pyOpenSSL-0.13.1-2.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) net-snmp-libs-1:5.5-54.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) evolution-data-server-2.32.3-23.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) gstreamer-plugins-bad-free-0.10.19-3.el6_5.x86_64 libcrypto.so.10()(64bit) is needed by (installed) xorg-x11-server-Xorg-1.15.0-36.el6.centos.x86_64 libcrypto.so.10()(64bit) is needed by (installed) hplip-libs-3.14.6-3.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) ntpdate-4.2.6p5-5.el6.centos.x86_64 libcrypto.so.10()(64bit) is needed by (installed) ntp-4.2.6p5-5.el6.centos.x86_64 libcrypto.so.10()(64bit) is needed by (installed) certmonger-0.77.5-1.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) cyrus-sasl-2.1.23-15.el6_6.2.x86_64 libcrypto.so.10()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64 libcrypto.so.10()(64bit) is needed by (installed) hpijs-1:3.14.6-3.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) ekiga-3.2.6-4.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) gnome-vfs2-smb-2.24.2-6.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) tcpdump-14:4.0.0-5.20090921gitdf3cb4.2.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) vsftpd-2.2.2-14.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) openssh-5.3p1-111.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) openssh-server-5.3p1-111.el6.x86_64 libcrypto.so.10()(64bit) is needed by (installed) openssh-clients-5.3p1-111.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) pyOpenSSL-0.13.1-2.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) net-snmp-libs-1:5.5-54.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) ntpdate-4.2.6p5-5.el6.centos.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) ntp-4.2.6p5-5.el6.centos.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) openssh-5.3p1-111.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) openssh-server-5.3p1-111.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1)(64bit) is needed by (installed) openssh-clients-5.3p1-111.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) is needed by (installed) certmonger-0.77.5-1.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64 libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) is needed by (installed) openssh-5.3p1-111.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) is needed by (installed) openssh-server-5.3p1-111.el6.x86_64 libcrypto.so.10(OPENSSL_1.0.1_EC)(64bit) is needed by (installed) openssh-clients-5.3p1-111.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) qt-1:4.6.2-28.el6_5.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) libssh2-1.4.2-1.el6_6.1.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) wget-1.12-5.el6_6.1.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) wpa_supplicant-1:0.7.3-6.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) bind-libs-32:9.8.2-0.37.rc1.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) mysql-libs-5.1.73-5.el6_6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) httpd-tools-2.2.15-45.el6.centos.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) cyrus-sasl-md5-2.1.23-15.el6_6.2.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) python-libs-2.6.6-64.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) pyOpenSSL-0.13.1-2.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) net-snmp-libs-1:5.5-54.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) gstreamer-plugins-bad-free-0.10.19-3.el6_5.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) xorg-x11-server-Xorg-1.15.0-36.el6.centos.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) ntpdate-4.2.6p5-5.el6.centos.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) ntp-4.2.6p5-5.el6.centos.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) certmonger-0.77.5-1.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) cyrus-sasl-2.1.23-15.el6_6.2.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) tcpdump-14:4.0.0-5.20090921gitdf3cb4.2.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) vsftpd-2.2.2-14.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) openssh-5.3p1-111.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) openssh-server-5.3p1-111.el6.x86_64 libcrypto.so.10(libcrypto.so.10)(64bit) is needed by (installed) openssh-clients-5.3p1-111.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) qt-1:4.6.2-28.el6_5.x86_64 libssl.so.10()(64bit) is needed by (installed) libssh2-1.4.2-1.el6_6.1.x86_64 libssl.so.10()(64bit) is needed by (installed) wget-1.12-5.el6_6.1.x86_64 libssl.so.10()(64bit) is needed by (installed) wpa_supplicant-1:0.7.3-6.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) mysql-libs-5.1.73-5.el6_6.x86_64 libssl.so.10()(64bit) is needed by (installed) httpd-tools-2.2.15-45.el6.centos.x86_64 libssl.so.10()(64bit) is needed by (installed) gnome-vfs2-2.24.2-6.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) ptlib-2.6.5-3.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) opal-3.6.6-4.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) python-libs-2.6.6-64.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) python-ldap-0:2.3.10-1.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) pyOpenSSL-0.13.1-2.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) evolution-data-server-2.32.3-23.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) gstreamer-plugins-bad-free-0.10.19-3.el6_5.x86_64 libssl.so.10()(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64 libssl.so.10()(64bit) is needed by (installed) ekiga-3.2.6-4.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) gnome-vfs2-smb-2.24.2-6.el6.x86_64 libssl.so.10()(64bit) is needed by (installed) vsftpd-2.2.2-14.el6.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) qt-1:4.6.2-28.el6_5.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) wget-1.12-5.el6_6.1.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) wpa_supplicant-1:0.7.3-6.el6.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) mysql-libs-5.1.73-5.el6_6.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) httpd-tools-2.2.15-45.el6.centos.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) python-libs-2.6.6-64.el6.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) pyOpenSSL-0.13.1-2.el6.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64 libssl.so.10(libssl.so.10)(64bit) is needed by (installed) vsftpd-2.2.2-14.el6.x86_64 openssl is needed by (installed) postfix-2:2.6.6-6.el6_5.x86_64
记录好依赖的这两个库文件
libcrypto.so.10 libssl.so.10
而后忽略依赖删除:
rpm -e --nodeps openssl-1.0.1e-42.el6.x86_64
作新的软链接映射:
[root@test0823 openssl-1.0.2h]# ln -s /root/openssl-1.0.2h/libssl.so.1.0.0 /usr/lib64/libssl.so.10 [root@test0823 openssl-1.0.2h]# ln -s /root/openssl-1.0.2h/libcrypto.so.1.0.0 /usr/lib64/libcrypto.so.10
若是是最后删除的openssl,那么还须要注意openssl软链接的状况,以下:
[root@test0823 apps]# ln -s /root/openssl-1.0.2h/apps/openssl /usr/bin/openssl
而后再次扫描已经没有SSL相关漏洞了。
个人专业不是SA,对Linux的编译安装了解也很少,因此这个加固过程当中难免有所纰漏或错误,欢迎内行指出供你们一块儿参考学习。 另外感谢网友:游荡 早期提供给个人ssh安装说明参考。 感谢www.linuxfromscratch.org网站提供的SSH/SSL安装操做说明。