MCPcopy Create free account
hub / github.com/evilsocket/shellz / Load

Function Load

models/storage.go:15–63  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13type Groups map[string]Shells
14
15func Load() (error, Identities, Shells, Groups) {
16 idents := make(Identities)
17 shells := make(Shells)
18 groups := make(Groups)
19
20 log.Debug("loading identities from %s ...", Paths["idents"])
21 err := fs.Glob(Paths["idents"], "*.json", func(fileName string) error {
22 if err, ident := LoadIdent(fileName); err != nil {
23 return fmt.Errorf("error while loading identity '%s': %s", fileName, err)
24 } else if taken, found := idents[ident.Name]; found {
25 return fmt.Errorf("identity '%s' has name %s which is already taken by '%s'", fileName, ident.Name, taken.Path)
26 } else {
27 idents[ident.Name] = ident
28 }
29 return nil
30 })
31 if err != nil {
32 return err, nil, nil, nil
33 }
34
35 log.Debug("loading shells from %s ...", Paths["shells"])
36 err = fs.Glob(Paths["shells"], "*.json", func(fileName string) error {
37 if err, shell := LoadShell(fileName, idents); err != nil {
38 return fmt.Errorf("error while loading shell '%s': %s", fileName, err)
39 } else if taken, found := shells[shell.Name]; found {
40 return fmt.Errorf("shell '%s' has name %s which is already taken by '%s'", fileName, shell.Name, taken.Path)
41 } else {
42 shells[shell.Name] = shell
43 }
44 return nil
45 })
46 if err != nil {
47 return err, nil, nil, nil
48 }
49
50 log.Debug("creating groups ...")
51 for _, sh := range shells {
52 for _, group := range append(sh.Groups, "all") {
53 ref, found := groups[group]
54 if found == false {
55 ref = make(Shells)
56 groups[group] = ref
57 }
58 ref[sh.Name] = sh
59 }
60 }
61
62 return nil, idents, shells, groups
63}

Callers 1

mainFunction · 0.92

Calls 3

LoadIdentFunction · 0.85
LoadShellFunction · 0.85
DebugMethod · 0.80

Tested by

no test coverage detected