ssh_scan - 验证 Linux 中的 SSH 服务器配置和策略
ssh_scan 是一款适用于 Linux 和 UNIX 服务器的易于使用的原型 SSH 配置和策略扫描器,受到 Mozilla OpenSSH 安全指南的启发,它为 SSH 配置参数(例如密码、MAC)提供了合理的基线策略建议、KexAlgos 等等。
它具有以下一些优点:
- 它具有最小的依赖性,ssh_scan 仅使用本机 Ruby 和 BinData 来完成其工作,没有严重的依赖性。
- 它是可移植的,您可以在另一个项目中使用 ssh_scan 或用于任务自动化。
- 它易于使用,只需将其指向 SSH 服务即可获取有关其支持内容及其策略状态的 JSON 报告。
- 它也是可配置的,您可以创建自己的自定义策略来满足您的特定策略要求。
建议阅读: 如何在 Linux 中安装和配置 OpenSSH 服务器
如何在 Linux 中安装 ssh_scan
您可以通过三种方式安装ssh_scan,它们是:
要安装并作为 gem 运行,请输入:
----------- On Debian/Ubuntu -----------
sudo apt-get install ruby gem
sudo gem install ssh_scan
----------- On CentOS/RHEL -----------
yum install ruby rubygem
gem install ssh_scan
要从 Docker 容器运行,请键入:
docker pull mozilla/ssh_scan
docker run -it mozilla/ssh_scan /app/bin/ssh_scan -t github.com
要从源安装并运行,请键入:
git clone https://github.com/mozilla/ssh_scan.git
cd ssh_scan
gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
curl -sSL https://get.rvm.io | bash -s stable
rvm install 2.3.1
rvm use 2.3.1
gem install bundler
bundle install
./bin/ssh_scan
如何在 Linux 中使用 ssh_scan
使用 ssh_scan 的语法如下:
ssh_scan -t ip-address
ssh_scan -t server-hostname
例如,要扫描服务器 92.168.43.198 的 SSH 配置和策略,请输入:
ssh_scan -t 192.168.43.198
请注意,您还可以将 [IP/范围/主机名] 传递给 -t
选项,如以下选项所示:
ssh_scan -t 192.168.43.198,200,205
ssh_scan -t test.tecmint.lan
样本输出
I, [2017-05-09T10:36:17.913644 #7145] INFO -- : You're using the latest version of ssh_scan 0.0.19
[
{
"ssh_scan_version": "0.0.19",
"ip": "192.168.43.198",
"port": 22,
"server_banner": "SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1",
"ssh_version": 2.0,
"os": "ubuntu",
"os_cpe": "o:canonical:ubuntu:16.04",
"ssh_lib": "openssh",
"ssh_lib_cpe": "a:openssh:openssh:7.2p2",
"cookie": "68b17bcca652eeaf153ed18877770a38",
"key_algorithms": [
"[email ",
"ecdh-sha2-nistp256",
"ecdh-sha2-nistp384",
"ecdh-sha2-nistp521",
"diffie-hellman-group-exchange-sha256",
"diffie-hellman-group14-sha1"
],
"server_host_key_algorithms": [
"ssh-rsa",
"rsa-sha2-512",
"rsa-sha2-256",
"ecdsa-sha2-nistp256",
"ssh-ed25519"
],
"encryption_algorithms_client_to_server": [
"[email ",
"aes128-ctr",
"aes192-ctr",
"aes256-ctr",
"[email ",
"[email "
],
"encryption_algorithms_server_to_client": [
"[email ",
"aes128-ctr",
"aes192-ctr",
"aes256-ctr",
"[email ",
"[email "
],
"mac_algorithms_client_to_server": [
"[email ",
"[email ",
"[email ",
"[email ",
"[email ",
"[email ",
"[email ",
"hmac-sha2-256",
"hmac-sha2-512",
"hmac-sha1"
],
"mac_algorithms_server_to_client": [
"[email ",
"[email ",
"[email ",
"[email ",
"[email ",
"[email ",
"[email ",
"hmac-sha2-256",
"hmac-sha2-512",
"hmac-sha1"
],
"compression_algorithms_client_to_server": [
"none",
"[email "
],
"compression_algorithms_server_to_client": [
"none",
"[email "
],
"languages_client_to_server": [
],
"languages_server_to_client": [
],
"hostname": "tecmint",
"auth_methods": [
"publickey",
"password"
],
"fingerprints": {
"rsa": {
"known_bad": "false",
"md5": "0e:d0:d7:11:f0:9b:f8:33:9c:ab:26:77:e5:66:9e:f4",
"sha1": "fc:8d:d5:a1:bf:52:48:a6:7e:f9:a6:2f:af:ca:e2:f0:3a:9a:b7:fa",
"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"
}
},
"start_time": "2017-05-09 10:36:17 +0300",
"end_time": "2017-05-09 10:36:18 +0300",
"scan_duration_seconds": 0.221573169,
"duplicate_host_key_ips": [
],
"compliance": {
"policy": "Mozilla Modern",
"compliant": false,
"recommendations": [
"Remove these Key Exchange Algos: diffie-hellman-group14-sha1",
"Remove these MAC Algos: [email , [email , [email , hmac-sha1",
"Remove these Authentication Methods: password"
],
"references": [
"https://wiki.mozilla.org/Security/Guidelines/OpenSSH"
]
}
}
]
您可以使用 -p
指定不同的端口,使用 -L
启用记录器,使用 -V
定义详细级别,如下所示:
ssh_scan -t 192.168.43.198 -p 22222 -L ssh-scan.log -V INFO
此外,使用带有 -P
或 --policy [FILE]
的自定义策略文件(默认为 Mozilla Modern),如下所示:
ssh_scan -t 192.168.43.198 -L ssh-scan.log -V INFO -P /path/to/custom/policy/file
输入此命令可查看所有 ssh_scan 使用选项和更多示例:
ssh_scan -h
样本输出
ssh_scan v0.0.17 (https://github.com/mozilla/ssh_scan)
Usage: ssh_scan [options]
-t, --target [IP/Range/Hostname] IP/Ranges/Hostname to scan
-f, --file [FilePath] File Path of the file containing IP/Range/Hostnames to scan
-T, --timeout [seconds] Timeout per connect after which ssh_scan gives up on the host
-L, --logger [Log File Path] Enable logger
-O, --from_json [FilePath] File to read JSON output from
-o, --output [FilePath] File to write JSON output to
-p, --port [PORT] Port (Default: 22)
-P, --policy [FILE] Custom policy file (Default: Mozilla Modern)
--threads [NUMBER] Number of worker threads (Default: 5)
--fingerprint-db [FILE] File location of fingerprint database (Default: ./fingerprints.db)
--suppress-update-status Do not check for updates
-u, --unit-test [FILE] Throw appropriate exit codes based on compliance status
-V [STD_LOGGING_LEVEL],
--verbosity
-v, --version Display just version info
-h, --help Show this message
Examples:
ssh_scan -t 192.168.1.1
ssh_scan -t server.example.com
ssh_scan -t ::1
ssh_scan -t ::1 -T 5
ssh_scan -f hosts.txt
ssh_scan -o output.json
ssh_scan -O output.json -o rescan_output.json
ssh_scan -t 192.168.1.1 -p 22222
ssh_scan -t 192.168.1.1 -p 22222 -L output.log -V INFO
ssh_scan -t 192.168.1.1 -P custom_policy.yml
ssh_scan -t 192.168.1.1 --unit-test -P custom_policy.yml
查看有关 SSH 服务器的一些有用文章:
- 使用 SSH Keygen 进行 SSH 无密码登录,只需 5 个简单步骤
- 确保 SSH 服务器安全的 5 个最佳实践
- 使用 Chrooted Jail 限制 SSH 用户访问某些目录
- 如何配置自定义 SSH 连接以简化远程访问
有关更多详细信息,请访问 ssh_scan Github 存储库:https://github.com/mozilla/ssh_scan
在本文中,我们向您展示了如何在 Linux 中设置和使用 ssh_scan。您知道有类似的工具吗?请通过下面的反馈表告知我们,包括有关本指南的任何其他想法。