forked from lair-framework/browser-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dump_service_notes.js
61 lines (60 loc) · 1.71 KB
/
dump_service_notes.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
var dumpServiceNotes = function (noteRegex, ip) {
// Dump the contents of service notes matching a specific regex (matches against note 'title')
// By supplying an empty string for the 'ip' you can dump all notes.
// Examples:
// dumpServiceNotes('^SSL Self-Signed', '')
// dumpServiceNotes('Software Enumeration', '192.168.1.1')
//
// Usage: dumpServiceNotes(regex, ip);
// Created by: Dan Kottmann
// Requires client-side updates: false
var PID = Session.get('projectId');
var re = new RegExp(noteRegex, 'i');
var ports = Ports.find({
'project_id': PID,
'notes': {
$elemMatch: {
'title': {
$regex: noteRegex,
$options: 'i'
}
}
}
}, {
notes: 1,
host_id: 1
}).fetch();
var hostIds = _.pluck(ports, 'host_id');
var hosts = Hosts.find({
'_id': {
$in: hostIds
}
}, {
sort: {
long_addr: 1
},
string_addr: 1
}).fetch();
hosts.forEach(function (host) {
if (ip !== '' && ip !== host.string_addr) {
return;
}
ports = Ports.find({
'host_id': host._id
}, {
sort: {
port: 1
},
notes: 1,
port: 1,
protocol: 1
}).fetch();
ports.forEach(function (port) {
port.notes.forEach(function (note) {
if (re.test(note.title)) {
console.log(host.string_addr + ':' + port.port + '/' + port.protocol + ' - ' + note.title + '\n' + note.content);
}
});
});
});
};