Ssh

伺服器 ssh 證書鏈對抗 MITM 攻擊?

  • February 15, 2019

在第一次通過 ssh 與伺服器聯繫期間,將所選密鑰算法的伺服器公鑰呈現給使用者以對其進行驗證。驗證後,通常將結果保存到~/.ssh/known_hosts文件中以應對以後的 MITM 攻擊。

$ ssh host.example.com
The authenticity of host 'host.example.com (1.2.3.4)' can't be established.
ECDSA key fingerprint is SHA256:xxxxxxxxxxxxx.
Are you sure you want to continue connecting (yes/no)?

這顯然無助於第一次連接上的 MITM 攻擊,只會將問題轉移給使用者,使用者現在必須有一些流程來驗證提供的公鑰——我們都知道結果如何。

是否可以分發與公司 CA 簽署的 ssh 伺服器密鑰以在第一次聯繫時對抗 MITM 攻擊?帶有證書鏈的公私鑰基礎設施通常支持這一點——但我從未見過它在公司環境中用於保護 ssh 伺服器。

一般的想法是信任一組主機的 CA 密鑰:

trust *.example.com SHA256:<fingerprint(public key(corporate-ca))>

並且每個掌握這一點並已由 CA 簽名的主機都是受信任的:

ca.example.com
+- host.example.com

這類似於 HTTPS 的保護方式,並且由於 ssh 使用相同的底層技術 - 是否已經在 OpenSSH 中實現了類似的東西,而我只是沒有找到它?

這個有可能。

引用文件

AUTHORIZED_KEYS FILE FORMAT
[...]
    cert-authority
            Specifies that the listed key is a certification authority (CA)
            that is trusted to validate signed certificates for user authentication.

            Certificates may encode access restrictions similar to these key options.
            If both certificate restrictions and key options are present, the most
            restrictive union of the two is applied.

實現這一目標的步驟:

  • 生成 SSH 伺服器 CA 密鑰:
ssh-keygen -f server_ca
  • 生成 SSH 伺服器主機密鑰:
ssh-keygen -t ecdsa -b 521 -N '' -C 'somehost.example.com' -f ssh-ecdsa.key
  • 使用您的 ca 密鑰簽署主機密鑰:
ssh-keygen -s server_ca -I somehost.example.com -h -n 'somehost.example.com,somehost,<list of SANs>,<list of IPv4>,<list of IPv6>' -V +3650d ssh-ecdsa.key
  • 在您的 SSH 伺服器中部署主機密鑰 + 證書(將證書和密鑰複製到/etc/ssh,編輯/etc/ssh/sshd_config):
HostCertificate /etc/ssh/ssh-ecdsa.key-cert.pub
HostKey /etc/ssh/ssh-ecdsa.key
  • 設置您的客戶端以信任您的 CA 密鑰以辨識主機 (~/.ssh/known_hosts)
@cert-authority example.com ssh-rsa AAAA[...]

備註

  • 它與正常 X.509 PKI 不兼容。
  • 需要維護(和使用)密鑰撤銷列表 (KRL)。有關詳細資訊,請參閱OpenSSH 食譜
  • 麻煩的是,考慮使用類似Vault的東西和配置管理工具來自動執行此操作。
  • 查看Monkeysphere項目,了解“SSH 信任網路”的想法。

在下面的連結中找到更多資訊,特別是關於如何設置它來為使用者簽名密鑰。

連結:

引用自:https://serverfault.com/questions/954093