Detection rules › Kusto

Anomaly in SMB Traffic(ASIM Network Session schema)

Status
available
Severity
medium
Time window
14d
Group by
DstPortNumber, SrcIpAddr
Source
github.com/Azure/Azure-Sentinel

This detection detects abnormal SMB traffic, a file-sharing protocol. By calculating the average deviation of SMB connections over last 14 days, flagging sources exceeding 50 average deviations.

MITRE ATT&CK coverage

Event coverage

Rule body kusto

id: 8717e498-7b5d-4e23-9e7c-fa4913dbfd79
name: Anomaly in SMB Traffic(ASIM Network Session schema)
description: |
  'This detection detects abnormal SMB traffic, a file-sharing protocol. By calculating the average deviation of SMB connections over last 14 days, flagging sources exceeding 50 average deviations.'
severity: Medium
status: Available 
tags:
  - Schema: ASimNetworkSessions
    SchemaVersion: 0.2.4
requiredDataConnectors: []
queryFrequency: 1d
queryPeriod: 14d
triggerOperator: gt
triggerThreshold: 0
tactics:
  - LateralMovement
relevantTechniques:
  - T1021
  - T1021.002
query: |
  // Define the threshold for deviation
  let threshold = 50;
  // Define the time range for the baseline data
  let starttime = 14d;
  let endtime = 1d;
  // Define the SMB ports to monitor
  let SMBPorts = dynamic(["139", "445"]);
  // Get the baseline data for user network sessions and Filter for the defined time range
  let userBaseline = _Im_NetworkSession(starttime=ago(starttime), endtime=ago(endtime))
    | where ipv4_is_private(SrcIpAddr) and tostring(DstPortNumber) has_any (SMBPorts) and SrcIpAddr != DstIpAddr // Filter for private IP addresses and SMB ports
    | summarize Count = count() by SrcIpAddr, DstPortNumber // Group by source IP and destination port
    | summarize AvgCount = avg(Count) by SrcIpAddr, DstPortNumber; // Calculate the average count
  // Get the recent user activity data and Filter for recent activity
  let recentUserActivity = _Im_NetworkSession(starttime=ago(endtime))
    | where ipv4_is_private(SrcIpAddr) and tostring(DstPortNumber) has_any (SMBPorts) and SrcIpAddr != DstIpAddr // Filter for private IP addresses and SMB ports
    | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by SrcIpAddr, DstPortNumber; // Group by source IP and destination port
  // Join the baseline and recent activity data
  let UserBehaviorAnalysis = userBaseline
    | join kind=inner (recentUserActivity) on SrcIpAddr, DstPortNumber
    | extend Deviation = abs(RecentCount - AvgCount) / AvgCount; // Calculate the deviation
  // Filter for deviations greater than the threshold
  UserBehaviorAnalysis
    | where Deviation > threshold
    | project SrcIpAddr, DstPortNumber, Deviation, Count = RecentCount; // Project the required columns
entityMappings:
  - entityType: IP
    fieldMappings:
      - identifier: Address
        columnName: SrcIpAddr
eventGroupingSettings:
  aggregationKind: AlertPerResult
version: 1.0.0
kind: Scheduled

Stages and Predicates

Parameters

let threshold = 50;
let starttime = 14d;
let endtime = 1d;
let SMBPorts = dynamic(["139", "445"]);

Let binding: recentUserActivity

let recentUserActivity = _Im_NetworkSession(starttime=ago(endtime))
  | where ipv4_is_private(SrcIpAddr) and tostring(DstPortNumber) has_any (SMBPorts) and SrcIpAddr != DstIpAddr
  | summarize StartTimeUtc = min(TimeGenerated), EndTimeUtc = max(TimeGenerated), RecentCount = count() by SrcIpAddr, DstPortNumber;

Derived from starttime, endtime, SMBPorts.

The stages below define let UserBehaviorAnalysis (the rule's main pipeline source).

Stage 1: source

_Im_NetworkSession(starttime=ago(starttime), endtime=ago(endtime))

Stage 2: where

| where ipv4_is_private(SrcIpAddr) and tostring(DstPortNumber) has_any (SMBPorts) and SrcIpAddr != DstIpAddr

Stage 3: summarize

| summarize Count = count() by SrcIpAddr, DstPortNumber

Stage 4: summarize

| summarize AvgCount = avg(Count) by SrcIpAddr, DstPortNumber

Stage 5: join

| join kind=inner (recentUserActivity) on SrcIpAddr, DstPortNumber

Stage 6: extend

| extend Deviation = abs(RecentCount - AvgCount) / AvgCount

The stages below run on UserBehaviorAnalysis (the outer pipeline).

Stage 7: where

UserBehaviorAnalysis
| where Deviation > threshold

Stage 8: project

| project SrcIpAddr, DstPortNumber, Deviation, Count = RecentCount;

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
Deviationgt
  • 50 transforms: cased
DstPortNumbermatch
  • 139 transforms: tostring
  • 445 transforms: tostring
SrcIpAddrcidr_match
  • 10.0.0.0/8 corpus 9 (kusto 7, elastic 2)
  • 127.0.0.0/8 corpus 9 (kusto 7, elastic 2)
  • 169.254.0.0/16 corpus 8 (kusto 7, elastic 1)
  • 172.16.0.0/12 corpus 9 (kusto 7, elastic 2)
  • 192.168.0.0/16 corpus 9 (kusto 7, elastic 2)
SrcIpAddrne
  • DstIpAddr transforms: cased corpus 2 (kusto 2)

Output fields

Fields the rule emits when it matches. Chronicle authors list these in the outcome block; they appear on the detection and $risk_score drives alerting. Sentinel / Defender XDR rules build them up through project / summarize / extend stages. Sentinel maps these into alert fields via entityMappings and customDetails; Defender XDR custom detections surface them as alert fields directly.

FieldSource
Countproject
Deviationproject
DstPortNumberproject
SrcIpAddrproject