Initial Access (TA0001)(external, opens in a new tab or window)
text code block:FROM logs-o365.audit-* | WHERE @timestamp >= NOW() - 14 days AND data_stream.dataset == "o365.audit" AND event.provider == "AzureActiveDirectory" AND event.action == "UserLoggedIn" AND event.outcome == "success" AND TO_INTEGER(o365.audit.Target.Type) IN (0, 2, 3, 5, 6, 10) AND o365.audit.UserId IS NOT NULL AND o365.audit.UserId != "Not Available" AND source.geo.country_name IS NOT NULL AND source.geo.region_name IS NOT NULL AND (source.`as`.organization.name IS NULL OR source.`as`.organization.name NOT IN ("ZSCALER, INC.", "Zscaler Switzerland GmbH", "Netskope Inc")) AND o365.audit.ApplicationId IS NOT NULL AND o365.audit.ApplicationId NOT IN ( "08e18876-6177-487e-b8b5-cf950c1e598c", "29d9ed98-a469-4536-ade2-f981bc1d605e", "38aa3b87-a06d-4817-b275-7a316988d93b", "3e62f81e-590b-425b-9531-cad6683656cf", "a809996b-059e-42e2-9866-db24b99a9782", "d7b530a4-7680-4c23-a8bf-c52c121d2e87" ) AND o365.audit.ExtendedProperties.RequestType IS NOT NULL AND o365.audit.ExtendedProperties.RequestType NOT IN ( "BulkAADJToken:BulkAADJTokenPoll", "Consent:Set", "DeviceAuth:PKeyAuth", "DeviceAuth:ReprocessTls", "Federation:externalauthcallback", "Federation:oauth2claimsprovider", "Federation:oauth2msa", "KerberosProxy:kerberos", "Kmsi:kmsi", "Login:reprocess", "Login:resume", "MessagePrompt:MessagePrompt", "OrgIdWsFederation:federation", "OrgIdWsTrust2:extsts", "PermitSso:PermitSso", "RegionalCacheAuth:regionalcacheauthtoken", "SAS:BeginAuth", "SAS:EndAuth", "SAS:ProcessAuth", "SSPR:end", "Saml2:processrequest", "UserInfo:Index", "WebNativeBridgeController:WebNativeBridgeReprocess", "WsFederation:wsfederation" ) AND ( user_agent.original IS NULL OR ( user_agent.original NOT LIKE "*Android*" AND user_agent.original NOT LIKE "*PKeyAuth*" AND user_agent.original NOT LIKE "*WebView*" AND user_agent.original NOT LIKE "*iPad*" AND user_agent.original NOT LIKE "*iPhone*" ) ) | STATS Esql.first_seen = MIN(@timestamp), Esql.first_ingested = MIN(COALESCE(event.ingested, @timestamp)), Esql.last_seen = MAX(@timestamp), Esql.event_count = COUNT(*), Esql.source_as_organization_name_values = VALUES(source.`as`.organization.name), Esql.source_ip_values = VALUES(source.ip), Esql.user_agent_original_values = VALUES(user_agent.original), Esql.application_id_values = VALUES(o365.audit.ApplicationId), Esql.request_type_values = VALUES(o365.audit.ExtendedProperties.RequestType), Esql.object_id_values = VALUES(o365.audit.ObjectId), Esql.result_status_detail_values = VALUES(o365.audit.ExtendedProperties.ResultStatusDetail), Esql.user_type_values = VALUES(o365.audit.UserType), Esql.aad_session_id_values = VALUES(o365.audit.AppAccessContext.AADSessionId), Esql.actor_ip_values = VALUES(o365.audit.ActorIpAddress), Esql.user_key_values = VALUES(o365.audit.UserKey), Esql.token_object_id_values = VALUES(o365.audit.TokenObjectId) BY o365.audit.UserId, source.geo.country_name, source.geo.region_name | WHERE Esql.first_ingested >= NOW() - 10 minutes | KEEP Esql.*, o365.audit.UserId, source.geo.country_name, source.geo.region_name
Install detection rules in Elastic Security
Detect M365 Identity Login from Atypical Region in the Elastic Security detection engine by installing this rule into your Elastic Stack.
To setup this rule, check out the installation guide for Prebuilt Security Detection Rules(external, opens in a new tab or window).