【RHEL9】sshd_configで制御できないSSHの暗号化アルゴリズム脆弱性を塞ぐ

【RHEL9】sshd_configで制御できないSSHの暗号化アルゴリズム脆弱性を塞ぐ

概要

RHEL9(およびAlmaLinux9, Rocky9など)では、SSHの暗号化アルゴリズムやハッシュ方式が OpenSSLポリシー(crypto policy) で一括制御される。
そのため、/etc/ssh/sshd_config を編集しても、脆弱なSHA-1や古い暗号が残る場合がある。
この記事では、暗号ポリシーの確認からSHA-1の無効化、検証までの手順を整理する。


1. 暗号化アルゴリズムの制御構造を理解する

RHEL9では、SSHサーバ(sshd)の暗号制御はOpenSSLを経由して行われる。
そのため、sshd_config のみで脆弱なアルゴリズムを除外しても、OS全体のポリシーが優先される。


2. デフォルトの暗号化アルゴリズムポリシーを確認

まず、現在のシステム暗号ポリシーを確認する。

# update-crypto-policies --show

[root@localhost ~]# update-crypto-policies --show
DEFAULT

DEFAULT はRHEL標準ポリシーで、SHA-1がまだ一部許可されている。

DEFAULTポリシーは以下に設定されている

/usr/share/crypto-policies/policies

[root@localhost ~]# cd /usr/share/crypto-policies/policies
[root@localhost policies]# ls
DEFAULT.pol  EMPTY.pol  FIPS.pol  FUTURE.pol  LEGACY.pol  modules

DEFAULT.polの中身を確認すると使用される暗号化アルゴリズムが確認できる

[root@localhost policies]# cat DEFAULT.pol
# A reasonable default for today's standards.
# It should provide 112-bit security.
# SHA1 is allowed in HMAC where collision resistance does not matter.

# MACs: all HMAC with SHA1 or better + all modern MACs (Poly1305 etc)
# Curves: all prime >= 255 bits (including Bernstein curves)
# Signature algorithms: with SHA-224 hash or better (no DSA)
# Ciphers: >= 128-bit key, >= 128-bit block (AES, ChaCha20)
# key exchange: ECDHE, RSA, DHE (no DHE-DSS)
# DH params size: >= 2048
# RSA params size: >= 2048
# TLS protocols: TLS >= 1.2, DTLS >= 1.2

mac = AEAD HMAC-SHA2-256 HMAC-SHA1 UMAC-128 HMAC-SHA2-384 HMAC-SHA2-512
mac@Kerberos = HMAC-SHA2-384 HMAC-SHA2-256 AEAD UMAC-128 HMAC-SHA2-512 HMAC-SHA1

group = X25519 SECP256R1 X448 SECP521R1 SECP384R1 \
        FFDHE-2048 FFDHE-3072 FFDHE-4096 FFDHE-6144 FFDHE-8192

hash = SHA2-256 SHA2-384 SHA2-512 SHA3-256 SHA3-384 SHA3-512 SHA2-224 SHA3-224 \
       SHAKE-256

sign = ECDSA-SHA3-256 ECDSA-SHA2-256 ECDSA-SHA2-256-FIDO \
       ECDSA-SHA3-384 ECDSA-SHA2-384 \
       ECDSA-SHA3-512 ECDSA-SHA2-512 \
       EDDSA-ED25519 EDDSA-ED25519-FIDO EDDSA-ED448 \
       RSA-PSS-SHA3-256 RSA-PSS-SHA2-256 \
       RSA-PSS-SHA3-384 RSA-PSS-SHA2-384 \
       RSA-PSS-SHA3-512 RSA-PSS-SHA2-512 \
       RSA-PSS-RSAE-SHA3-256 RSA-PSS-RSAE-SHA2-256 \
       RSA-PSS-RSAE-SHA3-384 RSA-PSS-RSAE-SHA2-384 \
       RSA-PSS-RSAE-SHA3-512 RSA-PSS-RSAE-SHA2-512 \
       RSA-SHA3-256 RSA-SHA2-256 \
       RSA-SHA3-384 RSA-SHA2-384 \
       RSA-SHA3-512 RSA-SHA2-512 \
       ECDSA-SHA2-224 RSA-PSS-SHA2-224 RSA-SHA2-224 \
       ECDSA-SHA3-224 RSA-PSS-SHA3-224 RSA-SHA3-224

