-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdump_service_notes.js
77 lines (74 loc) · 1.83 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function dumpServiceNotes (projectId, noteRegex, iplist) {
// 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: mongo localhost:27017/lair --eval "load('./dump_service_notes.js'); dumpServiceNotes('cvxgsaKNC5cfLoeNn', ^SSL Self-Signed', '')"
//
// Created by: Matt Burch
//
// Original Browser Script
// Created by: Dan Kottmann
function checkmatch (host, iplist) {
skp = 1
if (iplist.length < 1) {
return 0
}
iplist.forEach( function(ip) {
if (ip !== '' && ip == host.ipv4) {
skp = 0
return
}
})
return skp
}
var hostIds = []
var re = new RegExp(noteRegex, 'i')
var services = db.services.find({
'projectId': projectId,
'notes': {
$elemMatch: {
'title': {
$regex: noteRegex,
$options: 'i'
}
}
}
}, {
notes: 1,
hostId: 1
}).toArray()
services.map( function(service) {
hostIds.push(service.hostId)
})
var hosts = db.hosts.find({
'_id': {
$in: hostIds
}
}).sort({
longIpv4Addr: 1,
ipv4: 1
}).toArray()
hosts.forEach(function (host) {
if (checkmatch(host,iplist)) {
return
}
services = db.services.find({
'hostId': host._id
}).sort({
service: 1,
notes: 1,
service: 1,
protocol: 1
}).toArray()
services.forEach(function (service) {
service.notes.forEach(function (note) {
if (re.test(note.title)) {
print(host.ipv4 + ':' + service.port + '/' + service.protocol + ' - ' + note.title + '\n' + note.content)
}
})
})
})
}