Skip to content

Commit

Permalink
Fix #1003
Browse files Browse the repository at this point in the history
  • Loading branch information
rkervella committed Nov 16, 2022
1 parent c7e77c8 commit 702c237
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
21 changes: 20 additions & 1 deletion implant/sliver/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}
11 changes: 10 additions & 1 deletion implant/sliver/handlers/handlers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down

0 comments on commit 702c237

Please sign in to comment.