OpenBSD Journal

The Potential for an SSH Worm

Contributed by sean on from the dept.

A few people have pointed out a paper from MIT ( pointed out by Bruce Schneier) regarding the potential to exploit 'saved knowledge' in SSH to spread like a worm.

A brief summary is provided below. The paper assumes the initial 'seed' machine has been already compromised. Once a machine is compromised anything is fair game. This being a given, the author's have pointed out that the known_hosts files as well as the /etc/hosts.* files are really good sources for addresses of new targets. This alone isn't enough to build a worm as it would still need a method to impersonate valid users or find some method to compromise these newly found hosts.

The standard methods of replacing daemons and binaries can aid in that task but the real killer is unencrypted ssh keys (ie. used frequently for automating remote tasks). Combine the information gleaned from known_hosts, authorized_keys and having access to an unencrypted ssh key (already authorized elsewhere) you have a very solid starting point for 'worm' like propagation.

The technique in the paper hinges on the accessibility of the known_hosts files and have proposed that this file be hashed/encrypted. This technique has already been implemented in OpenSSH 4.0 and the authors provide a patch backporting the feature to 3.9 and 3.9p1.

If you are already using a OpenSSH 4.0 (or the patched 3.9) setting up hashing of knowns hosts is pretty simple (as is described here). All you have to do is:
     echo "Host *" >> /etc/ssh/ssh_config
     echo "HashKnownHosts yes" >> /etc/ssh/ssh_config
You will also have to recreate the known_hosts files or convert your existing ones using a script provided by the authors.

For more information about this paper check out the MIT CSAIL page on the subject.

UPDATE: I'd like to point out that the authors do not state that the hashing of the known_hosts is a solution to this problem but as a means of mitigating this particular technique for address harvesting.

