ssh_scan – Verifies Your SSH Server Configuration and Policy in Linux

[‘

n

ssh_scan is an easy-to-use prototype SSH configuration and policy scanner for Linux and UNIX servers, inspired by Mozilla OpenSSH Security Guide, which provides a reasonable baseline policy recommendation for SSH configuration parameters such as Ciphers, MACs, and KexAlgos and much more.

n

It has some of the following benefits:

n

    n

  • It has minimal dependencies, ssh_scan only employs native Ruby and BinData to do its work, no heavy dependencies.
  • n

  • It’s portable, you can use ssh_scan in another project or for automation of tasks.
  • n

  • It’s easy to use, simply point it at an SSH service and get a JSON report of what it supports and it’s policy status.
  • n

  • It’s also configurable, you can create your own custom policies that fit your specific policy requirements.
  • n

n

Suggested Read: How to Install and Configure OpenSSH Server in Linux

n

How to Install ssh_scan in Linux

n

There are three ways you can install ssh_scan and they are:

n

To install and run as a gem, type:

n

----------- On Debian/Ubuntu ----------- rn$ sudo apt-get install ruby gemrn$ sudo gem install ssh_scanrnrn----------- On CentOS/RHEL ----------- rn# yum install ruby rubygemrn# gem install ssh_scanrn

n

To run from a docker container, type:

n

# docker pull mozilla/ssh_scanrn# docker run -it mozilla/ssh_scan /app/bin/ssh_scan -t github.comrn

n

To install and run from source, type:

n

# git clone https://github.com/mozilla/ssh_scan.gitrn# cd ssh_scanrn# gpg2 --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3rn# curl -sSL https://get.rvm.io | bash -s stablern# rvm install 2.3.1rn# rvm use 2.3.1rn# gem install bundlerrn# bundle installrn# ./bin/ssh_scanrn

n

How to Use ssh_scan in Linux

n

The syntax for using ssh_scan is as follows:

n

$ ssh_scan -t ip-addressrn$ ssh_scan -t server-hostnamern

n

For example to scan SSH configs and policy of server 92.168.43.198, enter:

n

$ ssh_scan -t 192.168.43.198rn

n

Note you can also pass a [IP/Range/Hostname] to the -t option as shown in the options below:

n

$ ssh_scan -t 192.168.43.198,200,205rn$ ssh_scan -t test.tecmint.lanrn

n

Sample Output

n

I, [2017-05-09T10:36:17.913644 #7145]  INFO -- : You're using the latest version of ssh_scan 0.0.19rn[rn  {rn    "ssh_scan_version": "0.0.19",rn    "ip": "192.168.43.198",rn    "port": 22,rn    "server_banner": "SSH-2.0-OpenSSH_7.2p2 Ubuntu-4ubuntu2.1",rn    "ssh_version": 2.0,rn    "os": "ubuntu",rn    "os_cpe": "o:canonical:ubuntu:16.04",rn    "ssh_lib": "openssh",rn    "ssh_lib_cpe": "a:openssh:openssh:7.2p2",rn    "cookie": "68b17bcca652eeaf153ed18877770a38",rn    "key_algorithms": [rn      "[emailxa0protected]",rn      "ecdh-sha2-nistp256",rn      "ecdh-sha2-nistp384",rn      "ecdh-sha2-nistp521",rn      "diffie-hellman-group-exchange-sha256",rn      "diffie-hellman-group14-sha1"rn    ],rn    "server_host_key_algorithms": [rn      "ssh-rsa",rn      "rsa-sha2-512",rn      "rsa-sha2-256",rn      "ecdsa-sha2-nistp256",rn      "ssh-ed25519"rn    ],rn    "encryption_algorithms_client_to_server": [rn      "[emailxa0protected]",rn      "aes128-ctr",rn      "aes192-ctr",rn      "aes256-ctr",rn      "[emailxa0protected]",rn      "[emailxa0protected]"rn    ],rn    "encryption_algorithms_server_to_client": [rn      "[emailxa0protected]",rn      "aes128-ctr",rn      "aes192-ctr",rn      "aes256-ctr",rn      "[emailxa0protected]",rn      "[emailxa0protected]"rn    ],rn    "mac_algorithms_client_to_server": [rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "hmac-sha2-256",rn      "hmac-sha2-512",rn      "hmac-sha1"rn    ],rn    "mac_algorithms_server_to_client": [rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "[emailxa0protected]",rn      "hmac-sha2-256",rn      "hmac-sha2-512",rn      "hmac-sha1"rn    ],rn    "compression_algorithms_client_to_server": [rn      "none",rn      "[emailxa0protected]"rn    ],rn    "compression_algorithms_server_to_client": [rn      "none",rn      "[emailxa0protected]"rn    ],rn    "languages_client_to_server": [rnrn    ],rn    "languages_server_to_client": [rnrn    ],rn    "hostname": "tecmint",rn    "auth_methods": [rn      "publickey",rn      "password"rn    ],rn    "fingerprints": {rn      "rsa": {rn        "known_bad": "false",rn        "md5": "0e:d0:d7:11:f0:9b:f8:33:9c:ab:26:77:e5:66:9e:f4",rn        "sha1": "fc:8d:d5:a1:bf:52:48:a6:7e:f9:a6:2f:af:ca:e2:f0:3a:9a:b7:fa",rn        "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"rn      }rn    },rn    "start_time": "2017-05-09 10:36:17 +0300",rn    "end_time": "2017-05-09 10:36:18 +0300",rn    "scan_duration_seconds": 0.221573169,rn    "duplicate_host_key_ips": [rnrn    ],rn    "compliance": {rn      "policy": "Mozilla Modern",rn      "compliant": false,rn      "recommendations": [rn        "Remove these Key Exchange Algos: diffie-hellman-group14-sha1",rn        "Remove these MAC Algos: [emailxa0protected], [emailxa0protected], [emailxa0protected], hmac-sha1",rn        "Remove these Authentication Methods: password"rn      ],rn      "references": [rn        "https://wiki.mozilla.org/Security/Guidelines/OpenSSH"rn      ]rn    }rn  }rn]rn

n

You can use -p to specify a different port, -L to enable the logger and -V to define the verbosity level as shown below:

n

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

n

Additionally, use a custom policy file (default is Mozilla Modern) with the -P or --policy [FILE] like so:

n

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

n

Type this to view all ssh_scan usage options and more examples:

n

$ ssh_scan -hrn

n

Sample Output

n

ssh_scan v0.0.17 (https://github.com/mozilla/ssh_scan)rnrnUsage: ssh_scan [options]rn    -t, --target [IP/Range/Hostname] IP/Ranges/Hostname to scanrn    -f, --file [FilePath]            File Path of the file containing IP/Range/Hostnames to scanrn    -T, --timeout [seconds]          Timeout per connect after which ssh_scan gives up on the hostrn    -L, --logger [Log File Path]     Enable loggerrn    -O, --from_json [FilePath]       File to read JSON output fromrn    -o, --output [FilePath]          File to write JSON output torn    -p, --port [PORT]                Port (Default: 22)rn    -P, --policy [FILE]              Custom policy file (Default: Mozilla Modern)rn        --threads [NUMBER]           Number of worker threads (Default: 5)rn        --fingerprint-db [FILE]      File location of fingerprint database (Default: ./fingerprints.db)rn        --suppress-update-status     Do not check for updatesrn    -u, --unit-test [FILE]           Throw appropriate exit codes based on compliance statusrn    -V [STD_LOGGING_LEVEL],rn        --verbosityrn    -v, --version                    Display just version inforn    -h, --help                       Show this messagernrnExamples:rnrn  ssh_scan -t 192.168.1.1rn  ssh_scan -t server.example.comrn  ssh_scan -t ::1rn  ssh_scan -t ::1 -T 5rn  ssh_scan -f hosts.txtrn  ssh_scan -o output.jsonrn  ssh_scan -O output.json -o rescan_output.jsonrn  ssh_scan -t 192.168.1.1 -p 22222rn  ssh_scan -t 192.168.1.1 -p 22222 -L output.log -V INFOrn  ssh_scan -t 192.168.1.1 -P custom_policy.ymlrn  ssh_scan -t 192.168.1.1 --unit-test -P custom_policy.ymlrn

n

Check out some useful artilces on SSH Server:

n

    n

  1. SSH Passwordless Login Using SSH Keygen in 5 Easy Steps
  2. n

  3. 5 Best Practices to Secure SSH Server
  4. n

  5. Restrict SSH User Access to Certain Directory Using Chrooted Jail
  6. n

  7. How to Configure Custom SSH Connections to Simplify Remote Access
  8. n

n

For more details visit ssh_scan Github repository: https://github.com/mozilla/ssh_scan

n

In this article, we showed you how to set up and use ssh_scan in Linux. Do you know of any similar tools out there? Let us know via the feedback form below, including any other thoughts concerning this guide.

n

‘]