<?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>Dynamic-Compilation — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/tags/dynamic-compilation/</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>Wed, 03 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/tags/dynamic-compilation/feed.xml" rel="self" type="application/rss+xml"/><item><title>Suspicious Dynamic .NET Compilation via Csc.exe</title><link>https://feed.craftedsignal.io/briefs/2024-01-dynamic-net-compilation/</link><pubDate>Wed, 03 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-dynamic-net-compilation/</guid><description>Attackers may use csc.exe to compile .NET code on the fly to evade detection, often placing the compiler and source code in suspicious locations, which can be detected by monitoring process creation events.</description><content:encoded><![CDATA[<p>Attackers often utilize the .NET Framework&rsquo;s command-line compiler, <code>csc.exe</code>, to compile malicious code dynamically on compromised systems. This tactic allows them to evade traditional signature-based detections and execute code in memory. The compilation often occurs from unusual or temporary directories such as <code>\Perflogs\</code>, <code>\Users\Public\</code>, or within the <code>AppData</code> directory. This technique has been observed in campaigns involving malware such as Agent Tesla and by actors like MuddyWater. Detection focuses on identifying <code>csc.exe</code> executions originating from or utilizing paths indicative of suspicious activity outside of normal software development workflows.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>Initial Access: The attacker gains initial access to the system through an exploit or social engineering.</li>
<li>Payload Delivery: A malicious payload containing .NET source code is delivered to the system, often dropped in a temporary directory or a user&rsquo;s profile directory.</li>
<li>Command Execution: The attacker uses a command-line interface (cmd.exe or powershell.exe) to execute <code>csc.exe</code>.</li>
<li>Dynamic Compilation: <code>csc.exe</code> compiles the .NET source code into an executable or DLL file.</li>
<li>File Creation: The compiled assembly is written to disk in a specified location.</li>
<li>Code Injection/Execution: The compiled assembly is loaded into memory and executed, often using techniques like reflective DLL injection.</li>
<li>Persistence (Optional): The attacker may establish persistence by creating a scheduled task or modifying registry keys to recompile and execute the malicious code on system startup.</li>
<li>Achieve Objectives: The attacker achieves their objectives, such as data exfiltration, lateral movement, or establishing a command and control channel.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation can lead to arbitrary code execution, allowing attackers to perform a wide range of malicious activities. This can result in data theft, system compromise, and the deployment of ransomware. While the number of victims and sectors targeted varies depending on the specific campaign, dynamic compilation techniques significantly increase the difficulty of detection and response, making systems vulnerable to persistent and stealthy attacks.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Deploy the provided Sigma rules to your SIEM to detect suspicious executions of <code>csc.exe</code> from unusual locations (process_creation logs).</li>
<li>Tune the Sigma rules for your environment to reduce false positives, considering legitimate uses of <code>csc.exe</code> by developers (Sigma rules).</li>
<li>Monitor process creation events for <code>csc.exe</code> with command-line arguments containing suspicious directory locations like <code>\Perflogs\</code>, <code>\Users\Public\</code>, <code>\AppData\Local\Temp\</code> (process_creation logs).</li>
<li>Investigate any instances where <code>csc.exe</code> is executed by processes other than legitimate software development tools, filtering out known good parent processes like <code>sdiagnhost.exe</code> or <code>w3wp.exe</code> (process_creation logs).</li>
<li>Consider blocking execution of <code>csc.exe</code> from user-writable directories if it is not a legitimate use case in your environment.</li>
</ul>
]]></content:encoded><category domain="severity">medium</category><category domain="type">advisory</category><category>defense-evasion</category><category>dynamic-compilation</category><category>csc.exe</category></item></channel></rss>