Safeguard
Application Security•

Detecting and Cleaning Up SID-History Injection (T1134.005)

SID-History was built for domain migrations, and attackers can stuff it with admin SIDs. How to detect changes and clear out stale values in Active Directory.

Safeguard Security Team
3 min read

A Windows security identifier, or SID, uniquely identifies a user or group. SIDs appear in security descriptors and in access tokens. T1134.005, SID-History Injection, abuses an Active Directory attribute that was designed to make migrations easier. It is an Access Token Manipulation sub-technique under stealth and privilege escalation, for Windows.

How attackers use it

An account can hold extra SIDs in its SID-History attribute. The point is interoperability during account migration between domains. Every value in SID-History is included in the account's access tokens.

MITRE's description of the abuse: with Domain Administrator rights or equivalent, harvested or well-known SID values can be inserted into SID-History. That lets an account impersonate arbitrary users or groups, such as Enterprise Administrators. The result can be elevated access to local resources, or access to domains that were previously out of reach through lateral movement over remote services, SMB and admin shares, or Windows Remote Management.

It needs high privilege to start, so it is mostly a persistence and reach technique rather than a first step. MITRE lists Mimikatz and Empire among tools that can do it.

How to detect it

MITRE's chain has four parts:

  1. Privileged operations or API calls such as DsAddSidHistory or related directory modification functions.
  2. Observed attribute changes to SID-History, logged as Event ID 5136.
  3. New logon sessions where the token includes unexpected or privileged SID-History values.
  4. Follow-on resource access using the elevated privileges.

Event ID 5136 (a directory service object was modified) needs auditing of directory service changes on the domain controllers. Windows also has dedicated events for SID-History being added to an account, 4765 on success and 4766 on failure. In a healthy domain these are rare, so any occurrence outside a planned migration deserves review.

How to reduce the risk

MITRE lists Active Directory configuration:

  • Clean up SID-History after migrations finish. Remove the old values once legitimate account migration is complete, so there is nothing for an attacker to blend into.
  • Apply SID filtering on interforest trusts. Forest trusts and external trusts can be set to exclude SID-History from requests for domain resources, so that authentication across a trust carries only SIDs from the trusted domain.

Also guard the rights needed to make the change. Domain Administrator equivalence is the entry price, so tiering and monitoring of those accounts apply.

Check your own environment

With the Active Directory PowerShell module, read-only:

Get-ADUser -Filter 'SIDHistory -like "*"' -Properties SIDHistory | Select-Object SamAccountName, SIDHistory
Get-ADTrust -Filter * | Select-Object Name, SIDFilteringQuarantined, SIDFilteringForestAware

The first lists users with SID-History values. Each one should match a past migration you can name. The second shows how SID filtering is set on each trust.

Then confirm directory service change auditing is on for your domain controllers so event 5136 exists when you need it.

Quick check

Why is SID-History a useful target?

Every value in it is included in the account's access tokens, so a privileged SID placed there is honored as if the account were a member of that group.

What two cleanup steps does MITRE recommend?

Remove SID-History values after legitimate migrations finish, and apply SID filtering on interforest trusts.

Sources

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.