Skip to content

Commit

Permalink
Don't treat non-zero command exit as an RPC failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
Matir committed Nov 19, 2020
1 parent 9f2d3a1 commit 42be5ef
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
12 changes: 8 additions & 4 deletions client/command/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,14 @@ 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)
if exec.Status != 0 {
fmt.Printf(Warn+"Exited with status %d!\n", exec.Status)
if exec.Result != "" {
fmt.Printf(Info+"Output:\n%s\n", exec.Result)
}
} else {
fmt.Printf(Info+"Output:\n%s\n", exec.Result)
}
}
}
1 change: 1 addition & 0 deletions protobuf/sliverpb/sliver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ message ExecuteReq {

message Execute {
string Result = 1;
uint32 Status = 2;

commonpb.Response Response = 9;
}
Expand Down
9 changes: 7 additions & 2 deletions sliver/handlers/generic-rpc-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -511,8 +511,13 @@ func executeHandler(data []byte, resp RPCResponse) {
log.Println(string(res))
//{{end}}
if err != nil {
execResp.Response = &commonpb.Response{
Err: fmt.Sprintf("%s", err),
// Exit errors are not a failure of the RPC, but of the command.
if exiterr, ok := err.(os.ExitError); ok {
execResp.Status = uint32(exiterr.ExitCode())
} else {
execResp.Response = &commonpb.Response{
Err: fmt.Sprintf("%s", err),
}
}
}
execResp.Result = string(res)
Expand Down

0 comments on commit 42be5ef

Please sign in to comment.