Detect PowerShell COMPRESS OBFUSCATION using ASCII text encoding and stream/compression APIs
Flags PowerShell script blocks that combine ASCII encoding with Deflate/stream handling indicative of obfuscated payload compression.
- Product
- windows
- Category
- ps_script
- Author
- Timur Zinniatullin, oscd.community (SigmaHQ), DRL 1.1
- Published
- 2020-10-18
- 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 identifies PowerShell script block content consistent with obfuscation routines that use ASCII text encoding and .NET stream and compression objects. Attackers may use these patterns to hide payload logic and make scripts harder to inspect. The detection relies on ScriptBlockText inspection for specific .NET API usage and distinctive string fragments within the script block.
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: Detect PowerShell COMPRESS OBFUSCATION using ASCII text encoding and stream/compression APIs
id: bf220408-131c-487a-9d58-1b607223f845
status: test
description: This rule identifies PowerShell script block content consistent with obfuscation routines that use ASCII text encoding and .NET stream and compression objects. Attackers may use these patterns to hide payload logic and make scripts harder to inspect. The detection relies on ScriptBlockText inspection for specific .NET API usage and distinctive string fragments within the script block.
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_compress.yml
author: Timur Zinniatullin, oscd.community, Huntrule Team
date: 2020-10-18
modified: 2022-11-29
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|contains|all:
- new-object
- text.encoding]::ascii
ScriptBlockText|contains:
- system.io.compression.deflatestream
- system.io.streamreader
ScriptBlockText|endswith: readtoend
condition: selection_4104
falsepositives:
- Unknown
level: medium
license: DRL-1.1
related:
- id: 20e5497e-331c-4cd5-8d36-935f6e2a9a07
type: derived