LoginSignup
9
9

More than 5 years have passed since last update.

Amazon Linux 2のsshサーバをよりセキュアに! 

Posted at

概要

Amazon Linux 2(ami-2724cf58)を外部の脆弱診断サービスを通して、検出されたsshサーバの脆弱性に対する対処法を紹介したいと思います
脆弱診断はしていませんが、先日正式リリースされたAmazon Linux 2(ami-e99f4896)でも同じような初期設定になっていたので、以下の対策は有効的だと思います

検出された脆弱性

まず、今回脆弱性が検出されたAmazon Linux 2の対処法について紹介したいと思います
Amazon LinuxはAmazonがカスタマイズしていることもあって、緊急を要する脆弱性は検出されませんでした
以下の2つの脆弱性になりうる問題が検出されました

  • 共通鍵暗号方式にCBC(Cipher Block Chaining)が利用できる問題
  • 共通鍵交換アルゴリズムで脆弱性のあるの鍵が利用できる問題

この二つは最新のOpenSSH 7.7(2018.6.17時点)にアップデートすることで解決できるかと思います

SSHクライアントの設定

下記の設定を行った後で、SSHクライアントで上記の暗号方式に対応していない場合は、
追加の設定やバージョンアップが必要になる場合もありますので、お忘れなく!
また、SSH鍵を再生成しなければならないこともありますので、予めSSH鍵生成&サーバに登録してから疎通確認した上で下記の対応を行ってください!

脆弱の確認方法

ssh接続時の通信ログで確認することができます

  • -vvv・・・通信ログを確認することができます
  • <private key>・・・秘密鍵
  • <user>・・・接続ユーザ
  • <remote server ip>・・・接続先のIP(ホスト名)
> ssh -i <private key> <user>@<remote server ip> -vvv


# local clientのあとがsshクライアントの情報になります
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,ext-info-c
debug2: host key algorithms: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1

# peer serverのあとがsshサーバの情報になります
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: host key algorithms: ssh-rsa,rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: MACs ctos: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1

共通鍵暗号方式にCBC(Cipher Block Chaining)が利用できる問題

CPNI-957037

修正前の確認

ciphers ctosとciphers stocに脆弱性のあるaes128-cbc、aes192-cbc、aes256-cbc、blowfish-cbc、cast128-cbc、3des-cbcが使えることを確認できます

debug2: peer server KEXINIT proposal
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,cast128-cbc,3des-cbc
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com,aes128-cbc,aes192-cbc,aes256-cbc,blowfish-cbc,cast128-cbc,3des-cbc

修正方法

xxxxx-cbcを除くciphersを設定します

/etc/ssh/sshd_config
Ciphers chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com

修正後の確認

sshdの再起動をお忘れずに!

xxxxx-cbcがないことが確認できます

debug2: peer server KEXINIT proposal
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com

共通鍵交換アルゴリズムで脆弱性のあるの鍵が利用できる問題

修正前の確認

鍵交換アルゴリズムが弱いecdh-sha2-nistp256、ecdh-sha2-nistp384、ecdh-sha2-nistp521、diffie-hellman-group-exchange-sha1、diffie-hellman-group14-sha1、diffie-hellman-group1-sha1が含まれていることを確認できます

debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha256,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

修正方法

OpenSSH 7.3以上を利用している場合は、diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256も追加してください

/etc/ssh/sshd_config
KexAlgorithms curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256

修正後の確認

sshdの再起動をお忘れずに!

debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256@libssh.org,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256

/etc/ssh/moduliの修正

SSHセッション開始時に生成する共有秘密鍵の強度を高めるために、2048bit未満の鍵を生成しないように以下の設定を行う必要があります

/etc/ssh/moduli
# Time         Type Tests Tries Size Generator Modulus
20150520233853 2    6     100   1023 5 DB662973FB21C0B7BF21AB46AFD3E2002AE70C92DE6B9AEAFECF7B0A96D7ACB024B7C29DB18E70CB945FA54
C7773519BC7161648AFE4939058AC40ECDBBD3636F5BF45863117E955007C9D0F9333BB4EF62F7C9F6298AB79A309C734F3CF201C61EBC3926ADD
4E80968A65D9F60535164ACE7A7BFEDC1022002BB2BBA2AC62AF

moduliの5カラム目(size)の値が2000以上の行を抽出し、上書きする


awk '$5 > 2000' /etc/ssh/moduli > "${HOME}/moduli"
wc -l "${HOME}/moduli"
mv "${HOME}/moduli" /etc/ssh/moduli

参照

9
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
9