cipher = AES-256-GCM AES-256-CCM CHACHA20-POLY1305 \
    AES-256-CTR AES-256-CBC \
    AES-128-GCM AES-128-CCM \
    AES-128-CTR AES-128-CBC

cipher@TLS = AES-256-GCM AES-256-CCM CHACHA20-POLY1305 AES-256-CBC \
    AES-128-GCM AES-128-CCM AES-128-CBC


# CBC ciphers in SSH are considered vulnerable to plaintext recovery attacks
# and disabled in client OpenSSH 7.6 (2017) and server OpenSSH 6.7 (2014).
cipher@SSH = -*-CBC

# 'RSA' is intentionally before DHE ciphersuites, as the DHE ciphersuites have
# interoperability issues in TLS.
key_exchange = ECDHE RSA DHE DHE-RSA PSK DHE-PSK ECDHE-PSK RSA-PSK ECDHE-GSS DHE-GSS

protocol@TLS = TLS1.3 TLS1.2 DTLS1.2
protocol@IKE = IKEv2

# Parameter sizes
min_dh_size = 2048
min_dsa_size = 2048  # DSA is disabled
min_rsa_size = 2048

# GnuTLS only for now
sha1_in_certs = 0

arbitrary_dh_groups = 1
ssh_certs = 1
etm@SSH = ANY

DEFAULTではHMAC-SHA1が許可されていることがわかる。
より制限の厳しい FUTURE やカスタムポリシーを設定することで、SHA-1などの脆弱アルゴリズムを無効化できる。


3. nmapでデフォルトポリシーの確認

暗号ポリシー適用前後で、SSHが実際にどのアルゴリズムを受け入れているかをnmapで確認する。

まずはnmapをインストールする

dnf install -y nmap

暗号スキャンする

nmap --script ssh2-enum-algos -p 22 localhost

出力(DEFAULTポリシー)

