<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Variable-Expansion — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/tags/variable-expansion/</link><description>Trending threats, MITRE ATT&amp;CK coverage, and detection metadata — refreshed continuously.</description><generator>Hugo</generator><language>en</language><managingEditor>hello@craftedsignal.io</managingEditor><webMaster>hello@craftedsignal.io</webMaster><lastBuildDate>Tue, 02 Jan 2024 10:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/tags/variable-expansion/feed.xml" rel="self" type="application/rss+xml"/><item><title>PowerShell Obfuscation via Backtick-Escaped Variable Expansion</title><link>https://feed.craftedsignal.io/briefs/2024-01-powershell-backtick-obfuscation/</link><pubDate>Tue, 02 Jan 2024 10:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-powershell-backtick-obfuscation/</guid><description>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.</description><content:encoded><![CDATA[<p>This rule detects PowerShell scripts employing backtick-escaped characters within <code>${}</code> 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 <code>${}</code> 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.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>An attacker gains initial access to a Windows system, potentially through phishing or exploiting a software vulnerability.</li>
<li>The attacker uploads or creates a PowerShell script on the target system.</li>
<li>The PowerShell script employs backtick-escaped variable expansion (e.g., <code>$env:use``r``na``me</code>) to obfuscate its contents.</li>
<li>The obfuscated script is executed using powershell.exe.</li>
<li>The script dynamically reconstructs commands and strings by evaluating the backtick-escaped variables.</li>
<li>The reconstructed commands perform malicious activities, such as downloading additional payloads or modifying system configurations.</li>
<li>The script attempts to evade detection by AMSI and other security tools.</li>
<li>The attacker achieves persistence and control over the compromised system, potentially leading to data exfiltration or further lateral movement.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>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.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Enable PowerShell Script Block Logging to generate event code 4104. (Reference: Setup section)</li>
<li>Deploy the Sigma rule <code>Detect PowerShell Backtick Variable Obfuscation</code> to identify scripts using backtick-escaped variable expansion.</li>
<li>Investigate any alerts generated by the Sigma rule, focusing on scripts with a high <code>Esql.script_block_pattern_count</code> value.</li>
<li>Monitor for process creation events where powershell.exe executes obfuscated commands as detected by the Sigma rule <code>Detect Suspicious PowerShell Encoded Commands</code>.</li>
<li>Review PowerShell logs for event code 4104 and examine <code>powershell.file.script_block_text</code> for suspicious patterns.</li>
</ul>
]]></content:encoded><category domain="severity">high</category><category domain="type">advisory</category><category>powershell</category><category>obfuscation</category><category>defense-evasion</category><category>variable-expansion</category><category>windows</category></item></channel></rss>