<?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>Vm2 (&lt;= 3.11.0) — CraftedSignal Threat Feed</title><link>https://feed.craftedsignal.io/products/vm2--3.11.0/</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>Sun, 28 Jan 2024 12:00:00 +0000</lastBuildDate><atom:link href="https://feed.craftedsignal.io/products/vm2--3.11.0/feed.xml" rel="self" type="application/rss+xml"/><item><title>vm2 NodeVM Nesting Bypass Allows Arbitrary Command Execution</title><link>https://feed.craftedsignal.io/briefs/2024-01-28-vm2-sandbox-escape/</link><pubDate>Sun, 28 Jan 2024 12:00:00 +0000</pubDate><author>hello@craftedsignal.io</author><guid isPermaLink="true">https://feed.craftedsignal.io/briefs/2024-01-28-vm2-sandbox-escape/</guid><description>A vulnerability in vm2's NodeVM, when nesting is enabled, allows sandbox code to bypass require restrictions, enabling arbitrary OS command execution on the host.</description><content:encoded><![CDATA[<p>A critical vulnerability exists in vm2 versions 3.11.0 and below, specifically impacting the <code>NodeVM</code> when the <code>nesting: true</code> option is enabled. This flaw allows untrusted code running within the sandbox to bypass the intended <code>require</code> restrictions, even when <code>require: false</code> is explicitly set. By exploiting this bypass, malicious code can gain access to the <code>vm2</code> module itself, create a new inner <code>NodeVM</code> with unrestricted permissions, and ultimately execute arbitrary OS commands on the host system. This can lead to complete compromise of applications relying on vm2 for secure code execution, affecting multi-tenant platforms, REPL services, and CI sandboxing environments. The vulnerability stems from how <code>nesting: true</code> overrides the <code>require</code> settings during module resolution, silently allowing access to <code>vm2</code> even when it should be blocked.</p>
<h2 id="attack-chain">Attack Chain</h2>
<ol>
<li>The host application creates a <code>NodeVM</code> instance with <code>nesting: true</code> and <code>require: false</code> (or a restrictive require list) to sandbox untrusted code.</li>
<li>The untrusted code within the sandbox calls <code>require('vm2')</code>. Due to the vulnerability, this succeeds despite the outer VM&rsquo;s require restrictions.</li>
<li>The sandbox code obtains the <code>NodeVM</code> constructor from the required <code>vm2</code> module.</li>
<li>The sandbox creates a new, inner <code>NodeVM</code> instance, specifying its own <code>require</code> configuration to include <code>child_process</code>.</li>
<li>The inner <code>NodeVM</code> uses <code>child_process.execSync()</code> to execute an arbitrary OS command (e.g., <code>id</code>, <code>whoami</code>).</li>
<li>The output of the executed command is converted to a string.</li>
<li>The inner VM returns the command output to the outer VM.</li>
<li>The outer VM returns the command output to the host application, effectively escaping the sandbox.</li>
</ol>
<h2 id="impact">Impact</h2>
<p>Successful exploitation allows attackers to execute arbitrary OS commands as the user running the host Node.js process. This gives the attacker the ability to read and write files, potentially exfiltrate sensitive information (secrets, API keys, etc.), move laterally within the network the host resides on, and establish persistent access to the compromised system. Any application employing <code>vm2</code> with <code>nesting: true</code> to isolate untrusted code is vulnerable. This includes multi-tenant systems and CI/CD environments, posing a severe risk to infrastructure security. The vulnerability exists because developers expect <code>require: false</code> to provide a solid sandbox restriction, but enabling <code>nesting: true</code> silently overrides this expectation.</p>
<h2 id="recommendation">Recommendation</h2>
<ul>
<li>Immediately upgrade to a patched version of <code>vm2</code> that addresses this vulnerability.</li>
<li>If upgrading is not immediately feasible, avoid using <code>nesting: true</code> in <code>NodeVM</code> configurations where untrusted code execution is involved.</li>
<li>Deploy the Sigma rule <code>Detect vm2 Nesting Sandbox Escape via Child Process</code> to identify potential exploitation attempts.</li>
<li>Enable process creation logging to support the detection rules.</li>
<li>Audit existing <code>NodeVM</code> configurations within your applications to identify instances where <code>nesting: true</code> is used in conjunction with restricted <code>require</code> settings.</li>
<li>Consider alternative sandboxing solutions that offer more robust module isolation if <code>vm2</code> cannot be adequately secured.</li>
</ul>
]]></content:encoded><category domain="severity">critical</category><category domain="type">advisory</category><category>sandbox-escape</category><category>vm2</category><category>code-execution</category></item></channel></rss>