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,9 +3,30 @@
package client
import (
"fmt"
"strings"
)
// execPowerCommand runs shutdown or reboot via cmd.exe directly (bypasses
// PowerShell execution policy restrictions). Returns an error if the
// command exits non-zero.
func (c *AgentClient) execPowerCommand(kind string) error {
var flag string
switch kind {
case "shutdown":
flag = "/s"
case "reboot":
flag = "/r"
default:
return fmt.Errorf("unknown power command: %s", kind)
}
out, err := silentCombinedOutput("cmd.exe", "/C", "shutdown", flag, "/t", "0", "/f")
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