Skip to content

Instantly share code, notes, and snippets.

@mattburch
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattburch/9619879 to your computer and use it in GitHub Desktop.
Save mattburch/9619879 to your computer and use it in GitHub Desktop.
var listHostsByVulnerabilityRegex = function(title,score) {
// Retrieves all host, port, protocol instances afflicted by a certain vulnerability Regex
//
// Created by: Matt Burch
// Usage: listHostsByVulnerabilityRegex(/Self-[Ss]igned/,'high')
// Requires client-side updates: false
score = score.toLowerCase();
var RATING = {
'hightop' : 10.0,
'highbot' : 7.0,
'mediumtop' : 6.9,
'mediumbot' : 4.0,
'lowtop' : 3.9,
'lowbot' : 1.0,
};
var PROJECT_ID = Session.get( 'projectId');
var vulnerability;
if (score == '') {
vulnerability = Vulnerabilities.find({ "project_id": PROJECT_ID, "title": { "$regex": title} }).fetch();
if ( !vulnerability) {
return ( "Vulnerability not found");
}
}
else if (RATING[score + 'top'] == undefined) {
return ("Vulnerability score must be: high, medium or low");
}
else {
vulnerability = Vulnerabilities.find({ "project_id": PROJECT_ID, "title": { "$regex": title}, "$and": [{"cvss": {"$gte": RATING[score + 'bot']}}, {"cvss": {"$lte": RATING[score + 'top']}}] }).fetch();
if ( !vulnerability) {
console.log( "Vulnerability not found");
return;
}
}
vulnerability.forEach( function(vulm) {
console.log(vulm.title + " CVSS:" + vulm.cvss);
var hosts = vulm.hosts;
hosts.forEach( function(host){
var realHost = Hosts.findOne({ "project_id": PROJECT_ID, "string_addr": host.string_addr});
console.log (host.string_addr + ":" + host.port + "/" + host.protocol);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment