-
Notifications
You must be signed in to change notification settings - Fork 360
/
report-bl-source-ips.go
65 lines (52 loc) · 1.41 KB
/
report-bl-source-ips.go
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
package reporting
import (
"bytes"
"html/template"
"os"
"sort"
"github.com/globalsign/mgo/bson"
"github.com/activecm/rita/pkg/host"
"github.com/activecm/rita/reporting/templates"
"github.com/activecm/rita/resources"
)
func printBLSourceIPs(db string, res *resources.Resources) error {
f, err := os.Create("bl-source-ips.html")
if err != nil {
return err
}
defer f.Close()
match := bson.M{
"$and": []bson.M{
bson.M{"blacklisted": true},
bson.M{"dat.count_src": bson.M{"$gt": 0}},
}}
data := getBlacklistedIPsResultsView(res, "conn_count", 1000, match, "src", "dst")
out, err := template.New("bl-source-ips.html").Parse(templates.BLSourceIPTempl)
if err != nil {
return err
}
w, err := getBLIPWriter(data)
if err != nil {
return err
}
return out.Execute(f, &templates.ReportingInfo{DB: db, Writer: template.HTML(w)})
}
func getBLIPWriter(results []host.AnalysisView) (string, error) {
tmpl := "<tr><td>{{.Host}}</td><td>{{.Connections}}</td><td>{{.UniqueConnections}}</td>" +
"<td>{{.TotalBytes}}</td>" +
"<td>{{range $idx, $host := .ConnectedHosts}}{{if $idx}}, {{end}}{{ $host }}{{end}}</td>" +
"</tr>\n"
out, err := template.New("blip").Parse(tmpl)
if err != nil {
return "", err
}
w := new(bytes.Buffer)
for _, result := range results {
sort.Strings(result.ConnectedHosts)
err := out.Execute(w, result)
if err != nil {
return "", err
}
}
return w.String(), nil
}