Detection rules › Kusto

Hijack Execution Flow - DLL Side-Loading

Status
available
Severity
medium
Time window
1h
Group by
DeviceId, DeviceName, FolderPath
Source
github.com/Azure/Azure-Sentinel

This detection tries to identify all DLLs loaded by "high integrity" processes and cross-checks the DLL paths against FileCreate/FileModify events of the same DLL by a medium integrity process. Of course, we need to do some magic to filter out false positives as much as possible. So any FileCreate/FileModify done by "NT Authoriy\System" and the "RID 500" users aren't interesting. Also, we only want to see the FileCreate/FileModify actions which are performed with a default or limited token elevation. If done with a full elevated token, the user is apparently admin already.

MITRE ATT&CK coverage

Telemetry coverage

Rule body

id: 3084b487-fad6-4000-9544-6085b9657290
name: Hijack Execution Flow - DLL Side-Loading
description: |
  This detection tries to identify all DLLs loaded by "high integrity" processes and cross-checks the DLL paths against FileCreate/FileModify events of the same DLL by a medium integrity process.
  Of course, we need to do some magic to filter out false positives as much as possible. So any FileCreate/FileModify done by "NT Authoriy\System" and the "RID 500" users aren't interesting.
  Also, we only want to see the FileCreate/FileModify actions which are performed with a default or limited token elevation. If done with a full elevated token, the user is apparently admin already.
severity: Medium
status: Available
requiredDataConnectors:
  - connectorId: MicrosoftThreatProtection
    dataTypes:
      - DeviceFileEvents
      - DeviceImageLoadEvents
queryFrequency: 1h
queryPeriod: 1h
triggerOperator: gt
triggerThreshold: 0
tactics:
  - Persistence
  - PrivilegeEscalation
  - DefenseEvasion
relevantTechniques:
  - T1574.002
query: |
  let imls = materialize(
      DeviceImageLoadEvents
      | where InitiatingProcessIntegrityLevel in ("High", "System") and FileName !endswith ".exe"
      | project FolderPath=tolower(FolderPath), InitiatingProcessFileName, InitiatingProcessIntegrityLevel, DeviceId, DeviceName
      | distinct FolderPath, InitiatingProcessFileName, InitiatingProcessIntegrityLevel, DeviceId, DeviceName
  );
  imls
  | join (
      DeviceFileEvents
      | where FolderPath in~ ((imls | project FolderPath)) and ActionType in ("FileCreated", "FileModified") and
      InitiatingProcessIntegrityLevel !in ("High", "System", "") and InitiatingProcessAccountSid != "S-1-5-18" and
      InitiatingProcessTokenElevation in ("TokenElevationTypeDefault", "TokenElevationTypeLimited") and InitiatingProcessAccountSid !endswith "-500"
      | extend FolderPath=tolower(FolderPath)
  ) on FolderPath, DeviceId, DeviceName
  | project-away FolderPath1
entityMappings:
  - entityType: Host
    fieldMappings:
      - identifier: FullName
        columnName: DeviceName
  - entityType: Account
    fieldMappings:
      - identifier: Sid
        columnName: InitiatingProcessAccountSid
      - identifier: Name
        columnName: InitiatingProcessAccountName
      - identifier: NTDomain
        columnName: InitiatingProcessAccountDomain
  - entityType: Process
    fieldMappings:
      - identifier: CommandLine
        columnName: InitiatingProcessCommandLine
version: 1.0.1
kind: Scheduled

Stages and Predicates

let imls is inlined into the numbered stages below.

Stage 1: source

let imls

Stage 2: source

DeviceImageLoadEvents

Stage 3: where

where not (FileName endswith ".exe") and InitiatingProcessIntegrityLevel in~ ("High", "System")

Stage 4: project

project DeviceId, DeviceName, FolderPath, InitiatingProcessFileName, InitiatingProcessIntegrityLevel

Stage 5: distinct

distinct DeviceId, DeviceName, FolderPath, InitiatingProcessFileName, InitiatingProcessIntegrityLevel

Stage 6: join

join (DeviceFileEvents) on FolderPath, DeviceId, DeviceName

Stage 7: project-away

project-away FolderPath1

Exclusions

The rule actively suppresses these predicates.

Indicators

These rows show field, operator, and value matches.

FieldKindValuesSearch
ActionTypein
  • FileCreated corpus 7 (kusto 7)
  • FileModified
field:"ActionType" kind:in
InitiatingProcessAccountSidne
  • S-1-5-18
field:"SubjectUserSid" kind:ne value:"S-1-5-18"
InitiatingProcessIntegrityLevelin
  • High corpus 21 (sigma 17, kusto 3, splunk 1)
  • System corpus 30 (sigma 22, splunk 4, elastic 3, kusto 1)
field:"IntegrityLevel" kind:in
InitiatingProcessTokenElevationin
  • TokenElevationTypeDefault
  • TokenElevationTypeLimited
field:"InitiatingProcessTokenElevation" kind:in

Output fields

These fields are emitted when the rule matches.

FieldSource
DeviceIdproject
DeviceNameproject
FolderPathproject
InitiatingProcessFileNameproject
InitiatingProcessIntegrityLevelproject