Query Details
// Rule : M365 - SharePoint / OneDrive Mass File Download or Sync
// Severity: High
// Tactics : Collection, Exfiltration
// MITRE : T1530 (Data from Cloud Storage), T1537 (Transfer Data to Cloud Account)
// Freq : PT1H Period: PT1H
// Description: Detects anomalous bulk file downloads or OneDrive sync activity
// from SharePoint. Baseline uses 14-day per-user average; triggers when
// current hour exceeds 3x baseline or an absolute threshold.
//==========================================================================================
let AbsoluteThreshold = 100; // files per hour trigger regardless of baseline
let BaselineMultiplier = 3.0;
let LookbackPeriod = 1h;
let BaselineDays = 14d;
// Per-user baseline download average per hour
let Baseline = OfficeActivity
| where TimeGenerated between (ago(BaselineDays) .. ago(LookbackPeriod))
| where RecordType in ("SharePoint", "OneDrive")
| where Operation in ("FileDownloaded", "FileSyncDownloadedFull", "FileSyncDownloadedPartial")
| summarize HourlyEvents = count() by UserId, bin(TimeGenerated, 1h)
| summarize AvgHourly = avg(HourlyEvents), StdDev = stdev(HourlyEvents) by UserId;
// Current hour
OfficeActivity
| where TimeGenerated > ago(LookbackPeriod)
| where RecordType in ("SharePoint", "OneDrive")
| where Operation in ("FileDownloaded", "FileSyncDownloadedFull", "FileSyncDownloadedPartial")
| summarize
DownloadCount = count(),
FileList = make_set(SourceFileName, 20),
SiteURLs = make_set(SiteUrl, 5),
ClientIPs = make_set(ClientIP, 5),
UserAgents = make_set(UserAgent, 3)
by UserId
| join kind=leftouter Baseline on UserId
| extend
AvgHourly = coalesce(AvgHourly, 0.0),
Threshold = max_of(todouble(AbsoluteThreshold), AvgHourly * BaselineMultiplier)
| where DownloadCount >= Threshold
| extend AlertSeverity = case(
DownloadCount >= 500, "High",
DownloadCount >= 200, "Medium",
"Low")
| project
TimeGenerated = now(),
UserId,
DownloadCount,
AvgHourlyBaseline = round(AvgHourly, 1),
Threshold = round(Threshold, 0),
FileList,
SiteURLs,
ClientIPs,
AlertSeverity
This query is designed to detect unusual bulk file downloads or synchronization activities from SharePoint or OneDrive, which could indicate potential data exfiltration. Here's a simplified breakdown of what the query does:
Thresholds and Baseline Setup:
Baseline Calculation:
Current Activity Monitoring:
Comparison and Alerting:
Alert Severity:
Output:
In essence, this query helps identify potential security incidents by flagging users who download an unusually large number of files from SharePoint or OneDrive within a short period.

David Alonso
Released: March 18, 2026
Tables
Keywords
Operators