@networkpro/blog 1.1.3 → 1.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,73 +35,76 @@ Mirrored to preserve information. Minor changes have been made, and this is note
35
35
 
36
36
  - [Skip to the good part.](#sshd)
37
37
 
38
- You may have heard that the NSA can decrypt SSH at least some of the time.
39
- If you have not, then read the [latest batch of Snowden documents][snowden-docs] now. All of it. This post will still be here when you finish. My goal with this post here is to make NSA analysts sad.
38
+ You may have heard that the NSA can decrypt SSH at least some of the time. If
39
+ you have not, then read the [latest batch of Snowden documents][snowden-docs]
40
+ now. All of it. This post will still be here when you finish. My goal with this
41
+ post here is to make NSA analysts sad.
40
42
 
41
- TL;DR: Scan this post for fixed width fonts, these will be the config file snippets and commands you have to use.
43
+ TL;DR: Scan this post for fixed width fonts, these will be the config file
44
+ snippets and commands you have to use.
42
45
 
43
46
  <!-- more -->
44
47
 
45
- _Warning_: You will need a recent OpenSSH version.
46
- It should work with 6.5 but I have only tested 6.7 and connections to Github.
47
- Here is a good [compatibility matrix][compat].
48
+ _Warning_: You will need a recent OpenSSH version. It should work with 6.5 but I
49
+ have only tested 6.7 and connections to Github. Here is a good [compatibility
50
+ matrix][compat].
48
51
 
49
52
  ---
50
53
 
51
54
  # The crypto
52
55
 
53
- Reading the documents, I have the feeling that the NSA can 1) decrypt weak crypto and 2) steal keys.
54
- Let's focus on the crypto first.
55
- SSH supports different key exchange algorithms, ciphers and message authentication codes.
56
- The server and the client choose a set of algorithms supported by both, then proceed with the key exchange.
57
- Some of the supported algorithms are not so great and should be disabled completely.
58
- This hurts interoperability but everyone uses OpenSSH anyway.
59
- Fortunately, downgrade attacks are not possible because the supported algorithm lists are included in the key derivation.
60
- If a man in the middle were to change the lists, then the server and the client would calculate different keys.
56
+ Reading the documents, I have the feeling that the NSA can 1) decrypt weak
57
+ crypto and 2) steal keys. Let's focus on the crypto first. SSH supports
58
+ different key exchange algorithms, ciphers and message authentication codes. The
59
+ server and the client choose a set of algorithms supported by both, then proceed
60
+ with the key exchange. Some of the supported algorithms are not so great and
61
+ should be disabled completely. This hurts interoperability but everyone uses
62
+ OpenSSH anyway. Fortunately, downgrade attacks are not possible because the
63
+ supported algorithm lists are included in the key derivation. If a man in the
64
+ middle were to change the lists, then the server and the client would calculate
65
+ different keys.
61
66
 
62
67
  ## Key exchange
63
68
 
64
- There are basically two ways to do key exchange: [Diffie-Hellman][dh] and [Elliptic Curve Diffie-Hellman][ecdh].
65
- Both provide [forward secrecy][forward-secrecy] which the NSA hates because they can't use passive collection and key recovery later.
66
- The server and the client will end up with a shared secret number at the end without a passive eavesdropper learning anything about this number.
67
- After we have a shared secret we have to derive a cryptographic key from this using a key derivation function.
68
- In case of SSH, this is a hash function.
69
- [Collision attacks][sloth] on this hash function have been proven to allow downgrade attacks.
69
+ There are basically two ways to do key exchange: [Diffie-Hellman][dh] and
70
+ [Elliptic Curve Diffie-Hellman][ecdh]. Both provide [forward
71
+ secrecy][forward-secrecy] which the NSA hates because they can't use passive
72
+ collection and key recovery later. The server and the client will end up with a
73
+ shared secret number at the end without a passive eavesdropper learning anything
74
+ about this number. After we have a shared secret we have to derive a
75
+ cryptographic key from this using a key derivation function. In case of SSH,
76
+ this is a hash function. [Collision attacks][sloth] on this hash function have
77
+ been proven to allow downgrade attacks.
70
78
 
71
- DH works with a multiplicative group of integers modulo a prime.
72
- Its security is based on the hardness of the [discrete logarithm problem][dlp].
79
+ DH works with a multiplicative group of integers modulo a prime. Its security is
80
+ based on the hardness of the [discrete logarithm problem][dlp].
73
81
 
74
82
  ## <pre><code id="diffie-hellman">Alice Bob
75
83
 
76
- Sa = random
77
- Pa = g^Sa --> Pa
78
- Sb = random
79
- Pb <-- Pb = g^Sb
80
- s = Pb^Sa s = Pa^Sb
81
- k = KDF(s) k = KDF(s)</code></pre>
84
+ Sa = random Pa = g^Sa --> Pa Sb = random Pb <-- Pb = g^Sb s = Pb^Sa s = Pa^Sb k
85
+ = KDF(s) k = KDF(s)</code></pre>
82
86
 
83
- ECDH works with elliptic curves over finite fields.
84
- Its security is based on the hardness of the elliptic curve discrete logarithm problem.
87
+ ECDH works with elliptic curves over finite fields. Its security is based on the
88
+ hardness of the elliptic curve discrete logarithm problem.
85
89
 
