-
Notifications
You must be signed in to change notification settings - Fork 225
/
Copy pathutil.go
70 lines (63 loc) · 1.87 KB
/
util.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
package main
import (
"errors"
"github.com/datadog/stratus-red-team/v2/pkg/stratus"
"github.com/jedib0t/go-pretty/v6/table"
"log"
"os"
"strings"
)
func GetDisplayTable() table.Writer {
t := table.NewWriter()
t.SetStyle(table.StyleDefault)
t.SetOutputMirror(os.Stdout)
return t
}
func resolveTechniques(names []string) ([]*stratus.AttackTechnique, error) {
var result []*stratus.AttackTechnique
for i := range names {
technique := stratus.GetRegistry().GetAttackTechniqueByName(names[i])
if technique == nil {
return nil, errors.New("unknown technique name " + names[i])
}
result = append(result, technique)
}
return result, nil
}
func handleErrorsChannel(errors <-chan error, jobsCount int) bool {
hasError := false
for i := 0; i < jobsCount; i++ {
err := <-errors
if err != nil {
log.Println(err)
hasError = true
}
}
return hasError
}
// VerifyPlatformRequirements ensures that the user is properly authenticated against all platforms
// of a list of attack techniques
func VerifyPlatformRequirements(attackTechniques []*stratus.AttackTechnique) {
platforms := map[stratus.Platform]bool{}
for i := range attackTechniques {
currentPlatform := attackTechniques[i].Platform
if _, checked := platforms[currentPlatform]; !checked {
log.Println("Checking your authentication against " + string(currentPlatform))
err := stratus.EnsureAuthenticated(currentPlatform)
if err != nil {
log.Fatalf(err.Error())
}
platforms[currentPlatform] = true
}
}
}
func getTechniquesCompletion(completionPrefix string) []string {
attackTechniques := stratus.GetRegistry().GetAttackTechniques(&stratus.AttackTechniqueFilter{})
var matchingTechniques []string
for _, technique := range attackTechniques {
if strings.HasPrefix(technique.ID, completionPrefix) {
matchingTechniques = append(matchingTechniques, technique.ID)
}
}
return matchingTechniques
}