Execute powershell commands in case of Windows host
This commit is contained in:
parent
d796db3366
commit
d335d9c20c
12
main.go
12
main.go
|
@ -155,8 +155,18 @@ func Heartbeat(conn net.Conn) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func executeCommand(conn net.Conn, command string) {
|
func executeCommand(conn net.Conn, command string) {
|
||||||
|
var out []byte
|
||||||
|
var err error
|
||||||
|
|
||||||
formattedCommand := strings.Fields(command)
|
formattedCommand := strings.Fields(command)
|
||||||
out, err := exec.Command(formattedCommand[0], formattedCommand[1:]...).Output()
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
t := []string{"-NoProfile"}
|
||||||
|
t = append(t, formattedCommand...)
|
||||||
|
out, err = exec.Command("powershell", t...).Output()
|
||||||
|
case "linux":
|
||||||
|
out, err = exec.Command(formattedCommand[0], formattedCommand[1:]...).Output()
|
||||||
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errorMsg := fmt.Sprintf("%v\n", err)
|
errorMsg := fmt.Sprintf("%v\n", err)
|
||||||
resp := Response{Successful: false, Message: errorMsg}
|
resp := Response{Successful: false, Message: errorMsg}
|
||||||
|
|
Loading…
Reference in New Issue