86
90
  ## <pre><code id="elliptic-curve-diffie-hellman">Alice Bob
87
91
 
88
- Sa = random
89
- Pa = Sa _G --> Pa
90
- Sb = random
91
- Pb <-- Pb = Sb_ G
92
- s = Sa _Pb s = Sb_ Pa
93
- k = KDF(s) k = KDF(s)</code></pre>
92
+ Sa = random Pa = Sa _G --> Pa Sb = random Pb <-- Pb = Sb_ G s = Sa _Pb s = Sb_
93
+ Pa k = KDF(s) k = KDF(s)</code></pre>
94
94
 
95
95
  ---
96
96
 
97
97
  ## <a id="sshd">SSHD Configuration</a>
98
98
 
99
- > **_NOTE:_** Emphasis added, it was not present in the originally published article.
100
- > Key exchange **1** (curve25519-sha256) alone is ideal, **8** is also acceptable for interoperability.
99
+ > **_NOTE:_** Emphasis added, it was not present in the originally published
100
+ > article.
101
+ > Key exchange **1** (curve25519-sha256) alone is ideal, **8** is also
102
+ > acceptable for interoperability.
101
103
 
102
104
  OpenSSH supports 11 key exchange protocols:
103
105
 
104
- 1. **[curve25519-sha256][libsshdoc]: ECDH over [Curve25519][curve25519] with SHA2**
106
+ 1. **[curve25519-sha256][libsshdoc]: ECDH over [Curve25519][curve25519] with
107
+ SHA2**
105
108
  1. [diffie-hellman-group1-sha1][rfc4253]: 1024 bit DH with SHA1
106
109
  1. [diffie-hellman-group14-sha1][rfc4253]: 2048 bit DH with SHA1
107
110
  1. [diffie-hellman-group14-sha256][dh-draft]: 2048 bit DH with SHA2
@@ -115,21 +118,23 @@ OpenSSH supports 11 key exchange protocols:
115
118
 
116
119
  We have to look at 3 things here:
117
120
 
118
- - _ECDH curve choice_:
119
- This eliminates **9-11** because [NIST curves suck][nist-sucks].
120
- They leak secrets through timing side channels and off-curve inputs.
121
- Also, [NIST is considered harmful][bullrun] and cannot be trusted.
122
- - _Bit size of the DH modulus_:
123
- This eliminates **2** because the NSA has supercomputers and possibly unknown attacks.
124
- 1024 bits simply don't offer sufficient security margin.
125
- - _Security of the hash function_:
126
- This eliminates **2**, **3**, and **7** because SHA1 is broken.
127
- We don't have to wait for a second preimage attack that takes 10 minutes on a cellphone to disable it right now.
121
+ - _ECDH curve choice_: This eliminates **9-11** because [NIST curves
122
+ suck][nist-sucks]. They leak secrets through timing side channels and
123
+ off-curve inputs. Also, [NIST is considered harmful][bullrun] and cannot be
124
+ trusted.
125
+ - _Bit size of the DH modulus_: This eliminates **2** because the NSA has
126
+ supercomputers and possibly unknown attacks. 1024 bits simply don't offer
127
+ sufficient security margin.
128
+ - _Security of the hash function_: This eliminates **2**, **3**, and **7**
129
+ because SHA1 is broken. We don't have to wait for a second preimage attack
130
+ that takes 10 minutes on a cellphone to disable it right now.
128
131
 
129
- We are left with **1** and **8**, as well as **4-6** which were added in [OpenSSH 7.3][73release].
130
- **1** is better and it's perfectly OK to only support that but for interoperability (with Eclipse, WinSCP), **8** can be included.
132
+ We are left with **1** and **8**, as well as **4-6** which were added in
133
+ [OpenSSH 7.3][73release]. **1** is better and it's perfectly OK to only support
134
+ that but for interoperability (with Eclipse, WinSCP), **8** can be included.
131
135
 
132
- > **_NOTE:_** 8 should no longer be necessary in newer versions of WinSCP. If in doubt, test with only 1 first. Add 8 if it won't connect otherwise.
136
+ > **_NOTE:_** 8 should no longer be necessary in newer versions of WinSCP. If in
137
+ > doubt, test with only 1 first. Add 8 if it won't connect otherwise.
133
138
 
134
139
  Recommended `/etc/ssh/sshd_config` snippet:
135
140
 
@@ -144,9 +149,12 @@ Recommended `/etc/ssh/ssh_config` snippet:
144
149
  Host *
145
150
  KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256</code></pre>
146
151
 
147
- > **_NOTE:_** GitHub should no longer need a separate setting, as they've transitioned away from SSH keys. They should not require an exception regardless.
152
+ > **_NOTE:_** GitHub should no longer need a separate setting, as they've
153
+ > transitioned away from SSH keys. They should not require an exception
154
+ > regardless.
148
155
 
149
- If you chose to enable **8**, open `/etc/ssh/moduli` if exists, and delete lines where the 5th column is less than 2000.
156
+ If you chose to enable **8**, open `/etc/ssh/moduli` if exists, and delete lines
157
+ where the 5th column is less than 2000.
150
158
 
151
159
  <pre><code id="server-moduli-filter">awk '$5 > 2000' /etc/ssh/moduli > "${HOME}/moduli"
152
160
  wc -l "${HOME}/moduli" # make sure there is something left
@@ -165,36 +173,41 @@ This will take a while so continue while it's running.
165
173
 
166
174
  ## Authentication
167
175
 
168
- The key exchange ensures that the server and the client shares a secret no one else knows.
169
- We also have to make sure that they share this secret with each other and not an NSA analyst.
176
+ The key exchange ensures that the server and the client shares a secret no one
177
+ else knows. We also have to make sure that they share this secret with each
178
+ other and not an NSA analyst.
170
179
 
171
180
  ### Server authentication
172
181
 
173
- The server proves its identity to the client by signing the key resulting from the key exchange.
174
- There are 4 public key algorithms for authentication:
182
+ The server proves its identity to the client by signing the key resulting from
183
+ the key exchange. There are 4 public key algorithms for authentication:
175
184
 
176
185
  1. DSA with SHA1
177
186
  1. ECDSA with SHA256, SHA384 or SHA512 depending on key size
178
187
  1. [Ed25519][ed25519] with SHA512
179
188
  1. RSA with SHA1
180
189
 
181
- DSA keys must be exactly 1024 bits so let's disable that.
182
- Number 2 here involves NIST suckage and should be disabled as well.
183
- Another important disadvantage of DSA and ECDSA is that it uses randomness for each signature.
184
- If the random numbers are not the best quality, then it is [possible to recover][ecdsa-same-k] the [secret key][ecdsa-sony].
185
- Fortunately, RSA using SHA1 is not a problem here because the value being signed is actually a SHA2 hash.
186
- The hash function SHA1(SHA2(x)) is just as secure as SHA2 (it has less bits of course but no better attacks).
190
+ DSA keys must be exactly 1024 bits so let's disable that. Number 2 here involves
191
+ NIST suckage and should be disabled as well. Another important disadvantage of
192
+ DSA and ECDSA is that it uses randomness for each signature. If the random
193
+ numbers are not the best quality, then it is [possible to recover][ecdsa-same-k]
194
+ the [secret key][ecdsa-sony]. Fortunately, RSA using SHA1 is not a problem here
195
+ because the value being signed is actually a SHA2 hash. The hash function
196
+ SHA1(SHA2(x)) is just as secure as SHA2 (it has less bits of course but no
197
+ better attacks).
187
198
 
188
199
  <pre><code id="server-auth">Protocol 2
189
200
  HostKey /etc/ssh/ssh_host_ed25519_key
190
201
  HostKey /etc/ssh/ssh_host_rsa_key</code></pre>
191
202
 
192
- The first time you connect to your server, you will be asked to accept the new fingerprint.
203
+ The first time you connect to your server, you will be asked to accept the new
204
+ fingerprint.
193
205
 
194
- This will also disable the horribly broken v1 protocol that you should not have enabled in the first place.
195
- We should remove the unused keys and only generate a large RSA key and an Ed25519 key.
196
- Your init scripts may recreate the unused keys.
197
- If you don't want that, remove any `ssh-keygen` commands from the init script.
206
+ This will also disable the horribly broken v1 protocol that you should not have
207
+ enabled in the first place. We should remove the unused keys and only generate a
208
+ large RSA key and an Ed25519 key. Your init scripts may recreate the unused
209
+ keys. If you don't want that, remove any `ssh-keygen` commands from the init
210
+ script.
198
211
 
199
212
  <pre><code id="server-keygen">cd /etc/ssh
200
213
  rm ssh_host_*key*
@@ -203,12 +216,13 @@ ssh-keygen -t rsa -b 4096 -f ssh_host_rsa_key -N "" < /dev/null</code></pre>
203
216
 
204
217
  ### Client authentication
205
218
 
206
- The client must prove its identity to the server as well.
207
- There are various methods to do that.
219
+ The client must prove its identity to the server as well. There are various
220
+ methods to do that.
208
221
 
209
- The simplest is password authentication.
210
- This should be disabled immediately _after_ setting up a more secure method because it allows compromised servers to steal passwords.
211
- Password authentication is also more vulnerable to online bruteforce attacks.
222
+ The simplest is password authentication. This should be disabled immediately
223
+ _after_ setting up a more secure method because it allows compromised servers to
224
+ steal passwords. Password authentication is also more vulnerable to online
225
+ bruteforce attacks.
212
226
 
213
227
  Recommended `/etc/ssh/sshd_config` snippet:
214
228
 
@@ -221,7 +235,8 @@ Recommended `/etc/ssh/ssh_config` snippet:
221
235
  PasswordAuthentication no
222
236
  ChallengeResponseAuthentication no</code></pre>
223
237
 
224
- The most common and secure method is public key authentication, basically the same process as the server authentication.
238
+ The most common and secure method is public key authentication, basically the
239
+ same process as the server authentication.
225
240
 
226
241
  Recommended `/etc/ssh/sshd_config` snippet:
227
242
 
@@ -240,19 +255,28 @@ ssh-keygen -t rsa -b 4096 -o -a 100</code></pre>
240
255
 
