Skip to content

Commit

Permalink
Dirty first version.
Browse files Browse the repository at this point in the history
  • Loading branch information
Mickael van der Beek committed Oct 4, 2014
1 parent 427377e commit dc0d318
Show file tree
Hide file tree
Showing 14 changed files with 317 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/cerberus.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var Fuzzer = require('./fuzzer');

module.exports = (function () {
'use strict';

Expand All @@ -9,6 +11,9 @@ module.exports = (function () {

};

Fuzzer.fuzzModules();
// console.log(Fuzzer.generatePayloads());

return Cerberus;

})();
142 changes: 142 additions & 0 deletions src/fuzzer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
var crypto = require('crypto');

var Validator = require('./validator');

var Functions = require('./payloads/functions');
var Booleans = require('./payloads/booleans');
var Objects = require('./payloads/objects');
var Numbers = require('./payloads/numbers');
var Strings = require('./payloads/strings');
var Buffers = require('./payloads/buffers');
var RegExps = require('./payloads/regexps');
var Errors = require('./payloads/errors');
var Arrays = require('./payloads/arrays');
var Dates = require('./payloads/dates');

var CryptoSchema = require('./schemas/core/crypto');

module.exports = (function () {
'use strict';

function Fuzzer () {
Validator.configure({
typeStrict: true,
formatStrict: true,
existenceStrict: true,
nullAsExistence: false,
undefinedAsExistence: false
});

this.payloads = [].concat(
[
undefined
],
Functions,
Booleans,
Objects,
Numbers,
Strings,
Buffers,
RegExps,
Errors,
Arrays,
Dates,
[
null
]
);

this.modules = {
crypto: crypto
}

this.schemas = {
crypto: CryptoSchema
}
}

Fuzzer.prototype.fuzzModules = function (config) {
var schema;
var module;

for(var moduleName in this.schemas) {
schema = this.schemas[moduleName];
module = this.modules[moduleName];

this.fuzzModule(schema, module);
}
};

Fuzzer.prototype.fuzzModule = function (schema, module) {
for(var methodName in schema) {
this.fuzzMethod(schema, module, methodName);
}
};

Fuzzer.prototype.fuzzMethod = function (schema, module, methodName) {
var outputSchema = schema[methodName].output;
var inputSchema = schema[methodName].input;

var overload = [];
for(var i = 0; i < inputSchema.length; i++) {
overload.push(this.payloads);
}

var payloads = this.generatePayloads(overload);
var len = payloads.length;
var output;
var input;

var errors = {};

while(len--) {
input = payloads[len];

console.log('1 INPUT:', input);
console.log('1 NAME:', methodName);

try {
output = module[methodName].apply(module, input);
}
catch(e) {
output = e;
}

if(output instanceof Error) {
if(!errors[output]) {
errors[output] = output;
console.log('\n---------------------');
console.log('1 OUTPUT:', output);
console.log('1 ERROR:', input);
}
}
else if(!Validator.validate(outputSchema, output)) {
console.log('\n---------------------');
console.log('2 OUTPUT:', output);
console.log('2 CORRUPT:', input);
}
}
};

Fuzzer.prototype.generatePayloads = function (payloads) {
var inputs = [];
var max = payloads.length - 1;
function getCombinations(array, i) {
for (var j = 0, l = payloads[i].length; j < l; j++) {
var combination = array.slice(0);
combination.push(payloads[i][j])
if (i === max) {
inputs.push(combination);
}
else {
getCombinations(combination, i + 1);
}
}
}
getCombinations([], 0);
return inputs;
};

return new Fuzzer();

})();
9 changes: 9 additions & 0 deletions src/payloads/arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var list = ['a'];

module.exports = [
[],
[1, 'a'],
(list['test'] = 1) && list,
new Array(),
new Array(5)
];
4 changes: 4 additions & 0 deletions src/payloads/booleans.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
false,
true
];
12 changes: 12 additions & 0 deletions src/payloads/buffers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = [
new Buffer(0),
new Buffer(1),
new Buffer(10, 'binary'),
new Buffer('fl∂∏', 'utf8'),
new Buffer('fl∂∏', 'ucs2'),
new Buffer('fl∂∏', 'utf16le'),
new Buffer('HelloWorld', 'base64'),
new Buffer('Hello World!', 'ascii'),
new Buffer('Hello World!', 'ascii'),
new Buffer('0123456789abcdef', 'hex')
];
6 changes: 6 additions & 0 deletions src/payloads/dates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = [
new Date(),
new Date(NaN),
new Date(8640000000000000),
new Date(-8640000000000000)
];
5 changes: 5 additions & 0 deletions src/payloads/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = [
new Error(),
new TypeError(),
new SyntaxError()
];
4 changes: 4 additions & 0 deletions src/payloads/falsies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
null,
undefined
];
5 changes: 5 additions & 0 deletions src/payloads/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = [
function () {},
new Function (),
function noop() {}
];
19 changes: 19 additions & 0 deletions src/payloads/numbers.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
module.exports = [
0,
-1,
1,
Math.pow(2, 8),
Math.pow(2, 8) + 1,
Math.pow(2, 8) - 1,
Math.pow(2, 16),
Math.pow(2, 16) + 1,
Math.pow(2, 16) - 1,
Math.pow(2, 32),
Math.pow(2, 32) + 1,
Math.pow(2, 32) - 1,
Math.pow(2, 64),
Math.pow(2, 64) + 1,
Math.pow(2, 64) - 1,
Number.MAX_VALUE,
Number.MIN_VALUE
];
8 changes: 8 additions & 0 deletions src/payloads/objects.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = [
{},
{
1: 'a',
a: '1'
},
new Object()
];
4 changes: 4 additions & 0 deletions src/payloads/regexps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = [
/.+/,
/.+/gim
];
32 changes: 32 additions & 0 deletions src/payloads/strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module.exports = [
'',
'`',
'´',
'_',
'.',
'-',
'+',
'˙',
'"',
'<',
'>',
';',
'&',
'@',
'--',
'\\',
'//',
'\n',
'\r',
'\'',
'://',
'\n\r',
'%00',
'\x00',
'\u0000',
'\0',
'null',
'fl∂∏ı',
'undefined',
new Buffer(0x64).toString()
];
62 changes: 62 additions & 0 deletions src/schemas/core/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,68 @@ var crypto = require('crypto');

module.exports = {

// createCredentials: {
// input: [{
// name: 'pfx',
// type: 'String' // or Buffer
// }, {
// name: 'key',
// type: 'String'
// }, {
// name: 'passphrase',
// type: 'String'
// }, {
// name: 'cert',
// type: 'String'
// }, {
// name: 'ca',
// type: 'String',
// optional: true
// }, {
// name: 'crl',
// type: 'String'
// }, {
// name: 'ciphers',
// type: 'String'
// }],
// output: [{
// type: 'String'
// }]
// },

createDiffieHellman: {
input: [{
name: 'prime_length',
type: 'Number'
}],
output: [{
type: crypto.Cipher
}]
},

createDiffieHellman: {
input: [{
name: 'prime',
type: 'Number'
}, {
name: 'encoding',
type: 'String'
}],
output: [{
type: 'String'
}]
},

createHash: {
input: [{
name: 'algorithm',
type: 'String'
}],
output: [{
type: 'String'
}]
},

createCipher: {
input: [{
name: 'algorithm',
Expand Down

0 comments on commit dc0d318

Please sign in to comment.