Microsoft Sentinel Analytic Rules
cloudbrothers.infoAzure Sentinel RepoToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeToggle Dark/Light/Auto modeBack to homepage

GSA Enriched Office 365 - SharePoint File Operation via Previously Unseen IPs

Back
Id7460e34e-4c99-47b2-b7c0-c42e339fc586
RulenameGSA Enriched Office 365 - SharePoint File Operation via Previously Unseen IPs
DescriptionIdentifies anomalies using user behavior by setting a threshold for significant changes in file upload/download activities from new IP addresses. It establishes a baseline of typical behavior, compares it to recent activity, and flags deviations exceeding a default threshold of 25.
SeverityMedium
TacticsExfiltration
TechniquesT1030
Required data connectorsAzureActiveDirectory
Office365
KindScheduled
Query frequency1d
Query period14d
Trigger threshold0
Trigger operatorgt
Source Urihttps://github.com/Azure/Azure-Sentinel/blob/master/Solutions/Global Secure Access/Analytic Rules/Office 365 - SharePoint_Downloads_byNewIP.yaml
Version2.0.6
Arm template7460e34e-4c99-47b2-b7c0-c42e339fc586.json
Deploy To Azure
let threshold = 25;
let szSharePointFileOperation = "SharePointFileOperation";
let szOperations = dynamic(["FileDownloaded", "FileUploaded"]);
let starttime = 14d;
let endtime = 1d;

// Define a baseline of normal user behavior for OfficeActivity
let userBaselineOffice = OfficeActivity
    | where TimeGenerated between(ago(starttime)..ago(endtime))
    | where RecordType =~ szSharePointFileOperation
    | where Operation in~ (szOperations)
    | where isnotempty(UserAgent)
    | summarize Count = count() by UserId, Operation, Site_Url, ClientIP
    | summarize AvgCount = avg(Count) by UserId, Operation, Site_Url, ClientIP;

// Get recent user activity for OfficeActivity
let recentUserActivityOffice = OfficeActivity
    | where TimeGenerated > ago(endtime)
    | where RecordType =~ szSharePointFileOperation
    | where Operation in~ (szOperations)
    | where isnotempty(UserAgent)
    | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by UserId, UserType, Operation, Site_Url, ClientIP, OfficeObjectId, OfficeWorkload, UserAgent;

// Define a baseline of normal user behavior for EnrichedMicrosoft365AuditLogs
let userBaselineEnriched = EnrichedMicrosoft365AuditLogs
    | where TimeGenerated between(ago(starttime)..ago(endtime))
    | where RecordType == szSharePointFileOperation
    | where Operation in (szOperations)
    | extend UserAgent = tostring(parse_json(tostring(AdditionalProperties)).UserAgent)
    | extend Site_Url = tostring(parse_json(tostring(AdditionalProperties)).SiteUrl)
    | where isnotempty(UserAgent)
    | summarize Count = count() by UserId, Operation, Site_Url, ClientIp
    | summarize AvgCount = avg(Count) by UserId, Operation, Site_Url, ClientIp;

// Get recent user activity for EnrichedMicrosoft365AuditLogs
let recentUserActivityEnriched = EnrichedMicrosoft365AuditLogs
    | where TimeGenerated > ago(endtime)
    | where RecordType == szSharePointFileOperation
    | where Operation in (szOperations)
    | extend UserAgent = tostring(parse_json(tostring(AdditionalProperties)).UserAgent)
    | extend Site_Url = tostring(parse_json(tostring(AdditionalProperties)).SiteUrl)
    | where isnotempty(UserAgent)
    | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by UserId, UserType, Operation, Site_Url, ClientIp, ObjectId, Workload, UserAgent;

