msfjs
Version:
Node library for interacting with metasploit
79 lines (44 loc) • 1.33 kB
JavaScript
var child_process = require('child_process'),
events = require('events');
var Exploits = function(msf, options) {
this.msf = msf;
this.path = options.path;
this.exploits = null;
this.gatherExploits();
}
Exploits.prototype.gatherExploits = function() {
child_process.exec(this.path + '/msfconsole -x "show exploits;exit"', function(err, stdout, stderr) {
var exploits = [];
stdout.split('\n').forEach(function(line) {
if(line.match(/.*\d{4}-\d{2}-\d{2}/)) {
line = line.replace(/\s{2,}/g, ' ').trim().split(' ');
var exploit = {
exploit: line[0],
date: line[1],
success: line[2],
description: line.splice(3).join(' ')
}
exploits.push(exploit);
}
});
this.exploits = exploits;
console.log("Loaded exploits.");
}.bind(this));
}
Exploits.prototype.getExploits = function(cb) {
cb(this.exploits);
};
Exploits.prototype.launch = function(exploit, cb) {
var event = new events.EventEmitter;
cb(event);
var opt = [];
opt.push(exploit.exploit)
opt.push("payload=" + exploit.payload);
for(var option in exploit.options) {
opt.push([ option, exploit.options[option] ].join("="));
}
opt.push('e');
var process = child_process.spawn(this.msf.path + "/msfcli", opt);
exploit.handle(process, event);
}
module.exports = Exploits;