前几天项目网站上线扫描到了一些ssh的漏洞,搜集了一些资料整理到此。
ssh版本低于7.4的会暴露一些容易遭到攻击的漏洞。
注意:如需隐藏ssh的banner信息可能需要在ssh升级之前修改配置文件编译安装包才能成功隐藏或修改。(反正我是安装后才修改的试了好几种方法都不行)
注意:升级ssh8以上版本最好准备xshell 7或以上版本(其他连接工具不清楚),低版本可能会连不上。
1、查看ssh版本
cd /opt ssh -V openssl version
2、升级失败可能导致没办法远程,建议先安装telnet
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
3、下载安装ssh
国内镜像地址
https://mirrors.aliyun.com/pub/OpenBSD/OpenSSH/portable/
国外镜像地址
https://cdn.openbsd.org/pub/OpenBSD/OpenSSH/portable/
yum install -y gcc gcc-c++ glibc make autoconf openssl openssl-devel pcre-devel pam-devel yum install -y pam* zlib* # 这里是写的9.0版本,要更换想要的版本修改版本号即可 cd /opt wget -c https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-9.0p1.tar.gz # 解压安装 tar xvf openssh-9.0p1.tar.gz cd openssh-9.0p1 yum install zlib* -y yum install -y libcry* yum install -y openssl-devel yum -y install pam-devel ./configure --prefix=/usr --sysconfdir=/etc/ssh --with-md5-passwords --with-pam --with-tcp-wrappers --with-ssl-dir=/usr/local/openssl --with-zlib=/usr/local/lib64 --without-hardening make # 安装过程中如果报错执行下列代码 chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key # 备份安装 mv /etc/ssh/ssh_config /etc/ssh/ssh_config.old mv /etc/ssh/sshd_config /etc/ssh/sshd_config.old mv /etc/ssh/moduli /etc/ssh/moduli.old make install # 与之前的配置对比 diff /etc/ssh/sshd_config /etc/ssh/sshd_config.old # 复制到系统服务目录 cp -a contrib/redhat/sshd.init /etc/init.d/sshd cp -a contrib/redhat/sshd.pam /etc/pam.d/sshd.pam # 检查启动ssh服务的文件是否有可执行权限 ll /etc/init.d/sshd # 设置开机启动 chkconfig --add sshd systemctl enable sshd /usr/lib/systemd/systemd-sysv-install enable sshd systemctl enable sshd # 移走之前的服务 mv /usr/lib/systemd/system/sshd.service ./sshd.service.old # 重启 /etc/init.d/sshd restart # 安装过程中如果报错执行下列代码 chmod 600 /etc/ssh/ssh_host_rsa_key /etc/ssh/ssh_host_ecdsa_key /etc/ssh/ssh_host_ed25519_key netstat -lntup ssh -V # 新开窗口测一下能否ssh连接再退出
注意:ssh默认禁用root用户登录,安装完毕后一定要在开一个窗口试试,如果root登录不上可以用其他用户登录然后再切到root用户,根据自己需求修改配置文件。
修改ssh的配置文件好像只有root跟被授权的用户才能修改。
- root用户登录失败,修改配置ssh文件让root登录
# 切换root su root # 输入密码 sudo vim /etc/ssh/sshd_config # 找到PermitRootLogin加上yes后重启ssh即可 # 若文件为PermitRootLogin prohibit-password在下边新加一行即可 PermitRootLogin yes # 重启服务 /etc/init.d/sshd restart sudo service sshd restart # 开窗口试一下