// Combine user baselines and recent activity, calculate deviation, and deduplicate
let UserBehaviorAnalysis = userBaselineOffice
    | join kind=inner (recentUserActivityOffice) on UserId, Operation, Site_Url, ClientIP
    | union (userBaselineEnriched | join kind=inner (recentUserActivityEnriched) on UserId, Operation, Site_Url, ClientIp)
    | extend Deviation = abs(RecentCount - AvgCount) / AvgCount;

// Filter for significant deviations
UserBehaviorAnalysis
    | where Deviation > threshold
    | project StartTimeUtc, EndTimeUtc, UserId, UserType, Operation, ClientIP, Site_Url, ObjectId, OfficeObjectId, OfficeWorkload, Workload, UserAgent, Deviation, Count = RecentCount
    | order by Count desc, ClientIP asc, Operation asc, UserId asc
    | extend AccountName = tostring(split(UserId, "@")[0]), AccountUPNSuffix = tostring(split(UserId, "@")[1]);
relevantTechniques:
- T1030
name: GSA Enriched Office 365 - SharePoint File Operation via Previously Unseen IPs
requiredDataConnectors:
- dataTypes:
  - EnrichedMicrosoft365AuditLogs
  connectorId: AzureActiveDirectory
- dataTypes:
  - OfficeActivity (SharePoint)
  connectorId: Office365
entityMappings:
- fieldMappings:
  - identifier: FullName
    columnName: UserId
  - identifier: Name
    columnName: AccountName
  - identifier: UPNSuffix
    columnName: AccountUPNSuffix
  entityType: Account
- fieldMappings:
  - identifier: Address
    columnName: ClientIP
  entityType: IP
- fieldMappings:
  - identifier: Url
    columnName: Site_Url
  entityType: URL
triggerThreshold: 0
id: 7460e34e-4c99-47b2-b7c0-c42e339fc586
tactics:
- Exfiltration
version: 2.0.6
OriginalUri: https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/Global Secure Access/Analytic Rules/Office 365 - SharePoint_Downloads_byNewIP.yaml
queryPeriod: 14d
kind: Scheduled
queryFrequency: 1d
severity: Medium
status: Available
description: |
    Identifies anomalies using user behavior by setting a threshold for significant changes in file upload/download activities from new IP addresses. It establishes a baseline of typical behavior, compares it to recent activity, and flags deviations exceeding a default threshold of 25.
