OSSTech株式会社

Lasso 脆弱性(CVE-2021-28091)のmod_auth_mellonへの影響

2021-06-07 - 相本 智仁

はじめに

先日 Lasso の脆弱性CVE-2021-28091が公開されました。 Lasso は SAML などのフェデレーションプロトコルを実装したライブラリで、SAML SP として動作するApacheモジュールの mod_auth_mellon はこのライブラリを使用しています。 Lasso で見つかった脆弱性が mod_auth_mellon で影響するか確認した所、脆弱性を突いた攻撃は成立しないことがわかりました。 どうして攻撃は成立しないのか解説します。

Lassoの脆弱性CVE-2021-28091

今回発見された Lasso の脆弱性は次のように公開されています。

Fix signature checking on unsigned response with multiple assertions

When AuthnResponse messages are not signed (which is permitted by the specifiation), all assertion’s signatures should be checked, but currently after the first signed assertion is checked all following assertions are accepted without checking their signature, and the last one is considered the main assertion.

Lasso は IdP からの AuthnResponse に複数のSAMLアサーションが含まれている場合、 最初のアサーションのみ署名をチェックし、残りのアサーションの署名はチェックしないとあります。

multiple assertions(複数のSAMLアサーション)とは次のようなものです。

<samlp:Response >
    <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion">https://ubuntu-openam.example.co.jp:8443/openam</saml:Issuer>
    <samlp:Status xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol">
        <samlp:StatusCode xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol"
                          Value="urn:oasis:names:tc:SAML:2.0:status:Success"
                          />
    </samlp:Status>
    // アサーションその1
    <saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
                    ID="s24d6cb3fad37f5a4eacc353795cfa9fc9cd937fe6"
                    IssueInstant="2021-06-04T05:59:52Z"
                    Version="2.0"
                    >
        <saml:Issuer>https://ubuntu-openam.example.co.jp:8443/openam</saml:Issuer>
        <ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
       // 署名
        </ds:Signature>
        <saml:Subject>
        // NameID
        </saml:Subject>
        // 属性とか
    </saml:Assertion>

    // アサーションその2
    <saml:Assertion xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion"
                    ID="s24d6cb3fad37f5a4eacc353795cfa9fc9cd937fe6"
                    IssueInstant="2021-06-04T05:59:52Z"
                    Version="2.0"
                    >
        // アサーションの内容
    </saml:Assertion>
</samlp:Response>

脆弱性は Lasso が上記の2つアサーションが送られて来た際 アサーションその1の署名は検証するがアサーションその2は署名は検証しないということです。

通常IdPで発行されるSAMLレスポンスのSAMLアサーションは一つです。

ここに意図的にSAMLアサーションを追加して Lasso を使っているSPに送信した際に、 追加したSAMLアサーション込みで「IdPが発行した信頼できるアサーション」としてしまうため問題となります。

別アカウントのNameIDや属性を追加して送ることで、なりすましが出来てしまう恐れがあります。

mod_auth_mellon で影響がない理由

mod_auth_mellon ではSAMLのアサーションの数が1つであることをチェックしています。 もしSAMLレスポンスにSAMLアサーションが複数存在すると認証を成功させずステータスコード400のエラーを応答します。

mod_auth_mellon の以下のコードが該当します。

1897 static int am_handle_reply_common(request_rec *r, LassoLogin *login,
1898                                   char *relay_state, char *saml_response,
1899                                   bool is_paos)
1900 {
〜
1947     if (g_list_length(response->Assertion) == 0) {
1948         AM_LOG_RERROR(APLOG_MARK, APLOG_ERR, 0, r,
1949                       "No Assertion in response.");
1950         lasso_login_destroy(login);
1951         return HTTP_BAD_REQUEST;
1952     }
1953     if (g_list_length(response->Assertion) > 1) {
1954         AM_LOG_RERROR(APLOG_MARK, APLOG_ERR, 0, r,
1955                       "More than one Assertion in response.");
1956         lasso_login_destroy(login);
1957         return HTTP_BAD_REQUEST;
1958     }

mod_auth_mellonが CVE-2021-28091 に該当する Lasso を使用していても、 Lassoのチェックはすり抜けてしまいますが、mod_auth_mellonとしてのチェックで防ぐため今回の脆弱性が影響しません。

実際にやってみた

mod_auth_mellon に対して、下記のパターンのSAMLアサーションを送って挙動を確認しました。

  1. 署名なしのSAMLアサーション1つ送付
  2. SAMLアサーションを2つ送付(署名なし、署名ありの順番)
  3. SAMLアサーションを2つ送付(署名あり、署名なしの順番)

確認した環境のバージョンは以下のとおりです。(LassoはCVE-2021-28091に該当するバージョンです。)

# rpm -qa | grep -e mellon -e lasso
lasso-2.5.1-5.el7.x86_64
osstech-mod_auth_mellon-0.16.0-17.el7.x86_64

動作としては全てステータスコード400が応答されました。各パターンで出力されたエラーログの内容は次のとおりです。

  1. のerror_log
[Mon Jun 07 04:19:04.211916 2021] [auth_mellon:error] [pid 10] [client 172.26.0.1:53418] Error processing authn response. Lasso error: [440] The profile cannot verify a signature on the message, SAML Response: StatusCode1="urn:oasis:names:tc:SAML:2.0:status:Success", StatusCode2="(null)", StatusMessage="(null)", referer: https://idp.simplesaml.aimoto.example.ac.jp:1443/
  1. のerror_log
[Mon Jun 07 04:20:09.061885 2021] [auth_mellon:error] [pid 8] [client 172.26.0.1:53490] Error processing authn response. Lasso error: [440] The profile cannot verify a signature on the message, SAML Response: StatusCode1="urn:oasis:names:tc:SAML:2.0:status:Success", StatusCode2="(null)", StatusMessage="(null)", referer: https://idp.simplesaml.aimoto.example.ac.jp:1443/
  1. のerror_log
[Mon Jun 07 04:21:04.041404 2021] [auth_mellon:error] [pid 11] [client 172.26.0.1:53562] More than one Assertion in response., referer: https://idp.simplesaml.aimoto.example.ac.jp:1443/

1 と 2 は Lasso が署名を検証出来なかったとエラー判定しています。(Lasso のエラーを受けてmod_auth_mellon がステータスコード 400 を応答しています。)

3 は Lasso ではエラーとならず、mod_auth_mellon がエラーと判定しています。

2 と 3 はSAMLアサーションの順番を変えただけですが、3 では Lasso のエラーとなっておらず今回の脆弱性に該当していることが確認出来ます。 しかし、Lasso のチェックをすり抜けても mod_auth_mellon でエラーとしており攻撃は成立しないことが確認出来ました。