OpenSSH远程代码执行漏洞(CNVD-2024-29805)
OpenSSH是由加拿大OpenBSD计划组开发的一套用于安全访问远程计算机的连接工具。作为SSH协议的开源实现,它支持对所有传输进行加密,有效防止窃听、连接劫持等网络攻击。该漏洞源于信号处理程序中的竞争条件,攻击者可借此在无需认证的情况下远程执行任意代码,获取系统控制权。
该漏洞影响OpenSSH 8.5p1至9.8p1之前的所有版本:
8.5p1 <= OpenSSH < 9.8p1
OpenSSH官方已发布新版本修复该漏洞,建议用户及时确认产品版本并采取修补措施。官方更新版本下载链接:
https://www.openssh.com/txt/release-9.8
OpenSSH是SSH(Secure Shell)协议的实现,用于在不安全的网络上提供安全通信。它广泛应用于远程登录、命令执行和文件传输,主要工具包括:
OpenSSL是一个功能强大的加密库,提供多种加密算法、哈希函数和加密协议(如TLS/SSL)的实现。它广泛用于保护网络通信,确保数据传输过程中的安全性,主要功能包括:
zlib在OpenSSH中主要用于:
为避免SSH关闭后无法远程连接,建议安装telnet-server。
rpm -q telnet-server # 检查telnet服务端
rpm -q telnet # 检查telnet客户端
sudo yum install yum-utils
mkdir telnet-server-install
cd telnet-server-install
yumdownloader --resolve telnet-server
cd ~/telnet-server-install
sudo rpm -ivh *.rpm
yum install telnet -y
systemctl enable telnet.socket # 设置开机启动
systemctl start telnet.socket # 启动服务
sudo firewall-cmd --permanent --add-service=telnet
sudo firewall-cmd --reload
telnet <IP地址>
默认系统禁止root用户通过telnet远程登录,需执行:
echo 'pts/0' >> /etc/securetty
echo 'pts/1' >> /etc/securetty
[root@standby opt]# telnet 10.10.10.171
Trying 10.10.10.171...
Connected to 10.10.10.171.
Escape character is '^]'.
Kernel 3.10.0-1160.el7.x86_64 on an x86_64
localhost login: root
Password:
Last failed login: Thu Jul 4 13:56:07 CST 2024 from ::ffff:10.10.10.42 on pts/0
There were 3 failed login attempts since the last successful login.
Last login: Thu Jul 4 10:30:43 from 172.20.1.1
若登录失败,可检查日志:
tail /var/log/secure
若出现"access denied: tty ‘pts/3’ is not secure",需添加:
echo 'pts/3' >> /etc/securetty
重启telnet服务后即可正常登录。
cd /usr/local/src/
wget https://www.zlib.net/fossils/zlib-1.3.1.tar.gz
tar zxvf zlib-1.3.tar.gz
cd zlib-1.3
yum install gcc gcc-c++ make -y
./configure --prefix=/usr/local/zlib
make && make install
cd /usr/local/src/
wget https://www.openssl.org/source/openssl-3.2.2.tar.gz
tar zxvf openssl-3.2.0.tar.gz
cd openssl-3.2.0
yum install -y perl-CPAN perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
./config --prefix=/usr/local/ssl --shared
完成后输出:
[root@localhost openssl-3.2.2]# ./config --prefix=/usr/local/ssl --shared
Configuring OpenSSL version 3.2.2 for target linux-x86_64
Using os-specific seed configuration
Created configdata.pm
Running configdata.pm
Created Makefile.in
Created Makefile
Created include/openssl/configuration.h
**********************************************************************
*** ***
*** OpenSSL has been successfully configured ***
*** ***
*** If you encounter a problem while building, please open an ***
*** issue on GitHub ***
*** and include the output from the following command: ***
*** ***
*** perl configdata.pm --dump ***
*** ***
*** (If you are new to OpenSSL, you might want to consult the ***
*** 'Troubleshooting' section in the INSTALL.md file first) ***
*** ***
**********************************************************************
make && make install
编译安装ssl,这个安装过程很长大概有10分钟左右
echo '/usr/local/ssl/lib64' >> /etc/ld.so.conf
路径写入etc/ld.so.conf
cp -p /usr/bin/ssh /usr/bin/ssh.bak
cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
cp -p /usr/sbin/sshd /usr/sbin/sshd.bak
cp -p /usr/bin/ssh-keygen /usr/bin/ssh-keygen.bak
cp -p /etc/ssh/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub.bak
cp -r /etc/ssh /etc/ssh.old
systemctl stop sshd
注意:切勿关闭远程连接
rpm -qa | grep openssh
输出示例:
openssh-server-7.4p1-21.el7.x86_64
openssh-7.4p1-21.el7.x86_64
openssh-clients-7.4p1-21.el7.x86_64
yum remove openssh-7.4p1-21.el7.x86_64 openssh-7.4p1-21.el7.x86_64 openssh-clients-7.4p1-21.el7.x86_64
rpm -qa | grep openssh
cd /usr/local/src/
wget http://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-9.8p1.tar.gz
tar zxvf openssh-9.8p1.tar.gz
cd openssh-9.8p1
./configure --prefix=/usr/local/openssh \
--with-zlib=/usr/local/zlib \
--with-ssl-dir=/usr/local/ssl
配置完成后将显示以下信息:
OpenSSH has been configured with the following options:
User binaries: /usr/local/openssh/bin
System binaries: /usr/local/openssh/sbin
Configuration files: /usr/local/openssh/etc
Askpass program: /usr/local/openssh/libexec/ssh-askpass
Manual pages: /usr/local/openssh/share/man/manX
PID file: /var/run
Privilege separation chroot path: /var/empty
sshd default user PATH: /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/openssh/bin
Manpage format: doc
PAM support: no
OSF SIA support: no
KerberosV support: no
SELinux support: no
libedit support: no
libldns support: no
Solaris process contract support: no
Solaris project support: no
Solaris privilege support: no
IP address in $DISPLAY hack: no
Translate v4 in v6 hack: yes
BSD Auth support: no
Random number source: OpenSSL internal ONLY
Privsep sandbox style: seccomp_filter
PKCS#11 support: yes
U2F/FIDO support: yes
Host: x86_64-pc-linux-gnu
Compiler: cc -std=gnu11
Compiler flags: -g -O2 -pipe -Wall -Wextra -Wpointer-arith -Wuninitialized -Wsign-compare -Wformat-security -Wsizeof-pointer-memaccess -Wno-pointer-sign -Wno-unused-parameter -Wno-unused-result -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -ftrapv -fno-builtin-memset -fstack-protector-strong -fPIE
Preprocessor flags: -I/usr/local/ssl/include -I/usr/local/zlib/include -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -D_DEFAULT_SOURCE -D_GNU_SOURCE -DOPENSSL_API_COMPAT=0x10100000L
Linker flags: -L/usr/local/ssl/lib64 -L/usr/local/zlib/lib -Wl,-z,relro -Wl,-z,now -Wl,-z,noexecstack -fstack-protector-strong -pie
Libraries: -ldl -lutil -lresolv
+for channels: -lcrypto -lz
+for sshd: -lcrypt
make && make install
# 允许 root 登录并启用密码验证
echo 'PermitRootLogin yes' >> /usr/local/openssh/etc/sshd_config
echo 'PubkeyAuthentication yes' >> /usr/local/openssh/etc/sshd_config
echo 'PasswordAuthentication yes' >> /usr/local/openssh/etc/sshd_config
# 复制配置文件到系统目录
cp /usr/local/openssh/etc/sshd_config /etc/ssh/sshd_config
cp /usr/local/openssh/sbin/sshd /usr/sbin/sshd
cp /usr/local/openssh/bin/ssh /usr/bin/ssh
cp /usr/local/openssh/bin/ssh-keygen /usr/bin/ssh-keygen
cp /usr/local/openssh/etc/ssh_host_ecdsa_key.pub /etc/ssh/ssh_host_ecdsa_key.pub
# 复制并设置启动脚本
cp -p contrib/redhat/sshd.init /etc/init.d/sshd
chmod +x /etc/init.d/sshd
另一种配置方法是通过编辑 /usr/lib/systemd/system/sshd.service
文件:
[Unit]
Description=OpenSSH server daemon
Documentation=man:sshd(8) man:sshd_config(5)
After=network.target sshd-keygen.service
Wants=sshd-keygen.service
[Service]
Type=notify
EnvironmentFile=/etc/sysconfig/sshd
ExecStart=/usr/sbin/sshd -D $OPTIONS
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure
RestartSec=42s
[Install]
WantedBy=multi-user.target
默认情况下,ExecStart
使用 /usr/local/openssh/etc/sshd_config
作为配置文件。如需指定其他配置文件,可使用 -f
参数,例如:ExecStart=/usr/sbin/sshd -f /etc/ssh/sshd_config
。
如需修改 SSH 默认端口,可编辑 sshd_config
文件中的 Port
配置项。
配置修改完成后,执行以下命令使更改生效:
systemctl daemon-reload
systemctl reload sshd
# 设置开机自启并重启服务
systemctl enable sshd
systemctl restart sshd
# 检查服务状态
systemctl status sshd
# 验证版本
ssh -V
# 输出示例:OpenSSH_9.8p1, OpenSSL 3.2.2 4 Jun 2024
至此,OpenSSH 升级完成。如有任何问题,欢迎交流指正。