Windows Security 4697: cmd.exe Launching Obfuscated PowerShell via Environment Variable Expansion

Alerts on EID 4697 service installation command lines containing obfuscated cmd.exe SET patterns used to execute PowerShell via environment variables.

FreeReviewedSigma · High · v2
Product
windows
Service
security
Author
Jonathan Cheong, oscd.community (SigmaHQ), DRL 1.1
Published
2020-10-15
Updated
2026-07-31

ATT&CK techniques

Execution → Defense Evasion
  1. Recon

  2. Resource Dev

  3. Initial Access

  4. Persistence

  5. Priv Esc

  6. Cred Access

  7. Discovery

  8. Lateral Movement

  9. Collection

  10. C2

  11. Exfiltration

  12. Impact

What it detects

This rule flags Windows Security audit events (EventID 4697) where a service is configured with a ServiceFileName that includes cmd.exe execution of SET with string formatting and environment-variable-based obfuscation consistent with PowerShell invocation. Attackers commonly use environment variable expansion and obfuscated command strings to evade detections and hinder analysis while still executing PowerShell. It relies on Security log telemetry for EventID 4697 and string matching within the ServiceFileName for cmd-related execution indicators.

Related detections9 linkedT1027 — drag to rearrange
Malicious FIN7 Powertrash Loader Execution via Obfuscated PowerShell (via process_creation)
Suspicious XOR Obfuscated PowerShell from ClickFix Distribution
Suspicious PowerShell Executing Code from Environment Variable (via process_creation)
Suspicious In-Memory Runspace Execution via PowerShell Script Block
Suspicious Encoded PowerShell Using Base64 Stream Decompression Routines (via process_creation)
Suspicious PowerShell In-Memory Execution with AES Decryption
Suspicious Encoded PowerShell Command Execution
Suspicious PEAKLIGHT Memory-Only PowerShell Downloader Flags (via process_creation)
Obfuscated PowerShell Script: Indirect Cmdlet Execution via ExportedCommands Array Index
Windows Security 4697: cmd.exe Launching Obfuscated PowerShell via Environment Variable Expansion
Pivot detection · T1027 · 9 related

Changelog

v2
  1. v2
    Candidate ingested via manual entry.2026-07-31
  2. v1
    No changelog recorded for this version.2026-07-30

Detection content is published as a reviewed draft. Tune thresholds and exclusions against your own telemetry before enabling this rule for alerting.