241
256
  You can deploy your new client public keys using `ssh-copy-id`.
242
257
 
243
- It is also possible to use OTP authentication to reduce the consequences of lost passwords.
244
- [Google Authenticator][google-auth] is a nice implementation of [TOTP][totp], or Timebased One Time Password.
245
- You can also use a [printed list of one time passwords][otp] or any other [PAM][pam] module, really, if you enable `ChallengeResponseAuthentication`.
258
+ It is also possible to use OTP authentication to reduce the consequences of lost
259
+ passwords. [Google Authenticator][google-auth] is a nice implementation of
260
+ [TOTP][totp], or Timebased One Time Password. You can also use a [printed list
261
+ of one time passwords][otp] or any other [PAM][pam] module, really, if you
262
+ enable `ChallengeResponseAuthentication`.
246
263
 
247
264
  ### User Authentication
248
265
 
249
- Even with Public Key authentication, you should only allow incoming connections from expected users. The `AllowUsers` setting in `sshd_config` lets you specify users who are allowed to connect, but this can get complicated with a large number of ssh users. Additionally, when deleting a user from the system, the username is [not removed][bug779880] from `sshd_config`, which adds to maintenance requirements. The solution is to use the `AllowGroups` setting instead, and add users to an `ssh-user` group.
266
+ Even with Public Key authentication, you should only allow incoming connections
267
+ from expected users. The `AllowUsers` setting in `sshd_config` lets you specify
268
+ users who are allowed to connect, but this can get complicated with a large
269
+ number of ssh users. Additionally, when deleting a user from the system, the
270
+ username is [not removed][bug779880] from `sshd_config`, which adds to
271
+ maintenance requirements. The solution is to use the `AllowGroups` setting
272
+ instead, and add users to an `ssh-user` group.
250
273
 
251
274
  Recommended `/etc/ssh/sshd_config` snippet:
252
275
 
253
276
  <pre><code id="client-auth-allowgroups">AllowGroups ssh-user</code></pre>
254
277
 
255
- Create the ssh-user group with `sudo groupadd ssh-user`, then add each ssh user to the group with `sudo usermod -a -G ssh-user <username>`.
278
+ Create the ssh-user group with `sudo groupadd ssh-user`, then add each ssh user
279
+ to the group with `sudo usermod -a -G ssh-user <username>`.
256
280
 
257
281
  ---
258
282
 
@@ -260,9 +284,11 @@ Create the ssh-user group with `sudo groupadd ssh-user`, then add each ssh user
260
284
 
261
285
  > **_NOTE:_** Emphasis added.
262
286
 
263
- Symmetric ciphers are used to encrypt the data after the initial key exchange and authentication is complete.
287
+ Symmetric ciphers are used to encrypt the data after the initial key exchange
288
+ and authentication is complete.
264
289
 
265
- Here we have quite a few algorithms (10-14 were removed in [OpenSSH 7.6][76release]):
290
+ Here we have quite a few algorithms (10-14 were removed in [OpenSSH
291
+ 7.6][76release]):
266
292
 
267
293
  1. 3des-cbc
268
294
  1. aes128-cbc
