Skip to content
Threat Feed
high advisory

PowerShell Obfuscation via Backtick-Escaped Variable Expansion

PowerShell scripts use backtick-escaped characters inside `${}` variable expansion to reconstruct strings at runtime, enabling attackers to split keywords, hide commands, and evade static analysis and AMSI.

This rule detects PowerShell scripts employing backtick-escaped characters within ${} variable expansion, a technique used to reconstruct strings at runtime. Attackers leverage variable-expansion obfuscation to split keywords, conceal commands, and bypass static analysis and AMSI (Antimalware Scan Interface). This obfuscation method involves inserting multiple backticks between word characters inside ${} blocks. Detecting this behavior is crucial as it signifies attempts to evade security measures and potentially execute malicious code on compromised systems. The rule focuses on identifying scripts with a length exceeding 500 characters to minimize false positives and targets PowerShell event code 4104.

Attack Chain

  1. An attacker gains initial access to a Windows system, potentially through phishing or exploiting a software vulnerability.
  2. The attacker uploads or creates a PowerShell script on the target system.
  3. The PowerShell script employs backtick-escaped variable expansion (e.g., $env:use``r``na``me) to obfuscate its contents.
  4. The obfuscated script is executed using powershell.exe.
  5. The script dynamically reconstructs commands and strings by evaluating the backtick-escaped variables.
  6. The reconstructed commands perform malicious activities, such as downloading additional payloads or modifying system configurations.
  7. The script attempts to evade detection by AMSI and other security tools.
  8. The attacker achieves persistence and control over the compromised system, potentially leading to data exfiltration or further lateral movement.

Impact

Successful exploitation can lead to arbitrary code execution, system compromise, and data theft. While the number of victims is unknown, PowerShell is a common attack vector on Windows environments. The sectors most affected are organizations relying on Windows infrastructure without adequate PowerShell monitoring and security controls. Failure to detect and prevent this technique allows attackers to bypass security measures and gain unauthorized access to sensitive data.

Recommendation

  • Enable PowerShell Script Block Logging to generate event code 4104. (Reference: Setup section)
  • Deploy the Sigma rule Detect PowerShell Backtick Variable Obfuscation to identify scripts using backtick-escaped variable expansion.
  • Investigate any alerts generated by the Sigma rule, focusing on scripts with a high Esql.script_block_pattern_count value.
  • Monitor for process creation events where powershell.exe executes obfuscated commands as detected by the Sigma rule Detect Suspicious PowerShell Encoded Commands.
  • Review PowerShell logs for event code 4104 and examine powershell.file.script_block_text for suspicious patterns.

Detection coverage 2

Detect PowerShell Backtick Variable Obfuscation

high

Detects PowerShell scripts that use backtick-escaped characters inside `${}` variable expansion.

sigma tactics: defense_evasion techniques: T1027 sources: process_creation, windows

Detect Suspicious PowerShell Encoded Commands

high

Detects PowerShell scripts that use Base64 encoded commands

sigma tactics: execution techniques: T1059.001 sources: process_creation, windows

Detection queries are kept inside the platform. Get full rules →