登录
首页 >  Golang >  Go问答

显示服务器支持的算法的 SSH 客户端

来源:stackoverflow

时间:2024-02-24 16:18:25 156浏览 收藏

对于一个Golang开发者来说,牢固扎实的基础是十分重要的,golang学习网就来带大家一点点的掌握基础知识点。今天本篇文章带大家了解《显示服务器支持的算法的 SSH 客户端》,主要介绍了,希望对大家的知识积累有所帮助,快点收藏起来吧,否则需要时就找不到了!

问题内容

为了检查队列中的所有服务器是否不支持已弃用的算法,我(以编程方式)执行以下操作:

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,[email protected],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,[email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]�[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1�[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1none,[email protected],[email protected]
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
|       [email protected]
|       ecdh-sha2-nistp256
|       ecdh-sha2-nistp384
|       ecdh-sha2-nistp521

解决方案


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

从安全视角进行操作是一件很有用的事情。 在我能找到的每个版本的 ssh 上进行了测试,从非常旧的 solaris 或 aix 机器上的 1.x 到 rhel 8.1。

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

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

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,[email protected],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 参数指定哪些选项,包括密码、mac 和 kexalgorithms

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《显示服务器支持的算法的 SSH 客户端》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>