【Linux】OpenSSH 命令注入漏洞(CVE-2020-15778)(iptables屏蔽22端口方式)

背景

漏洞名称:OpenSSH 命令注入漏洞(CVE-2020-15778)

详细描述:OpenSSH(OpenBSD Secure Shell)是OpenBSD计划组的一套用于安全访问远程计算机的连接工具。该工具是SSH协议的开源实现,支持对所有的传输进行加密,可有效阻止窃听、连接劫持以及其他网络级的攻击。

OpenSSH 9.0p1及之前版本中的scp的scp.c文件存在命令注入漏洞。该漏洞源于外部输入数据构造可执行命令过程中,网络系统或产品未正确过滤其中的特殊元素。攻击者可利用该漏洞执行非法命令。

解决方法:

厂商补丁:目前厂商暂未发布修复措施解决此安全问题,建议使用此软件的用户随时关注厂商主页或参考网址以获取解决办法:

https://www.openssh.com/

临时缓解措施:可以禁用scp,改用rsync等缓解风险(可能会导致小文件机器内拷贝变慢)

绿盟扫出来的漏洞,但是禁用scp漏洞复扫还是有这个漏洞,查询版本SSH版本也是没问题的

这就没辙了,只能限制服务器端口访问了,但是服务器不是我方管的,只能审慎执行命令,不然登不上去了还得找别人给帮忙处理

解决方式

1、换端口

就是把22端口换成其他端口

powershell 复制代码
##查看firewall配置清单
firewall-cmd --list-all
##查到为关闭态,启动防火墙
systemctl status firewalld.service

## 添加端口,这里从25到65535的tcp和udp都开起来,除了2181 
firewall-cmd --zone=public --add-port=25-65535/tcp --permanent
firewall-cmd --zone=public --add-port=25-65535/udp --permanent
##重新加载
firewall-cmd --reload
##查看firewall配置清单
firewall-cmd --list-all

然后修改

powershell 复制代码
 vi /etc/ssh/sshd_config

这里修改为

1022端口自定义

powershell 复制代码
Port 22
Port 1022
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

然后

powershell 复制代码
 ##重启sshd服务:
 systemctl reload sshd.service

验证1022端口是否可连接,可以的话回到上一步

改成

powershell 复制代码
#Port 22
Port 1022
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

然后

powershell 复制代码
 ##重启sshd服务:
 systemctl reload sshd.service

这样22端口就替换为1022端口了

2、限制固定服务器访问22端口

上面换端口麻烦是需要修改ssh客户端端口,不修改端口可以限制访问策略

操作过程中要边操作边验证,切记不要关闭已打开的窗口,保持开启,即使操作错误了,这个窗口也不会自动断开,还可以自行修复,否则就无法连接,直接找人吧。

验证方式是通过另开端口方式,验证是否可以再次访问,验证成功后再继续操作

powershell 复制代码
##查看当前的iptables规则,显示当前的防火墙规则列表
iptables -L
##允许指定IP地址访问22端口
iptables -A INPUT -p tcp -s 134.1.1.111 --dport 22 -j ACCEPT
##允许指定IP网段地址访问22端口
iptables -A INPUT -p tcp -s 134.1.1.0/24 --dport 22 -j ACCEPT
iptables -A INPUT -p tcp -s 10.1.1.0/24 --dport 22 -j ACCEPT
##拒绝其他IP地址访问22端口
iptables -A INPUT -p tcp --dport 22 -j DROP


##待确认
##保存设置并重新加载iptables规则
service iptables save
service iptables restart

##如果上面两条命令显示服务不存在,可以安装iptables服务
yum install iptables-services
##上面执行后,在执行保存和重启,试过好像不保存重启也行
##保存完是更新到下面文件,可查看保存效果
vi /etc/sysconfig/iptables

后续添加可以直接在这个文件里添加,然后 service iptables restart 重启即可

powershell 复制代码
[root@xxxxx ~]# service iptables save
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, force-reload, status). For other actions, please try to use systemctl.
[root@xxxxx ~]# service iptables restart
Redirecting to /bin/systemctl restart iptables.service
Failed to restart iptables.service: Unit iptables.service not found.
[root@xxxxx ~]# yum install iptables-services
Last metadata expiration check: 0:34:19 ago on Wed 29 Nov 2023 02:47:39 AM CST.
Dependencies resolved.
========================================================================================================================================
 Package                              Architecture              Version                                 Repository                 Size
========================================================================================================================================
Installing:
 iptables-services                    x86_64                    1.8.4-10.0.1.an8.4                      BaseOS                     60 k

Transaction Summary
========================================================================================================================================
Install  1 Package

Total size: 60 k
Installed size: 20 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                1/1 
  Installing       : iptables-services-1.8.4-10.0.1.an8.4.x86_64                                                                    1/1 
  Running scriptlet: iptables-services-1.8.4-10.0.1.an8.4.x86_64                                                                    1/1 
  Verifying        : iptables-services-1.8.4-10.0.1.an8.4.x86_64                                                                    1/1 

Installed:
  iptables-services-1.8.4-10.0.1.an8.4.x86_64                                                                                           

Complete!
[root@xxxxx ~]# service iptables save
iptables: Saving firewall rules to /etc/sysconfig/iptables:[  OK  ]
[root@xxxxx ~]# service iptables restart
Redirecting to /bin/systemctl restart iptables.service
[root@xxxxx ~]# vi /etc/sysconfig/iptables

附:删除命令

这个命令就是删除iptables -L列出的命令,后面数字为L列出来的顺序,建议从下往上删,

但保存到/etc/sysconfig/iptables后就不再追加了

powershell 复制代码
iptables -D INPUT 1

参考:

核心参考
禁用linux系统默认的22端口号
linux防火墙设置指定ip访问22端口

其他参考:
【Linux安全管理】Firewalld详解
Linux系统iptables命令详解
centos7使用firewalld限制ip登陆22端口
Linux系统通过firewall限制或开放端口
防火墙firewall rich-rule规则排序限制IP访问端口

相关推荐
南棱笑笑生4 分钟前
20250509让NanoPi NEO core开发板在Ubuntu core16.04系统下实测移远的4G模块EC200A-CN
linux·运维·ubuntu
hardStudy_h9 分钟前
Linux C语言线程编程入门笔记
linux·c语言·嵌入式实时数据库
Python私教13 分钟前
Python函数:从基础到进阶的完整指南
java·服务器·python
xmweisi021 小时前
Ansible内置模块之package
linux·ansible·rhce·rhca·红帽认证·it培训
xmweisi021 小时前
Ansible内置模块之service
linux·ansible·rhce·rhca·红帽认证
大神的风范1 小时前
从0开始学linux韦东山教程第一三章问题小结(1)
linux·服务器
wgc2k1 小时前
Java游戏服务器开发流水账(3)游戏数据的缓存简介
服务器·游戏
liuze4082 小时前
使用 docker 安装 nacos3.x
运维·docker·容器
橙色小博2 小时前
Python中的re库详细用法与代码解析
linux·python·正则表达式·php·re
10000hours2 小时前
【SGL】Scatter-Gather List内存传输技术
linux·数据结构·网络协议·list·存储·sgl