back to roadmap
Phase 3·T1059.001·Advanced

Memory-Only PowerShell Execution

Detect VirtualAlloc/CreateThread patterns used for fileless shellcode.

#PowerShell#Advanced

Detection Objective

Spot Win32 API references inside PowerShell script blocks.

Real-World Attack Scenario

PSInject-style loaders allocate RWX memory and call CreateThread.

Why This Detection Matters

Fileless attacks evade disk-based AV entirely.

ATT&CK Mapping

T1059.001 · PowerShell
Tactic: Execution

Required Telemetry

  • PowerShell4104
Windows Event IDs
4104
Sysmon Event IDs
Wazuh Log Source
PowerShell/Operational

Setup Steps

  1. 4104 enabled.

Safe Validation Command

Log an inert reference string.
powershell.exe -c "Write-Host 'detection-test: VirtualAlloc CreateThread reference'"
⚠ lab use only · this project does not execute real malware

Expected Log Output

4104 ScriptBlockText contains 'VirtualAlloc'

Detection Logic (Wazuh rule concept)

ScriptBlockText matches /(?i)VirtualAlloc|CreateThread|WriteProcessMemory|memcpy/

False Positives

  • Pen-test tooling installed by red team

Tuning Recommendations

  • Allowlist red team host group.

Analyst Triage Notes

  • Capture memory and pivot on parent process.

Detection Improvement Ideas

  • Add ETW-TI for memory protection changes.

log analysis layer

Detection is not complete until the logs prove what happened. The sections below show the telemetry produced by the validation above, how to read it like an analyst, and why this pattern matters.

siem · log evidence
rule 100485
Memory-Only PowerShell Execution
PowerShell/Operational
Event ID
Windows EID 4104
Image
C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
Parent
C:\Windows\explorer.exe
CommandLine
powershell.exe -c "Write-Host 'detection-test: VirtualAlloc CreateThread reference'"
User
CORP\j.doe
Agent
WIN10-LAB-01
Timestamp
2026-05-26T14:32:11Z
analyst note
Capture memory and pivot on parent process.

Parent → Child Analysis

explorer.exe → powershell.exe — review whether this lineage is expected for WIN10-LAB-01 and user CORP\j.doe.

Command-Line Flags Observed

  • (no high-risk flags in this test)
    Signal value comes from context (parent, network, persistence) rather than flags.

Parsed Fields the Analyst Reads

  • ImageProcess binary that executed — confirms PowerShell.
    C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
  • ParentImageWho launched it — context for legitimacy.
    C:\Windows\explorer.exe
  • CommandLineArguments — where attacker intent shows up.
    powershell.exe -c "Write-Host 'detection-test: VirtualAlloc CreateThread reference'"
  • UserAccount context — service vs interactive vs SYSTEM.
    CORP\j.doe
  • EventIDTelemetry channel and event type.
    Windows EID 4104
  • Wazuh Rule IDRule that matched and produced this alert.
    100485
  • AgentEndpoint that produced the telemetry.
    WIN10-LAB-01
  • TimestampWhen it happened — anchor for correlation.
    2026-05-26T14:32:11Z

Malicious Pattern

pattern
Memory-Only PowerShell Execution
description
PSInject-style loaders allocate RWX memory and call CreateThread.
analyst takeaway
Fileless attacks evade disk-based AV entirely. Treat this signal as higher-risk when combined with suspicious parents, hidden windows, download cradles, or unusual user context.

proof the detection worked

test command
powershell.exe -c "Write-Host 'detection-test: VirtualAlloc CreateThread reference'"
expected event
Windows EID 4104 on WIN10-LAB-01 with Image=powershell.exe and the validation command above in CommandLine.
expected wazuh alert
Wazuh rule 100485 — "Memory-Only PowerShell Execution" fires at a level matching severity=high.
confirming log fields
ImageParentImageCommandLineUserEventID
analyst interpretation
The recorded fields satisfy every clause of the detection logic. Parent process, user context, and command-line arguments together prove the behavior was observed end to end.
conclusion
Detection succeeded: telemetry was captured, the rule matched, and the alert reached the analyst with enough context to triage.