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.
- 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 EvasionRecon
Resource Dev
Initial Access
Execution
Persistence
Priv Esc
Defense Evasion
Cred Access
Discovery
Lateral Movement
Collection
C2
Exfiltration
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.
Reporting behind it
Changelog
v2- v2Candidate ingested via manual entry.2026-07-31
- v1No 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.
title: "Windows Security 4697: cmd.exe Launching Obfuscated PowerShell via Environment Variable Expansion"
id: 9a4dd2d2-093a-4d38-b2be-ad3fbbb3c753
related:
- id: 8ca7004b-e620-4ecb-870e-86129b5b8e75
type: derived
- id: dcf2db1f-f091-425b-a821-c05875b8925a
type: derived
status: test
description: 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.
references:
- https://github.com/SigmaHQ/sigma/issues/1009
- https://github.com/SigmaHQ/sigma/blob/master/rules/windows/builtin/security/win_security_invoke_obfuscation_var_services_security.yml
author: Jonathan Cheong, oscd.community, Huntrule Team
date: 2020-10-15
modified: 2022-11-29
tags:
- attack.stealth
- attack.t1027
- attack.execution
- attack.t1059.001
logsource:
product: windows
service: security
definition: The 'System Security Extension' audit subcategory need to be enabled to log the EID 4697
detection:
selection:
EventID: 4697
ServiceFileName|contains|all:
- cmd
- '"set'
- -f
ServiceFileName|contains:
- /c
- /r
condition: selection
falsepositives:
- Unknown
level: high
license: DRL-1.1