PowerShell Obfuscation Delivered via Stdin Using Set-and-Invoke Pattern
Detects obfuscated PowerShell script blocks that use chained stdin/environment/input patterns.
- Product
- windows
- Category
- ps_script
- Author
- Nikita Nazarov, oscd.community (SigmaHQ), DRL 1.1
- Published
- 2020-10-12
- 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 text that matches an obfuscated “set … && set … (environment|invoke|${input}) … && … " pattern, which is commonly used to hide malicious intent while still executing. Attackers may use stdin-driven and chained assignments/invocations to evade straightforward inspection and blend execution with environment/input handling. The detection relies on Script Block Logging telemetry that captures the full script block text executed in PowerShell.
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 Obfuscation Delivered via Stdin Using Set-and-Invoke Pattern
id: 9cc577c9-de1c-4b41-a05f-2a3c9d1b2c95
status: test
description: This rule flags PowerShell script block text that matches an obfuscated “set … && set … (environment|invoke|${input}) … && … " pattern, which is commonly used to hide malicious intent while still executing. Attackers may use stdin-driven and chained assignments/invocations to evade straightforward inspection and blend execution with environment/input handling. The detection relies on Script Block Logging telemetry that captures the full script block text executed in PowerShell.
references:
- https://github.com/SigmaHQ/sigma/issues/1009
- https://github.com/SigmaHQ/sigma/blob/master/rules/windows/powershell/powershell_script/posh_ps_invoke_obfuscation_via_stdin.yml
author: Nikita Nazarov, oscd.community, Huntrule Team
date: 2020-10-12
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: (?i)(set).*&&\s?set.*(environment|invoke|\$\{?input).*&&.*"
condition: selection_4104
falsepositives:
- Unknown
level: high
license: DRL-1.1
related:
- id: 86b896ba-ffa1-4fea-83e3-ee28a4c915c7
type: derived