Skip to content

Add hunting queries: Entra ID account takeover hunting pack (3 queries)#14335

Open
descambiado wants to merge 3 commits into
Azure:masterfrom
descambiado:add-entra-id-account-takeover-hunting-pack
Open

Add hunting queries: Entra ID account takeover hunting pack (3 queries)#14335
descambiado wants to merge 3 commits into
Azure:masterfrom
descambiado:add-entra-id-account-takeover-hunting-pack

Conversation

@descambiado
Copy link
Copy Markdown
Contributor

Summary

Three hunting queries targeting Entra ID account takeover techniques: device code phishing, post-compromise application persistence, and bulk credential resets by privileged actors.

Queries

1. DeviceCodeSignInFromUnseenASN (Hunting Queries/MultipleDataSources/)

Detects successful device code flow sign-ins from autonomous system numbers not seen for the user in the preceding 30 days. Device code phishing (used by Midnight Blizzard and other threat actors) involves an attacker initiating the OAuth device code flow and tricking a target into completing authentication — the attacker receives a valid session token without knowing the user's password or satisfying MFA directly.

Differentiated from the existing Possible device code phishing attempts.yaml which requires M365 Defender UrlClickEvents and EntraIdSignInEvents. This query runs on the standard Azure AD connector (SigninLogs) with no additional prerequisites.

MITRE: T1528, T1078.004

2. NewServicePrincipalGrantedAdminConsent (Hunting Queries/AuditLogs/)

Correlates service principal creation with admin consent or app role assignment within a 1-hour window for the same SP. An attacker with Application Administrator rights who creates an app and immediately grants it tenant-wide permissions is a pattern documented in NOBELIUM/Midnight Blizzard intrusions.

Differentiated from CredentialsAddAfterAdminConsentedToApp[Nobelium].yaml (requires M365 Defender CloudAppEvents) and ConsentToApplicationDiscovery.yaml (general consent discovery, no SP age correlation). This query uses only AuditLogs.

MITRE: T1528, T1098.003

3. BulkPasswordResetByActor (Hunting Queries/AuditLogs/)

Identifies a single actor resetting passwords for three or more distinct accounts within one hour. An attacker with User Administrator or Helpdesk Administrator privileges may perform bulk password resets to take over targeted accounts before the activity triggers an alert.

MITRE: T1098, T1078.004

Validation

  • Non-ASCII scan: clean on all three files
  • Description: under 500 chars, starts with "Identifies" on all three
  • OperationName: uses in~ (no has_any)
  • GUIDs: unique, generated fresh
  • Author: descambiado on all three

Detects successful device code flow sign-ins where the ASN has not
been seen for that user in the preceding 30 days. Targets device code
phishing (T1528, T1078.004) where an attacker initiates the flow and
tricks the victim into completing authentication.
… one hour

Correlates SP creation with admin consent or app role assignment within
a 1-hour window. Post-compromise persistence pattern where an attacker
with Application Admin rights registers an app and immediately grants it
tenant-wide permissions (T1528, T1098.003).
…e accounts

Detects a single actor resetting passwords for 3+ distinct accounts within
one hour. Targets attackers with User Administrator or Helpdesk Admin rights
using bulk password resets for account takeover (T1098, T1078.004).
@descambiado descambiado requested review from a team as code owners May 23, 2026 12:56
@v-maheshbh v-maheshbh added the Hunting Hunting specialty review needed label May 25, 2026
@v-atulyadav v-atulyadav requested a review from Copilot May 26, 2026 06:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Adds three new Microsoft Sentinel hunting queries focused on Entra ID account takeover and post-compromise persistence patterns, using only core Entra ID/Azure AD data sources.

Changes:

  • Added a SigninLogs-based hunt for successful device code sign-ins from an ASN not previously seen for the user.
  • Added an AuditLogs-based hunt correlating new service principal creation with rapid admin consent/app role assignment.
  • Added an AuditLogs-based hunt detecting bulk password resets by a single actor within an hour.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.

File Description
Hunting Queries/MultipleDataSources/DeviceCodeSignInFromUnseenASN.yaml New SigninLogs-based device code phishing hunt using unseen ASN history per user.
Hunting Queries/AuditLogs/NewServicePrincipalGrantedAdminConsent.yaml New AuditLogs correlation hunt for rapid post-registration admin consent/app role assignment on a new SP.
Hunting Queries/AuditLogs/BulkPasswordResetByActor.yaml New AuditLogs hunt for bulk admin-initiated password resets by a single actor over a short window.

Comment on lines +4 to +8
Identifies successful device code flow sign-ins where the autonomous system number
has not been observed for that user in the preceding 30 days. Device code phishing
involves an attacker initiating a device code request and tricking a target into
completing authentication, giving the attacker a valid session token without knowing
the user's credentials.
Comment on lines +4 to +7
Identifies service principals that received an app role assignment or admin consent
within one hour of being registered in the tenant. Registering an application and
immediately granting it admin consent is a technique used to establish persistent
OAuth access after compromising a privileged account.
Comment on lines +4 to +7
Identifies a single actor resetting passwords for three or more distinct accounts
within a one-hour window. An attacker with User Administrator or Helpdesk Administrator
privileges may reset multiple account passwords in rapid succession to establish control
over targeted users before the activity is detected.
| where Result =~ "success"
| project
SpCreatedTime = TimeGenerated,
SpId = tostring(TargetResources[0].id),
"Consent to application"
)
| where Result =~ "success"
| extend ConsentTargetId = tostring(TargetResources[0].id)
isnotempty(tostring(InitiatedBy.user.ipAddress)),
tostring(InitiatedBy.user.ipAddress),
tostring(InitiatedBy.app.ipAddress))
| join kind=inner NewSP on $left.ConsentTargetId == $right.SpId
Comment on lines +37 to +41
| extend TargetUpn = tostring(TargetResources[0].userPrincipalName)
| where isnotempty(Actor) and Actor != TargetUpn
| summarize
ResetCount = dcount(TargetUpn),
TargetAccounts = make_set(TargetUpn, 20),
Comment on lines +45 to +50
by Actor, bin(TimeGenerated, correlationWindow)
| where ResetCount >= resetThreshold
| extend AccountName = iff(Actor has "@", tostring(split(Actor, "@")[0]), Actor)
| extend AccountUPNSuffix = iff(Actor has "@", tostring(split(Actor, "@")[1]), "")
| project
TimeGenerated,
Comment on lines +45 to +50
by Actor, bin(TimeGenerated, correlationWindow)
| where ResetCount >= resetThreshold
| extend AccountName = iff(Actor has "@", tostring(split(Actor, "@")[0]), Actor)
| extend AccountUPNSuffix = iff(Actor has "@", tostring(split(Actor, "@")[1]), "")
| project
TimeGenerated,
Comment on lines +56 to +57
FirstReset,
LastReset,
@v-atulyadav
Copy link
Copy Markdown
Collaborator

v-atulyadav commented May 26, 2026

Hi @descambiado,
Please check Copilot’s suggestions and act accordingly. Once done, click the “Resolve conversation” button.
Also, please pull the latest changes from the master branch and push again to rerun the stuck validation. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hunting Hunting specialty review needed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants