Detection rules › Kusto

Potential Kerberoasting

Severity
medium
Time window
1d
Group by
ClientIPAddress, Computer, Status, TargetDomainName, TargetUserName, TicketEncryptionType, TicketOptions
Author
Microsoft Security Research
Source
github.com/Azure/Azure-Sentinel

A service principal name (SPN) is used to uniquely identify a service instance in a Windows environment. Each SPN is usually associated with a service account. Organizations may have used service accounts with weak passwords in their environment. An attacker can try requesting Kerberos ticket-granting service (TGS) service tickets for any SPN from a domain controller (DC) which contains a hash of the Service account. This can then be used for offline cracking. This hunting query looks for accounts that are generating excessive requests to different resources within the last hour compared with the previous 24 hours. Normal users would not make an unusually large number of request within a small time window. This is based on 4769 events which can be very noisy so environment based tweaking might be needed.

MITRE ATT&CK coverage

TacticTechniques
Credential AccessT1558 Steal or Forge Kerberos Tickets

Event coverage

Rule body kusto

id: 1572e66b-20a7-4012-9ec4-77ec4b101bc8
name: Potential Kerberoasting
description: |
  'A service principal name (SPN) is used to uniquely identify a service instance in a Windows environment.
  Each SPN is usually associated with a service account. Organizations may have used service accounts with weak passwords in their environment.
  An attacker can try requesting Kerberos ticket-granting service (TGS) service tickets for any SPN from a domain controller (DC) which contains a hash of the Service account. This can then be used for offline cracking.
  This hunting query looks for accounts that are generating excessive requests to different resources within the last hour compared with the previous 24 hours.  Normal users would not make an unusually large number of request within a small time window. This is based on 4769 events which can be very noisy so environment based tweaking might be needed.'
severity: Medium
requiredDataConnectors:
  - connectorId: SecurityEvents
    dataTypes:
      - SecurityEvent
  - connectorId: WindowsSecurityEvents
    dataTypes:
      - SecurityEvent
  - connectorId: WindowsForwardedEvents
    dataTypes:
      - WindowsEvent
queryFrequency: 1h
queryPeriod: 1d
triggerOperator: gt
triggerThreshold: 0
tactics:
  - CredentialAccess
relevantTechniques:
  - T1558
query: |
  let starttime = 1d;
  let endtime = 1h;
  let prev23hThreshold = 4;
  let prev1hThreshold = 15;
  let Kerbevent = (union isfuzzy=true
  (SecurityEvent
  | where TimeGenerated >= ago(starttime)
  | where EventID == 4769
  | parse EventData with * 'TicketEncryptionType">' TicketEncryptionType "<" *
  | where TicketEncryptionType == '0x17'
  | parse EventData with * 'TicketOptions">' TicketOptions "<" *
  | where TicketOptions == '0x40810000'
  | parse EventData with * 'Status">' Status "<" *
  | where Status == '0x0'
  | parse EventData with * 'ServiceName">' ServiceName "<" *
  | where ServiceName !contains "$" and ServiceName !contains "krbtgt"
  | parse EventData with * 'TargetUserName">' TargetUserName "<" *
  | where TargetUserName !contains "$@" and TargetUserName !contains ServiceName
  | parse EventData with * 'IpAddress">::ffff:' ClientIPAddress "<" *
  ),
  (
  WindowsEvent
  | where TimeGenerated >= ago(starttime)
  | where EventID == 4769 and EventData has '0x17' and EventData has '0x40810000' and EventData has 'krbtgt'
  | extend TicketEncryptionType = tostring(EventData.TicketEncryptionType)
  | where TicketEncryptionType == '0x17'
  | extend TicketOptions = tostring(EventData.TicketOptions)
  | where TicketOptions == '0x40810000'
  | extend Status = tostring(EventData.Status)
  | where Status == '0x0'
  | extend ServiceName = tostring(EventData.ServiceName)
  | where ServiceName !contains "$" and ServiceName !contains "krbtgt"
  | extend TargetUserName = tostring(EventData.TargetUserName)
  | where TargetUserName !contains "$@" and TargetUserName !contains ServiceName
  | extend ClientIPAddress = tostring(EventData.IpAddress)
  ));
  let Kerbevent23h = Kerbevent
  | where TimeGenerated >= ago(starttime) and TimeGenerated < ago(endtime)
  | summarize ServiceNameCountPrev23h = dcount(ServiceName), ServiceNameSet23h = makeset(ServiceName)
  by Computer, TargetUserName,TargetDomainName, ClientIPAddress, TicketOptions, TicketEncryptionType, Status
  | where ServiceNameCountPrev23h < prev23hThreshold;
  let Kerbevent1h =
  Kerbevent
  | where TimeGenerated >= ago(endtime)
  | summarize min(TimeGenerated), max(TimeGenerated), ServiceNameCountPrev1h = dcount(ServiceName), ServiceNameSet1h = makeset(ServiceName)
  by Computer, TargetUserName, TargetDomainName, ClientIPAddress, TicketOptions, TicketEncryptionType, Status;
  Kerbevent1h
  | join kind=leftanti
  (
  Kerbevent23h
  ) on TargetUserName, TargetDomainName
  // Threshold value set above is based on testing, this value may need to be changed for your environment.
  | where ServiceNameCountPrev1h > prev1hThreshold
  | project StartTime = min_TimeGenerated, EndTime = max_TimeGenerated, TargetUserName, Computer, ClientIPAddress, TicketOptions,
  TicketEncryptionType, Status, ServiceNameCountPrev1h, ServiceNameSet1h, TargetDomainName
  | extend HostName = tostring(split(Computer, ".")[0]), DomainIndex = toint(indexof(Computer, '.'))
  | extend HostNameDomain = iff(DomainIndex != -1, substring(Computer, DomainIndex + 1), Computer)
  | extend TargetAccount = strcat(TargetDomainName,  "\\", TargetUserName)
  | project-away DomainIndex
