JobPlus知识库 IT 基础架构 文章
ssh_scan:远程验证你SSH服务的配置和策略

ssh_scan 是一个面向 Linux 和 UNIX 服务器的易用的 SSH 服务参数配置和策略的扫描器程序,其思路来自Mozilla OpenSSH 安全指南,这个指南为 SSH 服务参数配置提供了一个可靠的安全策略基线的建议,如加密算法(Ciphers),报文认证信息码算法(MAC),密钥交换算法(KexAlgos)和其它。

ssh_scan 有如下好处:

· 它的依赖是最小化的,ssh_scan 只引入了本地 Ruby 和 BinData 来进行它的工作,没有太多的依赖。

· 它是可移植的,你可以在其它的项目中使用 ssh_scan 或者将它用在自动化任务上。

· 它是易于使用的,只需要简单的将它指向一个 SSH 服务就可以获得一个该服务所支持的选项和策略状态的 JSON 格式报告。

· 它同时也是易于配置的,你可以创建适合你策略需求的策略。

建议阅读: 如何在 Linux 上安装配置 OpenSSH 服务

如何在 Linux 上安装 ssh_scan

有如下三种安装 ssh_scan 的方式:

使用 Ruby gem 来安装运行,如下:

1. ----------- 在 Debian/Ubuntu -----------  

2. $ sudo apt-get install ruby gem 

3. $ sudo gem install ssh_scan 

4. ----------- 在 CentOS/RHEL -----------  

5. # yum install ruby rubygem 

6. # gem install ssh_scan 

使用docker 容器来运行,如下:

1. # docker pull mozilla/ssh_scan 

2. # docker run -it mozilla/ssh_scan /app/bin/ssh_scan -t github.com 

使用源码安装运行,如下:

1. # git clone https://github.com/mozilla/ssh_scan.git 

2. # cd ssh_scan 

3. # gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 

4. # curl -sSL https://get.rvm.io | bash -s stable 

5. # rvm install 2.3.1 

6. # rvm use 2.3.1 

7. # gem install bundler 

8. # bundle install 

9. # ./bin/ssh_scan 

如何在 Linux 上使用 ssh_scan

使用 ssh_scan 的语法如下:

1. $ ssh_scan -t ip地址 

2. $ ssh_scan -t 主机名 

举个例子来扫描 192.168.43.198 这台服务器的 SSH 配置和策略,键入:

1. $ ssh_scan -t 192.168.43.198 

注意你同时也可以像下方展示的给 -t 选项传入一个[IP地址/地址段/主机名]:

1. $ ssh_scan -t 192.168.43.198,200,205 

2. $ ssh_scan -t test.tecmint.lan 

输出示例:

