Microsoft Azure or Mail Sign-in from a Suspicious Source

This rule correlate Azure or Office 356 mail successful sign-in events with network security alerts by source.ip. Adversaries may trigger some network security alerts such as reputation or other anomalies before accessing cloud resources.

Elastic rule (View on GitHub)

  1[metadata]
  2creation_date = "2025/04/29"
  3integration = ["azure", "o365"]
  4maturity = "production"
  5updated_date = "2025/04/29"
  6min_stack_version = "8.17.0"
  7min_stack_comments = "Elastic ES|QL query functions limitation."
  8
  9
 10[rule]
 11author = ["Elastic"]
 12description = """
 13This rule correlate Azure or Office 356 mail successful sign-in events with network security alerts by source.ip.
 14Adversaries may trigger some network security alerts such as reputation or other anomalies before accessing cloud resources.
 15"""
 16false_positives = [
 17    """
 18    Custom network security rules that triggers on a proxy or gateway used by users to access Azure or O365.
 19    """,
 20]
 21from = "now-60m"
 22language = "esql"
 23license = "Elastic License v2"
 24name = "Microsoft Azure or Mail Sign-in from a Suspicious Source"
 25note = """## Triage and analysis
 26
 27### Investigating Microsoft Azure or Mail Sign-in from a Suspicious Source
 28
 29#### Possible investigation steps
 30
 31- Investiguate all the alerts associated with the source.ip.
 32  - Verify the network security alert details associated with this source.ip.
 33  - Verify all sign-in events associated with this source.ip.
 34  - Consider the source IP address and geolocation for the involved user account.
 35  - Consider the device used to sign in. Is it registered and compliant?
 36- Investigate other alerts associated with the user account during the past 48 hours.
 37- Contact the account owner and confirm whether they are aware of this activity.
 38- Check if this operation was approved and performed according to the organization's change management policy.
 39- If you suspect the account has been compromised, scope potentially compromised assets by tracking servers, services, and data accessed by the account in the last 24 hours.
 40
 41### Response and remediation
 42
 43- Initiate the incident response process based on the outcome of the triage.
 44- Disable or limit the account during the investigation and response.
 45- Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
 46    - Identify the account role in the cloud environment.
 47    - Assess the criticality of affected services and servers.
 48    - Work with your IT team to identify and minimize the impact on users.
 49    - Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
 50    - Identify any regulatory or legal ramifications related to this activity.
 51- Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords or delete API keys as needed to revoke the attacker's access to the environment. Work with your IT teams to minimize the impact on business operations during these actions.
 52- Check if unauthorized new users were created, remove unauthorized new accounts, and request password resets for other IAM users.
 53- Consider enabling multi-factor authentication for users.
 54- Follow security best practices [outlined](https://docs.microsoft.com/en-us/azure/security/fundamentals/identity-management-best-practices) by Microsoft.
 55- Determine the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
 56- Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).
 57
 58## Setup
 59
 60The Azure Fleet integration, Office 365 Logs Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule."""
 61risk_score = 73
 62rule_id = "f0cc239b-67fa-46fc-89d4-f861753a40f5"
 63severity = "high"
 64tags = [
 65    "Domain: Cloud",
 66    "Domain: SaaS",
 67    "Data Source: Azure",
 68    "Data Source: Entra ID",
 69    "Data Source: Entra ID Sign-in Logs",
 70    "Data Source: Microsoft 365",
 71    "Data Source: Microsoft 365 Audit Logs",
 72    "Use Case: Identity and Access Audit",
 73    "Use Case: Threat Detection",
 74    "Tactic: Initial Access",
 75    "Resources: Investigation Guide",
 76    "Rule Type: Higher-Order Rule"
 77]
 78timestamp_override = "event.ingested"
 79type = "esql"
 80
 81query = '''
 82FROM logs-*, .alerts-security.*
 83// query runs every 1 hour looking for activities occured during last 8 hours to match on disparate events
 84| where @timestamp > NOW() - 8 hours
 85// filter for Azure or M365 sign-in and External Alerts with source.ip not null
 86| where TO_IP(source.ip) is not null and (event.dataset in ("o365.audit", "azure.signinlogs") or kibana.alert.rule.name == "External Alerts") and
 87// exclude private IP ranges
 88  not CIDR_MATCH(TO_IP(source.ip), "10.0.0.0/8", "127.0.0.0/8", "169.254.0.0/16", "172.16.0.0/12", "192.0.0.0/24", "192.0.0.0/29", "192.0.0.8/32", "192.0.0.9/32", "192.0.0.10/32", "192.0.0.170/32", "192.0.0.171/32", "192.0.2.0/24", "192.31.196.0/24", "192.52.193.0/24", "192.168.0.0/16", "192.88.99.0/24", "224.0.0.0/4", "100.64.0.0/10", "192.175.48.0/24","198.18.0.0/15", "198.51.100.0/24", "203.0.113.0/24", "240.0.0.0/4", "::1","FE80::/10", "FF00::/8")
 89| keep source.ip, event.action, event.outcome, event.dataset, kibana.alert.rule.name, event.category
 90// split alerts to 3 buckets -  M365 mail access, azure sign-in and network related external alerts like NGFW and IDS
 91| eval mail_access_src_ip = case(event.dataset == "o365.audit" and event.action == "MailItemsAccessed" and event.outcome == "success", TO_IP(source.ip), null),
 92  azure_src_ip = case(event.dataset == "azure.signinlogs" and event.outcome == "success", TO_IP(source.ip), null),
 93  network_alert_src_ip = case(kibana.alert.rule.name == "External Alerts" and not event.dataset in ("o365.audit", "azure.signinlogs"), TO_IP(source.ip), null)
 94// aggregated alerts count by bucket and by source.ip
 95| stats total_alerts = count(*), is_mail_access = COUNT_DISTINCT(mail_access_src_ip), is_azure = COUNT_DISTINCT(azure_src_ip), unique_dataset = COUNT_DISTINCT(event.dataset),is_network_alert = COUNT_DISTINCT(network_alert_src_ip), datasets = VALUES(event.dataset), rules = VALUES(kibana.alert.rule.name), cat = VALUES(event.category) by source_ip = TO_IP(source.ip)
 96// filter for cases where there is a successful sign-in to azure or m365 mail and the source.ip is reported by a network external alert.
 97| where is_network_alert  > 0 and (is_mail_access > 0 or is_azure > 0 and unique_dataset >= 2)
 98'''
 99