(Comments are closed)

  1. By Anonymous Coward ( on

    His name is Schneier. Not Schnier.

    1. By phessler ( on

      Thanks. Updated.

      1. By sean ( on

        Damn, I always miss something. Thanks.

    2. By Gimlet ( on

      Hey, is it so hard to use an apostrophe to show possession? Typos are easy to make, calm down.

      1. By Anonymous Coward ( on

        oh snap!

  2. By Frank Denis ( on

    Unfortunately, enabling hashing disables completion for the ssh command in shells like Zsh. Sure, this is not critical and there is obviously no workaround, but when you are using the TAB key for everything for years, it's hard to get back to writing full host names again. However host names are still in your shell history, so unless you also disable history logging, hashing host names is pointless.

    1. By Bert ( blambert at thepresidency dot org on

      Nah, that's easy: hash the shell history file :p

      Seriously, though, i don't see this as being a massive problem. Although interesting, there are a number of obstacles to overcome to automate SSH logins as a vector. The largest of which (or, at least, it seems to me) is the heterogeneity of the sshd universe. An exploit for FreeBSD isn't the same as for Solaris, isn't the same as for Linux...

      As another poster mentioned, requiring a second authentication factor (e.g., password) that means that something carbon-based is on the other end, as well as restricting the actions of scripted logins to that which they need to do to fulfill their function, would mitigate this (yes, you lose convenience, but all of life's a tradeoff).

      Of course, I could need to take off the blinders.

    2. By David ( on

      Don't forget the last(1) command and wtmp database store related hostnames as well.

      1. By Frank Denis ( on

        and /var/log/* Host names and IPs are everywhere.

    3. By sand ( sandolo at on

      Another solution is to not hash any file and to choose good passphrases ;)
      Informations are everywhere, and IMHO hiding one or more files will only slow down the everyday tasks of the users, while the attacker can still gather A LOT of data from other sources.

      once again the rise and fall of security by obscurity, ALALA'.

    4. By Anonymous Coward ( on

      which is, of course, the point.

  3. By Kevin Kadow ( on

    Unencrypted DSA keys for making passwordless connections are a necessary evil for process automation.

    I only use authorized_keys on role accounts, never for normal login accounts, and always include a specific command in the authorized_keys file on the server. This limits the damage that can be done using these credentials to the exact task the key was created for.

    1. By Anonymous Coward ( on

      Definitely. And also (this is probably dead obvious to the people in this forum, but if I had a nickel for every time it didn't happen...) manually check your friggin accounts. Log in as that user, and try hacking into places you shouldn't. At least for a few minutes. Unless you're one of those admins whose work is so perfect it never needs to be verified :)

    2. By Sam ( on

      Pity that doesn't work for scp.

      1. By SH ( on

        You can use systrace for this, but it involves some work on the remote account. The remote account should have a systraced shell (there is an article on this on with appropiate systrace policy.

  4. By Anonymous Coward ( on

    OpenSSH is everywhere. It is also becoming the transport for many other protocols (yeah!). The choices of protocols to attack will shrink.
    Resist the temptation to add complexity to the software and protocol to protect against future attacks. Push in the direction of simplicity.

    1. By Ben ( on

      Sadly the days of KISS are over. They died with SSH protocol v1. *weak smile* v2 protocol complexity is off the scale (along with most protocols), and when you add BSM, PAM and other system security protocol/methods ontop of it you end up with more complexity. Add to that the need to keep backward compatible for buggy servers/clients and you have yet another subsection of complexity. *sigh* In regards to hashing. I remember the team taking about before I wandered off to work on other projects, and the main bonus isn't "oohh you can't see where I ssh to.." It's a speed factor if you are using OpenSSH on large multi-node clusters and you have TONS of systems you have to interact with. - Ben

  5. By Anonymous Coward ( on

    I call bullshit. Obscurity is NOT security. There are many ways an attacker can find out about ssh relationships... traffic analysis, shell histories, administration scripts, etc.

    And say a worm discovers that you ssh into Does that allow it to circumvent security? Hell no! The worm will only get in if I have screwed up something fundamental (like using passwords instead of public key auth, or not have a good (or any!) passphrase). Or if I am using ssh-agent, it may own me that way, but I was probably already its bitch at that point.

    Now, protecting the data in known_hosts is not necessarily a bad idea since it can make life harder for the bad guy. But it is a brittle countermeasure, since once an attacker gets the info by some path then the fact that known_hosts is hashed (or whatever) is totally useless.

    But the real issue is that to stop an attack like this you use strong authentication, not obscurity.

    1. By djm@ ( on

      I agree that all of the information in known_hosts is available by other means (e.g. netstat, ps, [uw]tmp), but nowhere is it as concentrated and directly correlated to trust relationships as known_hosts. So, I think it makes sense to spend a little effort in protecting it.

      Fortunately, the costs for the user of hashing hostnames are minimal. In fact, the new tools make handling known_hosts far easier than going in with vi and searching for an old key to manually zap it. Now you can do "ssh-keygen -R blah" to delete a key by hostname.

      Of course, if admins would scan their systems for ssh private keys with absent or trivial passwords, then this would be much less of a problem...

    2. By superhet ( on

      There is immediacy to propagating a worm through known_hosts, as opposed to going through ones history, or traffic analysis. The point is the immediacy here, and not the inevitable, which is a form of security through obscurity, yes. A point lost on some.... because I too at first thought "no big deal. If you are got, you are got." But the point here is that if a worm gets you via ssh stuffs, having a readily available known_hosts will increase the likelihood of the immediate propagation of that worm type paradigm. This reply was generated via 'links' and may have interesting formatting. Preaching to the choir here, I am. (Just saw SW3 yesterday)

    3. By Anonymous Coward ( on

      Actually, when it comes to slowing the spread of a virus, obscurity helps a good bit.
      All of you "obscurity isn't security" whiners need to learn how to think more about what happens in practice - rather than just blindly repeating a mantra that you don't really understand the implications of.

  6. By Anthony Roberts ( on

    I noticed when switching my known_hosts file over to the hashed system that it adds a host twice. Once for the DNS name, and once for the IP address. Isn't the number of IPv4 addresses small enough that a worm on a reasonably fast computer could simply test all the hashed entries against all IP addresses? Indeed, couldn't the black helicopter men do that too?

    1. By djm@ ( on

      If you are afraid of black helicopters and worms that try brute force attacks, then you can set CheckHostIP=no in ssh_config.


Copyright © - Daniel Hartmeier. All rights reserved. Articles and comments are copyright their respective authors, submission implies license to publish on this web site. Contents of the archive prior to as well as images and HTML templates were copied from the fabulous original with Jose's and Jim's kind permission. This journal runs as CGI with httpd(8) on OpenBSD, the source code is BSD licensed. undeadly \Un*dead"ly\, a. Not subject to death; immortal. [Obs.]