-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfind_note_by_regex.js
More file actions
141 lines (139 loc) · 3.46 KB
/
find_note_by_regex.js
File metadata and controls
141 lines (139 loc) · 3.46 KB
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
// Issue - searches the evidence field and notes
//
// Usage: findNote('.*Linux.*', 'all')
// Created by: Joey Belans
// Requires client-side updates: false
var projectId = Session.get('projectId')
var noteRe = new RegExp(noteRegex, 'i')
if (noteType === 'project' || noteType === 'all') {
console.log('Project Notes')
var curProj = Projects.findOne({
'_id': projectId
}, {
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({
'projectId': projectId,
$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.ipv4 + ' -> ' + note.title)
}
})
})
}
if (noteType === 'service' || noteType === 'all') {
console.log('Service Notes')
Services.find({
'projectId': projectId,
$or: [{
'notes': {
$elemMatch: {
'title': {
$regex: noteRegex,
$options: 'i'
}
}
}
}, {
'notes': {
$elemMatch: {
'content': {
$regex: noteRegex,
$options: 'i'
}
}
}
}]
}, {
notes: 1
}).fetch().forEach(function (service) {
service.notes.forEach(function (note) {
if (noteRe.test(note.title) || noteRe.test(note.content)) {
var serviceHost = Hosts.findOne({
'projectId': projectId,
'_id': service.hostId
})
console.log('\t' + serviceHost.ipv4 + ' -> ' + service.service.toString() + ' -> ' + note.title)
}
})
})
}
if (noteType === 'Issue' || noteType === 'all') {
console.log('Issue Notes')
Issues.find({
'projectId': projectId,
$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)
}
})
})
}
}