M365 and Entra ID Detection Reference
KQL that detects 30 Microsoft 365 and Entra ID attack techniques, from a phished session to a mailbox forwarding rule, with the log each reads and the false positives to expect, plus 4 correlations that join them.
What this is
Microsoft 365 and Entra ID are attacked through their own features: a phished session, a consented application, an inbox rule, an authenticator registered by the wrong person. Each leaves a record in a log you already collect. This reference gives a detection for each of 30 techniques and 4 correlations that join them, the table each reads, and what will fool it.
Every query here ran on practice data without error, and every column it names is in Microsoft's schema for its table. Practice data does not hold every attack, so some return nothing there. Thresholds and baseline windows are starting points for your own tenant.
The reference, in four parts
This hub pulls together four detailed references into one working order. Read them as a sequence: understand the attack surface, hunt for activity, write the detection, engineer it as a repeatable discipline.
Coverage map
Each card links to its detection below. Only techniques this page has a query for are on the map.
Initial access
The intrusion starts with a message or a credential. These detections read delivered mail and the sign-ins of the applications that hold credentials of their own.
Most first messages in a mail intrusion come from a sender domain the organization has never received mail from. The rule lists delivered mail from domains first seen in the detection window. Keep links out of the condition: a lure can carry an attachment, a QR code, or only text that asks for a reply.
let baseline = EmailEvents
| where Timestamp between (ago(30d) .. ago(21d))
| where EmailDirection == "Inbound"
| distinct SenderFromDomain;
EmailEvents
| where Timestamp > ago(21d)
| where EmailDirection == "Inbound" and DeliveryAction == "Delivered"
| join kind=leftanti baseline on SenderFromDomain
| summarize Emails = count(), Recipients = make_set(RecipientEmailAddress),
First = min(Timestamp) by SenderFromDomainApplications sign in as service principals from a small, stable set of addresses. A sign-in from an address the principal has never used is the first sign that its credential is in someone else's hands.
let baseline = AADServicePrincipalSignInLogs
| where TimeGenerated between (ago(30d) .. ago(21d))
| distinct ServicePrincipalName, IPAddress;
AADServicePrincipalSignInLogs
| where TimeGenerated > ago(21d)
| join kind=leftanti baseline on ServicePrincipalName, IPAddress
| summarize SignIns = count(), First = min(TimeGenerated)
by ServicePrincipalName, IPAddress
| sort by First ascCredential access
In a cloud-first tenant the attacker wants a valid session: a phished cookie, a sprayed password, an approved prompt, a consented application, or a forged token.
An adversary-in-the-middle page relays the real sign-in, MFA included, and keeps the session cookie it gets back. The attacker never needs the password or the second factor again. Entra ID Protection marks many of these sign-ins with risk detections of their own; hunt for them directly rather than waiting for an alert.
SigninLogs
| where TimeGenerated > ago(30d)
| where RiskLevelDuringSignIn in ("high", "medium")
or RiskEventTypes_V2 has_any ("adversaryInTheMiddle",
"anomalousToken", "tokenIssuerAnomaly")
| project TimeGenerated, UserPrincipalName, IPAddress, AppDisplayName,
RiskLevelDuringSignIn, RiskEventTypes_V2, ConditionalAccessStatus
| sort by TimeGenerated descThe replayed cookie shows mostly as token use in the non-interactive sign-in log, from an address the user never signs in from interactively. The rule compares the two logs per user and address.
let usual = SigninLogs
| where TimeGenerated > ago(30d) and ResultType == 0
| summarize SignIns = count() by UserPrincipalName, IPAddress
| where SignIns >= 5;
AADNonInteractiveUserSignInLogs
| where TimeGenerated > ago(14d) and ResultType == 0
| where UserPrincipalName !contains "#EXT#"
| join kind=leftanti usual on UserPrincipalName, IPAddress
| summarize Tokens = count(), First = min(TimeGenerated),
Last = max(TimeGenerated) by UserPrincipalName, IPAddress
| sort by First ascA user who consents to a malicious application gives it a token with the scopes they approved, and that access survives a password reset. The consent and the scopes are in the audit log. Mail and file scopes, and offline_access, which lets the application refresh its token without the user, are the ones to read first.
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in ("Consent to application",
"Add delegated permission grant")
| extend Target = parse_json(TargetResources)[0],
Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName)
| mv-expand Prop = Target.modifiedProperties
| where tostring(Prop.displayName) in ("ConsentAction.Permissions",
"DelegatedPermissionGrant.Scope")
| extend Permissions = tostring(Prop.newValue)
| where Permissions has_any ("Mail.", "Files.", "offline_access")
| project TimeGenerated, Actor, App = tostring(Target.displayName),
PermissionsA spray tries one or two common passwords against many accounts from one address, so each account sees too few failures to trip a per-account rule. Count distinct accounts failing with error 50126 (invalid username or password) per address and hour, and alert on what matters: a success from an address that was spraying. A spray spread over many addresses passes under any per-address count; group by application instead to hunt it.
let spraying = SigninLogs
| where TimeGenerated > ago(30d) and ResultType == 50126
| summarize Accounts = dcount(UserPrincipalName)
by IPAddress, Hour = bin(TimeGenerated, 1h)
| where Accounts >= 5;
SigninLogs
| where TimeGenerated > ago(30d) and ResultType == 0
| join kind=inner spraying on IPAddress
| where TimeGenerated between (Hour .. (Hour + 3h))
| project TimeGenerated, UserPrincipalName, IPAddress, Accounts,
AuthenticationRequirementAn attacker who already has the password sends MFA prompts until the user approves one. The prompts appear as error 500121 (strong authentication failed) and 50074 (strong authentication required); the approval is a success from the same address minutes later. The rule looks for both.
let prompted = SigninLogs
| where TimeGenerated > ago(30d)
| where ResultType in (500121, 50074)
| summarize Prompts = count(), LastPrompt = max(TimeGenerated)
by UserPrincipalName, IPAddress, bin(TimeGenerated, 10m)
| where Prompts >= 5;
SigninLogs
| where TimeGenerated > ago(30d) and ResultType == 0
| join kind=inner prompted on UserPrincipalName, IPAddress
| where TimeGenerated between (LastPrompt .. (LastPrompt + 30m))
| project TimeGenerated, UserPrincipalName, IPAddress, PromptsAn attacker who extracts the AD FS token-signing certificate can forge SAML tokens for any user with any claims, and those tokens are valid. There is no single signature for it. On the AD FS side, watch token issuance for volume from accounts that do not normally request tokens.
SecurityEvent
| where TimeGenerated > ago(30d)
| where EventSourceName == "AD FS Auditing"
// 1200 to 1202: AD FS token and credential validation audits
| where EventID in (1200, 1201, 1202)
| summarize Tokens = count() by Account, Computer,
bin(TimeGenerated, 1h)
| where Tokens > 50
| sort by Tokens descOn the cloud side the forged sign-ins arrive at Entra ID as federated sign-ins. A federated sign-in from an unusual address or user agent for a privileged account, or a token asserting a role the account does not hold, is the second pattern to hunt. The DKM read below is the theft itself.
AD FS encrypts its token-signing certificate with a key stored in Active Directory (the DKM container). Reading that container is how the certificate is stolen. With auditing on the container, event 4662 records who read it.
SecurityEvent
| where TimeGenerated > ago(30d)
| where EventID == 4662 // an operation on an AD object
| where ObjectName has "CN=ADFS" or Properties has "DKM"
| where AccountType == "User"
| project TimeGenerated, Account, ObjectName, AccessMask
| sort by TimeGenerated descPersistence and privilege
Once in, the attacker makes the access survive a password reset: a method, a device, a credential on an application, a weakened policy, a federated domain, a role. Most of these are routine administrative events, which is why they hide; the detections separate the attacker's version.
With a session in hand, an attacker registers an authenticator of their own so they can pass MFA later without the victim. Registration alone is ordinary onboarding. The rule lists each registration with the addresses the account signed in from in the hour before it, so a registration made from the attacker's address stands out.
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName == "User registered security info"
| extend Account = tostring(parse_json(TargetResources)[0].userPrincipalName)
| project Registered = TimeGenerated, Account
| join kind=inner (SigninLogs
| where TimeGenerated > ago(30d) and ResultType == 0
| project SignIn = TimeGenerated, Account = UserPrincipalName,
IPAddress)
on Account
| where SignIn between ((Registered - 1h) .. Registered)
| summarize Addresses = make_set(IPAddress) by Account, RegisteredConditional Access that requires a registered or compliant device is only as strong as device registration. An attacker who registers a device of their own turns the control into one they pass. Registration alone is onboarding; the pattern is a sign-in from an unmanaged platform followed within hours by a new device for the same user.
let newDevices = AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in ("Add device", "Add registered owner to device")
| extend Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName)
| where isnotempty(Actor)
| project DeviceTime = TimeGenerated, Actor,
DeviceName = tostring(parse_json(TargetResources)[0].displayName);
SigninLogs
| where TimeGenerated > ago(30d) and ResultType == 0
| extend DeviceOS = tostring(DeviceDetail.operatingSystem),
Managed = tostring(DeviceDetail.isManaged)
| where Managed != "true"
| project SignInTime = TimeGenerated, Actor = UserPrincipalName, DeviceOS,
IPAddress
| join kind=inner newDevices on Actor
| where DeviceTime between (SignInTime .. (SignInTime + 2h))
| project SignInTime, DeviceTime, Actor, DeviceOS, DeviceName, IPAddressAn application or service principal holds its own credentials. An attacker who adds a secret or certificate to one gets a way back in that authenticates as the application, with every permission it was granted, and survives any user password reset. It is a single audit event, and the actor is what matters: an account that has never managed applications adding a credential.
let admin_ops = dynamic(["Add service principal credentials",
"Update application – Certificates and secrets management"]);
let known = AuditLogs
| where TimeGenerated between (ago(60d) .. ago(14d))
| where OperationName in (admin_ops)
| extend Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName)
| distinct Actor;
AuditLogs
| where TimeGenerated > ago(14d)
| where OperationName in (admin_ops)
| extend Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName),
App = tostring(parse_json(TargetResources)[0].displayName)
| where Actor !in (known)
| project TimeGenerated, Actor, OperationName, AppAn attacker with a privileged account does not bypass Conditional Access, they edit it: a policy disabled, switched to report-only, or given an exclusion. The change is logged with its old and new values, and the highest-fidelity version flags a change made by someone who does not normally touch policy.
let known = AuditLogs
| where TimeGenerated between (ago(60d) .. ago(14d))
| where OperationName has "conditional access policy"
| extend Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName)
| distinct Actor;
AuditLogs
| where TimeGenerated > ago(14d)
| where OperationName in~ ("Add conditional access policy",
"Update conditional access policy", "Delete conditional access policy")
| extend Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName),
Target = parse_json(TargetResources)[0]
| where Actor !in (known)
| project TimeGenerated, Actor, OperationName,
Policy = tostring(Target.displayName),
NewValue = tostring(Target.modifiedProperties[0].newValue)An attacker who can configure domain authentication federates a domain to an identity provider they control and can then issue valid tokens for any user in it. The steps are audit events, and in order they read as the backdoor being built: an unverified domain added, verified, then set to federated.
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in ("Set domain authentication",
"Set federation settings on domain", "Add unverified domain",
"Verify domain")
| extend Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName),
ActorIP = tostring(parse_json(InitiatedBy).user.ipAddress),
Domain = tostring(parse_json(TargetResources)[0].displayName)
| project TimeGenerated, OperationName, Domain, Actor, ActorIP, Result
| sort by Domain asc, TimeGenerated ascThe federation settings themselves are not in the event. Read them with Get-MgDomainFederationConfiguration and check the issuer URI and signing certificate.
The clearest escalation in Entra ID is a member added to a tier-zero role: Global Administrator, Privileged Role Administrator, Application Administrator, Privileged Authentication Administrator. The role name is a modified property of the event; read it by name, because its position in the list is not fixed.
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in ("Add member to role",
"Add eligible member to role")
| extend Target = parse_json(TargetResources)[0],
Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName)
| mv-expand Prop = Target.modifiedProperties
| where tostring(Prop.displayName) == "Role.DisplayName"
| extend Role = tostring(Prop.newValue)
| where Role has_any ("Global Administrator",
"Privileged Role Administrator", "Application Administrator",
"Privileged Authentication Administrator")
| project TimeGenerated, Actor, OperationName, Role,
Member = tostring(Target.userPrincipalName)Collection and exfiltration
Read the mail, take the files, move the data out. Mailbox and SharePoint auditing must be on in Microsoft Purview for most of these events to exist; confirm that before trusting an empty result.
An attacker in a mailbox forwards its mail to an outside address and keeps reading it without signing in again. Forwarding can be set by an inbox rule or on the mailbox itself with Set-Mailbox, so watch both. Exclude your own domains so only external forwarding surfaces.
CloudAppEvents
| where Timestamp > ago(30d)
| where Application == "Microsoft Exchange Online"
| where ActionType in ("New-InboxRule", "Set-InboxRule", "Set-Mailbox",
"UpdateInboxRules")
| extend Raw = tostring(RawEventData)
| where Raw has_any ("ForwardTo", "ForwardAsAttachmentTo", "RedirectTo",
"ForwardingSmtpAddress", "DeliverToMailboxAndForward")
| where Raw !has "yourdomain.com" // set to your own domains
| project Timestamp, AccountDisplayName, AccountObjectId, ActionType,
IPAddress, CountryCode, Isp, RawRank what remains by whether the internet provider or country the rule came from is one the user has used before. A rule created from a provider new to the user is the high-confidence case.
Some malicious rules exist to hide mail rather than forward it: replies to the attacker, security notices and bounces are moved to a folder nobody reads, such as RSS Feeds or Conversation History, marked read, or deleted.
CloudAppEvents
| where Timestamp > ago(30d)
| where Application == "Microsoft Exchange Online"
| where ActionType in ("New-InboxRule", "Set-InboxRule")
| extend Raw = tostring(RawEventData)
| where Raw has "DeleteMessage"
or (Raw has_any ("MoveToFolder", "MarkAsRead")
and Raw has_any ("RSS", "Conversation History", "Archive"))
| project Timestamp, AccountDisplayName, IPAddress, ActionType, RawInstead of forwarding, the attacker grants an account they control full access or send-as rights on the victim's mailbox and reads it directly. No mail leaves the tenant, and the grant is an Exchange permission change.
CloudAppEvents
| where Timestamp > ago(30d)
| where Application == "Microsoft Exchange Online"
| where ActionType in ("Add-MailboxPermission", "Add-RecipientPermission",
"Add-MailboxFolderPermission")
| extend Raw = tostring(RawEventData)
| where Raw has_any ("FullAccess", "SendAs", "SendOnBehalf", "Owner")
| project Timestamp, Actor = AccountDisplayName, ActionType, IPAddress,
RawMailItemsAccessed records mail being read, with the client address. Reads from an address the user has never read from are the signal. Build the baseline from a window that ends before the activity you are hunting, or the attacker's own reads become part of what is usual.
let baseline = OfficeActivity
| where TimeGenerated between (ago(30d) .. ago(21d))
| where Operation == "MailItemsAccessed"
| distinct UserId, ClientIP;
OfficeActivity
| where TimeGenerated > ago(21d) and Operation == "MailItemsAccessed"
| join kind=leftanti baseline on UserId, ClientIP
| summarize Reads = count(), First = min(TimeGenerated),
Last = max(TimeGenerated) by UserId, ClientIP
| sort by First ascTeams holds as much as the mailbox, and a stolen token reads it through Microsoft Graph. Message reads at a rate no person scrolls, through an application the user does not normally use, are the fingerprint of a script.
CloudAppEvents
| where Timestamp > ago(30d)
| where ActionType == "MessagesListed"
| summarize Reads = count() by AccountDisplayName, OAuthAppId,
bin(Timestamp, 1h)
| where Reads > 50
| sort by Reads descAn application using its own credentials calls Microsoft Graph with no signed-in user, so the record carries no UserId. MicrosoftGraphActivityLogs records each call with the client address, the URI and the response size. App-only calls from outside your own address ranges, joined to IdentityInfo to name the mailboxes touched, show which applications read what.
// Replace 203.0.113. (a documentation range) with your own egress
MicrosoftGraphActivityLogs
| where TimeGenerated > ago(30d)
| where isempty(UserId) and not(IPAddress startswith "203.0.113.")
| extend Target = extract(@"/users/([0-9a-f-]{36})/", 1, RequestUri)
| join kind=leftouter (IdentityInfo
| summarize by Target = AccountObjectId, Mailbox = AccountUPN) on Target
| summarize Calls = count(), Mailboxes = dcount(Mailbox),
KB = round(sum(ResponseSizeBytes) / 1024.0, 0) by AppId, IPAddressRather than download files, an attacker builds a Power Automate flow that copies mail or files to an outside endpoint on every new item. Nothing interactive happens after it is created. Power Automate audits flow creation and edits with the connectors the flow uses.
CloudAppEvents
| where Timestamp > ago(30d)
| where Application == "Microsoft Power Automate"
| where ActionType contains "flow"
| extend Connectors = tostring(RawEventData.FlowConnectorNames)
| project Timestamp, AccountDisplayName, ActionType, Connectors, IPAddress
| sort by Timestamp descEvasion and discovery
An attacker who blinds the audit log blinds every other detection here, so treat tampering with it as the highest priority on the page. Discovery is quieter and earlier.
The Microsoft 365 unified audit log is behind most of the detections on this page. An account holding the Audit Logs role in Exchange Online can turn it off with one command, and the change is itself audited. If you see it and did not authorize it, assume compromise.
OfficeActivity
| where TimeGenerated > ago(30d)
| where Operation == "Set-AdminAuditLogConfig"
| extend Params = tostring(Parameters)
| where Params has "UnifiedAuditLogIngestionEnabled" and Params has "False"
| project TimeGenerated, UserId, ClientIP, Operation, Params
| sort by TimeGenerated descAfter sending an internal phish or a payment request from the mailbox, the attacker deletes it: hard deletes in Sent Items, a purge of Deleted Items. Exchange audits each delete.
CloudAppEvents
| where Timestamp > ago(30d)
| where Application == "Microsoft Exchange Online"
| where ActionType in ("HardDelete", "SoftDelete", "MoveToDeletedItems")
| summarize Deletes = count() by AccountDisplayName, ActionType,
bin(Timestamp, 1h)
| where Deletes > 20
| sort by Deletes descWith access in hand, an attacker lists users, groups, roles and applications to find the next target. Through Microsoft Graph that is a run of read requests against the directory endpoints, far more than a person makes.
MicrosoftGraphActivityLogs
| where TimeGenerated > ago(30d) and RequestMethod == "GET"
| where RequestUri matches regex
@"/(v1\.0|beta)/(users|groups|directoryRoles|servicePrincipals)"
| summarize Requests = count(), Endpoints = dcount(RequestUri)
by UserId, AppId, IPAddress, bin(TimeGenerated, 1h)
| where Requests > 100
| sort by Requests descImpact and fraud
For many intrusions this is the objective: use the mailbox to move money or reach more people, and slow the response while doing it.
Once inside a mailbox, the attacker phishes other employees from it. The mail comes from a trusted internal sender, so it carries a colleague's credibility. Look for internal mail Defender flagged, and for one sender reaching many internal recipients at once.
EmailEvents
| where Timestamp > ago(30d)
| where EmailDirection == "Intra-org"
| where ThreatTypes has_any ("Phish", "Malware")
| summarize Recipients = dcount(RecipientEmailAddress),
Subjects = make_set(Subject, 10)
by SenderFromAddress, bin(Timestamp, 1h)
| where Recipients > 5
| sort by Recipients descThe payoff of most mailbox compromises is a message sent as the victim: a change of bank details to a supplier, or a payment request. Rules on message content fail because the attacker writes the way the victim writes. A send from an address the account has never sent from catches the session instead.
let baseline = OfficeActivity
| where TimeGenerated between (ago(30d) .. ago(23d))
| where Operation == "Send"
| distinct UserId, ClientIP;
OfficeActivity
| where TimeGenerated > ago(23d) and Operation == "Send"
| join kind=leftanti baseline on UserId, ClientIP
| summarize Sends = count(), First = min(TimeGenerated),
Last = max(TimeGenerated) by UserId, ClientIPTo slow the response, an attacker resets the victim's password, revokes their sessions or disables the account, while keeping a live token of their own. In Entra ID that is an account change made by someone other than the account.
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in ("Reset user password", "Disable account",
"Revoke user sessions")
| extend Actor = tostring(parse_json(InitiatedBy).user.userPrincipalName),
Account = tostring(parse_json(TargetResources)[0].userPrincipalName)
| where isnotempty(Actor) and Actor != Account
| project TimeGenerated, Actor, Account, OperationName
| sort by TimeGenerated descOutlook rules can start an application or run a script when mail arrives, and they persist in the mailbox through a password reset. The actions are rare in current tenants, so any rule that carries one deserves a look.
CloudAppEvents
| where Timestamp > ago(30d)
| where Application == "Microsoft Exchange Online"
| where ActionType in ("New-InboxRule", "Set-InboxRule", "UpdateInboxRules")
| extend Raw = tostring(RawEventData)
| where Raw has_any ("StartApplication", "RunScript")
| project Timestamp, AccountDisplayName, IPAddress, ActionType, RawCorrelation detections
Single-technique rules catch single techniques. These join two events from the same account in a short window, and the alerts they produce are close to actionable on arrival.
The adversary-in-the-middle chain is a click on a phishing link, then a session from a new place using the stolen cookie. Users click links and travel every day; joined within an hour, the two are the attack.
let window = 1h;
let clicks = UrlClickEvents
| where Timestamp > ago(30d)
| where ThreatTypes has "Phish" or IsClickedThrough == true
| project ClickTime = Timestamp, AccountUpn, Url;
EntraIdSignInEvents
| where Timestamp > ago(30d)
| where RiskLevelDuringSignIn >= 50 // 50 medium, 100 high
| project SignInTime = Timestamp, AccountUpn, IPAddress, Country,
RiskLevelDuringSignIn
| join kind=inner clicks on AccountUpn
| where SignInTime between (ClickTime .. (ClickTime + window))
| project AccountUpn, ClickTime, Url, SignInTime, IPAddress, CountryMail compromise has a recognizable staging step: a sign-in from an address the user does not normally use, then within a day a rule that hides or forwards mail on the same account. It fires before the fraudulent message goes out. OfficeActivity records the UPN in UserId, so the join is on the account, not a display name.
let usual = SigninLogs
| where TimeGenerated > ago(30d) and ResultType == 0
| summarize SignIns = count() by UserPrincipalName, IPAddress
| where SignIns >= 5;
let new_address = union SigninLogs, AADNonInteractiveUserSignInLogs
| where TimeGenerated > ago(30d) and ResultType == 0
| join kind=leftanti usual on UserPrincipalName, IPAddress
| summarize SignIn = min(TimeGenerated) by UserPrincipalName, IPAddress;
OfficeActivity
| where TimeGenerated > ago(30d)
| where Operation in ("New-InboxRule", "Set-InboxRule", "Set-Mailbox")
| extend Params = tostring(Parameters)
| where Params has_any ("RSS", "Conversation History", "DeleteMessage",
"ForwardTo", "RedirectTo", "ForwardingSmtpAddress")
| project RuleTime = TimeGenerated, UserPrincipalName = UserId, Operation,
RuleIP = ClientIP
| join kind=inner new_address on UserPrincipalName
| where RuleTime between (SignIn .. (SignIn + 24h))
| project UserPrincipalName, IPAddress, SignIn, RuleTime, RuleIP, OperationConsent phishing gets a user to approve an application that then reads their mail. The consent records the user's object id; CloudAppEvents records mail reads with the mailbox owner's object id and, for an application, its AppId. Joining the two on the user shows an application reading the mailbox of the person who just consented.
let consents = AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in ("Consent to application",
"Add delegated permission grant")
| project ConsentTime = TimeGenerated,
AccountObjectId = tostring(parse_json(InitiatedBy).user.id),
App = tostring(parse_json(TargetResources)[0].displayName);
CloudAppEvents
| where Timestamp > ago(30d) and ActionType == "MailItemsAccessed"
| extend AppId = tostring(RawEventData.AppId)
| where isnotempty(AppId)
| summarize Reads = count(), FirstRead = min(Timestamp)
by AccountObjectId, AppId
| join kind=inner consents on AccountObjectId
| where FirstRead between (ConsentTime .. (ConsentTime + 7d))
| project AccountObjectId, App, AppId, ConsentTime, FirstRead, ReadsA taken-over administrator account gives itself away by speed: a risky sign-in followed within two hours by a role grant, a Conditional Access change, a credential added to an application, or a federation change. Administrators do these things from their usual places.
let risky = SigninLogs
| where TimeGenerated > ago(30d)
| where RiskLevelDuringSignIn in ("high", "medium")
| project RiskTime = TimeGenerated, UserPrincipalName, IPAddress,
Country = tostring(LocationDetails.countryOrRegion);
AuditLogs
| where TimeGenerated > ago(30d)
| where OperationName in~ ("Add member to role",
"Add conditional access policy", "Update conditional access policy",
"Add service principal credentials", "Set domain authentication")
| extend Actor = parse_json(InitiatedBy).user
| project ActionTime = TimeGenerated, OperationName,
UserPrincipalName = tostring(Actor.userPrincipalName)
| join kind=inner risky on UserPrincipalName
| where ActionTime between (RiskTime .. (RiskTime + 2h))
| project UserPrincipalName, RiskTime, IPAddress, Country, ActionTime,
OperationNameRun these detections in a working SOC
This reference shows you the detections. Microsoft SOC Detection and Response teaches you to run them in your own tenant: investigating the incidents they raise, and keeping the detections, automation and data behind them working.
Read the first module free →Weekly security engineering insights
Detection techniques, architecture patterns, and operational judgment, every Tuesday.
No spam. Unsubscribe anytime.