【问题标题】:ssh client to show server-supported algorithmsssh 客户端显示服务器支持的算法
【发布时间】:2022-03-25 00:35:43
【问题描述】:

为了检查队列中的所有服务器是否不支持已弃用的算法,我正在(以编程方式)这样做:

telnet localhost 22 
Trying 127.0.0.1...
Connected to localhost. 
Escape character is '^]'. 
SSH-2.0-OpenSSH_8.0p1 Ubuntu-6build1
SSH-2.0-Censor-SSH2 
4&m����&F �V��curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1Arsa-sha2-512,rsa-sha2-256,ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519lchacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.comlchacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com�umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1�umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1none,zlib@openssh.comnone,zlib@openssh.comSSH-2.0-Censor-SSH2
Connection closed by foreign host.

这应该是建立连接的各个阶段支持的算法列表。 (kex、主机密钥等)。每次我跑步时,我都会在开始时得到不同的奇数数据——总是不同的长度。

有一个 nmap 插件 - ssh2-enum-algos - 它以完整的形式返回数据,但我不想运行 nmap;我有一个打开端口并发送查询的 go 程序,但它与 telnet 相同。我缺少什么,我该如何解决?

为了比较,这里是 nmap 脚本输出的前几行:

$ nmap --script ssh2-enum-algos super
Starting Nmap 7.80 ( https://nmap.org ) at 2019-12-27 22:15 GMT
Nmap scan report for super (192.168.50.1)
Host is up (0.0051s latency).
rDNS record for 192.168.50.1: supermaster
Not shown: 998 closed ports
PORT    STATE SERVICE
22/tcp  open  ssh
| ssh2-enum-algos: 
|   kex_algorithms: (12)
|       curve25519-sha256
|       curve25519-sha256@libssh.org
|       ecdh-sha2-nistp256
|       ecdh-sha2-nistp384
|       ecdh-sha2-nistp521

【问题讨论】:

  • 运行“ssh -Q ”对于查找客户端支持的算法很有用——我需要确保服务器不提供使用过时的算法。
  • 您的数据很奇怪,因为 SSH 不是文本协议,它是二进制协议,而 telnet 命令对此一无所知。另一方面,Nmap 现在对 SSH 协议做了一些事情。仅仅因为您在协议中看到一些可识别的 ASCII 字符串并不一定意味着它是基于文本的协议。
  • telnet 需要知道什么?当然,在客户端和服务器能够建立加密(二进制)连接之前,它们会以“ASCII”进行协商(我把它放在引号中,因为我只希望算法名称是 ASCII)。使用 --script-trace 运行 nmap 脚本,它显示的数据与我从 telnet 获得的“二进制”格式相似,但 nmap 能够产生有用的输出。所以我同意 nmap 知道一些我不知道的事情——这确实是我的问题。
  • 该协议记录在RFC 4253 中——不要叫我雪莉。前 3 行输出(Trying 127.0.0.1... 等)与协议无关,只是 telnet 程序报告其进度。接下来的两个是 ASCII 版本信息的交换。之后,二进制协议就出现了。

标签: go ssh cryptography


【解决方案1】:

打开一个到端口 22 的 tcp 连接,(在 golang 中,使用 net.Dial)然后接受和发送连接字符串使我们能够从 Reader 中读取()进行连接。因此,数据采用 RFC 描述的标准格式。由此,我可以列出 ssh 连接的每个阶段支持的算法。这对于衡量所提供的内容非常有用,而不是看起来配置了什么(很容易配置 sshd 以使用不同的配置文件)。

能够从安全 POV 执行此操作很有用。 在我可以找到的每个版本的 ssh 上进行了测试,从非常旧的 solaris 或 AIX 机器上的 1.x 到 RHEL 8.1。

【讨论】:

    【解决方案2】:

    在某些情况下,您可以指定要使用的算法,如果您指定不支持的算法,服务器将回复支持的算法列表。

    例如,要检查支持的密钥交换算法,您可以使用:

    ssh 127.0.0.1 -oKexAlgorithms=diffie-hellman-group1-sha1
    

    diffie-hellman-group1-sha1 不安全,大多数现代服务器都应该缺少它。服务器可能会做出如下响应:

    Unable to negotiate with 127.0.0.1 port 22: no matching key exchange method found. Their offer: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256
    Exit 255
    

    输入:“ssh -Q cipher | cipher-auth | mac | kex | key” 将为您提供客户支持的算法列表

    输入:“man ssh” 将让您查看可以使用 -o 参数指定的选项,包括 Cipher、MAC 和 KexAlgorithms

    【讨论】:

      猜你喜欢
      • 2020-09-19
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 2011-12-19
      • 1970-01-01
      • 1970-01-01
      • 2010-10-01
      • 1970-01-01
      相关资源
      最近更新 更多