1. I, [2017-05-09T10:36:17.913644 #7145]  INFO -- : You're using the latest version of ssh_scan 0.0.19 

2. [ 

3.   { 

4.     "ssh_scan_version": "0.0.19", 

5.     "ip": "192.168.43.198", 

6.     "port": 22, 

7.     "server_banner": "SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1", 

8.     "ssh_version": 2.0, 

9.     "os": "ubuntu", 

10.     "os_cpe": "o:canonical:ubuntu:16.04", 

11.     "ssh_lib": "openssh", 

12.     "ssh_lib_cpe": "a:openssh:openssh:7.2p2", 

13.     "cookie": "68b17bcca652eeaf153ed18877770a38", 

14.     "key_algorithms": [ 

15.       "curve25519-sha256@libssh.org", 

16.       "ecdh-sha2-nistp256", 

17.       "ecdh-sha2-nistp384", 

18.       "ecdh-sha2-nistp521", 

19.       "diffie-hellman-group-exchange-sha256", 

20.       "diffie-hellman-group14-sha1" 

21.     ], 

22.     "server_host_key_algorithms": [ 

23.       "ssh-rsa", 

24.       "rsa-sha2-512", 

25.       "rsa-sha2-256", 

26.       "ecdsa-sha2-nistp256", 

27.       "ssh-ed25519" 

28.     ], 

29.     "encryption_algorithms_client_to_server": [ 

30.       "chacha20-poly1305@openssh.com", 

31.       "aes128-ctr", 

32.       "aes192-ctr", 

33.       "aes256-ctr", 

34.       "aes128-gcm@openssh.com", 

35.       "aes256-gcm@openssh.com" 

36.     ], 

37.     "encryption_algorithms_server_to_client": [ 

38.       "chacha20-poly1305@openssh.com", 

39.       "aes128-ctr", 

40.       "aes192-ctr", 

41.       "aes256-ctr", 

42.       "aes128-gcm@openssh.com", 

43.       "aes256-gcm@openssh.com" 

44.     ], 

45.     "mac_algorithms_client_to_server": [ 

46.       "umac-64-etm@openssh.com", 

47.       "umac-128-etm@openssh.com", 

48.       "hmac-sha2-256-etm@openssh.com", 

49.       "hmac-sha2-512-etm@openssh.com", 

50.       "hmac-sha1-etm@openssh.com", 

51.       "umac-64@openssh.com", 

52.       "umac-128@openssh.com", 

53.       "hmac-sha2-256", 

54.       "hmac-sha2-512", 

55.       "hmac-sha1" 

56.     ], 

57.     "mac_algorithms_server_to_client": [ 

58.       "umac-64-etm@openssh.com", 

59.       "umac-128-etm@openssh.com", 

60.       "hmac-sha2-256-etm@openssh.com", 

61.       "hmac-sha2-512-etm@openssh.com", 

62.       "hmac-sha1-etm@openssh.com", 

63.       "umac-64@openssh.com", 

64.       "umac-128@openssh.com", 

65.       "hmac-sha2-256", 

66.       "hmac-sha2-512", 

67.       "hmac-sha1" 

68.     ], 

69.     "compression_algorithms_client_to_server": [ 

70.       "none", 

71.       "zlib@openssh.com" 

72.     ], 

73.     "compression_algorithms_server_to_client": [ 

74.       "none", 

75.       "zlib@openssh.com" 

76.     ], 

77.     "languages_client_to_server": [ 

78.     ], 

79.     "languages_server_to_client": [ 

80.     ], 

81.     "hostname": "tecmint", 

82.     "auth_methods": [ 

83.       "publickey", 

84.       "password" 

85.     ], 

86.     "fingerprints": { 

87.       "rsa": { 

88.         "known_bad": "false", 

89.         "md5": "0e:d0:d7:11:f0:9b:f8:33:9c:ab:26:77:e5:66:9e:f4", 

90.         "sha1": "fc:8d:d5:a1:bf:52:48:a6:7e:f9:a6:2f:af:ca:e2:f0:3a:9a:b7:fa", 

91.         "sha256": "ff:00:b4:a4:40:05:19:27:7c:33:aa:db:a6:96:32:88:8e:bf:05:a1:81:c0:a4:a8:16:01:01:0b:20:37:81:11" 

92.       } 

93.     }, 

94.     "start_time": "2017-05-09 10:36:17 +0300", 

95.     "end_time": "2017-05-09 10:36:18 +0300", 

96.     "scan_duration_seconds": 0.221573169, 

97.     "duplicate_host_key_ips": [ 

98.     ], 

99.     "compliance": { 

100.       "policy": "Mozilla Modern", 

101.       "compliant": false

102.       "recommendations": [ 

103.         "Remove these Key Exchange Algos: diffie-hellman-group14-sha1", 

104.         "Remove these MAC Algos: umac-64-etm@openssh.com, hmac-sha1-etm@openssh.com, umac-64@openssh.com, hmac-sha1", 

105.         "Remove these Authentication Methods: password" 

106.       ], 

107.       "references": [ 

108.         "https://wiki.mozilla.org/Security/Guidelines/OpenSSH" 

109.       ] 

110.     } 

111.   } 

112. ] 

你可以使用 -p 选项来指定不同的端口,-L 选项来开启日志记录配合 -V 选项来指定日志级别:

1. $ ssh_scan -t 192.168.43.198 -p 22222 -L ssh-scan.log -V INFO 

另外,可以使用 -P 或 --policy 选项来指定一个策略文件(默认是 Mozilla Modern)(LCTT 译注:这里的 Modern 可能指的是 https://wiki.mozilla.org/Security/Server_Side_TLS 中提到的 Modern compatibility ):

1. $ ssh_scan -t 192.168.43.198 -L ssh-scan.log -V INFO -P /path/to/custom/policy/file 

ssh_scan 使用帮助与其它示例:

1. $ ssh_scan -h 

输出示例:

1. ssh_scan v0.0.17 (https://github.com/mozilla/ssh_scan) 

2. Usage: ssh_scan [options] 

3. -t, --target [IP/Range/Hostname] IP/Ranges/Hostname to scan 

4. -f, --file [FilePath]            File Path of the file containing IP/Range/Hostnames to scan 

5. -T, --timeout [seconds]          Timeout per connect after which ssh_scan gives up on the host 

6. -L, --logger [Log File Path]     Enable logger 

7. -O, --from_json [FilePath]       File to read JSON output from 

8. -o, --output [FilePath]          File to write JSON output to 

9. -p, --port [PORT]                Port (Default: 22) 

10. -P, --policy [FILE]              Custom policy file (Default: Mozilla Modern) 

11. --threads [NUMBER]           Number of worker threads (Default: 5) 

12. --fingerprint-db [FILE]      File location of fingerprint database (Default: ./fingerprints.db) 

13. --suppress-update-status     Do not check for updates 

14. -u, --unit-test [FILE]           Throw appropriate exit codes based on compliance status 

15. -V [STD_LOGGING_LEVEL], 

16. --verbosity 

17. -v, --version                    Display just version info 

18. -h, --help                       Show this message 

19. Examples: 

20. ssh_scan -t 192.168.1.1 

21. ssh_scan -t server.example.com 

22. ssh_scan -t ::1 

23. ssh_scan -t ::1 -T 5 

24. ssh_scan -f hosts.txt 

25. ssh_scan -o output.json 

26. ssh_scan -O output.json -o rescan_output.json 

27. ssh_scan -t 192.168.1.1 -p 22222 

28. ssh_scan -t 192.168.1.1 -p 22222 -L output.log -V INFO 

29. ssh_scan -t 192.168.1.1 -P custom_policy.yml 

30. ssh_scan -t 192.168.1.1 --unit-test -P custom_policy.yml 

SSH 服务器相关参考阅读:

1. 使用 SSH Keygen(ssh-keygen)五步实现 SSH 免密登录

2. 安全 SSH 服务器的 5 个最佳实践

3. 使用 Chroot 来限制 SSH 用户进入某些目录

4. 如何配置 SSH 连接来简化远程登录

 


如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

¥ 打赏支持
438人赞 举报
分享到
用户评价(0)

暂无评价,你也可以发布评价哦:)

扫码APP

扫描使用APP

扫码使用

扫描使用小程序