-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.go
More file actions
70 lines (56 loc) · 1.51 KB
/
command.go
File metadata and controls
70 lines (56 loc) · 1.51 KB
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"
"fmt"
"time"
)
type Command struct {
Index int
Name string `mapstructure:"name"`
Command string `mapstructure:"command"`
Vars map[string]interface{} `mapstructure:"vars"`
Directory string `mapstructure:"directory"`
Type string `mapstructure:"type"` // shell or pcap, default is pcap
Timeout time.Duration `mapstructure:"timeout"`
FinderId string `mapstructure:"finder"` // if not provide, use Job's
job *Job
finder *Finder
}
func (c *Command) String() string {
if c.Name != "" {
return fmt.Sprintf("%s [Command %s]", c.job, c.Name)
}
return fmt.Sprintf("%s [Command at index %d]", c.job, c.Index)
}
func (c *Command) check() error {
if c.Name == "" {
return errors.New("must have a human readable name")
}
if c.Command == "" {
return errors.New("command can not be empty")
}
if c.Type == "" {
c.Type = "pcap"
}
if c.Type != "shell" && c.Type != "pcap" {
return errors.New(fmt.Sprintf("unsupported command type: %s, currently only pcap and shell support", c.Type))
}
if c.FinderId == "" {
c.FinderId = c.job.FinderId
c.finder = c.job.finder
} else {
finder, ok := finders[c.FinderId]
if !ok {
return errors.New(fmt.Sprintf("unknown finder id: %s", c.FinderId))
}
c.finder = finder
}
if c.job.Enable {
c.finder.modifier.Used = true
c.finder.Used = true
}
if c.Timeout == 0 {
c.Timeout = config.CommandTimeout
}
return nil
}