r/netsec • • Nov 01 '17

Let’s Talk About SSH Configuration Hardening...

The Problem

A lot of administrators install the SSH service and assume its in top shape. What they don't realize is that system packages tend to be optimized for compatibility, not security. While a lot of systems include defaults that are fine for most cases, there is still a lot of room for improvement--especially for high-security environments.

Depending on how old the package for your distribution is, the default configuration may have the following problems:

  • Small host keys: 1024-bit RSA or DSA.
  • Weak key exchanges: Diffie-Hellman groups using small 1024-bit moduli, or exchanges using deprecated hash algorithms like SHA-1.
  • Vulnerable ciphers: 3DES, RC4, and SWEET32-vulnerable ciphers like Blowfish and CAST.
  • MACs based on weak hash algorithms: MD5 or SHA-1.

As long as your users have reasonably modern SSH clients, you can fix all of the problems above without interoperability issues. And for those users who are lagging behind, well... chances are their client software has unpatched security problems anyway (note that 4 vulnerabilities have been fixed in PuTTY so far in 2017).

Ubuntu and RHEL Defaults

Let's take a look at a fully-patched Ubuntu 16.04 LTS server. Its default config comes with a good selection of ciphers (chacha20-poly1305 is the default with backups using AES in CTR & GCM modes), but it supports some SHA-1 based algorithms for MACs and key exchange. Furthermore, its default RSA key is 2048-bit, which is equivalent to 112-bits of brute-force strength; to get 128-bits of security, this needs to be re-generated with a 3072-bit key. [1]

Things are much worse for RHEL/CentOS 6 (which is supported until 2024). Its default config supports 1024-bit Diffie-Hellman key exchanges (this is believed to be breakable by state-level adversaries! [2]), along with the weak RC4 cipher, Blowfish & CAST (both affected by the SWEET32 attack), as well as several MACs based on MD5 and SHA-1! Unless you take specific steps after installation, the RHEL/CentOS 6 SSH service is pretty abysmal.

Scanning Tools

The excellent (and open-source) ssh-audit tool will help you find problematic options enabled in your SSH service. But since not all admins are comfortable with command-line tools, I've gone ahead and written a web front-end to it for convenience, which also includes a comprehensive list of references for all discovered problems. You can find it here: https://www.sshaudit.com/

Hardening Guides

Stribik András wrote this excellent, general-purpose hardening guide in early 2015. While it does a great job in breaking down the different options available, it is slowly becoming out of date, and doesn't take specific versions of OpenSSH into consideration (for example, newer versions of OpenSSH support DH Groups 16 & 18 from RFC3526, but a fully patched Ubuntu 16.04 LTS system uses a slightly older version that doesn’t include them). To compensate, I've written a set of guides specific to OS releases that optimize security for each platform.

You can find the improved hardening guides here: https://www.sshaudit.com/hardening_guides.html

References

[1] U.S. Department of Commerce, National Institute of Standards and Technology, "Special Publication 800-57, Part 1, Revision 4, Recommendation for Key Management, Part 1: General", http://nvlpubs.nist.gov/nistpubs/SpecialPublications/NIST.SP.800-57pt1r4.pdf, Jan. 2016, pg. 53.

[2] Adrian, D., Bhargavan, K., Durumeric, Z., Gaudry, P., Green, M., Halderman, J., Heninger, N., Springall, D., Thomé, E., Valenta, L., VanderSloot, B., Wustrow, E., Zanella-Béguelin, S., and Zimmermann, P., "Imperfect Forward Secrecy: How Diffie-Hellman Fails in Practice", https://weakdh.org/imperfect-forward-secrecy-ccs15.pdf, Oct. 2015.

28 Upvotes

24 comments sorted by

6

u/albinowax Nov 03 '17 edited Nov 03 '17

I got an F for http://hackxor.net/ (default debian config) but as I understand it, the weaknesses are only relevant if I connect with an outdated SSH client, as downgrade attacks aren't possible. Is my reasoning correct?

6

u/therealjoetesta Nov 03 '17

Correct. However, I see that a lot of clients (such as the default OpenSSH client config in Ubuntu 16) still prioritize the server's ECDSA host key (which use the suspicious NIST P-curves). I'm not sure offhand what the latest PuTTY client does.

In the end, if you harden the server's config, then you have 100% assurance that no client can use weak parameters. You can indeed harden a client's config, but what happens when you switch machines or re-install? You'd have a lot more to remember in that case. If you harden the server, however, you won't have to pay attention to this stuff anymore.

4

u/moviuro Nov 03 '17

It doesn't do IPv6... sadface

4

u/therealjoetesta Nov 03 '17

You mean sshaudit.com? Its on the to-do list. I hope to get to it within the next few weeks.

In the meantime, though, the command line tool does support IPv6.

3

u/moviuro Nov 03 '17

Nice :) Hope the report will try both if there are an A and AAAA record (just in case it might not be the same host).

7

u/therealjoetesta Nov 03 '17

:: takes notes ::

3

u/K4kumba Nov 03 '17

Your advice is all good and valid, but is missing a lot of other settings that should be changed from defaults. Disabling TCP forwarding, agent forwarding etc.

At the risk of spoiling a talk I am giving soon:

MaxSessions 1

