Detection rules › Kusto

TI Map URL Entity to DeviceNetworkEvents

Severity
medium
Time window
14d
Group by
Id, ObservableValue, RemoteUrl, Url
Source
github.com/Azure/Azure-Sentinel

This query identifies any URL indicators of compromise (IOCs) from threat intelligence (TI) by searching for matches in DeviceNetworkEvents.

MITRE ATT&CK coverage

TacticTechniques
Command & Control

Telemetry coverage

Rule body

id: 4f0356b2-d344-4c19-9375-31b9575d80cb
name: TI Map URL Entity to DeviceNetworkEvents
description: |
  'This query identifies any URL indicators of compromise (IOCs) from threat intelligence (TI) by searching for matches in DeviceNetworkEvents.'
severity: Medium
requiredDataConnectors:
  - connectorId: MicrosoftThreatProtection
    dataTypes:
      - DeviceNetworkEvents
  - connectorId: ThreatIntelligence
    dataTypes:
      - ThreatIntelIndicators
  - connectorId: ThreatIntelligenceTaxii
    dataTypes:
      - ThreatIntelIndicators
  - connectorId: MicrosoftDefenderThreatIntelligence
    dataTypes:
      - ThreatIntelIndicators
queryFrequency: 1h
queryPeriod: 14d
triggerOperator: gt
triggerThreshold: 0
tactics:
  - CommandAndControl
relevantTechniques:
  - T1071
