简介
本文档介绍在Nexus平台中添加(或)删除密码、MAC和Kex算法的步骤。
先决条件
要求
Cisco建议您了解Linux和Bash的基础知识。
使用的组件
本文档中的信息基于下列硬件和软件版本:
- Nexus 3000和9000 NX-OS 7.0(3)I7(10)
- Nexus 3000和9000 NX-OS 9.3(13)
- Nexus 9000 NX-OS 10.2(7)
- Nexus 9000 NX-OS 10.3(5)
- Nexus 7000 NX-OS 8.4(8)
- Nexus 5600 NX-OS 7.3(14)N1(1)
本文档中的信息都是基于特定实验室环境中的设备编写的。本文档中使用的所有设备最初均采用原始(默认)配置。如果您的网络处于活动状态,请确保您了解所有命令的潜在影响。
背景信息
有时,安全扫描可能会发现Nexus设备使用的加密方法较弱。如果发生这种情况dcos_sshd_config
,则需要更改交换机上的文件,以删除这些不安全的算法。
查看可用的密码、MAC和Kex算法
要确认平台使用的密码、MAC和Kex算法以及从外部设备检查这些算法,您可以使用以下选项:
选项1.从PC使用CMD行
在可以访问Nexus设备的PC上打开CMD行并使用命令 ssh -vvv
.
C:\Users\xxxxx>ssh -vvv
--------- snipped ------------
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group1-sha1,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1,diffie-hellman-group-exchange-sha256,ecdh-sha2-nistp256,ecdh-sha2-nistp384,curve25519-sha256@libssh.org <--- Kex algorithms
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,aes192-cbc,aes256-cbc <--- encryption algorithms
debug2: MACs ctos: hmac-sha1
debug2: MACs stoc: hmac-sha1 <--- mac algorithms
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com <--- compression algorithms
选项2.使用Feature Bash-Shell访问“dcos_sshd_config”文件
这适用于:
- N3K运行7. X, 9. X, 10. X
- 所有N9K代码
- 运行8.2及更高版本的N7K
步骤:
- 启用bash-shell功能并进入bash模式:
switch(config)# feature bash-shell
switch(config)#
switch(config)# run bash
bash-4.3$
2.检查文件中的内容dcos_sshd_config
:
bash-4.3$ cat /isan/etc/dcos_sshd_config
注意:您可以使用egrep查看特定行: cat /isan/etc/dcos_sshd_config | grep MAC
选项3.使用Dplug文件访问“dcos_sshd_config”文件
这适用于:
- 所有N5K和N6K代码
- 运行6. X和7. X代码的N7Ks
步骤:
1.打开TAC案例以获取与交换机上运行的NXOS版本相匹配的dplug文件。
2.将dplug文件上传到bootflash并创建其副本。
switch# copy bootflash:nuova-or-dplug-mzg.7.3.8.N1.1 bootflash:dp
注意:在bootflash中创建原始dplug文件的副本(“dp”),这样在加载dplug后仅删除副本,而原始dplug文件仍保留在bootflash中以供后续运行。
3.通过命令加载插件的副load
本。
n5k-1# load bootflash:dp
Loading plugin version 7.3(8)N1(1)
###############################################################
Warning: debug-plugin is for engineering internal use only!
For security reason, plugin image has been deleted.
###############################################################
Successfully loaded debug-plugin!!!
Linux(debug)#
Linux(debug)#
2.查看文件dcos_sshd_config
。
Linux(debug)# cat /isan/etc/dcos_sshd_config
解决方案
步骤1.导出“dcos_sshd_config”文件
1.将文件副本发送到bootflashdcos_sshd_config
:
Linux(debug)# cd /isan/etc/
Linux(debug)# copy dcos_sshd_config /bootflash/dcos_sshd_config
Linux(debug)# exit
2.确认副本位于bootflash:
switch(config)# dir bootflash: | i ssh
7372 Mar 24 02:24:13 2023 dcos_sshd_config
3.导出到服务器:
switch# copy bootflash: ftp:
Enter source filename: dcos_sshd_config
Enter vrf (If no input, current vrf 'default' is considered): management
Enter hostname for the ftp server: <hostname>
Enter username: <username>
Password:
***** Transfer of file Completed Successfully *****
Copy complete, now saving to disk (please wait)...
Copy complete.
4.对文件进行必要的更改,然后导入回bootflash。
步骤2.导入“dcos_sshd_config”文件
1.上传修改后的文件dcos_sshd_config
,以引导闪存。
switch# copy ftp: bootflash:
Enter source filename: dcos_sshd_config_modified.txt
Enter vrf (If no input, current vrf 'default' is considered): management
Enter hostname for the ftp server: <hostname>
Enter username: <username>
Password:
***** Transfer of file Completed Successfully *****
Copy complete, now saving to disk (please wait)...
Copy complete.
switch#
步骤3.使用副本替换原始“dcos_sshd_config”文件
手动流程(在重新启动时不持久) — 所有平台
dcos_sshd_config
使用位于bootflash中的已修改文件/isan/etc/
,替换下的现有文件dcos_sshd_config
。此过程在重新启动后不会持续
- 将修改的
ssh config
文件上传到bootflash:
switch# dir bootflash: | i ssh
7372 Mar 24 02:24:13 2023 dcos_sshd_config_modified
2.在bash或Linux(debug)#模式下,用bootflash中的文件覆盖现有文件dcos_sshd_config
:
bash-4.3$ sudo su
bash-4.3# copy /bootflash/dcos_sshd_config_modified /isan/etc/dcos_sshd_config
3.确认更改成功:
bash-4.3$ cat /isan/etc/dcos_sshd_config
自动化流程 — N7K
通过使用在重新加载后日志“VDC_MGR-2-VDC_ONLINE”出现时触发的EEM脚本。dcos_sshd_config
如果触发EEM,将运行py脚本,并使用位于bootflash中的修改文件/isan/etc/
dcos_sshd_config
,替换现有文件。这仅适用于支持“feature bash-shell”的NX-OS版本。
- 将修改的ssh配置文件上传到bootflash:
switch# dir bootflash: | i ssh
7404 Mar 03 16:10:43 2023 dcos_sshd_config_modified_7k
switch#
2.创建将更改应用于文件的py脚dcos_sshd_config
。确保使用“py”扩展名保存文件。
#!/usr/bin/env python
import os
os.system("sudo usermod -s /bin/bash root")
os.system("sudo su -c \"cp /bootflash/dcos_sshd_config_modified_7k /isan/etc/dcos_sshd_config\"")
3.上传Python脚本到bootflash。
switch# dir bootflash:///scripts
175 Mar 03 16:11:01 2023 ssh_workaround_7k.py
注意:Python脚本在所有平台上几乎都是相同的,除了N7K,N7K包含一些额外的行来克服Cisco Bug ID CSCva14865。
4.确保脚本和bootflash(步骤1.)中的文件名相同dcos_sshd_config
:
switch# dir bootflash: | i ssh
7404 Mar 03 16:10:43 2023 dcos_sshd_config_modified_7k
switch#
switch# show file bootflash:///scripts/ssh_workaround_7k.py
#!/usr/bin/env python
import os
os.system("sudo usermod -s /bin/bash root")
os.system("sudo su -c \"cp /bootflash/dcos_sshd_config_modified_7k /isan/etc/dcos_sshd_config\"")
switch#
4.运行一次脚本,以便更dcos_sshd_config
改文件。
switch# source ssh_workaround_7k.py
switch#
5.配置EEM脚本,以便每次重新启动交换机并重新启动时都运行py脚本。
EEM N7K:
event manager applet SSH_workaround
event syslog pattern "vdc 1 has come online"
action 1.0 cli command "source ssh_workaround_7k.py"
action 2 syslog priority alerts msg "SSH Workaround implemented"
注意:EEM语法因不同的NXOS版本而异(某些版本需要“action <id> cli”和其他“action <id> cli command”),因此请确保正确执行EEM命令。
自动化流程 — N9K、N3K
- 将修改的SSH配置文件上传到bootflash。
switch# dir | i i ssh
7732 Jun 18 16:49:47 2024 dcos_sshd_config
7714 Jun 18 16:54:20 2024 dcos_sshd_config_modified
switch#
2.创建将更改应用于文件的py脚dcos_sshd_config
。确保使用“py”扩展名保存文件。
#!/usr/bin/env python
import os
os.system("sudo su -c \"cp /bootflash/dcos_sshd_config_modified /isan/etc/dcos_sshd_config\"")
3.上传python脚本到bootflash。
switch# dir | i i .py
127 Jun 18 17:21:39 2024 ssh_workaround_9k.py
switch#
4.确保脚本和bootflash(步骤1.)中的文件名相同dcos_sshd_config
:
switch# dir | i i ssh
7732 Jun 18 16:49:47 2024 dcos_sshd_config
7714 Jun 18 16:54:20 2024 dcos_sshd_config_modified
127 Jun 18 17:21:39 2024 ssh_workaround_9k.py
switch#
switch# sh file bootflash:ssh_workaround_9k.py
#!/usr/bin/env python
import os
os.system("sudo su -c \"cp /bootflash/dcos_sshd_config_modified /isan/etc/dcos_sshd_config\"")
switch#
4.运行一次脚本,以便更dcos_sshd_config
改文件。
switch# python bootflash:ssh_workaround_9k.py
5.配置EEM脚本,以便每次重新启动交换机并重新启动时都运行py脚本。
EEM N9K和N3K:
event manager applet SSH_workaround
event syslog pattern "vdc 1 has come online"
action 1.0 cli python bootflash:ssh_workaround_9k.py
action 2 syslog priority alerts msg SSH Workaround implemented
注意:EEM语法因不同的NXOS版本而异(某些版本需要“action <id> cli”和其他“action <id> cli command”),因此请确保正确执行EEM命令。
自动化流程 — N5K、N6K
已通过Cisco Bug ID CSCvr2348创建修改的dplug文件,以删除以下Kex算法:
- diffie-hellman-group-exchange-sha256
- diffie-hellman-group-exchange-sha1
- diffie-hellman-group1-sha1
通过Cisco Bug ID CSCvr23488提供的dpug文件与用于访问Linux Shell的dpug文件不同。打开TAC案例,从Cisco Bug ID CSCvr2348获取修改后的dplug。
- 验证默认
dcos_sshd_config
设置:
C:\Users\user>ssh -vvv admin@
---- snipped ----
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1, diffie-hellman-group14-sha1,diffie-hellman-group1-sha1 <--- kex algorithms
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr <--- encryption algorithms
debug2: MACs ctos: hmac-sha1
debug2: MACs stoc: hmac-sha1 <--- mac algorithms
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com <--- compression algorithms
2.创建修改后的dplug文件的副本。
switch# copy bootflash:nuova-or-dplug-mzg.7.3.14.N1.1_CSCvr23488.bin bootflash:dp
注意:在bootflash中创建原始dplug文件的副本(“dp”),这样在加载dplug后仅删除副本,而原始dplug文件仍保留在bootflash中以供后续运行。
3.手动应用来自Cisco Bug ID CSCvr23488的插件文件:
switch# load bootflash:dp2
Loading plugin version 7.3(14)N1(1)
###############################################################
Warning: debug-plugin is for engineering internal use only!
For security reason, plugin image has been deleted.
###############################################################
Successfully loaded debug-plugin!!!
Workaround for CSCvr23488 implemented
switch#
4.验证新设置dcos_sshd_config
:
C:\Users\user>ssh -vvv admin@<hostname>
---- snipped ----
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
debug2: host key algorithms: ssh-rsa
debug2: ciphers ctos: aes128-ctr,aes192-ctr,aes256-ctr
debug2: ciphers stoc: aes128-ctr,aes192-ctr,aes256-ctr
debug2: MACs ctos: hmac-sha1
debug2: MACs stoc: hmac-sha1
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
5.使用EEM脚本在重新启动后使此更改永久生效:
event manager applet CSCvr23488_workaround
event syslog pattern "VDC_MGR-2-VDC_ONLINE"
action 1 cli command "copy bootflash:nuova-or-dplug-mzg.7.3.14.N1.1_CSCvr23488.bin bootflash:dp"
action 2 cli command "load bootflash:dp"
action 3 cli command "conf t ; no feature ssh ;feature ssh"
action 4 syslog priority alerts msg "CSCvr23488 Workaround implemented"
注意:
- 应用修改后的dplug后,必须在此平台上重置SSH功能。
- 确保bootflash中存在dplug文件,并且EEM配置了正确的dplug文件名。插头文件名可能因交换机的版本而异,因此请务必根据需要修改脚本。
- 操作1在bootflash中将原始dplug文件复制到另一个名为“dp”的文件中,因此加载后不会删除原始dplug文件。
平台注意事项
N5K/N6K
- 不能通过修改dcos_sshd_config文件来更改这些平台上的MAC(消息验证代码)。唯一支持的MAC是hmac-sha1。
N7K
- 要更改的MAC,需要8.4代码。有关详细信息,请参阅Cisco Bug ID CSCwc26065。
- 默认情况下,“Sudo su”在8.X上不可用。参考Cisco Bug ID: CSCva14865。如果执行,则会出现以下错误:
F241.06.24-N7706-1(config)# feature bash-shell
F241.06.24-N7706-1(config)# run bash
bash-4.3$ sudo su
Cannot execute /isanboot/bin/nobash: No such file or directory <---
bash-4.3$
要解决此问题,请键入:
bash-4.3$ sudo usermod -s /bin/bash root
在这个“sudo su”奏效之后:
bash-4.3$ sudo su
bash-4.3#
- 每个VDC都有一个单独的文件
dcos_sshd_config
,如果需要在不同的VDC上修改SSH参数,请确保修改相应的文件dcos_sshd_config
。
N7K# run bash
bash-4.3$ cd /isan/etc/
bash-4.3$ ls -la | grep ssh
-rw-rw-r-- 1 root root 7564 Mar 27 13:48 dcos_sshd_config <--- VDC 1
-rw-rw-r-- 1 root root 7555 Mar 27 13:48 dcos_sshd_config.2 <--- VDC 2
-rw-rw-r-- 1 root root 7555 Mar 27 13:48 dcos_sshd_config.3 <--- VDC 3
N9K
- 文件的更改
dcos_sshd_config
,在任何Nexus平台重新启动后都不会持续。如果需要持续更改,则每次交换机启动时,都可以使用EEM修改文件。
- 对N9K的增强功能会改变此值,从10.4(2)开始。 10.5(1)中也有此版本。 它未被添加到先前软件系列的更新版本中。
- 有关详细信息,请参阅Cisco Bug ID CSCwd82985。
运行10.5(1)的交换机上的CLI示例:
switch(config)# ssh ?
cipher-mode Set Cipher-mode for ssh
ciphers Ciphers to encrypt the connection <<<<<<<<<
idle-timeout SSH Client session idle timeout value
kexalgos Key exchange methods that are used to generate per-connection keys <<<<<<<<<
key Generate SSH Key
keytypes Public key algorithms that the server can use to authenticate itself to the client
login-attempts Set maximum login attempts from ssh
login-gracetime Set login gracetime for ssh connection
macs Message authentication codes used to detect traffic modification <<<<<<<<<
port Set port number for ssh
rekey Renegotiate ssh key
switch(config)# ssh ciphers ?
WORD Algorithm name to be configured (Max Size 128)
aes256-gcm <Deprecated> enable aes256-gcm
all Control known weak SSH algorithms in current version of NX-OS in addition to the base set of strong algorithms
switch(config)# ssh macs ?
WORD Algorithm name to be configured (Max Size 128)
all Control known weak SSH algorithms in current version of NX-OS in addition to the base set of strong algorithms
switch(config)# ssh kexalgos ?
WORD Algorithm name to be configured (Max Size 128)
all Control known weak SSH algorithms in current version of NX-OS in addition to the base set of strong algorithms
运行10.3(6)的交换机上的CLI示例:
switch(config)# ssh kexalgos ?
all Enable algorithms supported in current version of SSH
ecdh-sha2-nistp384 Enable ecdh-sha2-nistp384
switch(config)# ssh ciphers ?
aes256-gcm Enable aes256-gcm
all Enable algorithms supported in current version of SSH
switch(config)# ssh macs ?
all Enable algorithms supported in current version of SSH
N7K、N9K、N3K
如果需要,可以添加其他密码、MAC和KexAlgorithms:
switch(config)# ssh kexalgos [all | key-exchangealgorithm-name]
switch(config)# ssh macs [all | mac-name]
switch(config)# ssh ciphers [ all | cipher-name ]