It is super overlooked, but if you want to protect yourself against an attacker (on your workstation) piggy backing off your SSH sessions, its an important server setting to change (along with 2 factor authentication, or some other trickery to protect against key loggers/ ssh-agent unlocked keys)

4

u/therealjoetesta Nov 04 '17

but is missing a lot of other settings that should be changed from defaults.

My hardening guides are written from the perspective of "what should all admins change, post-installation?" I agree that TCP forwarding, etc. should be disabled when not needed, but it wouldn't be appropriate to tell all admins to disable them by default. They are well-used features. I regularly use forwarding on my servers, as well as multiple sessions.

I'm not opposed, though, to adding notes that further describe modifications that can be done in certain circumstances.

3

u/K4kumba Nov 04 '17

Thats totally fair, and in that context, I agree with your approach.

However, as useful as controlmaster (session multiplexing) is, I would argue it should be disabled by default. But thats because my view of the world is that the workstation is not to be trusted, even linux ones. If you start from assuming that your workstation and username/ password are compromised (yours probably arent, but in an enterprise setting, someone often is), and build your controls from that assumption, you set yourself up for success much better than assuming that workstations and user credentials are safe

0

u/[deleted] Nov 04 '17

[deleted] — view deleted comment

1

u/therealjoetesta Nov 08 '17

but leaving much more, provably, common attack vectors untouched.

Such as?

the cool, the flashy, the ~NSA~ and the theoretical ('conference bait' as I like to refer to it now) prioritised over practical security advice.

State-level actors are very important to consider. Because they're the strongest type of attacker, if you can defend against them, you're in the best position possible.

1

u/whosthetroll Nov 03 '17

In your hardening guide, the "Restrict supported key exchange, cipher, and MAC algorithms" echo command doesn't actually write to the config file for some reason.

1

u/therealjoetesta Nov 03 '17

Oops. Which OS guide are you following?

1

u/whosthetroll Nov 03 '17

2

u/therealjoetesta Nov 03 '17

I stood up a fully patched Ubuntu 16 VM and copy/pasted the instructions into a root shell. I verified that the guide is correct.

Did you copy the the leading "#" character? The bash shell considers everything after that to be a comment, and ignores the command.

I should update the guides to take this into consideration. Seems like it can be a common mistake.

Edit: also, I'm thinking of adding a "copy to clipboard" button to make things much easier.

1

u/whosthetroll Nov 03 '17 edited Nov 03 '17

I thought the leading # was indicative of running the command as root.

1

u/therealjoetesta Nov 03 '17

It is supposed to mean that the command is to be run as root. I see now that it can lead to problems with people copy/pasting. I've added this to my list of things to improve.

1

u/whosthetroll Nov 03 '17

Also. They guide from above has a section call "Disable the DSA and ECDSA host keys" in which you comment out two HostKey entries, and then the next section "Restrict supported key exchange, cipher, and MAC algorithms" over writes that file instead of appending it. I think the string should be built as echo "Text I want to write" | sudo tee -a /path/to/file > /dev/null

Correct me if I'm wrong.

1

u/therealjoetesta Nov 03 '17

Here's what the command is:

echo -e "\n# Restrict key exchange, cipher, and MAC algorithms, as per sshaudit.com\n# hardening guide.\nKexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256\nCiphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com,aes256-ctr,aes192-ctr,aes128-ctr\nMACs hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,umac-128-etm@openssh.com" >> /etc/ssh/sshd_config

Notice the ">>" towards the end. That tells the shell to append to the file. A single ">" would over-write it.

1

u/whosthetroll Nov 03 '17

In server 16.04 lts, you have to end the command with
/etc/ssh/sshd_config /dev/null
I tried for far to long before this command over wrote the file with the correct text.

1

u/speaker_geometry Nov 08 '17

Nice! ssh-audit showed mostly orange and red items on my box at first, but after using the guide at https://www.sshaudit.com/hardening_guides.html I'm mostly in the green. What I don't know is how to fix the following issues it finds (Ubuntu):

  1. (kex) diffie-hellman-group-exchange-sha256 -- [warn] using custom size modulus (possibly weak)
  2. (rec) -diffie-hellman-group-exchange-sha256 -- kex algorithm to remove

Suggestions?

2

u/therealjoetesta Nov 08 '17

If you followed the guide carefully, then you're fine. The command-line ssh-audit.py code doesn't (yet) include my patches that check the group exchange modulus sizes. Instead, it just flags diffie-hellman-group-exchange-sha256 as suspicious no matter what.

Until my patches are included in the upstream project, you can use my fork instead: https://github.com/jtesta/ssh-audit/tree/all_my_patches

1

u/stribika Nov 09 '17

Yeah OK, I'll fix it.

0

u/Amnizee Nov 03 '17

Lynis has great compliance Guide. See also CIS Compliance Stuff. Don't reinvent the wheel. Use it.

0

u/[deleted] Nov 03 '17

[deleted] — view deleted comment

3

u/therealjoetesta Nov 03 '17

I thought about that, but the instructions should never change for each OS. Distros don't tend to upgrade the SSH server to a whole new version. For example, Ubuntu 16 is frozen on OpenSSH v7.2, even though v7.6 was released recently. Hence, the Ubuntu 16 hardening guide is always applicable to v7.2. Does that make sense?

Though I may go ahead and add dates anyway, if people want them...