@@ -282,22 +308,19 @@ Here we have quite a few algorithms (10-14 were removed in [OpenSSH 7.6][76relea
282
308
 
283
309
  We have to consider the following:
284
310
 
285
- - _Security of the cipher algorithm_:
286
- This eliminates **1** and **10-12** - both DES and RC4 are broken.
287
- Again, no need to wait for them to become even weaker, disable them now.
288
- - _Key size_:
289
- At least 128 bits, the more the better.
290
- - _Block size_:
291
- Does not apply to stream ciphers.
292
- At least 128 bits.
293
- This eliminates **13** and **14** because those have a 64 bit block size.
294
- - _Cipher mode_:
295
- The recommended approach here is to prefer [AE][ae] modes and optionally allow CTR for compatibility.
296
- CTR with Encrypt-then-MAC is provably secure.
297
-
298
- Chacha20-poly1305 is preferred over AES-GCM because the SSH protocol [does not encrypt message sizes][aes-gcm] when GCM (or EtM) is in use.
299
- This allows some traffic analysis even without decrypting the data.
300
- We will deal with that soon.
311
+ - _Security of the cipher algorithm_: This eliminates **1** and **10-12** - both
312
+ DES and RC4 are broken. Again, no need to wait for them to become even weaker,
313
+ disable them now.
314
+ - _Key size_: At least 128 bits, the more the better.
315
+ - _Block size_: Does not apply to stream ciphers. At least 128 bits. This
316
+ eliminates **13** and **14** because those have a 64 bit block size.
317
+ - _Cipher mode_: The recommended approach here is to prefer [AE][ae] modes and
318
+ optionally allow CTR for compatibility. CTR with Encrypt-then-MAC is provably
319
+ secure.
320
+
321
+ Chacha20-poly1305 is preferred over AES-GCM because the SSH protocol [does not
322
+ encrypt message sizes][aes-gcm] when GCM (or EtM) is in use. This allows some
323
+ traffic analysis even without decrypting the data. We will deal with that soon.
301
324
 
302
325
  Recommended `/etc/ssh/sshd_config` snippet:
303
326
 
@@ -314,28 +337,31 @@ Recommended `/etc/ssh/ssh_config` snippet:
314
337
 
315
338
  > Emphasis added.
316
339
 
317
- Encryption provides _confidentiality_, message authentication code provides _integrity_.
318
- We need both.
319
- If an AE cipher mode is selected, then extra MACs are not used, the integrity is already given.
320
- If CTR is selected, then we need a MAC to calculate and attach a tag to every message.
340
+ Encryption provides _confidentiality_, message authentication code provides
341
+ _integrity_. We need both. If an AE cipher mode is selected, then extra MACs are
342
+ not used, the integrity is already given. If CTR is selected, then we need a MAC
343
+ to calculate and attach a tag to every message.
321
344
 
322
- There are multiple ways to combine ciphers and MACs - not all of these are useful.
323
- The 3 most common:
345
+ There are multiple ways to combine ciphers and MACs - not all of these are
346
+ useful. The 3 most common:
324
347
 
325
- - _Encrypt-then-MAC_: encrypt the message, then attach the MAC of the ciphertext.
348
+ - _Encrypt-then-MAC_: encrypt the message, then attach the MAC of the
349
+ ciphertext.
326
350
  - _MAC-then-encrypt_: attach the MAC of the plaintext, then encrypt everything.
327
351
  - _Encrypt-and-MAC_: encrypt the message, then attach the MAC of the plaintext.
328
352
 
329
- Only Encrypt-then-MAC should be used, period.
330
- Using MAC-then-encrypt have lead to many attacks on TLS while Encrypt-and-MAC have lead to not quite that many attacks on SSH.
331
- The reason for this is that the more you fiddle with an attacker provided message, the more chance the attacker has to gain information through side channels.
332
- In case of Encrypt-then-MAC, the MAC is verified and if incorrect, discarded.
333
- Boom, one step, no timing channels.
334
- In case of MAC-then-encrypt, first the attacker provided message has to be decrypted and only then can you verify it.
335
- Decryption failure (due to invalid CBC padding for example) may take less time than verification failure.
336
- Encrypt-and-MAC also has to be decrypted first, leading to the same kind of potential side channels.
337
- It's even worse because no one said that a MAC's output can't leak what its input was.
338
- SSH by default, uses this method.
353
+ Only Encrypt-then-MAC should be used, period. Using MAC-then-encrypt have lead
354
+ to many attacks on TLS while Encrypt-and-MAC have lead to not quite that many
355
+ attacks on SSH. The reason for this is that the more you fiddle with an attacker
356
+ provided message, the more chance the attacker has to gain information through
357
+ side channels. In case of Encrypt-then-MAC, the MAC is verified and if
358
+ incorrect, discarded. Boom, one step, no timing channels. In case of
359
+ MAC-then-encrypt, first the attacker provided message has to be decrypted and
360
+ only then can you verify it. Decryption failure (due to invalid CBC padding for
361
+ example) may take less time than verification failure. Encrypt-and-MAC also has
362
+ to be decrypted first, leading to the same kind of potential side channels. It's
363
+ even worse because no one said that a MAC's output can't leak what its input
364
+ was. SSH by default, uses this method.
339
365
 
340
366
  Here are the available MAC choices:
341
367
 
@@ -358,20 +384,14 @@ Here are the available MAC choices:
358
384
 
359
385
  The selection considerations:
360
386
 
361
- - _Security of the hash algorithm_:
362
- No MD5 and SHA1.
363
- Yes, I know that HMAC-SHA1 does not need collision resistance but why wait?
364
- Disable weak crypto today.
365
- - _Encrypt-then-MAC_:
366
- I am not aware of a security proof for CTR-and-HMAC but I also don't think CTR decryption can fail.
367
- Since there are no downgrade attacks, you can add them to the end of the list.
368
- You can also do this on a host by host basis so you know which ones are less safe.
369
- - _Tag size_:
370
- At least 128 bits.
371
- This eliminates umac-64-etm.
372
- - _Key size_:
373
- At least 128 bits.
374
- This doesn't eliminate anything at this point.
387
+ - _Security of the hash algorithm_: No MD5 and SHA1. Yes, I know that HMAC-SHA1
388
+ does not need collision resistance but why wait? Disable weak crypto today.
389
+ - _Encrypt-then-MAC_: I am not aware of a security proof for CTR-and-HMAC but I
390
+ also don't think CTR decryption can fail. Since there are no downgrade
391
+ attacks, you can add them to the end of the list. You can also do this on a
392
+ host by host basis so you know which ones are less safe.
393
+ - _Tag size_: At least 128 bits. This eliminates umac-64-etm.
394
+ - _Key size_: At least 128 bits. This doesn't eliminate anything at this point.
375
395
 
376
396
  Recommended `/etc/ssh/sshd_config` snippet:
377
397
 
@@ -384,55 +404,54 @@ Recommended `/etc/ssh/ssh_config` snippet:
384
404
 
385
405
  # Preventing key theft
386
406
 
387
- Even with forward secrecy the secret keys must be kept secret.
388
- The NSA has a database of stolen keys - you do not want your key there.
407
+ Even with forward secrecy the secret keys must be kept secret. The NSA has a
408
+ database of stolen keys - you do not want your key there.
389
409
 
390
410
  ---
391
411
 
392
412
  ## System hardening
393
413
 
394
- OpenSSH has some undocumented, and rarely used features.
395
- UseRoaming is one such feature with a [known vulnerability][useroaming].
414
+ OpenSSH has some undocumented, and rarely used features. UseRoaming is one such
415
+ feature with a [known vulnerability][useroaming].
396
416
 
397
417
  Recommended `/etc/ssh/ssh_config` snippet:
398
418
 
399
419
  <pre><code id="client-features">Host *
400
420
  UseRoaming no</code></pre>
401
421
 
402
- This post is not intended to be a comprehensive system security guide.
403
- Very briefly:
404
-
405
- - _Don't install what you don't need_:
406
- Every single line of code has a chance of containing a bug.
407
- Some of these bugs are security holes.
408
- Fewer lines, fewer holes.
409
- - _Use free software_:
410
- As in speech.
411
- You want to use code that's actually reviewed or that you can review yourself.
412
- There is no way to achieve that without source code.
413
- Someone may have reviewed proprietary crap but who knows.
414
- - _Keep your software up to date_:
415
- New versions often fix critical security holes.
416
- - _Exploit mitigation_:
417
- Sad but true - there will always be security holes in your software.
418
- There are things you can do to prevent their exploitation, such as GCC's -fstack-protector.
419
- One of the best security projects out there is [Grsecurity][grsec].
420
- Use it or use OpenBSD.
422
+ This post is not intended to be a comprehensive system security guide. Very
423
+ briefly:
424
+
425
+ - _Don't install what you don't need_: Every single line of code has a chance of
426
+ containing a bug. Some of these bugs are security holes. Fewer lines, fewer
427
+ holes.
428
+ - _Use free software_: As in speech. You want to use code that's actually
429
+ reviewed or that you can review yourself. There is no way to achieve that
430
+ without source code. Someone may have reviewed proprietary crap but who knows.
431
+ - _Keep your software up to date_: New versions often fix critical security
432
+ holes.
433
+ - _Exploit mitigation_: Sad but true - there will always be security holes in
434
+ your software. There are things you can do to prevent their exploitation, such
435
+ as GCC's -fstack-protector. One of the best security projects out there is
436
+ [Grsecurity][grsec]. Use it or use OpenBSD.
421
437
 
422
438
  ---
423
439
 
424
440
  ## Traffic analysis resistance
425
441
 
426
- Set up [Tor hidden services][tor-hs] for your SSH servers.
427
- This has multiple advantages.
428
- It provides an additional layer of encryption and server authentication.
429
- People looking at your traffic will not know your IP, so they will be unable to scan and target other services running on the same server and client.
430
- Attackers can still attack these services but don't know if it has anything to do with the observed traffic until they actually break in.
442
+ Set up [Tor hidden services][tor-hs] for your SSH servers. This has multiple
443
+ advantages. It provides an additional layer of encryption and server
444
+ authentication. People looking at your traffic will not know your IP, so they
445
+ will be unable to scan and target other services running on the same server and
446
+ client. Attackers can still attack these services but don't know if it has
447
+ anything to do with the observed traffic until they actually break in.
431
448
 
432
- Now this is only true if you don't disclose your SSH server's fingerprint in any other way.
433
- You should only accept connections from the hidden service or from LAN, if required.
449
+ Now this is only true if you don't disclose your SSH server's fingerprint in any
450
+ other way. You should only accept connections from the hidden service or from
451
+ LAN, if required.
434
452
 
435
- If you don't need LAN access, you can add the following line to `/etc/ssh/sshd_config`:
453
+ If you don't need LAN access, you can add the following line to
454
+ `/etc/ssh/sshd_config`:
436
455
 
437
456
  <pre><code id="localhost-only">ListenAddress 127.0.0.1:22</code></pre>
438
457
 
@@ -441,10 +460,10 @@ Add this to `/etc/tor/torrc`:
441
460
  <pre><code id="hidden-service">HiddenServiceDir /var/lib/tor/hidden_service/ssh
442
461
  HiddenServicePort 22 127.0.0.1:22</code></pre>
443
462
 
444
- You will find the hostname you have to use in `/var/lib/tor/hidden_service/ssh/hostname`.
445
- You also have to configure the client to use Tor.
446
- For this, socat will be needed.
447
- Add the following line to `/etc/ssh/ssh_config`:
463
+ You will find the hostname you have to use in
464
+ `/var/lib/tor/hidden_service/ssh/hostname`. You also have to configure the
465
+ client to use Tor. For this, socat will be needed. Add the following line to
466
+ `/etc/ssh/ssh_config`:
448
467
 
449
468
  <pre><code id="onion-proxy">Host *.onion
450
469
  ProxyCommand socat - SOCKS4A:localhost:%h:%p,socksport=9050
@@ -452,45 +471,47 @@ Add the following line to `/etc/ssh/ssh_config`:
452
471
  Host *
453
472
  ...</code></pre>
454
473
 
455
- If you want to allow connections from LAN, don't use the `ListenAddress` line, configure your firewall instead.
474
+ If you want to allow connections from LAN, don't use the `ListenAddress` line,
475
+ configure your firewall instead.
456
476
 
457
477
  ---
458
478
 
459
479
  ## Key storage
460
480
 
461
- You should encrypt your client key files using a strong password.
462
- Additionally, you can use `ssh-keygen -o -a $number` to slow down cracking attempts by iterating the hash function many times.
463
- You may want to store them on a pendrive and only plug it in when you want to use SSH.
464
- Are you more likely to lose your pendrive or have your system compromised?
465
- I don't know.
481
+ You should encrypt your client key files using a strong password. Additionally,
482
+ you can use `ssh-keygen -o -a $number` to slow down cracking attempts by
483
+ iterating the hash function many times. You may want to store them on a pendrive
484
+ and only plug it in when you want to use SSH. Are you more likely to lose your
485
+ pendrive or have your system compromised? I don't know.
466
486
 
467
- Unfortunately, you can't encrypt your server key and it must be always available, or else sshd won't start.
468
- The only thing protecting it is OS access controls.
487
+ Unfortunately, you can't encrypt your server key and it must be always
488
+ available, or else sshd won't start. The only thing protecting it is OS access
489
+ controls.
469
490
 
470
491
  ---
471
492
 
472
493
  # The end
473
494
 
474
- It's probably a good idea to test the changes.
475
- `ssh -v` will print the selected algorithms and also makes problems easier to spot.
476
- Be extremely careful when configuring SSH on a remote host.
477
- Always keep an active session, never restart sshd.
478
- Instead you can send the `SIGHUP` signal to reload the configuration without killing your session.
479
- You can be even more careful by starting a new sshd instance on a different port and testing that.
495
+ It's probably a good idea to test the changes. `ssh -v` will print the selected
496
+ algorithms and also makes problems easier to spot. Be extremely careful when
497
+ configuring SSH on a remote host. Always keep an active session, never restart
498
+ sshd. Instead you can send the `SIGHUP` signal to reload the configuration
499
+ without killing your session. You can be even more careful by starting a new
500
+ sshd instance on a different port and testing that.
480
501
 
481
- Can you make these changes?
482
- If the answer is yes, then...
502
+ Can you make these changes? If the answer is yes, then...
483
503
 
484
- ![NSA Happy Dance](https://raw.githubusercontent.com/netwk-pro/netwk-pro.github.io/refs/heads/master/assets/nsa-happy-dance.png "Happy Dance!!")
504
+ ![NSA Happy Dance](https://raw.githubusercontent.com/netwk-pro/netwk-pro.github.io/refs/heads/master/assets/nsa-happy-dance.png 'Happy Dance!!')
485
505
 
486
- If the answer is no, it's probably due to compatibility problems.
487
- You can try to convince the other side to upgrade their security and turn it into a yes.
488
- I have created a [wiki page][sssh-wiki] where anyone can add config files for preserving compatibility with various SSH implementations and SSH based services.
506
+ If the answer is no, it's probably due to compatibility problems. You can try to
507
+ convince the other side to upgrade their security and turn it into a yes. I have
508
+ created a [wiki page][sssh-wiki] where anyone can add config files for
509
+ preserving compatibility with various SSH implementations and SSH based
510
+ services.
489
511
 
490
- If you work for a big company and change management doesn't let you do it, I'm sorry.
491
- I've seen the v1 protocol enabled in such places.
492
- There is no chance of improvement.
493
- Give up to preseve your sanity.
512
+ If you work for a big company and change management doesn't let you do it, I'm
513
+ sorry. I've seen the v1 protocol enabled in such places. There is no chance of
514
+ improvement. Give up to preseve your sanity.
494
515
 
495
516
  Special thanks to the people of Twitter for the improvements.
496
517
 
@@ -498,53 +519,66 @@ Special thanks to the people of Twitter for the improvements.
498
519
 
499
520
  # ChangeLog
500
521
 
501
- You may have noticed that this document changed since last time.
502
- I want to be very transparent about this.
503
- There were three major changes:
504
-
505
- - After some debate and going back and forth between including GCM or not, it's now back again.
506
- The reason for dropping it was that SSH doesn't encrypt packet sizes when using GCM.
507
- The reason for bringing it back is that SSH does the same with any EtM algorithms.
508
- There is no way around this unless you can live with chacha20-poly1305 only.
509
- Also, the leaked documents don't sound like they can figure out the lengths or confirm presence of some things, more like straight up "send it to us and we'll decrypt it for you".
510
- Wrapping SSH in a Tor hidden service will take care of any traffic analysis concerns.
522
+ You may have noticed that this document changed since last time. I want to be
523
+ very transparent about this. There were three major changes:
524
+
525
+ - After some debate and going back and forth between including GCM or not, it's
526
+ now back again. The reason for dropping it was that SSH doesn't encrypt packet
527
+ sizes when using GCM. The reason for bringing it back is that SSH does the
528
+ same with any EtM algorithms. There is no way around this unless you can live
529
+ with chacha20-poly1305 only. Also, the leaked documents don't sound like they
530
+ can figure out the lengths or confirm presence of some things, more like
531
+ straight up "send it to us and we'll decrypt it for you". Wrapping SSH in a
532
+ Tor hidden service will take care of any traffic analysis concerns.
511
533
  - I'm now allowing Encrypt-and-MAC algorithms with CTR ciphers as a last resort.
512
- I initially thought it was possible to use downgrade attacks, I now think it is not.
513
- - I briefly disabled RSA because it uses SHA1, this turned out to be a non-issue because we're signing SHA2 hashes.
514
-
515
- You can see the [full list of changes][changelog] on github.
516
- I promise not to use `git push -f`.
517
-
518
- [snowden-docs]: <https://www.spiegel.de/international/germany/inside-the-nsa-s-war-on-internet-security-a-1010361.html>)
519
- [compat]: <http://ssh-comparison.quendi.de/comparison.html>
534
+ I initially thought it was possible to use downgrade attacks, I now think it
535
+ is not.
536
+ - I briefly disabled RSA because it uses SHA1, this turned out to be a non-issue
537
+ because we're signing SHA2 hashes.
538
+
539
+ You can see the [full list of changes][changelog] on github. I promise not to
540
+ use `git push -f`.
541
+
542
+ [snowden-docs]:
543
+ <https://www.spiegel.de/international/germany/inside-the-nsa-s-war-on-internet-security-a-1010361.html>)
544
+ [compat]:
545
+ <http://ssh-comparison.quendi.de/comparison.html>
520
546
  [dh]: <https://en.wikipedia.org/wiki/Diffie%E2%80%93Hellman_key_exchange>
521
547
  [ecdh]: <https://en.wikipedia.org/wiki/Elliptic_curve_Diffie%E2%80%93Hellman>
522
548
  [forward-secrecy]: <https://en.wikipedia.org/wiki/Forward_secrecy>
523
549
  [dlp]: <https://en.wikipedia.org/wiki/Discrete_logarithm_problem>
524
550
  [libsshdoc]: <https://git.libssh.org/projects/libssh.git/tree/doc/curve25519-sha256@libssh.org.txt>
525
- [curve25519]: <https://cr.yp.to/ecdh.html>
551
+ [curve25519]:
552
+ <https://cr.yp.to/ecdh.html>
526
553
  [rfc4253]: <https://www.ietf.org/rfc/rfc4253.txt>
527
554
  [dh-draft]: <https://tools.ietf.org/html/draft-ietf-curdle-ssh-modp-dh-sha2-09>
528
- [73release]: <https://www.openssh.com/releasenotes.html#7.3>
555
+ [73release]:
556
+ <https://www.openssh.com/releasenotes.html#7.3>
529
557
  [76release]: <https://www.openssh.com/releasenotes.html#7.6>
530
558
  [rfc4419]: <https://www.ietf.org/rfc/rfc4419.txt>
531
559
  [ed25519]: <https://ed25519.cr.yp.to/>
532
560
  [google-auth]: <https://github.com/google/google-authenticator/wiki/PAM-Module-Instructions>
533
- [totp]: <https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm>
561
+ [totp]:
562
+ <https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm>
534
563
  [otp]: <https://www.cl.cam.ac.uk/~mgk25/otpw.html>
535
564
  [pam]: <https://en.wikipedia.org/wiki/Pluggable_authentication_module>
536
565
  [nist-sucks]: <https://blog.cr.yp.to/20140323-ecdsa.html>
537
566
  [bullrun]: <https://projectbullrun.org/dual-ec/vulnerability.html>
538
567
  [ecdsa-same-k]: <https://security.stackexchange.com/a/46781>
539
568
  [ecdsa-sony]: <https://events.ccc.de/congress/2010/Fahrplan/attachments/1780%5F27c3%5Fconsole%5Fhacking%5F2010.pdf>
540
- [ae]: <https://en.wikipedia.org/wiki/Authenticated_encryption>
569
+ [ae]:
570
+ <https://en.wikipedia.org/wiki/Authenticated_encryption>
541
571
  [aes-gcm]: <http://blog.djm.net.au/2013/11/chacha20-and-poly1305-in-openssh.html>
542
- [useroaming]: <https://security.stackexchange.com/questions/110639/how-exploitable-is-the-recent-useroaming-ssh-problem>
543
- [grsec]: <https://grsecurity.net/>
572
+ [useroaming]:
573
+ <https://security.stackexchange.com/questions/110639/how-exploitable-is-the-recent-useroaming-ssh-problem>
574
+ [grsec]:
575
+ <https://grsecurity.net/>
544
576
  [tor-hs]: <https://www.torproject.org/docs/hidden-services.html.en>
545
577
  [sssh-wiki]: <https://github.com/stribika/stribika.github.io/wiki/Secure-Secure-Shell>
546
- [changelog]: <https://github.com/stribika/stribika.github.io/commits/master/_posts/2015-01-04-secure-secure-shell.md>
547
- [bug779880]: <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779880>
578
+ [changelog]:
579
+ <https://github.com/stribika/stribika.github.io/commits/master/_posts/2015-01-04-secure-secure-shell.md>
580
+ [bug779880]:
581
+ <https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=779880>
548
582
  [sloth]: <https://www.mitls.org/downloads/transcript-collisions.pdf>
549
583
 
550
584
  &nbsp;