簡介
本文介紹在Nexus平台上新增(或)刪除Cipher、MAC和Kex演算法的步驟。
必要條件
需求
思科建議您瞭解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」檔案
這適用於:
- 運行6. X的N3Ks,該程式無法訪問bash-shell
- 所有N5K和N6K代碼
- N7Ks運行6. X和7. X代碼
步驟:
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.將檔案的副本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。
步驟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中的已修改dcos_sshd_config
檔案替換/isan/etc/
{\f13 }下的現有檔案。這僅適用於支援「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
附註:除N7K外,所有平台上的Python指令碼幾乎都相同,N7K包含一些用於克服思科錯誤ID CSCva14865的附加行。
4.確保dcos_sshd_config
指令碼和bootflash(步驟1.)中的檔名相同:
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.確保dcos_sshd_config
指令碼和bootflash(步驟1.)中的檔名相同:
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
已透過思科錯誤ID CSCvr23488建立修改的dplug檔案,以移除以下Kex演演算法:
- diffie-hellman-group-exchange-sha256
- diffie-hellman-group-exchange-sha1
- diffie-hellman-group1-sha1
透過Cisco錯誤ID CSCvr23488提供的dpug檔案與用於存取Linux Shell的檔案不同。開啟一個TAC案例,從思科錯誤ID CSCvr2348取得修改後的插頭。
- 驗證預設設定
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.手動套用思科錯誤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檔名。Dplug檔名可能因交換機的版本而異,因此請務必根據需要修改指令碼。
- 操作1在bootflash中將原始dplug檔案複製到另一個名為「dp」的檔案中,這樣在載入後就不會刪除原始dplug檔案。
平台注意事項
N5K/N6K
- 不能通過修改dcos_sshd_config檔案在這些平台上更改MAC(消息驗證代碼)。唯一支援的MAC是hmac-sha1。
N7K
- 若要變更MAC,需使用8.4代碼。如需詳細資訊,請參閱思科錯誤ID CSCwc26065。
- 預設情況下,8.X上不提供「Sudo su」。參考思科錯誤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
- 在任何Nexus平台
dcos_sshd_config
上,檔案上的更改在重新啟動後都不會持續。如果需要持久更改,則每次交換機啟動時,都可以使用EEM修改檔案。
- 對N9K的增強功能會從10.4(2)開始更改此設定。 10.5(1)中也有此版本。 它未被新增到先前軟體系列的更新版本中。
- 如需詳細資訊,請參閱思科錯誤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 ]