Before you run
Data & scope
- Required tables
- Time window
- 24-hour investigation window plus the preceding 7-day baseline
- Microsoft Entra ID connector with AuditLogs available for eight days in this workspace.
- Any Microsoft Entra ID license supports audit-log ingestion; query access and an Analytics table plan supporting the join are required.
Documentation review by Codex (AI). No live-tenant execution or detection-performance claim. Validate schema, data coverage and expected results in your workspace.
// Hunting starter. Documentation checked 2026-11-13; not tenant-tested.
let investigationStart = ago(1d);
let baselineStart = investigationStart - 7d;
let changes = materialize(
AuditLogs
| where TimeGenerated >= baselineStart and TimeGenerated <= now()
| extend AuditOperation = coalesce(ActivityDisplayName, OperationName)
| where AuditOperation in~ (
"Add service principal credentials",
"Remove service principal credentials",
"Update application - Certificates and secrets management")
| where Result =~ "success"
| extend ActorObjectId = tolower(coalesce(tostring(InitiatedBy.user.id),
tostring(InitiatedBy.app.servicePrincipalId))),
ActorName = coalesce(tostring(InitiatedBy.user.userPrincipalName),
tostring(InitiatedBy.app.displayName)),
ActorIp = coalesce(tostring(InitiatedBy.user.ipAddress),
tostring(InitiatedBy.app.ipAddress)),
DirectoryId = tolower(AADTenantId)
| mv-expand Target = TargetResources
| extend TargetType = tostring(Target.type),
TargetObjectId = tolower(tostring(Target.id)),
TargetName = tostring(Target.displayName),
ChangedProperties = Target.modifiedProperties
| where TargetType in~ ("Application", "ServicePrincipal")
| where isnotempty(DirectoryId) and isnotempty(TargetObjectId)
| project TimeGenerated, AuditId = Id, DirectoryId, AuditOperation,
ActorObjectId, ActorName, ActorIp, TargetType, TargetObjectId,
TargetName, ChangedProperties, CorrelationId
);
let baseline = changes
| where TimeGenerated < investigationStart
| summarize PriorActorTargetRows = count(), PriorLastSeen = max(TimeGenerated)
by DirectoryId, TargetType, TargetObjectId, ActorObjectId;
changes
| where TimeGenerated >= investigationStart
| join kind=leftouter baseline on DirectoryId, TargetType, TargetObjectId, ActorObjectId
| extend PriorActorTargetRows = coalesce(PriorActorTargetRows, 0)
| extend ActorHistory = case(isempty(ActorObjectId), "Actor ID unavailable",
PriorActorTargetRows == 0, "Not observed in available baseline", "Previously observed")
| project TimeGenerated, DirectoryId, AuditId, AuditOperation, TargetType,
TargetObjectId, TargetName, ActorObjectId, ActorName, ActorIp,
ActorHistory, PriorActorTargetRows, PriorLastSeen, ChangedProperties, CorrelationId
| order by PriorActorTargetRows asc, TimeGenerated desc
| take 200
Read-only query. Run in your own authorized workspace after checking prerequisites.
Use this hunt when reviewing who can change the credentials behind an application or enterprise application. It selects successful credential-management audit events from the last 24 hours, then checks whether the same actor/object pair appeared during the preceding seven days. The comparison is a triage aid: unfamiliar maintenance deserves context, but familiar maintenance can also be malicious.
The selected activities cover adding or removing service-principal credentials and the dedicated application certificates/secrets activity. They are an explicit, reviewable subset of the documented audit activities. General application updates and other credential mechanisms can require separate investigation; absence here is not proof that credentials stayed unchanged.
Understand the comparison
The two windows do not overlap. An event under investigation cannot establish its own historical precedent. The join uses directory, target type, target object ID and initiating object ID. Display names remain context rather than identity keys. Blank target identifiers are excluded; a missing actor identifier is labelled unknown instead of being presented as a newly observed person.
Each expanded target retains its modified-properties collection. Microsoft documents target IDs, types and changed attributes, while the contents of those changes depend on the operation. Read the actual old/new payload before deciding which credential was added, removed or replaced. The query does not infer credential lifetime, retrieve secret values, or turn a textual property difference into proof of credential use. Target resource contract.
The baseline counts expanded audit rows, not unique credential rotations. Duplicate delivery, several targets in one operation, and correlated management events can increase the count. The output keeps audit and correlation IDs so you can reconstruct the underlying transaction rather than treating each row as an independent incident.
Investigate the authority and the change
Resolve the initiator to its current directory object and determine what authority allowed the change. Then establish the target’s owner, production purpose, effective privileges and dependent workloads. Compare the event with the approved rotation or deployment record, including expected credential identifiers and timing.
Review the change payload in a restricted investigation workspace. Look for an unexplained additional credential, an unexpectedly long validity period, or removal that could impair recovery. Correlate subsequent sign-ins and resource activity separately. A credential update is a potential change to authentication authority; it does not demonstrate that the changed credential authenticated successfully. Microsoft’s application security operations guidance provides the broader monitoring context.
Tune and validate
Automated rotation, certificate renewal, application onboarding and emergency repair all produce legitimate unfamiliar pairs. Prefer a documented, expiring exception for a specific actor and target over excluding every event from a deployment account. Shorten the window for busy directories before raising the 200-row output cap; that cap does not reduce the preceding scan.
Confirm all eight days are retained and collected. A new connector, missing tenant, or ingestion delay can make normal activity appear unfamiliar. This read-only hunt was checked against documentation, not executed in a tenant. Validate a benign rotation, removal and missing-actor case before using its results operationally.
Verify the source
Microsoft references
Measure normal activity, validate known test cases, account for ingestion delays, choose a threshold and entity mapping, and assign an owner. Results require investigation.
Follow the detection learning path →