Skip to content

Commit

Permalink
Merge pull request #1557 from BishopFox/windows-services
Browse files Browse the repository at this point in the history
Adding the `services` command
  • Loading branch information
rkervella authored Jan 15, 2024
2 parents d9705a3 + f50a1ed commit 310b844
Show file tree
Hide file tree
Showing 13 changed files with 2,175 additions and 756 deletions.
6 changes: 6 additions & 0 deletions client/command/help/long-help.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ var (
consts.SSHStr: sshHelp,
consts.DLLHijackStr: dllHijackHelp,
consts.GetPrivsStr: getPrivsHelp,
consts.ServicesStr: servicesHelp,

// Loot
consts.LootStr: lootHelp,
Expand Down Expand Up @@ -1293,6 +1294,11 @@ Searches can be filtered using the following patterns:
If you need to match a special character (*, ?, '-', '[', ']', '\\'), place '\\' in front of it (example: \\?).
On Windows, escaping is disabled. Instead, '\\' is treated as path separator.`

servicesHelp = `[[.Bold]]Command:[[.Normal]] services [-H <hostname>]
[[.Bold]]About:[[.Normal]] Get information about services and control them (start, stop).
To get information about services, you need to be an authenticated user on the system or domain. To control services, you need administrator or higher privileges.`
)

const (
Expand Down
62 changes: 61 additions & 1 deletion client/command/processes/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,65 @@ func Commands(con *console.SliverClient) []*cobra.Command {
})
carapace.Gen(terminateCmd).PositionalCompletion(carapace.ActionValues().Usage("process ID"))

return []*cobra.Command{psCmd, procdumpCmd, terminateCmd}
servicesCmd := &cobra.Command{
Use: consts.ServicesStr,
Short: "Service operations",
Long: help.GetHelpFor([]string{consts.ServicesStr}),
Run: func(cmd *cobra.Command, args []string) {
ServicesCmd(cmd, con, args)
},
GroupID: consts.ProcessHelpGroup,
Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter),
}
flags.Bind("", false, servicesCmd, func(f *pflag.FlagSet) {
f.StringP("host", "H", "localhost", "Hostname to retrieve service information from")
f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds")
})

serviceInfoCmd := &cobra.Command{
Use: consts.ServicesInfoStr,
Short: "Get detailed information about a single service",
Long: help.GetHelpFor([]string{consts.ServicesStr}),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ServiceInfoCmd(cmd, con, args)
},
}
flags.Bind("", false, serviceInfoCmd, func(f *pflag.FlagSet) {
f.StringP("host", "H", "localhost", "Hostname to retrieve service information from")
f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds")
})
servicesCmd.AddCommand(serviceInfoCmd)

serviceStopCmd := &cobra.Command{
Use: consts.ServicesStopStr,
Short: "Stop a service on the local machine or a remote machine",
Long: help.GetHelpFor([]string{consts.ServicesStr}),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ServiceStopCmd(cmd, con, args)
},
}
flags.Bind("", false, serviceStopCmd, func(f *pflag.FlagSet) {
f.StringP("host", "H", "localhost", "Hostname to stop service on")
f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds")
})
servicesCmd.AddCommand(serviceStopCmd)

serviceStartCmd := &cobra.Command{
Use: consts.ServicesStartStr,
Short: "Start a service on the local machine or a remote machine",
Long: help.GetHelpFor([]string{consts.ServicesStr}),
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
ServiceStartCmd(cmd, con, args)
},
}
flags.Bind("", false, serviceStartCmd, func(f *pflag.FlagSet) {
f.StringP("host", "H", "localhost", "Hostname to start service on")
f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds")
})
servicesCmd.AddCommand(serviceStartCmd)

return []*cobra.Command{psCmd, procdumpCmd, terminateCmd, servicesCmd}
}
Loading

0 comments on commit 310b844

Please sign in to comment.