forked from lair-framework/browser-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_note_by_regex.js
141 lines (139 loc) · 4.49 KB
/
find_note_by_regex.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
var findNoteByRegex = function (noteRegex, noteType) {
// Performs case insensitive search of the appropriate notes (both the title and contents) for the given regex
// noteType can be one of the following:
// all
// project
// host
// service
// vulnerability - searches the evidence field and notes
//
// Usage: findNote('.*Linux.*', 'all');
// Created by: Joey Belans
// Requires client-side updates: false
var PROJECT_ID = Session.get('projectId');
var noteRe = new RegExp(noteRegex, 'i');
if (noteType === 'project' || noteType === 'all') {
console.log('Project Notes');
var curProj = Projects.findOne({
'_id': PROJECT_ID
}, {
notes: 1
});
curProj.notes.forEach(function (note) {
if (noteRe.test(note.title) || noteRe.test(note.content)) {
console.log('\t' + note.title);
}
});
}
if (noteType === 'host' || noteType === 'all') {
console.log('Host Notes');
Hosts.find({
'project_id': PROJECT_ID,
$or: [{
'notes': {
$elemMatch: {
'title': {
$regex: noteRegex,
$options: 'i'
}
}
}
}, {
'notes': {
$elemMatch: {
'content': {
$regex: noteRegex,
$options: 'i'
}
}
}
}]
}, {
notes: 1
}).fetch().forEach(function (host) {
host.notes.forEach(function (note) {
if (noteRe.test(note.title) || noteRe.test(note.content)) {
console.log('\t' + host.string_addr + ' -> ' + note.title);
}
});
});
}
if (noteType === 'service' || noteType === 'all') {
console.log('Service Notes');
Ports.find({
'project_id': PROJECT_ID,
$or: [{
'notes': {
$elemMatch: {
'title': {
$regex: noteRegex,
$options: 'i'
}
}
}
}, {
'notes': {
$elemMatch: {
'content': {
$regex: noteRegex,
$options: 'i'
}
}
}
}]
}, {
notes: 1
}).fetch().forEach(function (port) {
port.notes.forEach(function (note) {
if (noteRe.test(note.title) || noteRe.test(note.content)) {
var portHost = Hosts.findOne({
'project_id': PROJECT_ID,
'_id': port.host_id
});
console.log('\t' + portHost.string_addr + ' -> ' + port.port.toString() + ' -> ' + note.title);
}
});
});
}
if (noteType === 'vulnerability' || noteType === 'all') {
console.log('Vulnerability Notes');
Vulnerabilities.find({
'project_id': PROJECT_ID,
$or: [{
'evidence': {
$regex: noteRegex,
$options: 'i'
}
}, {
'notes': {
$elemMatch: {
'title': {
$regex: noteRegex,
$options: 'i'
}
}
}
}, {
'notes': {
$elemMatch: {
'content': {
$regex: noteRegex,
$options: 'i'
}
}
}
}]
}, {
notes: 1
}).fetch().forEach(function (vuln) {
if (noteRe.test(vuln.evidence)) {
console.log('\t' + vuln.title + ' -> Evidence Field');
}
vuln.notes.forEach(function (note) {
if (noteRe.test(note.title) || noteRe.test(note.content)) {
console.log('\t' + vuln.title + ' -> ' + note.title);
}
});
});
}
};