Skip to content

[Rule Tuning] M365 Exchange Inbox Rule with Obfuscated Name: grok expects two backslashes, rule never fires #7271

Backlog

Description

@ahmed-aoc

Link to Rule

https://github.com/elastic/detection-rules/blob/main/rules/integrations/o365/defense_evasion_exchange_inbox_rule_obfuscated_name.toml

Rule Tuning Type

False Negatives - Enhancing detection of true threats that were previously missed.

Description

The rule can never fire because the grok pattern never matches real o365.audit.ObjectId values.

The query uses a triple-quoted ES|QL string:

| grok o365.audit.ObjectId """.*\\\\(?<Esql.inbox_rule_name>.*)$"""

Triple-quoted strings are passed through as-is, so the regex engine receives \\\\, which matches two literal backslashes. Exchange writes one backslash between the mailbox identity and the rule name, for example:

NAMPR03A011.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/contoso.onmicrosoft.com/0b9c1c1e-1111-2222-3333-444455556666\Forward to archive

So Esql.inbox_rule_name is always null, the following rlike drops every row, and an inbox rule named only with symbols (for example ...) is never reported.

Repro against real New-InboxRule audit records (Elastic Cloud Serverless, current o365 integration):

FROM logs-o365.audit-*
| WHERE event.action == "New-InboxRule"
| GROK o365.audit.ObjectId """.*\\\\(?<Esql.inbox_rule_name>.*)$"""
| KEEP o365.audit.ObjectId, Esql.inbox_rule_name

returns null for Esql.inbox_rule_name on every row. With a single escaped backslash it returns the rule name correctly:

| GROK o365.audit.ObjectId """.*\\(?<Esql.inbox_rule_name>.*)$"""

Suggested fix: change the grok pattern to """.*\\(?<Esql.inbox_rule_name>.*)$""".

We tested the fixed rule in rule preview: it alerts on a New-InboxRule whose name is ... and stays quiet for a normal name such as Forward to archive.

Example Data

{
  "data_stream.dataset": "o365.audit",
  "event.provider": "Exchange",
  "event.action": "New-InboxRule",
  "event.outcome": "success",
  "o365.audit.UserId": "user@contoso.onmicrosoft.com",
  "o365.audit.ObjectId": "NAMPR03A011.PROD.OUTLOOK.COM/Microsoft Exchange Hosted Organizations/contoso.onmicrosoft.com/0b9c1c1e-1111-2222-3333-444455556666\\...",
  "source.ip": "203.0.113.10"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions