本文介紹在Nexus平台上新增(或)刪除Cipher、MAC和Kex演算法的步驟。
思科建議您瞭解Linux和Bash的基本知識。
本文件中的資訊是以下列硬體與軟體版本為依據:
本文中的資訊是根據特定實驗室環境內的裝置所建立。文中使用到的所有裝置皆從已清除(預設)的組態來啟動。如果您的網路運作中,請確保您瞭解任何指令可能造成的影響。
某些安全掃描可以發現Nexus裝置使用的加密方法較弱。如果發生這種情況,則需要更改交換機上的dcos_sshd_config檔案,以刪除不安全的演算法。
要確認平台使用的密碼、MAC和Kex演算法,請從外部裝置檢查此資訊。您可以使用以下選項:
在可以訪問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
這適用於:
1.在bash模式下啟用bash-shell功能:
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
這適用於:
步驟:
1.開啟TAC案例,取得與交換器上執行的NXOS版本相符的dplug檔案。
2.將dplug檔案上傳到bootflash並建立其副本。
switch# copy bootflash:nuova-or-dplug-mzg.7.3.8.N1.1 bootflash:dp
附註:原始dplug檔案的副本(「dp」)在bootflash中建立,因此,只有副本在載入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 檔案的副本傳送到bootflash:
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。
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#
使用位於bootflash中的已修改的dcos_sshd_config檔案替換/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
通過使用EEM指令碼,當重新載入後刷新日誌「VDC_MGR-2-VDC_ONLINE」時觸發此功能。如果觸發EEM,將運行py指令碼,並使用bootflash中經過修改的dcos_sshd_config檔案替換/isan/etc/下的現有dcos_sshd_config檔案。這僅適用於支援「feature bash-shell」的NX-OS版本。
switch# dir bootflash: | i ssh
7404 Mar 03 16:10:43 2023 dcos_sshd_config_modified_7k
switch#
2.建立將更改應用於dcos_sshd_config檔案的py腳本。確保使用「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
附註:除N7K外,所有平台上的Python指令碼幾乎都相同,N7K包含一些用於克服思科錯誤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#
5.運行一次指令碼,因此dcos_sshd_config檔案已更改。
switch# source ssh_workaround_7k.py
switch#
6.配置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 cli」和其他「action cli command」),確保EEM命令準確。
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.建立將更改應用於dcos_sshd_config檔案的py腳本。確保使用「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#
5.運行一次指令碼,因此dcos_sshd_config檔案已更改。
switch# python bootflash:ssh_workaround_9k.py
6.配置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 cli」和其他「action cli command」),確保EEM命令準確。
已透過思科錯誤ID CSCvr23488建立修改的dplug檔案,以移除以下Kex演演算法:
透過Cisco錯誤ID CSCvr23488提供的dpug檔案與用於存取Linux Shell的檔案不同。開啟一個TAC案例,從思科錯誤ID CSCvr2348取得修改後的插頭。
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
附註:原始dplug檔案的副本(「dp」)在bootflash中建立,只有副本在載入dplug後被刪除,且原始dplug檔案仍保留在bootflash中以供後續運行。
3.手動套用思科錯誤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檔案,並且必須使用正確的dplug檔名配置EEM。Dplug檔名因交換機版本而異,請確保根據需要修改指令碼。操作1在bootflash中將原始dplug檔案複製到另一個名為「dp」的檔案中,因此載入後不會刪除原始dplug檔案。
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
執行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
對於運行早期代碼的平台,您可以新增Ciphers、MAC和KexAlgorithms。這些版本不提供單獨選擇特定演算法的選項;僅支援「all」選項。
N9000(config)# ssh macs ?
all Enable algorithms supported in current version of SSH
N9000(config)# ssh kexalgos ?
all Enable algorithms supported in current version of SSH
ecdh-sha2-nistp384 Enable ecdh-sha2-nistp384
N9000(config)# ssh ciphers ?
aes256-gcm Enable aes256-gcm
all Enable algorithms supported in current version of SSH
附註:這些命令在Nexus 7000版本8.3(1)及更高版本中可用。對於Nexus 3000/9000平台,該命令在7.0(3)I7(8)版及更高版本中可用。(所有9.3(x)版本也使用此命令。請參閱Cisco Nexus 9000系列NX-OS安全配置指南9.3(x)版本。
| 修訂 | 發佈日期 | 意見 |
|---|---|---|
2.0 |
31-Jul-2026
|
已更新拼寫、語法、標題、插入的水平線以分隔各個部分/可讀性、固定CCW警報。 |
1.0 |
01-Jul-2024
|
初始版本 |