-
Notifications
You must be signed in to change notification settings - Fork 0
/
report-explodedDns.go
54 lines (43 loc) · 1.12 KB
/
report-explodedDns.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
package reporting
import (
"bytes"
"html/template"
"os"
"github.com/activecm/rita/datatypes/dns"
"github.com/activecm/rita/reporting/templates"
"github.com/activecm/rita/resources"
)
func printDNS(db string, res *resources.Resources) error {
f, err := os.Create("dns.html")
if err != nil {
return err
}
defer f.Close()
var results []dns.ExplodedDNS
iter := res.DB.Session.DB(db).C(res.Config.T.DNS.ExplodedDNSTable).Find(nil)
iter.Sort("-subdomains").Limit(1000).All(&results)
out, err := template.New("dns.html").Parse(templates.DNStempl)
if err != nil {
return err
}
w, err := getDNSWriter(results)
if err != nil {
return err
}
return out.Execute(f, &templates.ReportingInfo{DB: db, Writer: template.HTML(w)})
}
func getDNSWriter(results []dns.ExplodedDNS) (string, error) {
tmpl := "<tr><td>{{.Subdomains}}</td><td>{{.Visited}}</td><td>{{.Domain}}</td></tr>\n"
out, err := template.New("dns").Parse(tmpl)
if err != nil {
return "", err
}
w := new(bytes.Buffer)
for _, result := range results {
err := out.Execute(w, result)
if err != nil {
return "", err
}
}
return w.String(), nil
}