[root@localhost ~]# nmap --script ssh2-enum-algos -p 22 localhost
Starting Nmap 7.92 ( https://nmap.org ) at 2025-11-09 00:56 JST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000069s latency).
Other addresses for localhost (not scanned): ::1

PORT   STATE SERVICE
22/tcp open  ssh
| ssh2-enum-algos:
|   kex_algorithms: (10)
|       curve25519-sha256
|       curve25519-sha256@libssh.org
|       ecdh-sha2-nistp256
|       ecdh-sha2-nistp384
|       ecdh-sha2-nistp521
|       diffie-hellman-group-exchange-sha256
|       diffie-hellman-group14-sha256
|       diffie-hellman-group16-sha512
|       diffie-hellman-group18-sha512
|       kex-strict-s-v00@openssh.com
|   server_host_key_algorithms: (4)
|       rsa-sha2-512
|       rsa-sha2-256
|       ecdsa-sha2-nistp256
|       ssh-ed25519
|   encryption_algorithms: (5)
|       aes256-gcm@openssh.com
|       chacha20-poly1305@openssh.com
|       aes256-ctr
|       aes128-gcm@openssh.com
|       aes128-ctr
|   mac_algorithms: (8)
|       hmac-sha2-256-etm@openssh.com
|       hmac-sha1-etm@openssh.com
|       umac-128-etm@openssh.com
|       hmac-sha2-512-etm@openssh.com
|       hmac-sha2-256
|       hmac-sha1
|       umac-128@openssh.com
|       hmac-sha2-512
|   compression_algorithms: (2)
|       none
|_      zlib@openssh.com

Nmap done: 1 IP address (1 host up) scanned in 0.30 seconds

ここで hmac-sha1が残っていることが確認できる。


4. ssh -vv でクライアント側からの確認

nmapが使用できない場合はsshのデバッグモードを使用して確認できる。
自端末からlocalhostに対しコマンドを実行し、使用中のアルゴリズムを確認する。

# ssh -vv localhost

出力はdebug2: peer server KEXINIT proposalの結果を確認する

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-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,kex-strict-s-v00@openssh.com
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
debug2: ciphers stoc: aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
debug2: MACs ctos: hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512
debug2: MACs stoc: hmac-sha2-256-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,hmac-sha1,umac-128@openssh.com,hmac-sha2-512
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0

nmapの出力と同じであり、hmac-sha1アルゴリズムが利用されていることが確認できる


5. SHA-1を削除する(カスタムポリシー作成)

/etc/crypto-policies/policies/modules/ にカスタムモジュールを作成することで、
独自のポリシーを適用できる。

hmac-sha1アルゴリズムを除いたカスタムポリシーを作成する
# vi /etc/crypto-policies/policies/modules/DEL_SHA1.pmod

[root@localhost policies]# vi /etc/crypto-policies/policies/modules/DEL_SHA1.pmod
# Disable HMAC-SHA1
mac = -HMAC-SHA1

作成したカスタムモジュールを読み込むように設定する。

update-crypto-policies --set DEFAULT:DEL_SHA1

[root@localhost policies]# update-crypto-policies --set DEFAULT:DEL_SHA1
Setting system policy to DEFAULT:DEL_SHA1
Note: System-wide crypto policies are applied on application start-up.
It is recommended to restart the system for the change of policies
to fully take place.
[root@localhost policies]#

ポリシー設定が反映されたか確認する

update-crypto-policies --show

[root@localhost policies]# update-crypto-policies --show
DEFAULT:DEL_SHA1
[root@localhost policies]#

sshdを再起動して設定を反映させる

systemctl restart sshd

nmapssh -vvで設定反映を確認する

[root@localhost policies]# nmap --script ssh2-enum-algos -p 22 localhost
Starting Nmap 7.92 ( https://nmap.org ) at 2025-11-09 01:35 JST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000046s latency).
Other addresses for localhost (not scanned): ::1

PORT   STATE SERVICE
22/tcp open  ssh
| ssh2-enum-algos:
|   kex_algorithms: (10)
|       curve25519-sha256
|       curve25519-sha256@libssh.org
|       ecdh-sha2-nistp256
|       ecdh-sha2-nistp384
|       ecdh-sha2-nistp521
|       diffie-hellman-group-exchange-sha256
|       diffie-hellman-group14-sha256
|       diffie-hellman-group16-sha512
|       diffie-hellman-group18-sha512
|       kex-strict-s-v00@openssh.com
|   server_host_key_algorithms: (4)
|       rsa-sha2-512
|       rsa-sha2-256
|       ecdsa-sha2-nistp256
|       ssh-ed25519
|   encryption_algorithms: (5)
|       aes256-gcm@openssh.com
|       chacha20-poly1305@openssh.com
|       aes256-ctr
|       aes128-gcm@openssh.com
|       aes128-ctr
|   mac_algorithms: (6)
|       hmac-sha2-256-etm@openssh.com
|       umac-128-etm@openssh.com
|       hmac-sha2-512-etm@openssh.com
|       hmac-sha2-256
|       umac-128@openssh.com
|       hmac-sha2-512
|   compression_algorithms: (2)
|       none
|_      zlib@openssh.com

Nmap done: 1 IP address (1 host up) scanned in 0.17 seconds
[root@localhost policies]# ssh -vv localhost
(省略)
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-group14-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,kex-strict-s-v00@openssh.com
debug2: host key algorithms: rsa-sha2-512,rsa-sha2-256,ecdsa-sha2-nistp256,ssh-ed25519
debug2: ciphers ctos: aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
debug2: ciphers stoc: aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
debug2: MACs ctos: hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,umac-128@openssh.com,hmac-sha2-512
debug2: MACs stoc: hmac-sha2-256-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha2-256,umac-128@openssh.com,hmac-sha2-512
debug2: compression ctos: none,zlib@openssh.com
debug2: compression stoc: none,zlib@openssh.com
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0

これでhmac-sha1アルゴリズムは無効化されたことがわかる。


8. まとめ

  • RHEL9では/etc/ssh/sshd_configよりもOpenSSLポリシーが優先される
  • 脆弱なSHA-1を無効化するには、update-crypto-policiesでシステムレベルの変更が必要

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *