Query Details
// =========================================================
// RULE-15 | AD-SIDHistory-Injection
// Description : SID History injection detection — Event 4765
// (SID History Added) or Event 5136 (DS Object
// Modified) modifying the sIDHistory attribute.
// SID History allows an account to carry
// additional SIDs in its Kerberos PAC.
// Injecting an Enterprise Admins SID (RID-519)
// or Domain Admins SID (RID-512) into any user
// gives that user EA/DA privileges transparently.
// This is the persistence mechanism used in
// cross-forest attacks and post-DCSync
// persistence.
// Severity : Critical (EA/DA/BA SID injected)
// High (any cross-domain SID injected)
// Frequency : Every 15 minutes, look-back 15 minutes
// MITRE : T1134.005 — Token Impersonation/Theft:
// SID-History Injection
// Tables : SecurityEvent
// =========================================================
let LookBack = 15m;
// High-value SID patterns
let SensitiveSIDPatterns = dynamic([
"-512", // Domain Admins
"-519", // Enterprise Admins
"-518", // Schema Admins
"-500", // Built-in Administrator
"-544", // Local Administrators
"S-1-5-32-544"
]);
// Signal 1: Event 4765 — SID History Added (explicit event)
let Via4765 = SecurityEvent
| where TimeGenerated > ago(LookBack)
| where EventID == 4765
| extend
Source = "Event4765_SIDHistoryAdded",
ActorAccount = strcat(SubjectDomainName, "\\", SubjectUserName),
TargetAccount = strcat(TargetDomainName, "\\", TargetUserName),
InjectedSIDs = SidHistory
| extend
HasSensitiveSID = InjectedSIDs has_any (SensitiveSIDPatterns)
| project TimeGenerated, Source, ActorAccount, TargetAccount,
InjectedSIDs, HasSensitiveSID, Computer;
// Signal 2: Event 5136 — Direct attribute write to sIDHistory
let Via5136 = SecurityEvent
| where TimeGenerated > ago(LookBack)
| where EventID == 5136
| where AttributeLDAPDisplayName =~ "sIDHistory"
| extend
Source = "Event5136_sIDHistory_Write",
ActorAccount = strcat(SubjectDomainName, "\\", SubjectUserName),
TargetAccount = ObjectDN,
InjectedSIDs = AttributeValue
| extend
HasSensitiveSID = InjectedSIDs has_any (SensitiveSIDPatterns)
| project TimeGenerated, Source, ActorAccount, TargetAccount,
InjectedSIDs, HasSensitiveSID, Computer;
union Via4765, Via5136
| extend
Severity = case(
HasSensitiveSID, "Critical",
"High"
),
WhySuspicious = strcat(
"SIDHistory_Injected; ",
iff(HasSensitiveSID, "Sensitive_SID_EA_DA_or_RID500; ", ""),
"Target: ", TargetAccount, "; ",
"Actor: ", ActorAccount, "; ",
"SIDs: ", InjectedSIDs
)
| project
TimeGenerated,
Severity,
WhySuspicious,
ActorAccount,
TargetAccount,
InjectedSIDs,
HasSensitiveSID,
Source,
Computer
| order by Severity asc, TimeGenerated desc
This query is designed to detect suspicious activities related to SID History injection in a network environment. Here's a simplified breakdown:
Purpose: The query aims to identify instances where a user account's SID History is modified, which could indicate unauthorized privilege escalation. Specifically, it looks for events where high-value SIDs, like those of Domain Admins or Enterprise Admins, are injected into a user's SID History.
Events Monitored:
Sensitive SIDs: The query focuses on specific SIDs that are considered high-value targets, such as those associated with administrative privileges.
Severity Levels:
Frequency: The query runs every 15 minutes and looks back over the previous 15 minutes to catch recent events.
Output: The results include details such as the time of the event, severity, reasons for suspicion, the accounts involved, and the computer where the event was logged. The results are sorted by severity and time.
Overall, this query helps in identifying potential security breaches where attackers might be trying to gain elevated privileges by manipulating SID History.

David Alonso
Released: March 24, 2026
Tables
Keywords
Operators