Detection rules › Splunk
Powershell DLL_EXE Injection (PowerShell)
DLL injection simply refers to the (forced) injection of a DLL into the space of another process and then execution of its code.What makes Reflective DLL Injection different? The DLL injection code and the source of the DLL are obtained via its full path on disk. Because of this, it is not considered a very stealthy approach and also has an external dependency which may be problematic should it ever be separated. These issues can be addressed by using Reflective DLL Injection which allows the sourcing of the DLL in the form of its raw data
MITRE ATT&CK coverage
| Tactic | Techniques |
|---|---|
| Privilege Escalation | T1055.001 Process Injection: Dynamic-link Library Injection |
| Stealth | T1055.001 Process Injection: Dynamic-link Library Injection |
References
Event coverage
| Provider | Event | Title |
|---|---|---|
| PowerShell | Event ID 4104 | Creating Scriptblock text (MessageNumber of MessageTotal). |
Rule body yaml
id: '1082.1121'
title: Powershell DLL_EXE Injection
description: 'DLL injection simply refers to the (forced) injection of a DLL into
the space of another process and then execution of its code.What makes Reflective
DLL Injection different? The DLL injection code and the source of the DLL are obtained
via its full path on disk. Because of this, it is not considered a very stealthy
approach and also has an external dependency which may be problematic should it
ever be separated. These issues can be addressed by using Reflective DLL Injection
which allows the sourcing of the DLL in the form of its raw data. Threat Actor Association:
Carbanak, TA2541, TA551 Software Association: IcedID'
logic_format: Splunk
logic: '`get_endpoint_data``get_endpoint_data_powershell` TERM(EventCode=4104) ("VirtualAlloc"
OR "VirtualAllocEx" OR "WriteProcessMemory" OR "CreateRemoteThread" OR "VirtualFree"
OR "CreateThread" OR "System.Diagnostics.Process") | rex field=_raw (?<Keywords_1>"(?i)VirtualAlloc(Ex)?")|
rex field=_raw (?<Keywords_2>"(?i)WriteProcessMemory")| rex field=_raw (?<Keywords_3>"(?i)CreateRemoteThread")|
rex field=_raw (?<Keywords_4>"(?i)VirtualFree")| rex field=_raw (?<Keywords_5>"(?i)CreateThread")|
rex field=Message max_match=5 "(?i)System\.Diagnostics\.Process\s+\W?(?<injected_process>((\w+\-){1,})?\w+)"|
rex field=_raw max_match=0 (?<script>"(?i)((\w+\-){1,})?\w+\.ps1")| eval keywords=mvappend(Keywords_1,
Keywords_2, Keywords_3, Keywords_4, Keywords_5)| table _time, host, user event_id,
keywords, process, process_*, signature_id, user, user_id, script, injected_process
| bin span=15s | stats values(*) as * by _time, host |where (match(process, "(?i)VirtualAlloc(Ex)?")
AND match(process, "(?i)WriteProcessMemory|virtualfree") AND match(process, "(?i)CreateRemoteThread|Createthread")) '
techniques:
- privilege-escalation:process injection:dynamic-link library injection
technique_id:
- T1055.001
data_category:
- PowerShell logs
- Process command-line parameters
references:
- https://attack.mitre.org/techniques/T1055/001/
Stages and Predicates
Stage 1: search
`get_endpoint_data``get_endpoint_data_powershell` TERM(EventCode=4104) ("VirtualAlloc" OR "VirtualAllocEx" OR "WriteProcessMemory" OR "CreateRemoteThread" OR "VirtualFree" OR "CreateThread" OR "System.Diagnostics.Process")
Stage 2: rex
| rex field=_raw (?<Keywords_1>"(?i)VirtualAlloc(Ex)?")
Stage 3: rex
| rex field=_raw (?<Keywords_2>"(?i)WriteProcessMemory")
Stage 4: rex
| rex field=_raw (?<Keywords_3>"(?i)CreateRemoteThread")
Stage 5: rex
| rex field=_raw (?<Keywords_4>"(?i)VirtualFree")
Stage 6: rex
| rex field=_raw (?<Keywords_5>"(?i)CreateThread")
Stage 7: rex
| rex field=Message max_match=5 "(?i)System\.Diagnostics\.Process\s+\W?(?<injected_process>((\w+\-){1,})?\w+)"
Stage 8: rex
| rex field=_raw max_match=0 (?<script>"(?i)((\w+\-){1,})?\w+\.ps1")
Stage 9: eval
| eval keywords=mvappend(Keywords_1, Keywords_2, Keywords_3, Keywords_4, Keywords_5)
Stage 10: table
| table _time, host, user event_id, keywords, process, process_*, signature_id, user, user_id, script, injected_process
Stage 11: bucket
| bin span=15s
Stage 12: stats
| stats values(*) as * by _time, host
Stage 13: where
| where (match(process, "(?i)VirtualAlloc(Ex)?") AND match(process, "(?i)WriteProcessMemory|virtualfree") AND match(process, "(?i)CreateRemoteThread|Createthread"))
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.
Search terms
Bare-string tokens in the SPL search body. Splunk matches each token against _raw (the untyped raw event text) anywhere it appears, not against a specific field. These don't surface in the Indicators table because they aren't predicates on a known field.
| Stage | Term |
|---|---|
| 1 | TERM |
| 1 | "VirtualAlloc" |
| 1 | "VirtualAllocEx" |
| 1 | "WriteProcessMemory" |
| 1 | "CreateRemoteThread" |
| 1 | "VirtualFree" |
| 1 | "CreateThread" |
| 1 | "System.Diagnostics.Process" |