{
  "$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/cd8ec49c-b654-49be-b040-e552b8eba7c8')]",
      "kind": "Scheduled",
      "name": "[concat(parameters('workspace'),'/Microsoft.SecurityInsights/cd8ec49c-b654-49be-b040-e552b8eba7c8')]",
      "properties": {
        "alertDetailsOverride": {
          "alertDisplayNameFormat": "SpyCloud identity access record exposure - {{AccountUpn}}"
        },
        "alertRuleTemplateName": "cd8ec49c-b654-49be-b040-e552b8eba7c8",
        "customDetails": {
          "DocumentID": "DocumentId",
          "InfectedMachineId": "InfectedMachineId",
          "InfectedTime": "InfectedTime",
          "SpyCloudPublishDate": "SpyCloudPublishDate"
        },
        "description": "#DONT_CORR#\n'Identifies exposure of identity access material such as session cookies, OAuth tokens,\nor SSO credentials. This material can grant direct account access without a password,\nso it bypasses password resets and single-factor controls. Revoking active sessions is\nthe primary containment action.'\n",
        "displayName": "SpyCloud identity access record exposure",
        "enabled": true,
        "entityMappings": [
          {
            "entityType": "Account",
            "fieldMappings": [
              {
                "columnName": "AccountUpn",
                "identifier": "FullName"
              }
            ]
          },
          {
            "entityType": "Mailbox",
            "fieldMappings": [
              {
                "columnName": "AccountEmail",
                "identifier": "MailboxPrimaryAddress"
              }
            ]
          },
          {
            "entityType": "Host",
            "fieldMappings": [
              {
                "columnName": "HostName",
                "identifier": "HostName"
              }
            ]
          },
          {
            "entityType": "IP",
            "fieldMappings": [
              {
                "columnName": "IPAddress",
                "identifier": "Address"
              }
            ]
          }
        ],
        "eventGroupingSettings": {
          "aggregationKind": "AlertPerResult"
        },
        "OriginalUri": "https://github.com/Azure/Azure-Sentinel/blob/master/Solutions/SpyCloud%20Enterprise%20Protection%20CCF/Analytic%20Rules/AR_Access_Records_30.yaml",
        "query": "// Human-readable constant for the severity threshold used below\nlet severityThreshold = 30;\nSpyCloudBreachWatchlistV2_CL\n| where Severity == severityThreshold\n| extend AccountName = Username, AccountEmail = Email, HostName = UserHostName,\n    AccountUpn = iff(isnotempty(Email), Email, Username),\n    // Under AlertPerResult every row becomes its own alert, so mv-expand on IPAddresses\n    // would raise one alert per IP for the same identity. Take the first address instead.\n    IPAddress = tostring(IPAddresses[0])\n// One alert per exposed identity. Session revocation acts per user, so a user appearing\n// several times in the same window would otherwise be revoked repeatedly. Deduplication is\n// per rule execution, so a reappearance in a later window correctly raises a new alert.\n| summarize arg_max(TimeGenerated, *) by AccountUpn\n| project TimeGenerated, DocumentId, SourceId, SpyCloudPublishDate, AccountEmail,\n    AccountName, AccountUpn, HostName, TargetDomain, TargetUrl, AccountType, PasswordType,\n    InfectedMachineId, InfectedTime, UserOS, IPAddress\n",
        "queryFrequency": "PT1H",
        "queryPeriod": "PT1H",
        "severity": "High",
        "subTechniques": [],
        "suppressionDuration": "PT1H",
        "suppressionEnabled": false,
        "tactics": [
          "CredentialAccess",
          "DefenseEvasion"
        ],
        "techniques": [
          "T1528",
          "T1539",
          "T1550"
        ],
        "templateVersion": "1.0.0",
        "triggerOperator": "GreaterThan",
        "triggerThreshold": 0
      },
      "type": "Microsoft.OperationalInsights/workspaces/providers/alertRules"
    }
  ]
}
