Query Details
// Rule : M365 - Suspicious File Extension Uploaded to SharePoint / OneDrive / Teams
// Severity : High
// Tactics : InitialAccess, Execution, LateralMovement
// MITRE : T1105 (Ingress Tool Transfer), T1566.002 (Phishing: Spear Phishing Link),
// T1204.002 (User Execution: Malicious File)
// Freq : PT1H / Period: P1D
// Purpose : Detect uploads of executables, scripts, and other high-risk file types to
// SharePoint, OneDrive, or Teams. Adversaries stage tools via cloud storage to
// bypass perimeter email gateways. Rule fires on any single suspicious upload;
// severity is scaled by extension risk tier.
//==========================================================================================
let LookbackDays = 1d;
// Tier-1 (High): binary executables and loaders
let Tier1 = dynamic([
".exe", ".dll", ".scr", ".pif", ".com", ".cpl",
".ocx", ".sys", ".drv"]);
// Tier-2 (High): scripting and macro languages
let Tier2 = dynamic([
".ps1", ".psm1", ".psd1",
".bat", ".cmd",
".vbs", ".vbe", ".js", ".jse", ".wsf", ".wsh",
".hta", ".sh", ".bash"]);
// Tier-3 (Medium): package installers and archives with code
let Tier3 = dynamic([
".msi", ".msp", ".mst",
".jar", ".war", ".ear",
".py", ".rb", ".pl", ".php"]);
OfficeActivity
| where TimeGenerated > ago(LookbackDays)
| where RecordType in (
"SharePoint", "SharePointFileOperation",
"OneDrive", "OneDriveFileOperation",
"MicrosoftTeams")
| where Operation in (
"FileUploaded",
"FileSyncUploadedFull",
"FileCheckedIn",
"FileModifiedExtended",
"FileAdded")
| extend FileName = tostring(SourceFileName)
| extend FileExtension = tolower(extract(@"(\.[^.\\/:*?""<>|]+)$", 1, FileName))
| where FileExtension in (array_concat(Tier1, Tier2, Tier3))
| extend
RiskTier = case(
FileExtension in (Tier1), "Tier1-Binary",
FileExtension in (Tier2), "Tier2-Script",
"Tier3-Installer"),
AlertSeverity = case(
FileExtension in (Tier1), "High",
FileExtension in (Tier2), "High",
"Medium"),
Workload = case(
RecordType in ("SharePoint","SharePointFileOperation"), "SharePoint",
RecordType in ("OneDrive","OneDriveFileOperation"), "OneDrive",
RecordType == "MicrosoftTeams", "Teams",
"Other"),
IsGuest = UserId has "#EXT#"
| project
TimeGenerated,
UserId,
IsGuest,
Workload,
Operation,
FileName,
FileExtension,
RiskTier,
AlertSeverity,
SiteUrl,
ClientIP,
UserAgent
| sort by AlertSeverity asc, TimeGenerated desc
This query is designed to detect potentially dangerous file uploads to Microsoft 365 services like SharePoint, OneDrive, and Teams. Here's a simple breakdown of what it does:
Purpose: The query aims to identify uploads of executable files, scripts, and other risky file types to cloud storage services. This is important because attackers might use these services to bypass security measures like email gateways.
Time Frame: It looks at activities from the past day.
File Categories:
.exe and .dll..ps1 and .bat..msi and .jar.Data Source: It examines records from SharePoint, OneDrive, and Teams activities.
Operations Monitored: It checks for file uploads, syncs, check-ins, modifications, and additions.
File Extension Check: It extracts the file extension from the uploaded files and checks if it belongs to any of the risky categories (Tier-1, Tier-2, Tier-3).
Risk Assessment:
Additional Information:
Output: The query projects relevant details like the time of the event, user ID, whether the user is a guest, the service used, the operation performed, file details, risk tier, alert severity, site URL, client IP, and user agent.
Sorting: The results are sorted by alert severity (ascending) and time (descending), so the most recent and severe alerts are prioritized.
In summary, this query helps security teams monitor and respond to suspicious file uploads that could indicate malicious activity or security breaches.

David Alonso
Released: March 18, 2026
Tables
Keywords
Operators