Detecting Fileless Attacks on Endpoints
When to Use
Use this skill when:
- Building detection rules for fileless malware that operates entirely in memory
- Hunting for PowerShell-based attacks, reflective DLL injection, and WMI abuse
- Configuring endpoint telemetry (Sysmon, AMSI, PowerShell logging) to capture fileless indicators
- Investigating incidents where traditional AV found no malicious files
Do not use for detecting file-based malware or for malware reverse engineering.
Prerequisites
- Sysmon with process creation and WMI event logging enabled
- PowerShell Script Block Logging and Module Logging enabled
- AMSI (Antimalware Scan Interface) enabled for script content inspection
- EDR with behavioral detection capabilities (MDE, CrowdStrike, SentinelOne)
Workflow
Step 1: Enable Required Telemetry
# Enable PowerShell Script Block Logging (GPO or registry)
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging" `
-Name EnableScriptBlockLogging -Value 1 -PropertyType DWORD -Force
# Enable PowerShell Module Logging
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging" `
-Name EnableModuleLogging -Value 1 -PropertyType DWORD -Force
# Enable PowerShell Transcription
New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription" `
-Name EnableTranscripting -Value 1 -PropertyType DWORD -Force
# Sysmon config for fileless detection (key events):
# Event ID 1: Process creation (captures CommandLine)
# Event ID 7: Image loaded (DLL loading)
# Event ID 8: CreateRemoteThread (injection)
# Event ID 10: Process access (LSASS access)
# Event ID 19/20/21: WMI events
Step 2: Detect PowerShell-Based Attacks
# Indicators of malicious PowerShell:
# Encoded command execution
EventID: 1
CommandLine contains: "powershell" AND ("-enc" OR "-e " OR "-encodedcommand" OR "FromBase64String")
# Download cradle patterns
CommandLine contains: "IEX" AND ("Net.WebClient" OR "DownloadString" OR "Invoke-WebRequest")
CommandLine contains: "Invoke-Expression" AND "New-Object"
# AMSI bypass attempts (Event ID 4104 - Script Block)
ScriptBlock contains: "AmsiUtils" OR "amsiInitFailed" OR "SetValue.*amsi"
# Splunk query for suspicious PowerShell:
index=windows source="WinEventLog:Microsoft-Windows-PowerShell/Operational" EventCode=4104
| where match(ScriptBlockText, "(?i)(iex|invoke-expression|downloadstring|net\.webclient|frombase64|bypass|amsiutils)")
| table _time host ScriptBlockText
Step 3: Detect Process Injection Techniques
# Reflective DLL injection - loads DLL from memory without touching disk
# Detection: Sysmon Event 7 (ImageLoaded) where image path is unusual
EventID: 7
ImageLoaded NOT starts with: "C:\Windows\" AND NOT starts with: "C:\Program Files"
# Process hollowing - creates process in suspended state, replaces memory
# Detection: Process creation followed by immediate memory write
EventID: 1 + 10 correlation
# Process created then accessed with PROCESS_VM_WRITE
# APC injection - queues code to thread's async procedure call queue
# Detection: Sysmon CreateRemoteThread from non-system process
EventID: 8
SourceImage NOT IN (known_legitimate_sources)
# MDE KQL:
DeviceEvents
| where ActionType in ("CreateRemoteThreadApiCall", "NtAllocateVirtualMemoryApiCall")
| where InitiatingProcessFileName !in ("MsMpEng.exe", "svchost.exe")
| project Timestamp, DeviceName, ActionType, InitiatingProcessFileName,
InitiatingProcessCommandLine, FileName
Step 4: Detect WMI-Based Persistence
# Sysmon Event IDs 19/20/21 for WMI events
EventID: 19 # WmiEventFilter activity detected
EventID: 20 # WmiEventConsumer activity detected
EventID: 21 # WmiEventConsumerToFilter activity detected
# Any WMI event subscription creation is suspicious unless expected
# Common malicious WMI persistence:
Consumer contains: "CommandLineEventConsumer" OR "ActiveScriptEventConsumer"
# Query for WMI subscriptions via osquery or PowerShell:
Get-WMIObject -Namespace root\Subscription -Class __EventFilter
Get-WMIObject -Namespace root\Subscription -Class __EventConsumer
Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding
Step 5: Detect Registry-Based Execution
# Malware stored in registry values and executed via PowerShell
# Sysmon Event 13 - Registry value set with encoded content
EventID: 13
TargetObject contains: "CurrentVersion\Run"
Details: unusually long value or Base64-encoded content
# Detection query:
index=sysmon EventCode=13
| where match(Details, "[A-Za-z0-9+/=]{100,}")
| table _time host TargetObject Details Image
Key Concepts
| Term |
Definition |
| Fileless Malware |
Malware that operates entirely in memory without writing executable files to disk |
| AMSI |
Antimalware Scan Interface; Windows API allowing security products to inspect script content before execution |
| Reflective DLL Injection |
Loading a DLL from memory rather than disk, avoiding file-based detection |
| Process Hollowing |
Creating a legitimate process in suspended state and replacing its memory with malicious code |
| Script Block Logging |
PowerShell logging feature that captures deobfuscated script content (Event ID 4104) |
Tools & Systems
- Sysmon: Kernel-level process, DLL, and WMI monitoring
- AMSI: Windows script content inspection API
- PowerShell Logging: Script Block, Module, and Transcription logging
- Microsoft Defender for Endpoint: Behavioral detection for fileless techniques
- Volatility 3: Memory forensics for post-incident fileless malware analysis
Common Pitfalls
- Relying on file-based AV: Traditional AV that scans files on disk will miss fileless attacks entirely. Behavioral detection and AMSI are required.
- Disabled PowerShell logging: Without Script Block Logging, deobfuscated PowerShell commands are invisible to defenders.
- AMSI bypass not detected: Sophisticated attackers bypass AMSI before executing payloads. Detect AMSI bypass attempts as a high-priority alert.
- Not monitoring WMI events: WMI persistence is a favored technique of APT groups. Sysmon events 19-21 must be enabled.
1---2name: detecting-fileless-attacks-on-endpoints3description: >4 Detects fileless malware and in-memory attacks that execute entirely in RAM without writing5 persistent files to disk, evading traditional antivirus. Use when building detections for6 PowerShell-based attacks, reflective DLL injection, WMI persistence, and registry-resident7 malware. Activates for requests involving fileless malware detection, in-memory attacks,8 PowerShell exploitation, or living-off-the-land techniques.9domain: cybersecurity10subdomain: endpoint-security11tags: [endpoint, fileless-malware, memory-attacks, PowerShell, detection-engineering]12version: 1.0.013author: mahipal14license: MIT15metadata:16 source: https://skillmd.com/skills/njones17/detecting-fileless-attacks-on-endpoints17---1819# Detecting Fileless Attacks on Endpoints2021## When to Use2223Use this skill when:24- Building detection rules for fileless malware that operates entirely in memory25- Hunting for PowerShell-based attacks, reflective DLL injection, and WMI abuse26- Configuring endpoint telemetry (Sysmon, AMSI, PowerShell logging) to capture fileless indicators27- Investigating incidents where traditional AV found no malicious files2829**Do not use** for detecting file-based malware or for malware reverse engineering.3031## Prerequisites3233- Sysmon with process creation and WMI event logging enabled34- PowerShell Script Block Logging and Module Logging enabled35- AMSI (Antimalware Scan Interface) enabled for script content inspection36- EDR with behavioral detection capabilities (MDE, CrowdStrike, SentinelOne)3738## Workflow3940### Step 1: Enable Required Telemetry4142```powershell43# Enable PowerShell Script Block Logging (GPO or registry)44New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ScriptBlockLogging" `45 -Name EnableScriptBlockLogging -Value 1 -PropertyType DWORD -Force4647# Enable PowerShell Module Logging48New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\ModuleLogging" `49 -Name EnableModuleLogging -Value 1 -PropertyType DWORD -Force5051# Enable PowerShell Transcription52New-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Microsoft\Windows\PowerShell\Transcription" `53 -Name EnableTranscripting -Value 1 -PropertyType DWORD -Force5455# Sysmon config for fileless detection (key events):56# Event ID 1: Process creation (captures CommandLine)57# Event ID 7: Image loaded (DLL loading)58# Event ID 8: CreateRemoteThread (injection)59# Event ID 10: Process access (LSASS access)60# Event ID 19/20/21: WMI events61```6263### Step 2: Detect PowerShell-Based Attacks6465```66# Indicators of malicious PowerShell:6768# Encoded command execution69EventID: 170CommandLine contains: "powershell" AND ("-enc" OR "-e " OR "-encodedcommand" OR "FromBase64String")7172# Download cradle patterns73CommandLine contains: "IEX" AND ("Net.WebClient" OR "DownloadString" OR "Invoke-WebRequest")74CommandLine contains: "Invoke-Expression" AND "New-Object"7576# AMSI bypass attempts (Event ID 4104 - Script Block)77ScriptBlock contains: "AmsiUtils" OR "amsiInitFailed" OR "SetValue.*amsi"7879# Splunk query for suspicious PowerShell:80index=windows source="WinEventLog:Microsoft-Windows-PowerShell/Operational" EventCode=410481| where match(ScriptBlockText, "(?i)(iex|invoke-expression|downloadstring|net\.webclient|frombase64|bypass|amsiutils)")82| table _time host ScriptBlockText83```8485### Step 3: Detect Process Injection Techniques8687```88# Reflective DLL injection - loads DLL from memory without touching disk89# Detection: Sysmon Event 7 (ImageLoaded) where image path is unusual90EventID: 791ImageLoaded NOT starts with: "C:\Windows\" AND NOT starts with: "C:\Program Files"9293# Process hollowing - creates process in suspended state, replaces memory94# Detection: Process creation followed by immediate memory write95EventID: 1 + 10 correlation96# Process created then accessed with PROCESS_VM_WRITE9798# APC injection - queues code to thread's async procedure call queue99# Detection: Sysmon CreateRemoteThread from non-system process100EventID: 8101SourceImage NOT IN (known_legitimate_sources)102103# MDE KQL:104DeviceEvents105| where ActionType in ("CreateRemoteThreadApiCall", "NtAllocateVirtualMemoryApiCall")106| where InitiatingProcessFileName !in ("MsMpEng.exe", "svchost.exe")107| project Timestamp, DeviceName, ActionType, InitiatingProcessFileName,108 InitiatingProcessCommandLine, FileName109```110111### Step 4: Detect WMI-Based Persistence112113```114# Sysmon Event IDs 19/20/21 for WMI events115EventID: 19 # WmiEventFilter activity detected116EventID: 20 # WmiEventConsumer activity detected117EventID: 21 # WmiEventConsumerToFilter activity detected118119# Any WMI event subscription creation is suspicious unless expected120# Common malicious WMI persistence:121Consumer contains: "CommandLineEventConsumer" OR "ActiveScriptEventConsumer"122123# Query for WMI subscriptions via osquery or PowerShell:124Get-WMIObject -Namespace root\Subscription -Class __EventFilter125Get-WMIObject -Namespace root\Subscription -Class __EventConsumer126Get-WMIObject -Namespace root\Subscription -Class __FilterToConsumerBinding127```128129### Step 5: Detect Registry-Based Execution130131```132# Malware stored in registry values and executed via PowerShell133# Sysmon Event 13 - Registry value set with encoded content134EventID: 13135TargetObject contains: "CurrentVersion\Run"136Details: unusually long value or Base64-encoded content137138# Detection query:139index=sysmon EventCode=13140| where match(Details, "[A-Za-z0-9+/=]{100,}")141| table _time host TargetObject Details Image142```143144## Key Concepts145146| Term | Definition |147|------|-----------|148| **Fileless Malware** | Malware that operates entirely in memory without writing executable files to disk |149| **AMSI** | Antimalware Scan Interface; Windows API allowing security products to inspect script content before execution |150| **Reflective DLL Injection** | Loading a DLL from memory rather than disk, avoiding file-based detection |151| **Process Hollowing** | Creating a legitimate process in suspended state and replacing its memory with malicious code |152| **Script Block Logging** | PowerShell logging feature that captures deobfuscated script content (Event ID 4104) |153154## Tools & Systems155156- **Sysmon**: Kernel-level process, DLL, and WMI monitoring157- **AMSI**: Windows script content inspection API158- **PowerShell Logging**: Script Block, Module, and Transcription logging159- **Microsoft Defender for Endpoint**: Behavioral detection for fileless techniques160- **Volatility 3**: Memory forensics for post-incident fileless malware analysis161162## Common Pitfalls163164- **Relying on file-based AV**: Traditional AV that scans files on disk will miss fileless attacks entirely. Behavioral detection and AMSI are required.165- **Disabled PowerShell logging**: Without Script Block Logging, deobfuscated PowerShell commands are invisible to defenders.166- **AMSI bypass not detected**: Sophisticated attackers bypass AMSI before executing payloads. Detect AMSI bypass attempts as a high-priority alert.167- **Not monitoring WMI events**: WMI persistence is a favored technique of APT groups. Sysmon events 19-21 must be enabled.