entityMappings:
  - entityType: Account
    fieldMappings:
      - identifier: FullName
        columnName: TargetAccount
      - identifier: Name
        columnName: TargetUserName
      - identifier: NTDomain
        columnName: TargetDomainName
  - entityType: Host
    fieldMappings:
      - identifier: FullName
        columnName: Computer
      - identifier: HostName
        columnName: HostName
      - identifier: DnsDomain
        columnName: HostNameDomain
  - entityType: IP
    fieldMappings:
      - identifier: Address
        columnName: ClientIPAddress
version: 1.1.7
kind: Scheduled
metadata:
    source:
        kind: Community
    author:
        name: Microsoft Security Research
    support:
        tier: Community
    categories:
        domains: [ "Security - Others", "Identity" ]

Stages and Predicates

Stage 0: let

let starttime = 1d;
let endtime = 1h;
let prev23hThreshold = 4;
let prev1hThreshold = 15;
let Kerbevent = (union <inlined as stages below>;
let Kerbevent23h = Kerbevent
| where TimeGenerated >= ago(starttime) and TimeGenerated < ago(endtime)
| summarize ServiceNameCountPrev23h = dcount(ServiceName), ServiceNameSet23h = makeset(ServiceName)
by Computer, TargetUserName,TargetDomainName, ClientIPAddress, TicketOptions, TicketEncryptionType, Status
| where ServiceNameCountPrev23h < prev23hThreshold;
let Kerbevent1h = Kerbevent <inlined as stages below>;

Stage 1: source

let Kerbevent

Stage 2: source

let Kerbevent23h

Stage 3: source

let Kerbevent1h

Stage 4: union

union isfuzzy=true

Stage 5: source

SecurityEvent

Stage 6: where time_window=86400s

| where TimeGenerated >= ago(starttime)

Stage 7: where

| where EventID == 4769

Stage 8: parse

| parse EventData with * 'TicketEncryptionType">' TicketEncryptionType "<" *

Stage 9: where

| where TicketEncryptionType == '0x17'

Stage 10: parse

| parse EventData with * 'TicketOptions">' TicketOptions "<" *

Stage 11: where

| where TicketOptions == '0x40810000'

Stage 12: parse

| parse EventData with * 'Status">' Status "<" *

Stage 13: where

| where Status == '0x0'

Stage 14: parse

| parse EventData with * 'ServiceName">' ServiceName "<" *

Stage 15: where

| where ServiceName !contains "$" and ServiceName !contains "krbtgt"

Stage 16: parse

| parse EventData with * 'TargetUserName">' TargetUserName "<" *

Stage 17: where

| where TargetUserName !contains "$@" and TargetUserName !contains ServiceName

Stage 18: parse

| parse EventData with * 'IpAddress">::ffff:' ClientIPAddress "<" *

Stage 19: source

WindowsEvent

Stage 20: where time_window=86400s

| where TimeGenerated >= ago(starttime)

Stage 21: where

| where EventID == 4769 and EventData has '0x17' and EventData has '0x40810000' and EventData has 'krbtgt'

Stage 22: extend

| extend TicketEncryptionType = tostring(EventData.TicketEncryptionType)

Stage 23: where

| where TicketEncryptionType == '0x17'

Stage 24: extend

| extend TicketOptions = tostring(EventData.TicketOptions)

Stage 25: where

| where TicketOptions == '0x40810000'

Stage 26: extend

| extend Status = tostring(EventData.Status)

Stage 27: where

| where Status == '0x0'

Stage 28: extend

| extend ServiceName = tostring(EventData.ServiceName)

Stage 29: where

| where ServiceName !contains "$" and ServiceName !contains "krbtgt"

Stage 30: extend

| extend TargetUserName = tostring(EventData.TargetUserName)

Stage 31: where

| where TargetUserName !contains "$@" and TargetUserName !contains ServiceName

Stage 32: extend

| extend ClientIPAddress = tostring(EventData.IpAddress)

Stage 33: where time_window=3600s

| where TimeGenerated >= ago(endtime)

Stage 34: summarize

| summarize min(TimeGenerated), max(TimeGenerated), ServiceNameCountPrev1h = dcount(ServiceName), ServiceNameSet1h = makeset(ServiceName)
by Computer, TargetUserName, TargetDomainName, ClientIPAddress, TicketOptions, TicketEncryptionType, Status

Stage 35: join

| join kind=leftanti
(
Kerbevent23h
) on TargetUserName, TargetDomainName

Stage 36: where

| where ServiceNameCountPrev1h > prev1hThreshold

Stage 37: project

| project StartTime = min_TimeGenerated, EndTime = max_TimeGenerated, TargetUserName, Computer, ClientIPAddress, TicketOptions,
TicketEncryptionType, Status, ServiceNameCountPrev1h, ServiceNameSet1h, TargetDomainName

Stage 38: extend

| extend HostName = tostring(split(Computer, ".")[0]), DomainIndex = toint(indexof(Computer, '.'))

Stage 39: extend

| extend HostNameDomain = iff(DomainIndex != -1, substring(Computer, DomainIndex + 1), Computer)

Stage 40: extend

| extend TargetAccount = strcat(TargetDomainName,  "\\", TargetUserName)

Stage 41: project-away

| project-away DomainIndex

Exclusions

Top-level NOT(...) conjuncts: predicates this rule actively suppresses.

StageFieldKindExcluded values
15ServiceNamecontains$
15ServiceNamecontainskrbtgt
17TargetUserNamecontains$@
17TargetUserNamecontainsServiceName
29ServiceNamecontains$
29ServiceNamecontainskrbtgt
31TargetUserNamecontains$@
31TargetUserNamecontainsServiceName
35ServiceNamecontains$
35ServiceNamecontainskrbtgt
35TargetUserNamecontains$@
35TargetUserNamecontainsServiceName

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
EventDatamatch
  • 0x17
  • 0x40810000
  • krbtgt
EventIDeq
  • 4769 transforms: cased corpus 10 (splunk 6, kusto 4)
ServiceNameCountPrev1hgt
  • 15 transforms: cased
ServiceNameCountPrev23hlt
  • 4 transforms: cased
Statuseq
  • 0x0 transforms: cased corpus 3 (kusto 2, sigma 1)
TicketEncryptionTypeeq
  • 0x17 transforms: cased corpus 8 (splunk 4, sigma 3, kusto 1)
TicketOptionseq
  • 0x40810000 transforms: cased corpus 4 (splunk 2, sigma 1, kusto 1)

Output fields

Fields the rule emits when it matches. Chronicle authors list these in the outcome block; they appear on the detection and $risk_score drives alerting. Sentinel / Defender XDR rules build them up through project / summarize / extend stages. Sentinel maps these into alert fields via entityMappings and customDetails; Defender XDR custom detections surface them as alert fields directly.

FieldSource
ClientIPAddressproject
Computerproject
EndTimeproject
ServiceNameCountPrev1hproject
ServiceNameSet1hproject
StartTimeproject
Statusproject
TargetDomainNameproject
TargetUserNameproject
TicketEncryptionTypeproject
TicketOptionsproject
HostNameextend
HostNameDomainextend
TargetAccountextend