-
Notifications
You must be signed in to change notification settings - Fork 196
/
registry.go
81 lines (63 loc) · 1.58 KB
/
registry.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
package stratus
import (
"github.com/datadog/stratus-red-team/pkg/stratus/mitreattack"
)
var registry Registry
func init() {
registry = NewRegistry()
}
func GetRegistry() *Registry {
return ®istry
}
type Registry struct {
techniques []*AttackTechnique
}
func NewRegistry() Registry {
return Registry{techniques: []*AttackTechnique{}}
}
func (m *Registry) RegisterAttackTechnique(technique *AttackTechnique) {
m.techniques = append(m.techniques, technique)
}
func (m *Registry) GetAttackTechniqueByName(name string) *AttackTechnique {
for i := range m.techniques {
if m.techniques[i].ID == name {
return m.techniques[i]
}
}
return nil
}
func (m *Registry) GetAttackTechniques(filter *AttackTechniqueFilter) []*AttackTechnique {
var ret = []*AttackTechnique{}
for i := range m.techniques {
technique := m.techniques[i]
if filter.matches(technique) {
ret = append(ret, technique)
}
}
return ret
}
func (m *Registry) ListAttackTechniques() []*AttackTechnique {
return m.techniques
}
type AttackTechniqueFilter struct {
Platform Platform
Tactic mitreattack.Tactic
}
func (m *AttackTechniqueFilter) matches(technique *AttackTechnique) bool {
var platformMatches = false
var mitreAttackTacticMatches = false
if m.Platform == "" || technique.Platform == m.Platform {
platformMatches = true
}
if m.Tactic == 0 {
mitreAttackTacticMatches = true
} else {
for i := range technique.MitreAttackTactics {
if technique.MitreAttackTactics[i] == m.Tactic {
mitreAttackTacticMatches = true
break
}
}
}
return platformMatches && mitreAttackTacticMatches
}