diff --git a/implant/sliver/handlers/handlers.go b/implant/sliver/handlers/handlers.go index 8478501a76..07dbd1902f 100644 --- a/implant/sliver/handlers/handlers.go +++ b/implant/sliver/handlers/handlers.go @@ -530,7 +530,16 @@ func executeHandler(data []byte, resp RPCResponse) { } execResp := &sliverpb.Execute{} - cmd := exec.Command(execReq.Path, execReq.Args...) + exePath, err := expandPath(execReq.Path) + if err != nil { + execResp.Response = &commonpb.Response{ + Err: fmt.Sprintf("%s", err), + } + proto.Marshal(execResp) + resp(data, err) + return + } + cmd := exec.Command(exePath, execReq.Args...) if execReq.Output { stdOutBuff := new(bytes.Buffer) @@ -929,3 +938,13 @@ func compressDir(path string, filter string, recurse bool, buf io.Writer) (int, } return readFiles, unreadableFiles, nil } + +func expandPath(exePath string) (string, error) { + if !strings.ContainsRune(exePath, os.PathSeparator) { + _, err := exec.LookPath(exePath) + if err != nil { + return filepath.Abs(exePath) + } + } + return exePath, nil +} diff --git a/implant/sliver/handlers/handlers_windows.go b/implant/sliver/handlers/handlers_windows.go index 3b6c4f818f..41af45c334 100644 --- a/implant/sliver/handlers/handlers_windows.go +++ b/implant/sliver/handlers/handlers_windows.go @@ -303,7 +303,16 @@ func executeWindowsHandler(data []byte, resp RPCResponse) { } execResp := &sliverpb.Execute{} - cmd := exec.Command(execReq.Path, execReq.Args...) + exePath, err := expandPath(execReq.Path) + if err != nil { + execResp.Response = &commonpb.Response{ + Err: fmt.Sprintf("%s", err), + } + proto.Marshal(execResp) + resp(data, err) + return + } + cmd := exec.Command(exePath, execReq.Args...) // Execute with current token cmd.SysProcAttr = &syscall.SysProcAttr{}