|
测试环境
cisco设备使用gns3模拟csr1k,版本为。
R1>show ver
Cisco IOS XE Software, Version 17.03.02
Cisco IOS Software [Amsterdam], Virtual XE Software (X86_64_LINUX_IOSD-UNIVERSALK9-M), Version 17.3.2, RELEASE SOFTWARE (fc3)华为设备使用一台V2R021版本的S5720交换机。
<test>dis ver
Huawei Versatile Routing Platform Software
VRP (R) software, Version 5.170 (S5720 V200R021C00SPC100)问题
csico可以使用ssh client连接netconf端口,但是使用ssh client连接不上华为的netconf端口。
分析处理
进行netconf简单测试的时候,cisco设备可以使用ssh client连接netconf端口:
@guobin:~> ssh cisco@192.168.101.101 -p 830 -v
OpenSSH_8.9p1, OpenSSL 1.1.1s 1 Nov 2022
......
debug1: Local version string SSH-2.0-OpenSSH_8.9
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.9 PKIX[11.6]
debug1: compat_banner: match: OpenSSH_7.9 PKIX[11.6] pat OpenSSH* compat 0x04000000
......
debug1: Next authentication method: password
cisco@192.168.101.101&#39;s password: 但是同样的方式,使用ssh client连接华为交换机的netconf端口会失败,在ssh client的debug模式下,可以看到在&#34;protocol version exchange&#34;阶段,华为交换机回复了一个错误的“protocol version”格式的:
@guobin:~> ssh -v netconf_user@192.168.200.105 -p 55555
OpenSSH_8.9p1, OpenSSL 1.1.1s 1 Nov 2022
......
debug1: Local version string SSH-2.0-OpenSSH_8.9
Bad remote protocol version identification: &#39;SSH-2.0-&#39;
banner exchange: Connection to 192.168.200.105 port 55555: invalid format使用wireshark抓取了交互过程中的报文,使用ssh client连接cisco设备在ssh连接的protocol version exchange阶段,ssh client向cisco设备发送了版本信息SSH-2.0-OpenSSH_8.9,cisco设备回复了它的版本信息SSH-2.0-OpenSSH_7.9 PK IX[11.6]。

使用wireshark抓取了交互过程中的报文,使用ssh client连接华为设备在ssh连接的protocol version exchange阶段,ssh client向华为设备发送了版本信息SSH-2.0-OpenSSH_8.9,华为设备回复了它的版本信息SSH-2.0-。

根据ssh client连接华为设备netconf端口debug的错误信息在互联网搜索未果。
Bad remote protocol version identification: &#39;SSH-2.0-&#39;
banner exchange: Connection to 192.168.200.105 port 55555: invalid format通过访问Openssh网站 了解到SSH2的几个RFC标准分别是RFC 4251定义ssh协议的架构、4253定义了传输层、4252定义了认证协议、4254定义了连接协议。
RFC | 用途 | RFC 4253 | The Secure Shell(SSH) Transport Layer Protocol | RFC 4252 | The Secure Shell(SSH) Authentication Protocol | RFC 4254 | The Secure Shell(SSH) Connection Protocol | RFC 4251 | The Secure Shell (SSH) Protocol Architecture | 在RFC 4253 The Secure Shell(SSH) Transport Layer Protocol 中的4.2. Protocol Version Exchange定义了协议版本交换的格式
SSH-protoversion-softwareversion SP comments CR LF其中protoversion和softwareversion是必须的。
再看前面抓取的数据,在Protocol Version Exchange阶段,ssh client(openssh)发送了正确格式的协议版本信息SSH-2.0-OpenSSH_8.9,cisco设备也向client发送了正确格式的协议版本信息SSH-2.0-OpenSSH_7.9 PK IX[11.6]。
但是华为设备向client发送了错误的协议版本信息SSH-2.0-,这里包含了protoversion,但是未包含softwareversion信息,所以ssh client(openssh)试图连接华为交换机的netconf端口时,出现了错误”错误的远程协议版本“。
debug1: Local version string SSH-2.0-OpenSSH_8.9
Bad remote protocol version identification: &#39;SSH-2.0-&#39;
banner exchange: Connection to 192.168.200.105 port 55555: invalid format但是,但是,使用paramiko连接华为交换机的netconf端口,是可以正常来连接上的。paramiko向华为交换机发送了版本信息SSH-2.0-paramiko_2.11.0,华为交换机返回了错误格式的版本信息SSH-2.0-,但是并不影响paramiko与华为交换机的netconf端口建立ssh连接。

# 使用paramiko登录netconf
from time import sleep
import paramiko
TERMINATOR = b&#39;]]>]]>&#39;
def read(chan, responses=1):
&#34;&#34;&#34;Read responses.&#34;&#34;&#34;
while responses:
sleep(1)
response = chan.recv(2048)
yield response
responses -= response.count(TERMINATOR)
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.connect(hostname=&#39;192.168.200.105&#39;,
username=&#39;netconf_user&#39;,
password=&#39;huawei&#39;,
port=55555,
timeout=300,
look_for_keys=False)
ssh_client.get_transport().set_keepalive(600)
chan = ssh_client.get_transport().open_session()
chan.invoke_subsystem(&#39;netconf&#39;)
print(list(read(chan)))
chan.close()
代码参考:Huawei NetConf Example with Paramiko

但是呢,我使用ssh client(openssh)连接华为交换机的22端口,其返回的版本信息是SSH-2.0--。

我尝试使用ssh client(openssh)去连接华为交换机的netconf端口时,其返回的ssh版本信息是SSH-2.0-,是一个不符合RFC 4253中4.2节定义的Protocol Version Exchange格式。
我使用ssh client(openssh)去连接华为交换机的22管理端口,其返回的ssh版本信息是SSH-2.0--,多了一个-,ssh client(openssh)解析出来了SSH版本2.0,软件版本-,是一个符合RFC 4253中4.2节定义的Protocol Version Exchange格式。
我使用ssh client(openssh)去连接cisco交换机的22管理端口,其返回的ssh版本信息是SSH-1.99-cisco-1.25。
总结
根据测试数据得出的总结:
1、华为交换机Netconf的ssh连接在Protocol Version Exchange阶段,向客户端返回了不符合RFC4253标准的 ssh version信息。导致使用openssh客户端不能与华为交换机的Netconf建立ssh连接。
2、csico交换机Netconf的ssh连接在Protocol Version Exchange阶段,向客户端返回了符合RFC4253标准的ssh version信息。可以使用Openssh客户端与cisco交换机的Netconf建立ssh连接。
3、使用paramiko可以与华为交换机的NetConf建立SSH连接。因水平有限,看不懂paramiko的代码,猜测它应该是故意忽略 RFC 4253中4.2节定义的Protocol Version Exchange格式,以兼容更多的场景吧。
4、也许openssh client也有方法可以忽略ssh version信息吧,反正我是没找到。 |
|