forked from owasp-amass/amass
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdot.go
81 lines (68 loc) · 1.7 KB
/
dot.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// Copyright 2017 Jeff Foley. All rights reserved.
// Use of this source code is governed by Apache 2 LICENSE that can be found in the LICENSE file.
package viz
import (
"io"
"strconv"
"text/template"
)
const dotTemplate = `
digraph "{{ .Name }}" {
size = "7.5,10"; ranksep="2.5 equally"; ratio=auto;
{{ range .Nodes }}
node [label="{{ .Label }}",color="{{ .Color }}",type="{{ .Type }}",source="{{ .Source }}"]; n{{ .ID }};
{{ end }}
{{ range .Edges }}
n{{ .Source }} -> n{{ .Destination }} [label="{{ .Label }}"];
{{ end }}
}
`
type dotEdge struct {
Source string
Destination string
Label string
}
type dotNode struct {
ID string
Label string
Color string
Type string
Source string
}
type dotGraph struct {
Name string
Nodes []dotNode
Edges []dotEdge
}
// WriteDOTData generates a DOT file to display the Amass graph.
func WriteDOTData(output io.Writer, nodes []Node, edges []Edge) {
colors := map[string]string{
"subdomain": "green",
"domain": "red",
"address": "orange",
"ptr": "yellow",
"ns": "cyan",
"mx": "purple",
"netblock": "pink",
"as": "blue",
}
graph := &dotGraph{Name: "OWASP Amass Network Mapping"}
for idx, node := range nodes {
graph.Nodes = append(graph.Nodes, dotNode{
ID: strconv.Itoa(idx + 1),
Label: node.Label,
Color: colors[node.Type],
Type: node.Type,
Source: node.Source,
})
}
for _, edge := range edges {
graph.Edges = append(graph.Edges, dotEdge{
Source: strconv.Itoa(edge.From + 1),
Destination: strconv.Itoa(edge.To + 1),
Label: edge.Title,
})
}
t := template.Must(template.New("graph").Parse(dotTemplate))
t.Execute(output, graph)
}