improve recovery cmd

This commit is contained in:
wh1te909 2020-11-19 15:09:17 -08:00
parent f58e5cfdc9
commit 8b37fe2f10
2 changed files with 10 additions and 4 deletions

View File

@ -557,9 +557,15 @@ func (a *WindowsAgent) RecoverMesh() {
//RecoverCMD runs a shell recovery command //RecoverCMD runs a shell recovery command
func (a *WindowsAgent) RecoverCMD(command string) { func (a *WindowsAgent) RecoverCMD(command string) {
a.Logger.Debugln("Attempting shell recovery on", a.Hostname) a.Logger.Infoln("Attempting shell recovery with command:", command)
a.Logger.Debugln(command) // call the command with cmd /C so that the parent process is cmd
_, _ = CMDShell("cmd", []string{}, command, 18000, true) // and not tacticalrmm.exe so that we don't kill ourself
cmd := exec.Command("cmd.exe")
cmd.SysProcAttr = &windows.SysProcAttr{
CreationFlags: windows.DETACHED_PROCESS | windows.CREATE_NEW_PROCESS_GROUP,
CmdLine: fmt.Sprintf("cmd.exe /C %s", command), // properly escape in case double quotes are in the command
}
cmd.Start()
} }
func (a *WindowsAgent) LocalSaltCall(saltfunc string, args []string, timeout int) ([]byte, error) { func (a *WindowsAgent) LocalSaltCall(saltfunc string, args []string, timeout int) ([]byte, error) {

View File

@ -113,7 +113,7 @@ func (a *WindowsAgent) WinAgentSvc() {
go a.RecoverMesh() go a.RecoverMesh()
case "command": case "command":
if cmd, ok := data["cmd"].(string); ok { if cmd, ok := data["cmd"].(string); ok {
go a.RecoverCMD(cmd) a.RecoverCMD(cmd)
} }
} }
} }