Query Details
// Exploring M365 Accounts Investigation // https://www.linkedin.com/posts/0x534c_cybersecurity-m365investigation-kql-activity-7300859391950344192-xedq/ let UserSSPR = AuditLogs | where TimeGenerated > ago(90d) | where OperationName has "Self-service password reset" | distinct tostring(TargetResources[0].userPrincipalName); let UserEPNonManaged = SigninLogs | where TimeGenerated > ago(90d) | where UserPrincipalName has_any(UserSSPR) | extend DeviceName = tostring(DeviceDetail.displayName) | extend TrustType = tostring(DeviceDetail.trustType) | extend OS = tostring(DeviceDetail.operatingSystem) | where OS !has "ios" and OS !has "android" | where TrustType !has "AD" | distinct UserPrincipalName; CloudAppEvents | where TimeGenerated > ago(90d) | where IPCategory has "VPN" or IPTags has "Anonymous proxy" | where tostring(RawEventData.UserId) has_any(UserEPNonManaged) | summarize Count=count() by ActionType, UserAgent, tostring(RawEventData.UserId) | sort by Count desc
This query is designed to investigate Microsoft 365 accounts with a focus on identifying potentially suspicious activities related to self-service password resets and non-managed devices. Here's a simplified breakdown:
Identify Users with Password Resets:
UserSSPR.Find Non-Managed Device Sign-ins:
UserSSPR) signed in from devices that are not managed by the organization (i.e., devices that are not iOS, Android, or trusted by Active Directory). These users are collected into a list called UserEPNonManaged.Analyze Cloud App Events for VPN or Proxy Usage:
UserEPNonManaged have accessed services through a VPN or an anonymous proxy. It summarizes the number of such events by action type, user agent, and user ID, and sorts the results by the count of occurrences in descending order.In essence, this query helps identify users who have reset their passwords and then accessed Microsoft 365 services from potentially untrusted devices, especially through VPNs or proxies, which could indicate suspicious activity.

Steven Lim
Released: February 27, 2025
Tables
Keywords
Operators