Detection rules › Kusto
Hijack Execution Flow - DLL Side-Loading
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
| Tactic | Techniques |
|---|---|
| Stealth |
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.
| Field | Kind | Excluded values | Search |
|---|---|---|---|
FileName | ends_with | .exe | excludes:FileName field:"FileName" value:".exe" |
InitiatingProcessAccountSid | ends_with | -500 | excludes:InitiatingProcessAccountSid field:"InitiatingProcessAccountSid" value:"-500" |
InitiatingProcessIntegrityLevel | in | High, System | excludes:InitiatingProcessIntegrityLevel field:"InitiatingProcessIntegrityLevel" value:"High" field:"InitiatingProcessIntegrityLevel" value:"System" |
Indicators
These rows show field, operator, and value matches.
| Field | Kind | Values | Search |
|---|---|---|---|
ActionType | in |
| field:"ActionType" kind:in |
InitiatingProcessAccountSid | ne |
| field:"SubjectUserSid" kind:ne value:"S-1-5-18" |
InitiatingProcessIntegrityLevel | in |
| field:"IntegrityLevel" kind:in |
InitiatingProcessTokenElevation | in |
| field:"InitiatingProcessTokenElevation" kind:in |
Output fields
These fields are emitted when the rule matches.
| Field | Source |
|---|---|
DeviceId | project |
DeviceName | project |
FolderPath | project |
InitiatingProcessFileName | project |
InitiatingProcessIntegrityLevel | project |