AlmaLinxuでのSSHセキュリティ弱体化攻撃「Terrapin」の暫定対処

# 結論
1. `/etc/crypto-policies/back-ends/opensshserver.config` のファイル修正
2. `systemctl restart sshd.service` でSSHD再起動

# 概要
SSH接続においてハンドシェイク中にシーケンス番号の操作を可能とする攻撃手法「Terrapin Attack」が報告されております
対処方法として2つあります
1. SSHを最新版にする(本対処)
1. 以下の暗号方式を無効化(暫定対処)
Ciphers chacha20-poly1305@openssh.com
MACs *etm@openssh.com

https://jvn.jp/ta/JVNTA95077890/index.html

# 事前確認
脆弱性スキャナツールがGitHubで公開されてますので、環境に応じたバイナリを取得します

https://github.com/RUB-NDS/Terrapin-Scanner/releases/tag/v1.1.2

ここではaarch64で動いている仮想マシン自身に調査してみました

```bash
$ ./Terrapin_Scanner_Linux_aarch64 -connect localhost
================================================================================
==================================== Report ====================================
================================================================================

Remote Banner: SSH-2.0-OpenSSH_8.7

ChaCha20-Poly1305 support:   true
CBC-EtM support:             false

Strict key exchange support: false

The scanned peer is VULNERABLE to Terrapin.

Note: This tool is provided as is, with no warranty whatsoever. It determines
      the vulnerability of a peer by checking the supported algorithms and
      support for strict key exchange. It may falsely claim a peer to be
      vulnerable if the vendor supports countermeasures other than strict key
      exchange.

For more details visit our website available at https://terrapin-attack.com
```

**The scanned peer is VULNERABLE to Terrapin.** と表示されているので
脆弱性がありますねー

ssh コマンドでサポートされている暗号スイートを見てみます
```bash
$ ssh -vv localhost : 2>&1 |grep ciphers |tail -1 |cut -d ' ' -f 4
aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
```
ここに"chacha20-poly1305@openssh.com"が含まれてます


# 暫定対処...できない
当初はsshd_configに設定を加えればよいと考え、下記を実施しました
```bash
sudo su -
echo 'Ciphers -chacha20-poly1305@openssh.com' > /etc/ssh/sshd_config.d/anti-terrapin-attack.conf
echo 'Ciphers -chacha20-poly1305@openssh.com' > /etc/ssh/ssh_config.d/anti-terrapin-attack.conf
systemctl restart sshd.service
```

結果は反映されませんでした:confused:

# 暫定対応できた
色々調べてみたところ、CentOS8頃から「crypto-policies」というもので
暗号スイートを管理しているとあり、確かに設定があります

```bash
# cat /etc/crypto-policies/back-ends/opensshserver.config
Ciphers aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr

###～省略～###
```
"chacha20-poly1305@openssh.com"が
「/etc/crypto-policies/back-ends/opensshserver.config」に含まれてるので、
変更して消してしまいましょう

```bash
# cat /etc/crypto-policies/back-ends/opensshserver.config
#Ciphers aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
Ciphers aes256-gcm@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr

###～省略～###
```

忘れずにSSHD再起動
```bash
systemctl restart sshd.service
```

結果、脆弱性の暫定対処が完了しました
```bash
$ ./Terrapin_Scanner_Linux_aarch64 -connect localhost
================================================================================
==================================== Report ====================================
================================================================================

Remote Banner: SSH-2.0-OpenSSH_8.7

ChaCha20-Poly1305 support:   false
CBC-EtM support:             false

Strict key exchange support: false

The scanned peer supports Terrapin mitigations and can establish
connections that are NOT VULNERABLE to Terrapin. Glad to see this.
For strict key exchange to take effect, both peers must support it.

Note: This tool is provided as is, with no warranty whatsoever. It determines
      the vulnerability of a peer by checking the supported algorithms and
      support for strict key exchange. It may falsely claim a peer to be
      vulnerable if the vendor supports countermeasures other than strict key
      exchange.

For more details visit our website available at https://terrapin-attack.com
```

暗号スイートを確認しても"chacha20-poly1305@openssh.com"が消えてますね
```bash
$ ssh -vv localhost : 2>&1 |grep ciphers |tail -1 |cut -d ' ' -f 4
aes256-gcm@openssh.com,aes256-ctr,aes128-gcm@openssh.com,aes128-ctr
```

### 参考文献
https://qiita.com/raccy/items/c06b133c5674bc9061d1