query: |
  let dt_lookBack = 1h;
  let ioc_lookBack = 14d;
  let DeviceNetworkEvents_ = DeviceNetworkEvents
    | where TimeGenerated >= ago(dt_lookBack)
    | where ActionType !has "ConnectionFailed"
    | project-rename DeviceNetworkEvents_TimeGenerated = TimeGenerated;
  let DeviceNetworkEventUrls = DeviceNetworkEvents_
    | distinct Url = RemoteUrl
    | summarize make_list(Url);
  ThreatIntelIndicators
  //extract key part of kv pair
  | extend IndicatorType = replace(@"\[|\]|\""", "", tostring(split(ObservableKey, ":", 0)))
  | where IndicatorType == "url"
  | extend Url = ObservableValue
  | extend TrafficLightProtocolLevel = tostring(parse_json(AdditionalFields).TLPLevel)
  | where TimeGenerated >= ago(ioc_lookBack)
  | extend Url = tolower(Url)
  | where Url in (DeviceNetworkEventUrls)
  | summarize LatestIndicatorTime = arg_max(TimeGenerated, *) by Id, ObservableValue
  | where IsActive and (ValidUntil > now() or isempty(ValidUntil))
  | extend Description = tostring(parse_json(Data).description)
  | where Description !contains_cs "State: inactive;" and Description !contains_cs "State: falsepos;"
     | project-reorder *, Tags, TrafficLightProtocolLevel, Url, Type
  | join kind=innerunique (DeviceNetworkEvents_) on $left.Url == $right.RemoteUrl
  | where DeviceNetworkEvents_TimeGenerated < ValidUntil
  | summarize DeviceNetworkEvents_TimeGenerated = arg_max(DeviceNetworkEvents_TimeGenerated, *) by Id, Url
  | extend Description = tostring(parse_json(Data).description)
  | extend ActivityGroupNames = extract(@"ActivityGroup:(\S+)", 1, tostring(parse_json(Data).labels))
  | project DeviceNetworkEvents_TimeGenerated, Id, Url, Confidence, Description, Type, Tags, TrafficLightProtocolLevel, ActionType, DeviceId, DeviceName, InitiatingProcessAccountUpn, InitiatingProcessCommandLine, RemoteIP, RemotePort
  | extend Name = tostring(split(InitiatingProcessAccountUpn, '@', 0)[0]), UPNSuffix = tostring(split(InitiatingProcessAccountUpn, '@', 1)[0])
  | extend timestamp = DeviceNetworkEvents_TimeGenerated, UserPrincipalName = InitiatingProcessAccountUpn
entityMappings:
  - entityType: Account
    fieldMappings:
      - identifier: Name
        columnName: Name
      - identifier: UPNSuffix
        columnName: UPNSuffix
  - entityType: Host
    fieldMappings:
      - identifier: FullName
        columnName: DeviceName
  - entityType: URL
    fieldMappings:
      - identifier: Url
        columnName: Url
  - entityType: Process
    fieldMappings:
      - identifier: CommandLine
        columnName: InitiatingProcessCommandLine
version: 1.0.5
kind: Scheduled

Stages and Predicates

Parameters

let dt_lookBack = 1h;
let ioc_lookBack = 14d;

Let binding: DeviceNetworkEvents_ used in Stages 1, 16

let DeviceNetworkEvents_ = DeviceNetworkEvents
  | where TimeGenerated >= ago(dt_lookBack)
  | where ActionType !has "ConnectionFailed"
  | project-rename DeviceNetworkEvents_TimeGenerated = TimeGenerated;

Let binding: DeviceNetworkEventUrls used in Stages 2, 10

let DeviceNetworkEventUrls = DeviceNetworkEvents_
  | distinct Url = RemoteUrl
  | summarize make_list(Url);

Stage 1: source

let DeviceNetworkEvents_

Stage 2: source

let DeviceNetworkEventUrls

Stage 3: source

ThreatIntelIndicators

Stage 4: extend

extend IndicatorType

Stage 5: where

where IndicatorType =~ "url"

Stage 6: extend

extend Url

Stage 7: extend

extend TrafficLightProtocolLevel

Stage 8: where

where TimeGenerated >= ago(1209600s)

Stage 9: extend

extend Url

Stage 10: where

where Url =~ "DeviceNetworkEventUrls"

Stage 11: summarize

summarize LatestIndicatorTime by Id, ObservableValue

Stage 12: where

where (isempty(ValidUntil) or ValidUntil > now())

Stage 13: extend

extend Description

Stage 14: where

where not (Description contains "State: falsepos;") and not (Description contains "State: inactive;")

Stage 15: project-reorder

project-reorder

Stage 16: join

join kind=innerunique (DeviceNetworkEvents_) on Url, RemoteUrl

Stage 17: where

where DeviceNetworkEvents_TimeGenerated < ValidUntil

Stage 18: summarize

summarize DeviceNetworkEvents_TimeGenerated by Id, Url

Stage 19: extend

extend Description

Stage 20: extend

extend ActivityGroupNames

Stage 21: project

project ActionType, Confidence, Description, DeviceId, DeviceName, DeviceNetworkEvents_TimeGenerated, Id, InitiatingProcessAccountUpn, InitiatingProcessCommandLine, RemoteIP, RemotePort, Tags, TrafficLightProtocolLevel, Type, Url

Stage 22: extend

extend Name, UPNSuffix

Stage 23: extend

extend UserPrincipalName, timestamp

Exclusions

The rule actively suppresses these predicates.

FieldKindExcluded valuesSearch
DescriptioncontainsState: falsepos;excludes:Description field:"Description" value:"State: falsepos;"
DescriptioncontainsState: inactive;excludes:Description field:"Description" value:"State: inactive;"
ActionTypematchConnectionFailedexcludes:ActionType field:"ActionType" value:"ConnectionFailed"

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
DeviceNetworkEvents_TimeGeneratedcross_field_compare
  • ValidUntil transforms: op:lt corpus 2 (kusto 2)
field:"DeviceNetworkEvents_TimeGenerated" kind:cross_field_compare value:"ValidUntil"
IndicatorTypeeq
  • url corpus 11 (kusto 11)
field:"IndicatorType" kind:eq value:"url"
Urlin
  • DeviceNetworkEventUrls corpus 2 (kusto 2)
field:"Url" kind:in value:"DeviceNetworkEventUrls"
ValidUntilis_null
  • (no value, null check)
field:"ValidUntil" kind:is_null

Output fields

These fields are emitted when the rule matches.

FieldSource
ActionTypeproject
Confidenceproject
Descriptionproject
DeviceIdproject
DeviceNameproject
DeviceNetworkEvents_TimeGeneratedproject
Idproject
InitiatingProcessAccountUpnproject
InitiatingProcessCommandLineproject
RemoteIPproject
RemotePortproject
Tagsproject
TrafficLightProtocolLevelproject
Typeproject
Urlproject
Nameextend
UPNSuffixextend
UserPrincipalNameextend
timestampextend