Detection rules › YARA-L

O365 OneDrive Anonymous File Accessed

Severity
medium
Type
hunt
Time window
5m
Match by
ip
Author
Google Cloud Security
Source
github.com/chronicle/detection-rules

Anonymous links can be used to export files from OneDrive. While this isn't always a sign of malicious activity, some organizations do not support the use of anonymous links because of the risk of data leakage. This rule detects when anonymous links are used to access files from OneDrive.

MITRE ATT&CK coverage

Telemetry coverage

PlatformRecord / event type
Microsoft 365FileAccessed

Rule body

// Copyright 2025 Google LLC. Licensed under Apache-2.0.

rule o365_onedrive_anonymous_file_accessed {

  meta:
    author = "Google Cloud Security"
    description = "Anonymous links can be used to export files from OneDrive. While this isn't always a sign of malicious activity, some organizations do not support the use of anonymous links because of the risk of data leakage. This rule detects when anonymous links are used to access files from OneDrive."
    rule_id = "mr_f713e2b0-31b1-4165-8764-59a5e2c5eabc"
    rule_name = "O365 OneDrive Anonymous File Accessed"
    tactic = "TA0010"
    technique = "T1048.002"
    type = "hunt"
    platform = "azure"
    data_source = "o365"
    severity = "Medium"
    priority = "Medium"

  events:
    $file.metadata.event_type = "USER_RESOURCE_ACCESS"
    $file.metadata.product_event_type = "FileAccessed"
    $file.metadata.product_name = "Office 365"
    $file.metadata.vendor_name = "Microsoft"
    (
        $file.principal.user.userid = /^urn:spo:anon#/ or
        $file.principal.user.userid = "anonymous"
    )
    $file.principal.ip = $ip

  match:
    $ip over 5m

  outcome:
    $risk_score = 35
    $event_count = count_distinct($file.metadata.id)
    $referral_url = array_distinct($file.network.http.referral_url)
    $user_agent = array_distinct($file.network.http.user_agent)
    $principal_application = array_distinct($file.principal.application)
    $principal_ip = array_distinct($file.principal.ip)  //IP is a Microsoft IP address not the individual who accessed the file
    $target_application = array_distinct($file.target.application)
    $principal_user_userid = array_distinct($file.principal.user.userid)
    $target_file_full_path = array_distinct($file.target.file.full_path)
    $target_url = array_distinct($file.target.url)

  condition:
    $file
}

YARA-L rule structure

Condition

Fires when at least one $file event in the 5m window.

Events

$file USER_RESOURCE_ACCESS

  • metadata.product_event_type = "FileAccessed"
  • principal.user.userid matches "^urn:spo:anon#"
  • principal.user.userid = "anonymous"

Match and correlation

Match key
$ip (principal.ip)
Within
5m

Outcome

Outcome variables add context to a detection. When the rule generates an alert, $risk_score is displayed with it.

FieldExpression
risk_score35
event_countcount_distinct($file.metadata.id)
referral_urlarray_distinct($file.network.http.referral_url)
user_agentarray_distinct($file.network.http.user_agent)
principal_applicationarray_distinct($file.principal.application)
principal_iparray_distinct($file.principal.ip)
target_applicationarray_distinct($file.target.application)
principal_user_useridarray_distinct($file.principal.user.userid)
target_file_full_patharray_distinct($file.target.file.full_path)
target_urlarray_distinct($file.target.url)