-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile.go
67 lines (56 loc) · 1.38 KB
/
file.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
package plugins
import (
"bytes"
"flag"
"fmt"
"github.com/RyanJarv/liquidswards/lib/types"
"github.com/RyanJarv/liquidswards/lib/utils"
"github.com/alitto/pond"
"os"
"strings"
"sync"
)
var file = flag.String("file", "", "A file containing a list of additional file to enumerate.")
type NewFilePluginInput struct {
types.GlobalPluginArgs
}
func NewFile(_ utils.Context, in types.GlobalPluginArgs) types.Plugin {
return &FilePlugin{
GlobalPluginArgs: in,
m: &sync.RWMutex{},
covered: map[string]bool{},
}
}
func (a *FilePlugin) Name() string {
return "file"
}
func (a *FilePlugin) Enabled() (bool, string) {
if *file == "" {
return false, "no -file arg provided"
} else {
return true, fmt.Sprintf("will read from %s", *file)
}
}
type FilePlugin struct {
types.GlobalPluginArgs
FileLocation string
Pool *pond.WorkerPool
m *sync.RWMutex
covered map[string]bool
}
func (f *FilePlugin) Run(ctx utils.Context) {
file, err := os.ReadFile(f.FileLocation)
if err != nil {
ctx.Error.Printf("error reading %s: %s", f.FileLocation, err)
}
file = bytes.Trim(file, " \t\n")
for _, line := range strings.Split(string(file), "\n") {
arn := strings.Trim(line, " \t")
if f.Scope != nil && !utils.ArnInScope(f.Scope, arn) {
continue
}
if f.FoundRoles.Add(types.NewRole(arn)) {
fmt.Printf("File: Found role %s\n", arn)
}
}
}