query: |
  let threshold = 25;
  let szSharePointFileOperation = "SharePointFileOperation";
  let szOperations = dynamic(["FileDownloaded", "FileUploaded"]);
  let starttime = 14d;
  let endtime = 1d;

  // Define a baseline of normal user behavior for OfficeActivity
  let userBaselineOffice = OfficeActivity
      | where TimeGenerated between(ago(starttime)..ago(endtime))
      | where RecordType =~ szSharePointFileOperation
      | where Operation in~ (szOperations)
      | where isnotempty(UserAgent)
      | summarize Count = count() by UserId, Operation, Site_Url, ClientIP
      | summarize AvgCount = avg(Count) by UserId, Operation, Site_Url, ClientIP;

  // Get recent user activity for OfficeActivity
  let recentUserActivityOffice = OfficeActivity
      | where TimeGenerated > ago(endtime)
      | where RecordType =~ szSharePointFileOperation
      | where Operation in~ (szOperations)
      | where isnotempty(UserAgent)
      | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by UserId, UserType, Operation, Site_Url, ClientIP, OfficeObjectId, OfficeWorkload, UserAgent;

  // Define a baseline of normal user behavior for EnrichedMicrosoft365AuditLogs
  let userBaselineEnriched = EnrichedMicrosoft365AuditLogs
      | where TimeGenerated between(ago(starttime)..ago(endtime))
      | where RecordType == szSharePointFileOperation
      | where Operation in (szOperations)
      | extend UserAgent = tostring(parse_json(tostring(AdditionalProperties)).UserAgent)
      | extend Site_Url = tostring(parse_json(tostring(AdditionalProperties)).SiteUrl)
      | where isnotempty(UserAgent)
      | summarize Count = count() by UserId, Operation, Site_Url, ClientIp
      | summarize AvgCount = avg(Count) by UserId, Operation, Site_Url, ClientIp;

  // Get recent user activity for EnrichedMicrosoft365AuditLogs
  let recentUserActivityEnriched = EnrichedMicrosoft365AuditLogs
      | where TimeGenerated > ago(endtime)
      | where RecordType == szSharePointFileOperation
      | where Operation in (szOperations)
      | extend UserAgent = tostring(parse_json(tostring(AdditionalProperties)).UserAgent)
      | extend Site_Url = tostring(parse_json(tostring(AdditionalProperties)).SiteUrl)
      | where isnotempty(UserAgent)
      | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by UserId, UserType, Operation, Site_Url, ClientIp, ObjectId, Workload, UserAgent;

  // Combine user baselines and recent activity, calculate deviation, and deduplicate
  let UserBehaviorAnalysis = userBaselineOffice
      | join kind=inner (recentUserActivityOffice) on UserId, Operation, Site_Url, ClientIP
      | union (userBaselineEnriched | join kind=inner (recentUserActivityEnriched) on UserId, Operation, Site_Url, ClientIp)
      | extend Deviation = abs(RecentCount - AvgCount) / AvgCount;

  // Filter for significant deviations
  UserBehaviorAnalysis
      | where Deviation > threshold
      | project StartTimeUtc, EndTimeUtc, UserId, UserType, Operation, ClientIP, Site_Url, ObjectId, OfficeObjectId, OfficeWorkload, Workload, UserAgent, Deviation, Count = RecentCount
      | order by Count desc, ClientIP asc, Operation asc, UserId asc
      | extend AccountName = tostring(split(UserId, "@")[0]), AccountUPNSuffix = tostring(split(UserId, "@")[1]);  
