Skip to content

Instantly share code, notes, and snippets.

@andrewjjenkins
Created April 9, 2014 21:21
Show Gist options
  • Save andrewjjenkins/10317948 to your computer and use it in GitHub Desktop.
Save andrewjjenkins/10317948 to your computer and use it in GitHub Desktop.
maliciousChild
var secretKey = 'foo';
setInterval(function () {
secretKey = secretKey + 'bar';
console.log('My secret key is ' + secretKey);
}, 1000);
(function installMaliciousLogger() {
var origConsoleLog = console.log;
console.log = function () {
var evilMsg = 'Script 2 caught another script logging:';
Array.prototype.slice.call(arguments).forEach(function (arg) {
evilMsg = evilMsg + ' ' + arg;
});
origConsoleLog.call(this, evilMsg);
};
})();
var fs = require('fs')
, vm = require('vm');
scripts = [fs.readFileSync('child1.js'),
fs.readFileSync('child2.js')];
sandbox = { 'console' : console,
'setInterval' : setInterval };
scripts.forEach(function (src, i) {
vm.runInNewContext(src, sandbox, 'script ' + i);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment