Windows Security: Detect Obfuscated PowerShell IEX Invocation via ServiceFileName Patterns (Event ID 4697)
Alerts on EventID 4697 instances where ServiceFileName matches obfuscated IEX-style PowerShell invocation patterns consistent with Invoke-Obfuscation.
- Product
- windows
- Service
- security
- Author
- Daniel Bohannon (@Mandiant/@FireEye), oscd.community (SigmaHQ), DRL 1.1
- Published
- 2019-11-08
- Updated
- 2026-07-31
ATT&CK techniques
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 Event ID 4697 where the recorded service binary path contains specific strings consistent with obfuscated PowerShell IEX invocation patterns. Attackers commonly use obfuscation to evade command-line inspection and to hide the real payload delivery mechanism. Telemetry relies on the Security log producing Event ID 4697 along with the ServiceFileName field matching multiple predefined regular-expression patterns.
Reporting behind it
- github.comhttps://github.com/danielbohannon/Invoke-Obfuscation/blob/f20e7f843edd0a3a7716736e9eddfa423395dd26/Out-ObfuscatedStringCommand.ps1#L873-L888
- github.comhttps://github.com/SigmaHQ/sigma/blob/master/rules/windows/builtin/security/win_security_invoke_obfuscation_obfuscated_iex_services_security.yml
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: Detect Obfuscated PowerShell IEX Invocation via ServiceFileName Patterns (Event ID 4697)"
id: bba8f149-30ae-4ae2-b511-12178b894952
related:
- id: 51aa9387-1c53-4153-91cc-d73c59ae1ca9
type: derived
- id: fd0f5778-d3cb-4c9a-9695-66759d04702a
type: derived
status: test
description: This rule flags Windows Security audit Event ID 4697 where the recorded service binary path contains specific strings consistent with obfuscated PowerShell IEX invocation patterns. Attackers commonly use obfuscation to evade command-line inspection and to hide the real payload delivery mechanism. Telemetry relies on the Security log producing Event ID 4697 along with the ServiceFileName field matching multiple predefined regular-expression patterns.
references:
- https://github.com/danielbohannon/Invoke-Obfuscation/blob/f20e7f843edd0a3a7716736e9eddfa423395dd26/Out-ObfuscatedStringCommand.ps1#L873-L888
- https://github.com/SigmaHQ/sigma/blob/master/rules/windows/builtin/security/win_security_invoke_obfuscation_obfuscated_iex_services_security.yml
author: Daniel Bohannon (@Mandiant/@FireEye), oscd.community, Huntrule Team
date: 2019-11-08
modified: 2022-11-27
tags:
- attack.stealth
- attack.t1027
logsource:
product: windows
service: security
definition: The 'System Security Extension' audit subcategory need to be enabled to log the EID 4697
detection:
selection_eid:
EventID: 4697
selection_servicefilename:
- ServiceFileName|re: \$PSHome\[\s*\d{1,3}\s*\]\s*\+\s*\$PSHome\[
- ServiceFileName|re: \$ShellId\[\s*\d{1,3}\s*\]\s*\+\s*\$ShellId\[
- ServiceFileName|re: \$env:Public\[\s*\d{1,3}\s*\]\s*\+\s*\$env:Public\[
- ServiceFileName|re: \$env:ComSpec\[(\s*\d{1,3}\s*,){2}
- ServiceFileName|re: \\*mdr\*\W\s*\)\.Name
- ServiceFileName|re: \$VerbosePreference\.ToString\(
- ServiceFileName|re: \String\]\s*\$VerbosePreference
condition: all of selection_*
falsepositives:
- Unknown
level: high
license: DRL-1.1