PowerShell: Obfuscated invocation via Environment Variables in Script Block
Alerts on PowerShell script blocks launching cmd /c or /r with obfuscated set-and-{n} variable expansion patterns.
- Product
- windows
- Category
- ps_script
- 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 PowerShell script block content that constructs command execution using environment variable expansion in an obfuscated manner. Attackers use this pattern to hide the executed command and evade casual inspection while still relying on standard PowerShell and command invocation semantics. It relies on PowerShell Script Block logging telemetry to match suspicious script block text patterns containing the obfuscated cmd/cmd /r logic and set-variable usage.
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: "PowerShell: Obfuscated invocation via Environment Variables in Script Block"
id: ab42c64b-bc91-4148-988d-1a7d65ca0cbf
status: test
description: This rule flags PowerShell script block content that constructs command execution using environment variable expansion in an obfuscated manner. Attackers use this pattern to hide the executed command and evade casual inspection while still relying on standard PowerShell and command invocation semantics. It relies on PowerShell Script Block logging telemetry to match suspicious script block text patterns containing the obfuscated cmd/cmd /r logic and set-variable usage.
references:
- https://github.com/SigmaHQ/sigma/issues/1009
- https://github.com/SigmaHQ/sigma/blob/master/rules/windows/powershell/powershell_script/posh_ps_invoke_obfuscation_var.yml
author: Jonathan Cheong, oscd.community, Huntrule Team
date: 2020-10-15
modified: 2024-04-05
tags:
- attack.stealth
- attack.t1027
- attack.execution
- attack.t1059.001
logsource:
product: windows
category: ps_script
definition: "Requirements: Script Block Logging must be enabled"
detection:
selection_4104:
ScriptBlockText|re: cmd.{0,5}(?:/c|/r)(?:\s|)"set\s[a-zA-Z]{3,6}.*(?:\{\d\}){1,}\\"\s+?-f(?:.*\)){1,}.*"
condition: selection_4104
falsepositives:
- Unknown
level: high
license: DRL-1.1
related:
- id: 0adfbc14-0ed1-11eb-adc1-0242ac120002
type: derived