100
101[[rule.threat]]
102framework = "MITRE ATT&CK"
103[[rule.threat.technique]]
104id = "T1078"
105name = "Valid Accounts"
106reference = "https://attack.mitre.org/techniques/T1078/"
107
108
109[rule.threat.tactic]
110id = "TA0001"
111name = "Initial Access"
112reference = "https://attack.mitre.org/tactics/TA0001/"

Triage and analysis

Investigating Microsoft Azure or Mail Sign-in from a Suspicious Source

Possible investigation steps

  • Investiguate all the alerts associated with the source.ip.
    • Verify the network security alert details associated with this source.ip.
    • Verify all sign-in events associated with this source.ip.
    • Consider the source IP address and geolocation for the involved user account.
    • Consider the device used to sign in. Is it registered and compliant?
  • Investigate other alerts associated with the user account during the past 48 hours.
  • Contact the account owner and confirm whether they are aware of this activity.
  • Check if this operation was approved and performed according to the organization's change management policy.
  • If you suspect the account has been compromised, scope potentially compromised assets by tracking servers, services, and data accessed by the account in the last 24 hours.

Response and remediation

  • Initiate the incident response process based on the outcome of the triage.
  • Disable or limit the account during the investigation and response.
  • Identify the possible impact of the incident and prioritize accordingly; the following actions can help you gain context:
    • Identify the account role in the cloud environment.
    • Assess the criticality of affected services and servers.
    • Work with your IT team to identify and minimize the impact on users.
    • Identify if the attacker is moving laterally and compromising other accounts, servers, or services.
    • Identify any regulatory or legal ramifications related to this activity.
  • Investigate credential exposure on systems compromised or used by the attacker to ensure all compromised accounts are identified. Reset passwords or delete API keys as needed to revoke the attacker's access to the environment. Work with your IT teams to minimize the impact on business operations during these actions.
  • Check if unauthorized new users were created, remove unauthorized new accounts, and request password resets for other IAM users.
  • Consider enabling multi-factor authentication for users.
  • Follow security best practices outlined by Microsoft.
  • Determine the initial vector abused by the attacker and take action to prevent reinfection via the same vector.
  • Using the incident response data, update logging and audit policies to improve the mean time to detect (MTTD) and the mean time to respond (MTTR).

Setup

The Azure Fleet integration, Office 365 Logs Fleet integration, Filebeat module, or similarly structured data is required to be compatible with this rule.

Related rules

to-top