forked from gaulliath/operative-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system.go
72 lines (60 loc) · 1.4 KB
/
system.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
package system
import (
"os"
"os/exec"
"github.com/Oni-kuki/operative-framework/session"
)
type SystemModule struct {
session.SessionModule
sess *session.Session `json:"-"`
Stream *session.Stream `json:"-"`
}
func PushSystemModuleModule(s *session.Session) *SystemModule {
mod := SystemModule{
sess: s,
Stream: &s.Stream,
}
mod.CreateNewParam("cmd", "Command to exec e.g: ls -l", "", true, session.STRING)
return &mod
}
func (module *SystemModule) Name() string {
return "sh"
}
func (module *SystemModule) Description() string {
return "Execute system command"
}
func (module *SystemModule) Author() string {
return "Tristan Granier"
}
func (module *SystemModule) GetType() []string {
return []string{
session.T_TARGET_COMMAND,
}
}
func (module *SystemModule) GetInformation() session.ModuleInformation {
information := session.ModuleInformation{
Name: module.Name(),
Description: module.Description(),
Author: module.Author(),
Type: module.GetType(),
Parameters: module.Parameters,
}
return information
}
func (module *SystemModule) Start() {
command, err := module.GetParameter("CMD")
if err != nil {
module.sess.Stream.Error(err.Error())
return
}
cmd := exec.Command(command.Value)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
err = cmd.Run()
if err != nil {
module.sess.Stream.Error(err.Error())
return
}
return
}