triggerOperator: gt
{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "workspace": {
      "type": "String"
    }
  },
  "resources": [
    {
      "apiVersion": "2024-01-01-preview",
      "id": "[concat(resourceId('Microsoft.OperationalInsights/workspaces/providers', parameters('workspace'), 'Microsoft.SecurityInsights'),'/alertRules/7460e34e-4c99-47b2-b7c0-c42e339fc586')]",
      "kind": "Scheduled",
      "name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/7460e34e-4c99-47b2-b7c0-c42e339fc586')]",
      "properties": {
        "alertRuleTemplateName": "7460e34e-4c99-47b2-b7c0-c42e339fc586",
        "customDetails": null,
        "description": "Identifies anomalies using user behavior by setting a threshold for significant changes in file upload/download activities from new IP addresses. It establishes a baseline of typical behavior, compares it to recent activity, and flags deviations exceeding a default threshold of 25.\n",
        "displayName": "GSA Enriched Office 365 - SharePoint File Operation via Previously Unseen IPs",
        "enabled": true,
        "entityMappings": [
          {
            "entityType": "Account",
            "fieldMappings": [
              {
                "columnName": "UserId",
                "identifier": "FullName"
              },
              {
                "columnName": "AccountName",
                "identifier": "Name"
              },
              {
                "columnName": "AccountUPNSuffix",
                "identifier": "UPNSuffix"
              }
            ]
          },
          {
            "entityType": "IP",
            "fieldMappings": [
              {
                "columnName": "ClientIP",
                "identifier": "Address"
              }
            ]
          },
          {
            "entityType": "URL",
            "fieldMappings": [
              {
                "columnName": "Site_Url",
                "identifier": "Url"
              }
            ]
          }
        ],
        "OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/Global Secure Access/Analytic Rules/Office 365 - SharePoint_Downloads_byNewIP.yaml",
        "query": "let threshold = 25;\nlet szSharePointFileOperation = \"SharePointFileOperation\";\nlet szOperations = dynamic([\"FileDownloaded\", \"FileUploaded\"]);\nlet starttime = 14d;\nlet endtime = 1d;\n\n// Define a baseline of normal user behavior for OfficeActivity\nlet userBaselineOffice = OfficeActivity\n    | where TimeGenerated between(ago(starttime)..ago(endtime))\n    | where RecordType =~ szSharePointFileOperation\n    | where Operation in~ (szOperations)\n    | where isnotempty(UserAgent)\n    | summarize Count = count() by UserId, Operation, Site_Url, ClientIP\n    | summarize AvgCount = avg(Count) by UserId, Operation, Site_Url, ClientIP;\n\n// Get recent user activity for OfficeActivity\nlet recentUserActivityOffice = OfficeActivity\n    | where TimeGenerated > ago(endtime)\n    | where RecordType =~ szSharePointFileOperation\n    | where Operation in~ (szOperations)\n    | where isnotempty(UserAgent)\n    | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by UserId, UserType, Operation, Site_Url, ClientIP, OfficeObjectId, OfficeWorkload, UserAgent;\n\n// Define a baseline of normal user behavior for EnrichedMicrosoft365AuditLogs\nlet userBaselineEnriched = EnrichedMicrosoft365AuditLogs\n    | where TimeGenerated between(ago(starttime)..ago(endtime))\n    | where RecordType == szSharePointFileOperation\n    | where Operation in (szOperations)\n    | extend UserAgent = tostring(parse_json(tostring(AdditionalProperties)).UserAgent)\n    | extend Site_Url = tostring(parse_json(tostring(AdditionalProperties)).SiteUrl)\n    | where isnotempty(UserAgent)\n    | summarize Count = count() by UserId, Operation, Site_Url, ClientIp\n    | summarize AvgCount = avg(Count) by UserId, Operation, Site_Url, ClientIp;\n\n// Get recent user activity for EnrichedMicrosoft365AuditLogs\nlet recentUserActivityEnriched = EnrichedMicrosoft365AuditLogs\n    | where TimeGenerated > ago(endtime)\n    | where RecordType == szSharePointFileOperation\n    | where Operation in (szOperations)\n    | extend UserAgent = tostring(parse_json(tostring(AdditionalProperties)).UserAgent)\n    | extend Site_Url = tostring(parse_json(tostring(AdditionalProperties)).SiteUrl)\n    | where isnotempty(UserAgent)\n    | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by UserId, UserType, Operation, Site_Url, ClientIp, ObjectId, Workload, UserAgent;\n\n// Combine user baselines and recent activity, calculate deviation, and deduplicate\nlet UserBehaviorAnalysis = userBaselineOffice\n    | join kind=inner (recentUserActivityOffice) on UserId, Operation, Site_Url, ClientIP\n    | union (userBaselineEnriched | join kind=inner (recentUserActivityEnriched) on UserId, Operation, Site_Url, ClientIp)\n    | extend Deviation = abs(RecentCount - AvgCount) / AvgCount;\n\n// Filter for significant deviations\nUserBehaviorAnalysis\n    | where Deviation > threshold\n    | project StartTimeUtc, EndTimeUtc, UserId, UserType, Operation, ClientIP, Site_Url, ObjectId, OfficeObjectId, OfficeWorkload, Workload, UserAgent, Deviation, Count = RecentCount\n    | order by Count desc, ClientIP asc, Operation asc, UserId asc\n    | extend AccountName = tostring(split(UserId, \"@\")[0]), AccountUPNSuffix = tostring(split(UserId, \"@\")[1]);\n",
        "queryFrequency": "P1D",
        "queryPeriod": "P14D",
        "severity": "Medium",
        "status": "Available",
        "subTechniques": [],
        "suppressionDuration": "PT1H",
        "suppressionEnabled": false,
        "tactics": [
          "Exfiltration"
        ],
        "techniques": [
          "T1030"
        ],
        "templateVersion": "2.0.6",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 0
      },
      "type": "Microsoft.OperationalInsights/workspaces/providers/alertRules"
    }
  ]
}