早在2011年,我写了一篇关于如何在思科路由器和交换机上启用SSH的帖子。不幸的是,它不包含任何会加强Cisco IOS SSH服务器的高级配置。公平地说,有较旧的IOS软件版本不包括我将在此处介绍的高级SSH命令。在这篇文章中,我想至少分享网络工程师应该考虑添加到模板中的最低级SSH配置。
如果您是macOS 10.13.2用户并且使用它连接到Cisco路由器和交换机,您可能已经看到此错误消息。
1 2 | Mac mini:~ networkjutsu$ ssh router01 Unable to negotiate with 192.168.100.200 port 22: no matching cipher found. Their offer: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc |
这里的问题是OpenSSH在最新版本的macOS的默认SSH配置中弃用了较弱的密码。遗憾的是,默认情况下,旧的Cisco IOS软件使用AES 3DES-CBC作为SSH服务器。以下是运行旧版IOS的Cisco路由器的示例,该版本使用默认的SSH配置。
1 2 3 4 5 | router01>sh ssh Connection Version Mode Encryption Hmac State Username 0 2.0 IN 3des-cbc hmac-sha1 Session started networkjutsu 0 2.0 OUT 3des-cbc hmac-sha1 Session started networkjutsu %No SSHv1 server connections running. |
有两种方法可以摆脱错误消息。其中一个选项是配置客户端以接受遗留密码。在我看来,正确的行动方针是更改SSH服务器配置。但是,我们仍然需要能够连接到我们的Cisco IOS设备来纠正问题。
这里的快速解决方法是继续使用客户端可以接受的兼容密码。可以使用三种方法来解决此问题。从技术上讲,他们都在做同样的事情,但只是采取不同的方法。
使用此选项,用户只需在连接SSH服务器时在SSH命令中指定密码和KEX算法。可以创建一个别名,以包含更短键击的所有必要命令标志。
1 2 3 | Mac mini:~ networkjutsu$ ssh -oKexAlgorithms=diffie-hellman-group1-sha1 -c 3des-cbc router01 Password: router01> |
使用此选项,用户无需创建别名或键入上面显示的整个命令。所述 的.ssh / 配置文件是一个用户特定的配置文件。当发出的命令不包含命令标志时,OpenSSH从该文件接收其配置。
1 2 3 4 5 6 7 | Mac mini:~ networkjutsu$ cat .ssh/config # *** # *** General settings (these apply to all connections) # *** HostkeyAlgorithms +ssh-dss KexAlgorithms +diffie-hellman-group1-sha1 Ciphers +3des-cbc |
使用此选项,所有用户都受此配置文件的影响。但是,发出的命令和特定于用户的配置文件优先于全局配置文件。
1 2 3 4 | Mac mini:~ networkjutsu$ cat /etc/ssh/ssh_config HostkeyAlgorithms +ssh-dss KexAlgorithms +diffie-hellman-group1-sha1 Ciphers +3des-cbc |
如前所述,服务器端选项是正确的操作过程。但是,仍然需要连接Cisco IOS设备来解决问题。也就是说,SSH客户端解决方案仍然起着重要作用。
下面显示的命令用于更改Cisco IOS设备上使用的SSH加密密钥算法。如果收到错误消息,则该IOS版本中的命令不可用。
1 2 3 4 5 6 7 8 9 | router01(config)#ip ssh server algorithm encryption ? 3des-cbc Three-key 3DES in CBC mode aes128-cbc AES with 128-bit key in CBC mode aes128-ctr AES with 128-bit key in CTR mode aes192-cbc AES with 192-bit key in CBC mode aes192-ctr AES with 192-bit key in CTR mode aes256-cbc AES with 256-bit key in CBC mode aes256-ctr AES with 256-bit key in CTR mode router01(config)#ip ssh server algorithm encryption aes256-ctr |
在这个特定的IOS版本中,SSH服务器支持加密算法:AES-CTR,AES-CBC和3DES。根据此线程,如果可用,请使用EAX或GCM。如果没有,作者说使用CTR而不是CBC模式。通过指定加密算法,我们告诉Cisco IOS仅向尝试连接它的任何客户端提供AES-256-CTR模式。
下面显示了使用默认SSH配置的Cisco IOS设备的详细输出。
1 2 3 4 5 6 7 | Mac mini:~ networkjutsu$ ssh -vvv router01 OpenSSH_7.6p1, LibreSSL 2.6.2 <-- Output omitted for brevity --> debug2: peer server KEXINIT proposal debug2: ciphers ctos: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc debug2: ciphers stoc: aes128-cbc,3des-cbc,aes192-cbc,aes256-cbc |
下面显示了使用上述SSH配置的Cisco IOS设备的详细输出。
1 2 3 4 5 6 7 | Mac-mini:~ networkjutsu$ ss -vvv router01 OpenSSH_7.6p1, LibreSSL 2.6.2 <-- Output omitted for brevity --> debug2: peer server KEXINIT proposal debug2: ciphers ctos: aes256-ctr debug2: ciphers stoc: aes256-ctr |
要更改Cisco IOS设备上使用的默认SSH MAC算法,请使用以下命令。
1 2 3 4 | router01(config)#ip ssh server algorithm mac ? hmac-sha1 HMAC-SHA1 (digest length = key length = 160 bits) hmac-sha1-96 HMAC-SHA1-96 (digest length = 96 bits, key length = 160 bits) router01(config)#ip ssh server algorithm mac hmac-sha1 |
在此特定的IOS版本中,SSH服务器支持两种消息验证代码(MAC)算法:HMAC-SHA1和HMAC-SHA1-96。两种算法之间的区别在于摘要长度。HMAC-SHA1-96是截断的消息摘要。由于我的理解有限,HMAC-SHA1-96是HMAC-SHA1的弱化版本,因为缩短了消息摘要。
下面显示了使用默认SSH配置的Cisco IOS设备的详细输出。
1 2 3 4 5 6 7 | Mac-mini:~ networkjutsu$ ss -vvv router01 OpenSSH_7.6p1, LibreSSL 2.6.2 <-- Output omitted for brevity --> debug2: peer server KEXINIT proposal debug2: MACs ctos: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96 debug2: MACs stoc: hmac-sha1,hmac-sha1-96,hmac-md5,hmac-md5-96 |
下面显示了使用上述SSH配置的Cisco IOS设备的详细输出。
1 2 3 4 5 6 7 | Mac-mini:~ networkjutsu$ ss -vvv router01 OpenSSH_7.6p1, LibreSSL 2.6.2 <-- Output omitted for brevity --> debug2: peer server KEXINIT proposal debug2: MACs ctos: hmac-sha1 debug2: MACs stoc: hmac-sha1 |
如果我的记忆正确,即使在macOS High Sierra之前,OpenSSH也不赞成使用SHA-1进行Diffie-Hellman密钥交换。也就是说,尝试使用默认SSH配置连接到Cisco IOS设备的用户会收到错误消息,如下所示。
1 2 | Mac mini:~ networkjutsu$ ssh router01 Unable to negotiate with 192.168.100.200 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 |
真正的问题是,大多数Cisco IOS版本默认使用用于密钥交换的Diffie-Hellman的1024位密钥大小。但是,默认情况下,旧的Cisco IOS版本使用768位DH密钥大小。在2016年之前,1024位密钥大小就足够了。但是,NIST的建议是使用2048位密钥大小或更高。此外,LogJam论文的作者认为,民族国家有可能打破1024位群体。因此,作者建议禁用DH组1。
1 2 3 4 5 6 7 8 9 | router01(config)#sh ip ssh <-- Output omitted for brevity --> Minimum expected Diffie Hellman key size : 1024 bits router01(config)#ip ssh dh min size ? 1024 Diffie Group 1 1024-bit key 2048 Diffie Group 14 2048-bit key 4096 Diffie Group 16 4096-bit key router01(config)#ip ssh dh min size 4096 |
下面显示了使用上述SSH配置的Cisco IOS设备的详细输出。
1 2 3 4 5 6 7 | Mac-mini:~ networkjutsu$ ss -vvv router01 OpenSSH_7.6p1, LibreSSL 2.6.2 <-- Output omitted for brevity --> debug1: kex: algorithm: diffie-hellman-group-exchange-sha1 debug1: kex: host key algorithm: ssh-rsa debug1: kex: server->client cipher: aes256-ctr MAC: hmac-sha1 compression: none debug1: kex: client->server cipher: aes256-ctr MAC: hmac-sha1 compression: none |
注意:将DH密钥大小更改为4096值可能会破坏某些连接到Cisco IOS设备的应用程序。例如, HPE Opsware Network Automation(现在是Micro Focus)使用基于Java的SSH客户端,该客户端与使用高于2048位DH密钥的SSH服务器不兼容。
此处介绍的命令值得考虑,因为它们可以提高对Cisco IOS SSH服务器的保护级别。
如本文所述,我在第二个例子中使用了4096位模数。Cisco IOS用户应考虑产生高于NIST推荐的2048位模数。生成高于建议值可能需要一两分钟(取决于平台)。此外,连接到Cisco IOS设备时可能需要几秒钟才能获得提示。也就是说,在使用高于推荐值之前,请务必考虑这两个事实。理论上,较新的思科平台可以处理更高的值而不会对性能产生重大影响。
1 2 3 4 5 6 7 8 9 10 11 12 | router01(config)#crypto key gen rsa mod ? <360-4096> size of the key modulus [360-4096] router01(config)#crypto key gen rsa modulus 4096 label SSH_KEY The name for the keys will be: SSH_KEY % The key modulus size is 4096 bits % Generating 4096 bit RSA keys, keys will be non-exportable... [OK] (elapsed time was 103 seconds) |
如果您对此处提到的RSA和DH之间的区别感到困惑,那么我建议您阅读本文。这篇文章很好地解释了SSH连接过程。如果您只是想知道RSA和DH之间的区别,请跳到会话部分的协商加密。
没有理由认证超时,因此建议将该值降低到60秒或更短。此特定路由器的SSH身份验证超时设置为120秒。我们将它改为30秒。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | router01#sh ip ssh SSH Enabled - version 2.0 Authentication methods:publickey,keyboard-interactive,password Authentication timeout: 120 secs; Authentication retries: 3 <-- Output omitted for brevity --> router01#conf t Enter configuration commands, one per line. End with CNTL/Z. router01(config)#ip ssh time-out 30 router01(config)#do sh ip ssh SSH Enabled - version 2.0 Authentication methods:publickey,keyboard-interactive,password Authentication timeout: 30 secs; Authentication retries: 3 <-- Output omitted for brevity --> |
在VTY配置下有四个Cisco IOS功能值得考虑,因为它们为网络设备提供了更高级别的保护。
正如本文中所提到的,默认情况下,当用户不禁用它时,Cisco IOS仍然允许telnet连接。要禁用,请发出以下命令。如果你只需要5个vty行,我建议禁用剩余的vty行。
1 2 3 4 5 6 | router01(config)#line vty 0 4 router01(config-line)#transport input ssh router01(config)#line vty ? <0-98> First Line number router01(config)#line vty 5 98 router01(config-line)#transport input none |
创建和应用ACL到SSH是最好的做法,所以我决定在这里介绍它,即使这被认为是非常基本的安全性。
1 2 3 4 | router01(config)#access-list 1 permit 172.16.0.0 0.0.0.63 router01(config)#access-list 1 permit 192.168.100.0 0.0.0.255 router01(config)#line vty 0 4 router01(config-line)#access-class 1 in |
我认为这是一个有争议的设置,需要与网络团队进行一些讨论。该STIG建议将其设置为10分钟或更少。默认情况下,Cisco IOS使用10分钟进行此设置。请随意将其更改为符合您的安全策略或网络团队建议设置的其他内容。
1 2 3 4 5 6 7 8 9 10 11 12 | router01#sh run all | sec line vty line vty 0 4 motd-banner exec-banner exec-timeout 10 0 <-- Output omitted for brevity --> router01(config)#line vty 0 4 router01(config-line)#exec-timeout ? <0-35791> Timeout in minutes router01(config-line)#exec-timeout 5 ? <0-2147483> Timeout in seconds router01(config-line)#exec-timeout 5 0 |
这里介绍的所有配置都是我所说的所有Cisco IOS设备的最低安全标准。我对寻求保护网络设备免受管理平面攻击的网络工程师的建议必须考虑将其包含在他们的配置模板中。虽然,这篇博文只是保护管理层的一小部分。也就是说,我敦促网络工程师们更多地研究保护管理平面的其他设置。
CCNP Security Secure 642-637官方证书指南
评论专区