Yesterday we discussed revisiting SSH configurations and updating settings. Now that this is done across your organization (just kidding), how will you audit this. In particular, what about hosts that you don’t know are there, or that you don’t know are running SSH?
For starters, nmap makes a great audit tool. A simple scan for port 22 will look like this:
nmap –p 22 –Pn --open x.x.x0/24
(note that this only probes port 22, you might want to add 222 or 2222 or 2323 – or even scan all of 1-65535, and look for SSH on other ports)
A more useful scan though will give you information on the services (-sV) and OS (-O):
nmap –p 22 –Pn --open –sV –O x.x.x0/24
If you have thousands of hosts to assess, you can look at MASSCAN instead of nmap to get the initial “find the open ports” scan job done quicker. While MASSCAN will do the initial scan at blinding speed, Nmap and other tools will do a better job once you start asking for more complex output.
Or, looking for SSH version 1 servers:
nmap –p 22 –Pn –open x.x.x.0/24 –script sshv1.nse
Or even more useful, just pull the ciphers supported in the target SSH servers:
nmap –p 22 –Pn –open x.x.x.0/24 –script ssh2-enum-algos.nse
A tool that I’ve been playing with the last week or so goes one better. Ssh-scan assesses the target host, then dumps it’s ciphers and the config bits that it can deduce remotely, then gives you recommendations based on policies (some default policies are included with the tool). This is by no means the only SSH scanner out there, there are certainly dozens of similar tools, ssh_scan is just a new one that popped up in my Twitter feed this past month. Tools like Nessus or OpenVAS will also do a good job on these assessments (try one against the next against the next, let us know what you see!)
Ssh_scan is extremely easy to install – on Kali (or almost any Linux distro with Ruby installed), simply run:
gem install ssh_scan
Their site also has instructions to run this in Docker.
A scan of a typical host (an ESXi with a default SSH config) might look like this (note the recommendations section, in red)
#ssh_scan -t 192.168.122.50
Note the recommendations section. On ESXi especially, if you combine this with the advice from VMware and the CIS Hardening Guide, the guidance really boils down to “why did you enable SSH on that box anyway?” – for vSphere, really you are better off to use the API to script against the environment (which is usually why people enable SSH on that platform)
In another example, scanning a pfSense firewall (just the recommendations shown):
Here we see that the recommendations include removal of the default “password, keyboard interactive” authentication (in other words, go to keys for authentication instead of userid/password), as well as some SSH "tech" recommendations.
While you should scan everything with tools like Nessus or OpenVAS, the output from these tools can be a tidal wave of duplicate and overlapping advice. You can certainly tune either product to give you pinpoint results, but that can be a bit of a job too. If you are just looking to have a “fix SSH in my infrastructure” day, combining nmap and ssh_scan can give you “just the facts” to get the job done!
Have you worked with a different or maybe a better SSH audit tool? Please, use our comment form and let us know!
If you book yourself a "fix my SSH services" day, and you're able to share some war stories, please also use that comment form!
Nov 2nd 2017
1 year ago
The tool I use for this kind of work is ssh-audit (https://github.com/arthepsy/ssh-audit)
Seems to work pretty well.
Nov 2nd 2017
1 year ago