Fix command delivery: close dead sockets on write error, use cmd.exe for power commands

This commit is contained in:
AetherForge
2026-06-02 22:29:42 -07:00
parent ed4d22ce32
commit b18007f563
4 changed files with 76 additions and 8 deletions

View File

@@ -3,10 +3,29 @@
package client
import (
"fmt"
"os/exec"
"strings"
)
// execPowerCommand runs shutdown or reboot on Unix/Linux/macOS.
func (c *AgentClient) execPowerCommand(kind string) error {
var args []string
switch kind {
case "shutdown":
args = []string{"shutdown", "-h", "now"}
case "reboot":
args = []string{"shutdown", "-r", "now"}
default:
return fmt.Errorf("unknown power command: %s", kind)
}
out, err := exec.Command(args[0], args[1:]...).CombinedOutput()
if err != nil {
return fmt.Errorf("%w: %s", err, strings.TrimSpace(string(out)))
}
return nil
}
func (c *AgentClient) platformRecon(action, command string) (handled bool, success bool, message string) {
var out []byte
var err error