Detection rules › Elastic

Potential PowerShell Obfuscation via Invalid Escape Sequences

Author
Elastic
Source
upstream

Detects PowerShell scripts with repeated invalid backtick escapes between word characters (letters, digits, underscore, or dash), splitting tokens while preserving execution. Attackers use this obfuscation to fragment keywords and evade pattern-based detection and AMSI.

MITRE ATT&CK coverage

TacticTechniques
ExecutionT1059 Command and Scripting Interpreter, T1059.001 Command and Scripting Interpreter: PowerShell
Defense EvasionT1027 Obfuscated Files or Information, T1027.010 Obfuscated Files or Information: Command Obfuscation, T1140 Deobfuscate/Decode Files or Information

Event coverage

ProviderEvent IDTitle
PowerShell4104Creating Scriptblock text (MessageNumber of MessageTotal).

Stages and Predicates

Stage 1: esql:from

Stage 2: esql:where

powershell.file.script_block_text:"`"

Stage 3: esql:eval

Stage 4: esql:eval

Stage 5: esql:keep

Stage 6: esql:where

Esql.script_block_pattern_count >= 20

Stage 7: esql:where

(not file.name:* or <macro:>)

Stage 8: esql:where

not powershell.file.script_block_text:"$([char]0x1b)]633"

Stage 9: esql:where

(not file.directory:"C:\\\\Program Files\\\\MVPSI\\\\JAMS\\\\Agent\\\\Temp" or not file.directory:*)

Exclusions

Top-level NOT(...) conjuncts — predicates this rule actively suppresses.

StageFieldKindExcluded values
1ScriptBlockTextmatch$([char]0x1b)]633

Indicators

Each row is a field, operator, and value that the rule matches. The corpus column counts how many other rules in the catalog look for the same combination: high numbers point to widely-used, community-vetted indicators. Blank or 1 shows that the indicator is specific to this rule.

FieldKindValues
Esql.script_block_pattern_countge
  • 20
powershell.file.script_block_textwildcard
  • *`*

Neighbors

Stricter alternatives (narrower than this rule)

The rules below may be useful if you find the current rule is too noisy / lacks specificity.