-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.go
144 lines (129 loc) · 3.42 KB
/
template.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
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
142
143
144
package main
import (
"log"
"os"
"text/template"
"gopkg.in/yaml.v3"
)
// generated from https://zhwt.github.io/yaml-to-go/
type T struct {
Tactics []struct {
Description string `yaml:"description"`
Id string `yaml:"id"`
Name string `yaml:"name"`
ObjectType string `yaml:"object-type"`
} `yaml:"tactics"`
Techniques []struct {
AccessRequired string `yaml:"access-required"`
ArchitectureSegment string `yaml:"architecture-segment"`
Bluf string `yaml:"bluf"`
Criticalassets []struct {
Description string `yaml:"Description"`
Name string `yaml:"Name"`
} `yaml:"criticalassets"`
Description string `yaml:"description"`
Detections []struct {
Detects string `yaml:"detects"`
Fgdsid string `yaml:"fgdsid"`
Name string `yaml:"name"`
} `yaml:"detections"`
ID string `yaml:"id"`
Mitigations []struct {
Fgmid string `yaml:"fgmid"`
Mitigates string `yaml:"mitigates"`
Name string `yaml:"name"`
} `yaml:"mitigations"`
Name string `yaml:"name"`
ObjectType string `yaml:"object-type"`
Platforms string `yaml:"platforms"`
Preconditions []struct {
Description string `yaml:"Description"`
Name string `yaml:"Name"`
} `yaml:"preconditions"`
Procedureexamples []struct {
Description string `yaml:"Description"`
Name string `yaml:"Name"`
} `yaml:"procedureexamples"`
References []string `yaml:"references"`
Status string `yaml:"status"`
SubtechniqueOf string `yaml:"subtechnique-of"`
Tactics []string `yaml:"tactics"`
Typecode string `yaml:"typecode"`
} `yaml:"techniques"`
}
type A struct {
Techniques map[string]string
}
func (t *T) parseFightYaml() *T {
yamlFile, err := os.ReadFile("fight.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, t)
if err != nil {
log.Fatalf("error: %v", err)
}
/*
for _, technique := range t.Techniques {
fmt.Printf("%s\n", technique.Name)
}
*/
return t
}
func (a *A) parseAccuknoxYaml() *A {
yamlFile, err := os.ReadFile("accuknox_support.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
err = yaml.Unmarshal(yamlFile, a)
if err != nil {
log.Fatalf("error: %v", err)
}
/*
for tactic, support := range a.Techniques {
fmt.Printf("%s: %s\n", tactic, support)
}
*/
return a
}
func (t displayT) generateAllTacticsPage(out *os.File) error {
tacticList := template.Must(template.New("tacticList").Parse(`
<h1>Tactics List <h1>
<table>
<th style='text-align: left'>
{{range .Tactics}}
<th><a href="https://5GSEC.github.io/tactic-{{.Id}}.html">{{.Name}}</a></th>
{{end}}
</th>
</table>
`))
if err := tacticList.Execute(out, t); err != nil {
return err
}
return nil
}
func (t Tactic) generateTechniquesPerTacticPage(out *os.File) error {
techniqueList := template.Must(template.New("techniqueList").Parse(`
<h1>Tactic:<a href="https://fight.mitre.org/tactics/{{.Id}}">{{.Name}}</a></h1>
<table>
<tr style='text-align: left'>
<td>Technique Name</td>
<td>Accuknox Support</td>
</th>
{{range .Techniques}}
<tr>
<td><a href="https://fight.mitre.org/techniques/{{.Id}}">{{.Name}}</a></td>
<td>
{{if eq .Support "yes"}}🟢
{{else if eq .Support "no"}}🔴
{{end}}
</td>
</tr>
{{end}}
</table>
`))
if err := techniqueList.Execute(out, t); err != nil {
return err
}
return nil
}