From 44ceccff12123e5e8afe832cd80c78facba4066a Mon Sep 17 00:00:00 2001 From: maxlandon Date: Wed, 7 Jun 2023 21:44:01 +0200 Subject: [PATCH 01/14] Fix some newlines printed or not --- client/command/generate/implants.go | 2 +- client/console/console.go | 3 +-- client/console/log.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/client/command/generate/implants.go b/client/command/generate/implants.go index 3cdc0afc5a..5553188b0a 100644 --- a/client/command/generate/implants.go +++ b/client/command/generate/implants.go @@ -120,7 +120,7 @@ func PrintImplantBuilds(configs map[string]*clientpb.ImplantConfig, filters Impl } con.Println(tw.Render()) - con.Println() + con.Println("\n") } // ImplantBuildNameCompleter - Completer for implant build names diff --git a/client/console/console.go b/client/console/console.go index 02f4923f31..fde4a37587 100644 --- a/client/console/console.go +++ b/client/console/console.go @@ -408,7 +408,7 @@ func (con *SliverConsoleClient) triggerBeaconTaskCallback(data []byte) { if callback, ok := con.BeaconTaskCallbacks[task.ID]; ok { if con.Settings.BeaconAutoResults { if beacon != nil { - con.PrintEventSuccessf("%s completed task %s", beacon.Name, strings.Split(task.ID, "-")[0]) + con.PrintSuccessf("%s completed task %s", beacon.Name, strings.Split(task.ID, "-")[0]) } task_content, err := con.Rpc.GetBeaconTaskContent(ctx, &clientpb.BeaconTask{ ID: task.ID, @@ -419,7 +419,6 @@ func (con *SliverConsoleClient) triggerBeaconTaskCallback(data []byte) { } else { con.PrintErrorf("Could not get beacon task content: %s", err) } - con.Println() } delete(con.BeaconTaskCallbacks, task.ID) } diff --git a/client/console/log.go b/client/console/log.go index 71807efac0..cb2d0d35c3 100644 --- a/client/console/log.go +++ b/client/console/log.go @@ -148,7 +148,7 @@ func (con *SliverConsoleClient) PrintAsyncResponse(resp *commonpb.Response) { con.PrintWarnf(err.Error()) return } - con.PrintInfof("Tasked beacon %s (%s)", beacon.Name, strings.Split(resp.TaskID, "-")[0]) + con.PrintInfof("Tasked beacon %s (%s)\n", beacon.Name, strings.Split(resp.TaskID, "-")[0]) } func (con *SliverConsoleClient) Printf(format string, args ...any) { From bce0c8de0617032885a5781bccee6e9459af2fbd Mon Sep 17 00:00:00 2001 From: maxlandon Date: Wed, 7 Jun 2023 22:24:19 +0200 Subject: [PATCH 02/14] Add a flags package, in which we store some command utility functions to bind flags, completions, apply command filters, etc. --- client/command/flags/flags.go | 71 +++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 client/command/flags/flags.go diff --git a/client/command/flags/flags.go b/client/command/flags/flags.go new file mode 100644 index 0000000000..7f55a0784d --- /dev/null +++ b/client/command/flags/flags.go @@ -0,0 +1,71 @@ +package flags + +import ( + "strings" + + "github.com/reeflective/console" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" +) + +// Bind is a convenience function to bind flags to a command, through newly created +// pflag.Flagset type. This function can be called any number of times for any command. +// desc - An optional name for the flag set (can be empty, but might end up useful). +// persistent - If true, the flags bound will apply to all subcommands of this command. +// cmd - The pointer to the command the flags should be bound to. +// flags - A function using this flag set as parameter, for you to register flags. +func Bind(desc string, persistent bool, cmd *cobra.Command, flags func(f *pflag.FlagSet)) { + flagSet := pflag.NewFlagSet(desc, pflag.ContinueOnError) + flags(flagSet) + + if persistent { + cmd.PersistentFlags().AddFlagSet(flagSet) + } else { + cmd.Flags().AddFlagSet(flagSet) + } +} + +// RestrictTargets generates a cobra annotation map with a single console.CommandHiddenFilter key +// to a comma-separated list of filters to use in order to expose/hide commands based on requirements. +// Ex: cmd.Annotations = RestrictTargets("windows") will only show the command if the target is Windows. +// Ex: cmd.Annotations = RestrictTargets("windows", "beacon") show the command if target is a beacon on Windows. +func RestrictTargets(filters ...string) map[string]string { + if len(filters) == 0 { + return nil + } + + if len(filters) == 1 { + return map[string]string{ + console.CommandFilterKey: filters[0], + } + } + + filts := strings.Join(filters, ",") + + return map[string]string{ + console.CommandFilterKey: filts, + } +} + +// NewCompletions registers the command to the application completion engine and returns +// you a type through which you can register all sorts of completions for this command, +// from flag arguments, positional ones, per index or remaining, etc. +// +// See https://rsteube.github.io/carapace/ for a complete documentation of carapace completions. +func NewCompletions(cmd *cobra.Command) *carapace.Carapace { + return carapace.Gen(cmd) +} + +// BindFlagCompletions is a convenience function for binding completers to flags requiring arguments. +// (It wraps a few steps to be used through the *carapace.Carapace type so you don't have to bother). +// cmd - The target command/subcommand which flags to be completed. +// bind - A function using a map "flag-name":carapace.Action for you to bind completions to the flag. +// +// See https://rsteube.github.io/carapace/ for a complete documentation of carapace completions. +func BindFlagCompletions(cmd *cobra.Command, bind func(comp *carapace.ActionMap)) { + comps := make(carapace.ActionMap) + bind(&comps) + + carapace.Gen(cmd).FlagCompletion(comps) +} From ec88f9bd02eda7d9348d7fe1b47e01bb3ad5330e Mon Sep 17 00:00:00 2001 From: maxlandon Date: Wed, 7 Jun 2023 23:00:29 +0200 Subject: [PATCH 03/14] Start splitting commands declarations --- client/cli/implant.go | 2 +- client/command/alias/commands.go | 62 ++++++++++ client/command/armory/commands.go | 69 +++++++++++ client/command/exit/exit.go | 13 +++ client/command/flags/flags.go | 4 + client/command/jobs/commands.go | 169 +++++++++++++++++++++++++++ client/command/operators/commands.go | 29 +++++ client/command/update/commands.go | 46 ++++++++ server/console/console.go | 8 +- 9 files changed, 397 insertions(+), 5 deletions(-) create mode 100644 client/command/alias/commands.go create mode 100644 client/command/armory/commands.go create mode 100644 client/command/jobs/commands.go create mode 100644 client/command/operators/commands.go create mode 100644 client/command/update/commands.go diff --git a/client/cli/implant.go b/client/cli/implant.go index 5c1251f79c..1f24db8ba8 100644 --- a/client/cli/implant.go +++ b/client/cli/implant.go @@ -67,7 +67,7 @@ func makeCompleters(cmd *cobra.Command, con *console.SliverConsoleClient) { }) // Bind completers to flags (wrap them to use the same pre-runners) - command.FlagComps(cmd, func(comp *carapace.ActionMap) { + command.BindFlagCompletions(cmd, func(comp *carapace.ActionMap) { (*comp)["use"] = carapace.ActionCallback(func(c carapace.Context) carapace.Action { cmd.PersistentPreRunE(cmd, c.Args) return use.SessionIDCompleter(con) diff --git a/client/command/alias/commands.go b/client/command/alias/commands.go new file mode 100644 index 0000000000..5b7bff8727 --- /dev/null +++ b/client/command/alias/commands.go @@ -0,0 +1,62 @@ +package alias + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the `alias` command and its child commands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + aliasCmd := &cobra.Command{ + Use: consts.AliasesStr, + Short: "List current aliases", + Long: help.GetHelpFor([]string{consts.AliasesStr}), + Run: func(cmd *cobra.Command, args []string) { + AliasesCmd(cmd, con, args) + }, + GroupID: consts.GenericHelpGroup, + } + + aliasLoadCmd := &cobra.Command{ + Use: consts.LoadStr + " [ALIAS]", + Short: "Load a command alias", + Long: help.GetHelpFor([]string{consts.AliasesStr, consts.LoadStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + AliasesLoadCmd(cmd, con, args) + }, + } + aliasCmd.AddCommand(aliasLoadCmd) + flags.NewCompletions(aliasLoadCmd).PositionalCompletion(carapace.ActionDirectories().Tag("alias directory").Usage("path to the alias directory")) + + aliasInstallCmd := &cobra.Command{ + Use: consts.InstallStr + " [ALIAS]", + Short: "Install a command alias", + Long: help.GetHelpFor([]string{consts.AliasesStr, consts.InstallStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + AliasesInstallCmd(cmd, con, args) + }, + } + aliasCmd.AddCommand(aliasInstallCmd) + flags.NewCompletions(aliasInstallCmd).PositionalCompletion(carapace.ActionFiles().Tag("alias file")) + + aliasRemove := &cobra.Command{ + Use: consts.RmStr + " [ALIAS]", + Short: "Remove an alias", + Long: help.GetHelpFor([]string{consts.RmStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + AliasesRemoveCmd(cmd, con, args) + }, + } + flags.NewCompletions(aliasRemove).PositionalCompletion(AliasCompleter()) + aliasCmd.AddCommand(aliasRemove) + + return []*cobra.Command{aliasCmd} +} diff --git a/client/command/armory/commands.go b/client/command/armory/commands.go new file mode 100644 index 0000000000..27e41c8735 --- /dev/null +++ b/client/command/armory/commands.go @@ -0,0 +1,69 @@ +package armory + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the `armory` command and its subcommands. +func Commands(con *console.SliverConsoleClient) *cobra.Command { + armoryCmd := &cobra.Command{ + Use: consts.ArmoryStr, + Short: "Automatically download and install extensions/aliases", + Long: help.GetHelpFor([]string{consts.ArmoryStr}), + Run: func(cmd *cobra.Command, args []string) { + ArmoryCmd(cmd, con, args) + }, + GroupID: consts.GenericHelpGroup, + } + flags.Bind("connection", true, armoryCmd, func(f *pflag.FlagSet) { + f.BoolP("insecure", "I", false, "skip tls certificate validation") + f.StringP("proxy", "p", "", "specify a proxy url (e.g. http://localhost:8080)") + f.BoolP("ignore-cache", "c", false, "ignore metadata cache, force refresh") + f.StringP("timeout", "t", "15m", "download timeout") + }) + + armoryInstallCmd := &cobra.Command{ + Use: consts.InstallStr, + Short: "Install an alias or extension", + Long: help.GetHelpFor([]string{consts.ArmoryStr, consts.InstallStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ArmoryInstallCmd(cmd, con, args) + }, + } + armoryCmd.AddCommand(armoryInstallCmd) + flags.NewCompletions(armoryInstallCmd).PositionalCompletion( + AliasExtensionOrBundleCompleter().Usage("name of the extension or alias to install"), + ) + + armoryUpdateCmd := &cobra.Command{ + Use: consts.UpdateStr, + Short: "Update installed an aliases and extensions", + Long: help.GetHelpFor([]string{consts.ArmoryStr, consts.UpdateStr}), + Run: func(cmd *cobra.Command, args []string) { + ArmoryUpdateCmd(cmd, con, args) + }, + } + armoryCmd.AddCommand(armoryUpdateCmd) + + armorySearchCmd := &cobra.Command{ + Use: consts.SearchStr, + Short: "Search for aliases and extensions by name (regex)", + Long: help.GetHelpFor([]string{consts.ArmoryStr, consts.SearchStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ArmorySearchCmd(cmd, con, args) + }, + } + armoryCmd.AddCommand(armorySearchCmd) + flags.NewCompletions(armorySearchCmd).PositionalCompletion(carapace.ActionValues().Usage("a name regular expression")) + + return armoryCmd +} diff --git a/client/command/exit/exit.go b/client/command/exit/exit.go index b94e11ee33..951a25c4cb 100644 --- a/client/command/exit/exit.go +++ b/client/command/exit/exit.go @@ -25,6 +25,7 @@ import ( "github.com/AlecAivazis/survey/v2" "github.com/bishopfox/sliver/client/console" + "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/spf13/cobra" ) @@ -53,3 +54,15 @@ func ExitCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } os.Exit(0) } + +// Commands returns the `exit` command. +func Command(con *console.SliverConsoleClient) *cobra.Command { + return &cobra.Command{ + Use: "exit", + Short: "Exit the program", + Run: func(cmd *cobra.Command, args []string) { + ExitCmd(cmd, con, args) + }, + GroupID: constants.GenericHelpGroup, + } +} diff --git a/client/command/flags/flags.go b/client/command/flags/flags.go index 7f55a0784d..ea679082fe 100644 --- a/client/command/flags/flags.go +++ b/client/command/flags/flags.go @@ -9,6 +9,10 @@ import ( "github.com/spf13/pflag" ) +const ( + DefaultTimeout = 60 +) + // Bind is a convenience function to bind flags to a command, through newly created // pflag.Flagset type. This function can be called any number of times for any command. // desc - An optional name for the flag set (can be empty, but might end up useful). diff --git a/client/command/jobs/commands.go b/client/command/jobs/commands.go new file mode 100644 index 0000000000..d3564d2a2a --- /dev/null +++ b/client/command/jobs/commands.go @@ -0,0 +1,169 @@ +package jobs + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/generate" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + // Job control + jobsCmd := &cobra.Command{ + Use: consts.JobsStr, + Short: "Job control", + Long: help.GetHelpFor([]string{consts.JobsStr}), + Run: func(cmd *cobra.Command, args []string) { + JobsCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("jobs", true, jobsCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.Bind("jobs", false, jobsCmd, func(f *pflag.FlagSet) { + f.Int32P("kill", "k", -1, "kill a background job") + f.BoolP("kill-all", "K", false, "kill all jobs") + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.BindFlagCompletions(jobsCmd, func(comp *carapace.ActionMap) { + (*comp)["kill"] = JobsIDCompleter(con) + }) + + // Mutual TLS + mtlsCmd := &cobra.Command{ + Use: consts.MtlsStr, + Short: "Start an mTLS listener", + Long: help.GetHelpFor([]string{consts.MtlsStr}), + Run: func(cmd *cobra.Command, args []string) { + MTLSListenerCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("mTLS listener", false, mtlsCmd, func(f *pflag.FlagSet) { + f.StringP("lhost", "L", "", "interface to bind server to") + f.Uint32P("lport", "l", generate.DefaultMTLSLPort, "tcp listen port") + f.BoolP("persistent", "p", false, "make persistent across restarts") + }) + + // Wireguard + wgCmd := &cobra.Command{ + Use: consts.WGStr, + Short: "Start a WireGuard listener", + Long: help.GetHelpFor([]string{consts.WGStr}), + Run: func(cmd *cobra.Command, args []string) { + WGListenerCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("WireGuard listener", false, wgCmd, func(f *pflag.FlagSet) { + f.StringP("lhost", "L", "", "interface to bind server to") + f.Uint32P("lport", "l", generate.DefaultWGLPort, "udp listen port") + f.Uint32P("nport", "n", generate.DefaultWGNPort, "virtual tun interface listen port") + f.Uint32P("key-port", "x", generate.DefaultWGKeyExPort, "virtual tun interface key exchange port") + f.BoolP("persistent", "p", false, "make persistent across restarts") + }) + + // DNS + dnsCmd := &cobra.Command{ + Use: consts.DnsStr, + Short: "Start a DNS listener", + Long: help.GetHelpFor([]string{consts.DnsStr}), + Run: func(cmd *cobra.Command, args []string) { + DNSListenerCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("DNS listener", false, dnsCmd, func(f *pflag.FlagSet) { + f.StringP("domains", "d", "", "parent domain(s) to use for DNS c2") + f.BoolP("no-canaries", "c", false, "disable dns canary detection") + f.StringP("lhost", "L", "", "interface to bind server to") + f.Uint32P("lport", "l", generate.DefaultDNSLPort, "udp listen port") + f.BoolP("disable-otp", "D", false, "disable otp authentication") + f.BoolP("persistent", "p", false, "make persistent across restarts") + }) + + // HTTP + httpCmd := &cobra.Command{ + Use: consts.HttpStr, + Short: "Start an HTTP listener", + Long: help.GetHelpFor([]string{consts.HttpStr}), + Run: func(cmd *cobra.Command, args []string) { + HTTPListenerCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("HTTP listener", false, httpCmd, func(f *pflag.FlagSet) { + f.StringP("domain", "d", "", "limit responses to specific domain") + f.StringP("website", "w", "", "website name (see websites cmd)") + f.StringP("lhost", "L", "", "interface to bind server to") + f.Uint32P("lport", "l", generate.DefaultHTTPLPort, "tcp listen port") + f.BoolP("disable-otp", "D", false, "disable otp authentication") + f.StringP("long-poll-timeout", "T", "1s", "server-side long poll timeout") + f.StringP("long-poll-jitter", "J", "2s", "server-side long poll jitter") + f.BoolP("persistent", "p", false, "make persistent across restarts") + }) + + // HTTPS + httpsCmd := &cobra.Command{ + Use: consts.HttpsStr, + Short: "Start an HTTPS listener", + Long: help.GetHelpFor([]string{consts.HttpsStr}), + Run: func(cmd *cobra.Command, args []string) { + HTTPSListenerCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("HTTPS listener", false, httpsCmd, func(f *pflag.FlagSet) { + f.StringP("domain", "d", "", "limit responses to specific domain") + f.StringP("website", "w", "", "website name (see websites cmd)") + f.StringP("lhost", "L", "", "interface to bind server to") + f.Uint32P("lport", "l", generate.DefaultHTTPSLPort, "tcp listen port") + f.BoolP("disable-otp", "D", false, "disable otp authentication") + f.StringP("long-poll-timeout", "T", "1s", "server-side long poll timeout") + f.StringP("long-poll-jitter", "J", "2s", "server-side long poll jitter") + + f.StringP("cert", "c", "", "PEM encoded certificate file") + f.StringP("key", "k", "", "PEM encoded private key file") + f.BoolP("lets-encrypt", "e", false, "attempt to provision a let's encrypt certificate") + f.BoolP("disable-randomized-jarm", "E", false, "disable randomized jarm fingerprints") + + f.BoolP("persistent", "p", false, "make persistent across restarts") + }) + + // Staging listeners + stageCmd := &cobra.Command{ + Use: consts.StageListenerStr, + Short: "Start a stager listener", + Long: help.GetHelpFor([]string{consts.StageListenerStr}), + Run: func(cmd *cobra.Command, args []string) { + StageListenerCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("stage listener", false, stageCmd, func(f *pflag.FlagSet) { + f.StringP("profile", "p", "", "implant profile name to link with the listener") + f.StringP("url", "u", "", "URL to which the stager will call back to") + f.StringP("cert", "c", "", "path to PEM encoded certificate file (HTTPS only)") + f.StringP("key", "k", "", "path to PEM encoded private key file (HTTPS only)") + f.BoolP("lets-encrypt", "e", false, "attempt to provision a let's encrypt certificate (HTTPS only)") + f.String("aes-encrypt-key", "", "encrypt stage with AES encryption key") + f.String("aes-encrypt-iv", "", "encrypt stage with AES encryption iv") + f.StringP("compress", "C", "none", "compress the stage before encrypting (zlib, gzip, deflate9, none)") + f.BoolP("prepend-size", "P", false, "prepend the size of the stage to the payload (to use with MSF stagers)") + }) + flags.BindFlagCompletions(stageCmd, func(comp *carapace.ActionMap) { + (*comp)["profile"] = generate.ProfileNameCompleter(con) + (*comp)["cert"] = carapace.ActionFiles().Tag("certificate file") + (*comp)["key"] = carapace.ActionFiles().Tag("key file") + (*comp)["compress"] = carapace.ActionValues([]string{"zlib", "gzip", "deflate9", "none"}...).Tag("compression formats") + }) + + return []*cobra.Command{jobsCmd, mtlsCmd, wgCmd, httpCmd, httpsCmd, stageCmd} +} diff --git a/client/command/operators/commands.go b/client/command/operators/commands.go new file mode 100644 index 0000000000..03edb8b160 --- /dev/null +++ b/client/command/operators/commands.go @@ -0,0 +1,29 @@ +package operators + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) *cobra.Command { + operatorsCmd := &cobra.Command{ + Use: consts.OperatorsStr, + Short: "Manage operators", + Long: help.GetHelpFor([]string{consts.OperatorsStr}), + Run: func(cmd *cobra.Command, args []string) { + OperatorsCmd(cmd, con, args) + }, + GroupID: consts.GenericHelpGroup, + } + flags.Bind("operators", false, operatorsCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return operatorsCmd +} diff --git a/client/command/update/commands.go b/client/command/update/commands.go new file mode 100644 index 0000000000..251d2c41f3 --- /dev/null +++ b/client/command/update/commands.go @@ -0,0 +1,46 @@ +package update + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + updateCmd := &cobra.Command{ + Use: consts.UpdateStr, + Short: "Check for updates", + Long: help.GetHelpFor([]string{consts.UpdateStr}), + Run: func(cmd *cobra.Command, args []string) { + UpdateCmd(cmd, con, args) + }, + GroupID: consts.GenericHelpGroup, + } + flags.Bind("update", false, updateCmd, func(f *pflag.FlagSet) { + f.BoolP("prereleases", "P", false, "include pre-released (unstable) versions") + f.StringP("proxy", "p", "", "specify a proxy url (e.g. http://localhost:8080)") + f.StringP("save", "s", "", "save downloaded files to specific directory (default user home dir)") + f.BoolP("insecure", "I", false, "skip tls certificate validation") + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + versionCmd := &cobra.Command{ + Use: consts.VersionStr, + Short: "Display version information", + Long: help.GetHelpFor([]string{consts.VersionStr}), + Run: func(cmd *cobra.Command, args []string) { + VerboseVersionsCmd(cmd, con, args) + }, + GroupID: consts.GenericHelpGroup, + } + flags.Bind("update", false, versionCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{updateCmd, versionCmd} +} diff --git a/server/console/console.go b/server/console/console.go index 8bef5a82d9..92a5807c9a 100644 --- a/server/console/console.go +++ b/server/console/console.go @@ -78,7 +78,7 @@ func serverOnlyCmds() (commands []*cobra.Command) { Run: startMultiplayerModeCmd, GroupID: consts.MultiplayerHelpGroup, } - command.Flags("multiplayer", false, startMultiplayer, func(f *pflag.FlagSet) { + command.Bind("multiplayer", false, startMultiplayer, func(f *pflag.FlagSet) { f.StringP("lhost", "L", "", "interface to bind server to") f.Uint16P("lport", "l", 31337, "tcp listen port") f.BoolP("persistent", "p", false, "make persistent across restarts") @@ -93,13 +93,13 @@ func serverOnlyCmds() (commands []*cobra.Command) { Run: newOperatorCmd, GroupID: consts.MultiplayerHelpGroup, } - command.Flags("operator", false, newOperator, func(f *pflag.FlagSet) { + command.Bind("operator", false, newOperator, func(f *pflag.FlagSet) { f.StringP("lhost", "l", "", "listen host") f.Uint16P("lport", "p", 31337, "listen port") f.StringP("save", "s", "", "directory/file in which to save config") f.StringP("name", "n", "", "operator name") }) - command.FlagComps(newOperator, func(comp *carapace.ActionMap) { + command.BindFlagCompletions(newOperator, func(comp *carapace.ActionMap) { (*comp)["save"] = carapace.ActionDirectories() }) commands = append(commands, newOperator) @@ -112,7 +112,7 @@ func serverOnlyCmds() (commands []*cobra.Command) { GroupID: consts.MultiplayerHelpGroup, } - command.Flags("operator", false, kickOperator, func(f *pflag.FlagSet) { + command.Bind("operator", false, kickOperator, func(f *pflag.FlagSet) { f.StringP("name", "n", "", "operator name") }) commands = append(commands, kickOperator) From f370e96058aab0787796e9f9ff975a6ad1b855d5 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Tue, 20 Jun 2023 13:28:03 +0200 Subject: [PATCH 04/14] Finish splitting server commands in their files --- client/command/armory/commands.go | 4 +- client/command/beacons/commands.go | 75 + client/command/builders/commands.go | 29 + client/command/command.go | 74 +- client/command/crack/commands.go | 143 ++ client/command/creds/commands.go | 83 + client/command/exit/commands.go | 17 + client/command/exit/exit.go | 6 +- client/command/generate/commands.go | 352 ++++ client/command/hosts/commands.go | 59 + client/command/info/commands.go | 32 + client/command/licenses/commands.go | 25 + client/command/loot/commands.go | 116 ++ client/command/monitor/commands.go | 33 + client/command/operators/commands.go | 4 +- client/command/prelude-operator/commands.go | 45 + client/command/reaction/commands.go | 87 + client/command/server.go | 1725 +------------------ client/command/sessions/commands.go | 85 + client/command/settings/commands.go | 92 + client/command/shikata-ga-nai/commands.go | 40 + client/command/use/commands.go | 53 + client/command/websites/commands.go | 99 ++ client/command/wireguard/commands.go | 37 + client/console/console.go | 11 + 25 files changed, 1635 insertions(+), 1691 deletions(-) create mode 100644 client/command/beacons/commands.go create mode 100644 client/command/builders/commands.go create mode 100644 client/command/crack/commands.go create mode 100644 client/command/creds/commands.go create mode 100644 client/command/exit/commands.go create mode 100644 client/command/generate/commands.go create mode 100644 client/command/hosts/commands.go create mode 100644 client/command/info/commands.go create mode 100644 client/command/licenses/commands.go create mode 100644 client/command/loot/commands.go create mode 100644 client/command/monitor/commands.go create mode 100644 client/command/prelude-operator/commands.go create mode 100644 client/command/reaction/commands.go create mode 100644 client/command/sessions/commands.go create mode 100644 client/command/settings/commands.go create mode 100644 client/command/shikata-ga-nai/commands.go create mode 100644 client/command/use/commands.go create mode 100644 client/command/websites/commands.go create mode 100644 client/command/wireguard/commands.go diff --git a/client/command/armory/commands.go b/client/command/armory/commands.go index 27e41c8735..5e59ef2a44 100644 --- a/client/command/armory/commands.go +++ b/client/command/armory/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the `armory` command and its subcommands. -func Commands(con *console.SliverConsoleClient) *cobra.Command { +func Commands(con *console.SliverConsoleClient) []*cobra.Command { armoryCmd := &cobra.Command{ Use: consts.ArmoryStr, Short: "Automatically download and install extensions/aliases", @@ -65,5 +65,5 @@ func Commands(con *console.SliverConsoleClient) *cobra.Command { armoryCmd.AddCommand(armorySearchCmd) flags.NewCompletions(armorySearchCmd).PositionalCompletion(carapace.ActionValues().Usage("a name regular expression")) - return armoryCmd + return []*cobra.Command{armoryCmd} } diff --git a/client/command/beacons/commands.go b/client/command/beacons/commands.go new file mode 100644 index 0000000000..433e204f2d --- /dev/null +++ b/client/command/beacons/commands.go @@ -0,0 +1,75 @@ +package beacons + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/command/use" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + beaconsCmd := &cobra.Command{ + Use: consts.BeaconsStr, + Short: "Manage beacons", + Long: help.GetHelpFor([]string{consts.BeaconsStr}), + GroupID: consts.SliverHelpGroup, + Run: func(cmd *cobra.Command, args []string) { + BeaconsCmd(cmd, con, args) + }, + } + flags.Bind("beacons", true, beaconsCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.Bind("beacons", false, beaconsCmd, func(f *pflag.FlagSet) { + f.StringP("kill", "k", "", "kill the designated beacon") + f.BoolP("kill-all", "K", false, "kill all beacons") + f.BoolP("force", "F", false, "force killing the beacon") + + f.StringP("filter", "f", "", "filter beacons by substring") + f.StringP("filter-re", "e", "", "filter beacons by regular expression") + }) + flags.BindFlagCompletions(beaconsCmd, func(comp *carapace.ActionMap) { + (*comp)["kill"] = use.BeaconIDCompleter(con) + }) + beaconsRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a beacon", + Long: help.GetHelpFor([]string{consts.BeaconsStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + BeaconsRmCmd(cmd, con, args) + }, + } + carapace.Gen(beaconsRmCmd).PositionalCompletion(use.BeaconIDCompleter(con)) + beaconsCmd.AddCommand(beaconsRmCmd) + + beaconsWatchCmd := &cobra.Command{ + Use: consts.WatchStr, + Short: "Watch your beacons", + Long: help.GetHelpFor([]string{consts.BeaconsStr, consts.WatchStr}), + Run: func(cmd *cobra.Command, args []string) { + BeaconsWatchCmd(cmd, con, args) + }, + } + beaconsCmd.AddCommand(beaconsWatchCmd) + + beaconsPruneCmd := &cobra.Command{ + Use: consts.PruneStr, + Short: "Prune stale beacons automatically", + Long: help.GetHelpFor([]string{consts.BeaconsStr, consts.PruneStr}), + Run: func(cmd *cobra.Command, args []string) { + BeaconsPruneCmd(cmd, con, args) + }, + } + flags.Bind("beacons", false, beaconsPruneCmd, func(f *pflag.FlagSet) { + f.StringP("duration", "d", "1h", "duration to prune beacons that have missed their last checkin") + }) + beaconsCmd.AddCommand(beaconsPruneCmd) + + return []*cobra.Command{beaconsCmd} +} diff --git a/client/command/builders/commands.go b/client/command/builders/commands.go new file mode 100644 index 0000000000..882cb50952 --- /dev/null +++ b/client/command/builders/commands.go @@ -0,0 +1,29 @@ +package builders + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + buildersCmd := &cobra.Command{ + Use: consts.BuildersStr, + Short: "List external builders", + Long: help.GetHelpFor([]string{consts.BuildersStr}), + Run: func(cmd *cobra.Command, args []string) { + BuildersCmd(cmd, con, args) + }, + GroupID: consts.PayloadsHelpGroup, + } + flags.Bind("builders", false, buildersCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{buildersCmd} +} diff --git a/client/command/command.go b/client/command/command.go index 840be14e43..9ba69ab42f 100644 --- a/client/command/command.go +++ b/client/command/command.go @@ -25,15 +25,17 @@ import ( "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" + + client "github.com/bishopfox/sliver/client/console" ) const defaultTimeout = 60 -// Flags is a convenience function to bind flags to a given command. +// Bind is a convenience function to bind flags to a given command. // name - The name of the flag set (can be empty). // cmd - The command to which the flags should be bound. // flags - A function exposing the flag set through which flags are declared. -func Flags(name string, persistent bool, cmd *cobra.Command, flags func(f *pflag.FlagSet)) { +func Bind(name string, persistent bool, cmd *cobra.Command, flags func(f *pflag.FlagSet)) { flagSet := pflag.NewFlagSet(name, pflag.ContinueOnError) // Create the flag set. flags(flagSet) // Let the user bind any number of flags to it. @@ -44,22 +46,21 @@ func Flags(name string, persistent bool, cmd *cobra.Command, flags func(f *pflag } } -// FlagComps is a convenience function for adding completions to a command's flags. +// BindFlagCompletions is a convenience function for adding completions to a command's flags. // cmd - The command owning the flags to complete. // bind - A function exposing a map["flag-name"]carapace.Action. -func FlagComps(cmd *cobra.Command, bind func(comp *carapace.ActionMap)) { +func BindFlagCompletions(cmd *cobra.Command, bind func(comp *carapace.ActionMap)) { comps := make(carapace.ActionMap) bind(&comps) carapace.Gen(cmd).FlagCompletion(comps) } -// hideCommand generates a cobra annotation map with a single -// console.CommandHiddenFilter key, which value is a comma-separated list -// of filters to use in order to expose/hide commands based on requirements. -// Ex: cmd.Annotations = hideCommand("windows") will hide the cmd -// if the target session/beacon is not a Windows host. -func hideCommand(filters ...string) map[string]string { +// RestrictTargets generates a cobra annotation map with a single console.CommandHiddenFilter key +// to a comma-separated list of filters to use in order to expose/hide commands based on requirements. +// Ex: cmd.Annotations = RestrictTargets("windows") will only show the command if the target is Windows. +// Ex: cmd.Annotations = RestrictTargets("windows", "beacon") show the command if target is a beacon on Windows. +func RestrictTargets(filters ...string) map[string]string { if len(filters) == 0 { return nil } @@ -76,3 +77,56 @@ func hideCommand(filters ...string) map[string]string { console.CommandFilterKey: filts, } } + +// [ Core ] +// [ Sessions ] +// [ Execution ] +// [ Filesystem ] +// [ Info ] +// [ Network (C2)] +// [ Network tools ] +// [ Payloads ] +// [ Privileges ] +// [ Processes ] +// [ Aliases ] +// [ Extensions ] + +// Commands not to bind in CLI: +// - portforwarders +// - Socks (and wg-socks ?) +// - shell ? + +// Take care of: +// - double bind help command +// - double bind session commands +// - don't bind readline command in CLI. + +// bindCommands is a helper used to bind a list of root commands to a given menu, for a given "command help group". +// @group - Name of the group under which the command should be shown. Preferably use a string in the constants package. +// @menu - The command menu to which the commands should be bound (either server or implant menu). +// @ cmds - A list of functions returning a list of root commands to bind. See any package's `commands.go` file and function. +func bindCommands(group string, menu *cobra.Command, con *client.SliverConsoleClient, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { + found := false + + // Ensure the given command group is available in the menu. + if group != "" { + for _, grp := range menu.Groups() { + if grp.Title == group { + found = true + break + } + } + + if !found { + menu.AddGroup(&cobra.Group{ + ID: group, + Title: group, + }) + } + } + + // Bind the command to the root + for _, command := range cmds { + menu.AddCommand(command(con)...) + } +} diff --git a/client/command/crack/commands.go b/client/command/crack/commands.go new file mode 100644 index 0000000000..44b0982c0c --- /dev/null +++ b/client/command/crack/commands.go @@ -0,0 +1,143 @@ +package crack + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + crackCmd := &cobra.Command{ + Use: consts.CrackStr, + Short: "Crack: GPU password cracking", + Long: help.GetHelpFor([]string{consts.CrackStr}), + GroupID: consts.GenericHelpGroup, + Run: func(cmd *cobra.Command, args []string) { + CrackCmd(cmd, con, args) + }, + } + flags.Bind("", true, crackCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + crackStationsCmd := &cobra.Command{ + Use: consts.StationsStr, + Short: "Manage crackstations", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.StationsStr}), + Run: func(cmd *cobra.Command, args []string) { + CrackStationsCmd(cmd, con, args) + }, + } + crackCmd.AddCommand(crackStationsCmd) + + wordlistsCmd := &cobra.Command{ + Use: consts.WordlistsStr, + Short: "Manage wordlists", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.WordlistsStr}), + Run: func(cmd *cobra.Command, args []string) { + CrackWordlistsCmd(cmd, con, args) + }, + } + crackCmd.AddCommand(wordlistsCmd) + + wordlistsAddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add a wordlist", + Run: func(cmd *cobra.Command, args []string) { + CrackWordlistsAddCmd(cmd, con, args) + }, + } + flags.Bind("", false, wordlistsAddCmd, func(f *pflag.FlagSet) { + f.StringP("name", "n", "", "wordlist name (blank = filename)") + }) + carapace.Gen(wordlistsAddCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to local wordlist file")) + wordlistsCmd.AddCommand(wordlistsAddCmd) + + wordlistsRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a wordlist", + Run: func(cmd *cobra.Command, args []string) { + CrackWordlistsRmCmd(cmd, con, args) + }, + } + wordlistsCmd.AddCommand(wordlistsRmCmd) + carapace.Gen(wordlistsRmCmd).PositionalCompletion(CrackWordlistCompleter(con).Usage("wordlist to remove")) + + rulesCmd := &cobra.Command{ + Use: consts.RulesStr, + Short: "Manage rule files", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.RulesStr}), + Run: func(cmd *cobra.Command, args []string) { + CrackRulesCmd(cmd, con, args) + }, + } + crackCmd.AddCommand(rulesCmd) + + rulesAddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add a rules file", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.RulesStr, consts.AddStr}), + Run: func(cmd *cobra.Command, args []string) { + CrackRulesAddCmd(cmd, con, args) + }, + } + flags.Bind("", false, rulesAddCmd, func(f *pflag.FlagSet) { + f.StringP("name", "n", "", "rules name (blank = filename)") + }) + carapace.Gen(rulesAddCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to local rules file")) + rulesCmd.AddCommand(rulesAddCmd) + + rulesRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove rules", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.RulesStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + CrackRulesRmCmd(cmd, con, args) + }, + } + carapace.Gen(rulesRmCmd).PositionalCompletion(CrackRulesCompleter(con).Usage("rules to remove")) + rulesCmd.AddCommand(rulesRmCmd) + + hcstat2Cmd := &cobra.Command{ + Use: consts.Hcstat2Str, + Short: "Manage markov hcstat2 files", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.Hcstat2Str}), + Run: func(cmd *cobra.Command, args []string) { + CrackHcstat2Cmd(cmd, con, args) + }, + } + crackCmd.AddCommand(hcstat2Cmd) + + hcstat2AddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add a hcstat2 file", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.Hcstat2Str, consts.AddStr}), + Run: func(cmd *cobra.Command, args []string) { + CrackHcstat2AddCmd(cmd, con, args) + }, + } + flags.Bind("", false, hcstat2AddCmd, func(f *pflag.FlagSet) { + f.StringP("name", "n", "", "hcstat2 name (blank = filename)") + }) + carapace.Gen(hcstat2AddCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to local hcstat2 file")) + hcstat2Cmd.AddCommand(hcstat2AddCmd) + + hcstat2RmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove hcstat2 file", + Long: help.GetHelpFor([]string{consts.CrackStr, consts.Hcstat2Str, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + CrackHcstat2RmCmd(cmd, con, args) + }, + } + carapace.Gen(hcstat2RmCmd).PositionalCompletion(CrackHcstat2Completer(con).Usage("hcstat2 to remove")) + hcstat2Cmd.AddCommand(hcstat2RmCmd) + + return []*cobra.Command{crackCmd} +} diff --git a/client/command/creds/commands.go b/client/command/creds/commands.go new file mode 100644 index 0000000000..4ec0bfec49 --- /dev/null +++ b/client/command/creds/commands.go @@ -0,0 +1,83 @@ +package creds + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + credsCmd := &cobra.Command{ + Use: consts.CredsStr, + Short: "Manage the database of credentials", + Long: help.GetHelpFor([]string{consts.CredsStr}), + GroupID: consts.GenericHelpGroup, + Run: func(cmd *cobra.Command, args []string) { + CredsCmd(cmd, con, args) + }, + } + flags.Bind("creds", true, credsCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + credsAddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add a credential to the database", + Long: help.GetHelpFor([]string{consts.CredsStr, consts.AddStr}), + Run: func(cmd *cobra.Command, args []string) { + CredsAddCmd(cmd, con, args) + }, + } + flags.Bind("", false, credsAddCmd, func(f *pflag.FlagSet) { + f.StringP("collection", "c", "", "name of collection") + f.StringP("username", "u", "", "username for the credential") + f.StringP("plaintext", "p", "", "plaintext for the credential") + f.StringP("hash", "P", "", "hash of the credential") + f.StringP("hash-type", "H", "", "hash type of the credential") + }) + flags.BindFlagCompletions(credsAddCmd, func(comp *carapace.ActionMap) { + (*comp)["hash-type"] = CredsHashTypeCompleter(con) + }) + credsCmd.AddCommand(credsAddCmd) + + credsAddFileCmd := &cobra.Command{ + Use: consts.FileStr, + Short: "Add a credential to the database", + Long: help.GetHelpFor([]string{consts.CredsStr, consts.AddStr, consts.FileStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + CredsAddHashFileCmd(cmd, con, args) + }, + } + flags.Bind("", false, credsAddFileCmd, func(f *pflag.FlagSet) { + f.StringP("collection", "c", "", "name of collection") + f.StringP("file-format", "F", HashNewlineFormat, "file format of the credential file") + f.StringP("hash-type", "H", "", "hash type of the credential") + }) + flags.BindFlagCompletions(credsAddFileCmd, func(comp *carapace.ActionMap) { + (*comp)["collection"] = CredsCollectionCompleter(con) + (*comp)["file-format"] = CredsHashFileFormatCompleter(con) + (*comp)["hash-type"] = CredsHashTypeCompleter(con) + }) + carapace.Gen(credsAddFileCmd).PositionalCompletion(carapace.ActionFiles().Tag("credential file")) + credsAddCmd.AddCommand(credsAddFileCmd) + + credsRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a credential to the database", + Long: help.GetHelpFor([]string{consts.CredsStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + CredsRmCmd(cmd, con, args) + }, + } + carapace.Gen(credsRmCmd).PositionalCompletion(CredsCredentialIDCompleter(con).Usage("id of credential to remove (leave empty to select)")) + credsCmd.AddCommand(credsRmCmd) + + return []*cobra.Command{credsCmd} +} diff --git a/client/command/exit/commands.go b/client/command/exit/commands.go new file mode 100644 index 0000000000..75b67ea3a6 --- /dev/null +++ b/client/command/exit/commands.go @@ -0,0 +1,17 @@ +package exit + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + return nil +} diff --git a/client/command/exit/exit.go b/client/command/exit/exit.go index 951a25c4cb..ba0f1ee79b 100644 --- a/client/command/exit/exit.go +++ b/client/command/exit/exit.go @@ -56,13 +56,13 @@ func ExitCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } // Commands returns the `exit` command. -func Command(con *console.SliverConsoleClient) *cobra.Command { - return &cobra.Command{ +func Command(con *console.SliverConsoleClient) []*cobra.Command { + return []*cobra.Command{{ Use: "exit", Short: "Exit the program", Run: func(cmd *cobra.Command, args []string) { ExitCmd(cmd, con, args) }, GroupID: constants.GenericHelpGroup, - } + }} } diff --git a/client/command/generate/commands.go b/client/command/generate/commands.go new file mode 100644 index 0000000000..c30db8c28e --- /dev/null +++ b/client/command/generate/commands.go @@ -0,0 +1,352 @@ +package generate + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + // [ Generate ] -------------------------------------------------------------- + generateCmd := &cobra.Command{ + Use: consts.GenerateStr, + Short: "Generate an implant binary", + Long: help.GetHelpFor([]string{consts.GenerateStr}), + Run: func(cmd *cobra.Command, args []string) { + GenerateCmd(cmd, con, args) + }, + GroupID: consts.PayloadsHelpGroup, + } + flags.Bind("generate", true, generateCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + // Session flags and completions. + coreImplantFlags("session", generateCmd) + compileImplantFlags("session", generateCmd) + coreImplantFlagCompletions(generateCmd, con) + + generateBeaconCmd := &cobra.Command{ + Use: consts.BeaconStr, + Short: "Generate a beacon binary", + Long: help.GetHelpFor([]string{consts.GenerateStr, consts.BeaconStr}), + Run: func(cmd *cobra.Command, args []string) { + GenerateBeaconCmd(cmd, con, args) + }, + } + + // Beacon flags and completions. + coreImplantFlags("beacon", generateBeaconCmd) + compileImplantFlags("beacon", generateBeaconCmd) + coreImplantFlagCompletions(generateBeaconCmd, con) + + generateCmd.AddCommand(generateBeaconCmd) + + generateStagerCmd := &cobra.Command{ + Use: consts.MsfStagerStr, + Short: "Generate a stager using Metasploit (requires local Metasploit installation)", + Long: help.GetHelpFor([]string{consts.MsfStagerStr}), + Run: func(cmd *cobra.Command, args []string) { + GenerateStagerCmd(cmd, con, args) + }, + } + flags.Bind("stager", false, generateStagerCmd, func(f *pflag.FlagSet) { + f.StringP("os", "o", "windows", "operating system") + f.StringP("arch", "a", "amd64", "cpu architecture") + f.StringP("lhost", "L", "", "Listening host") + f.Uint32P("lport", "l", 8443, "Listening port") + f.StringP("protocol", "r", "tcp", "Staging protocol (tcp/http/https)") + f.StringP("format", "f", "raw", "Output format (msfvenom formats, see help generate msf-stager for the list)") + f.StringP("badchars", "b", "", "bytes to exclude from stage shellcode") + f.StringP("save", "s", "", "directory to save the generated stager to") + f.StringP("advanced", "d", "", "Advanced options for the stager using URI query syntax (option1=value1&option2=value2...)") + }) + generateCmd.AddCommand(generateStagerCmd) + + generateInfoCmd := &cobra.Command{ + Use: consts.CompilerInfoStr, + Short: "Get information about the server's compiler", + Long: help.GetHelpFor([]string{consts.CompilerInfoStr}), + Run: func(cmd *cobra.Command, args []string) { + GenerateInfoCmd(cmd, con, args) + }, + } + generateCmd.AddCommand(generateInfoCmd) + + // Traffic Encoder SubCommands + trafficEncodersCmd := &cobra.Command{ + Use: consts.TrafficEncodersStr, + Short: "Manage implant traffic encoders", + Long: help.GetHelpFor([]string{consts.GenerateStr, consts.TrafficEncodersStr}), + Run: func(cmd *cobra.Command, args []string) { + TrafficEncodersCmd(cmd, con, args) + }, + } + generateCmd.AddCommand(trafficEncodersCmd) + + trafficEncodersAddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add a new traffic encoder to the server from the local file system", + Long: help.GetHelpFor([]string{consts.GenerateStr, consts.TrafficEncodersStr, consts.AddStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + TrafficEncodersAddCmd(cmd, con, args) + }, + } + flags.Bind("", false, trafficEncodersAddCmd, func(f *pflag.FlagSet) { + f.BoolP("skip-tests", "s", false, "skip testing the traffic encoder (not recommended)") + }) + carapace.Gen(trafficEncodersAddCmd).PositionalCompletion(carapace.ActionFiles("wasm").Tag("wasm files").Usage("local file path (expects .wasm)")) + trafficEncodersCmd.AddCommand(trafficEncodersAddCmd) + + trafficEncodersRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a traffic encoder from the server", + Long: help.GetHelpFor([]string{consts.GenerateStr, consts.TrafficEncodersStr, consts.RmStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + TrafficEncodersRemoveCmd(cmd, con, args) + }, + } + carapace.Gen(trafficEncodersRmCmd).PositionalCompletion(TrafficEncodersCompleter(con).Usage("traffic encoder to remove")) + trafficEncodersCmd.AddCommand(trafficEncodersRmCmd) + + // [ Regenerate ] -------------------------------------------------------------- + + regenerateCmd := &cobra.Command{ + Use: consts.RegenerateStr, + Short: "Regenerate an implant", + Long: help.GetHelpFor([]string{consts.RegenerateStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + RegenerateCmd(cmd, con, args) + }, + GroupID: consts.PayloadsHelpGroup, + } + flags.Bind("regenerate", false, regenerateCmd, func(f *pflag.FlagSet) { + f.StringP("save", "s", "", "directory/file to the binary to") + }) + flags.BindFlagCompletions(regenerateCmd, func(comp *carapace.ActionMap) { + (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") + }) + carapace.Gen(regenerateCmd).PositionalCompletion(ImplantBuildNameCompleter(con)) + + // [ Profiles ] -------------------------------------------------------------- + + profilesCmd := &cobra.Command{ + Use: consts.ProfilesStr, + Short: "List existing profiles", + Long: help.GetHelpFor([]string{consts.ProfilesStr}), + Run: func(cmd *cobra.Command, args []string) { + ProfilesCmd(cmd, con, args) + }, + GroupID: consts.PayloadsHelpGroup, + } + flags.Bind("profiles", true, profilesCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + profilesGenerateCmd := &cobra.Command{ + Use: consts.GenerateStr, + Short: "Generate implant from a profile", + Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.GenerateStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ProfilesGenerateCmd(cmd, con, args) + }, + } + flags.Bind("profiles", false, profilesGenerateCmd, func(f *pflag.FlagSet) { + f.StringP("save", "s", "", "directory/file to the binary to") + f.BoolP("disable-sgn", "G", false, "disable shikata ga nai shellcode encoder") + }) + flags.BindFlagCompletions(profilesGenerateCmd, func(comp *carapace.ActionMap) { + (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") + }) + carapace.Gen(profilesGenerateCmd).PositionalCompletion(ProfileNameCompleter(con)) + profilesCmd.AddCommand(profilesGenerateCmd) + + profilesNewCmd := &cobra.Command{ + Use: consts.NewStr, + Short: "Create a new implant profile (interactive session)", + Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.NewStr}), + Run: func(cmd *cobra.Command, args []string) { + ProfilesNewCmd(cmd, con, args) + }, + } + profilesCmd.AddCommand(profilesNewCmd) + + // Session flags and completions. + coreImplantFlags("session", profilesNewCmd) + compileImplantFlags("session", profilesNewCmd) + coreImplantFlagCompletions(profilesNewCmd, con) + + profilesNewBeaconCmd := &cobra.Command{ + Use: consts.BeaconStr, + Short: "Create a new implant profile (beacon)", + Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.NewStr, consts.BeaconStr}), + Run: func(cmd *cobra.Command, args []string) { + ProfilesNewBeaconCmd(cmd, con, args) + }, + } + profilesNewCmd.AddCommand(profilesNewBeaconCmd) + + // Beacon flags and completions. + coreImplantFlags("beacon", profilesNewBeaconCmd) + compileImplantFlags("beacon", profilesNewBeaconCmd) + coreImplantFlagCompletions(profilesNewBeaconCmd, con) + + profilesRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a profile", + Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.RmStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ProfilesRmCmd(cmd, con, args) + }, + } + carapace.Gen(profilesRmCmd).PositionalCompletion(ProfileNameCompleter(con)) + profilesCmd.AddCommand(profilesRmCmd) + + // [ Implants ] -------------------------------------------------------------- + + implantBuildsCmd := &cobra.Command{ + Use: consts.ImplantBuildsStr, + Short: "List implant builds", + Long: help.GetHelpFor([]string{consts.ImplantBuildsStr}), + Run: func(cmd *cobra.Command, args []string) { + ImplantsCmd(cmd, con, args) + }, + GroupID: consts.PayloadsHelpGroup, + } + flags.Bind("implants", true, implantBuildsCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.Bind("implants", false, implantBuildsCmd, func(f *pflag.FlagSet) { + f.StringP("os", "o", "", "filter builds by operating system") + f.StringP("arch", "a", "", "filter builds by cpu architecture") + f.StringP("format", "f", "", "filter builds by artifact format") + f.BoolP("only-sessions", "s", false, "filter interactive sessions") + f.BoolP("only-beacons", "b", false, "filter beacons") + f.BoolP("no-debug", "d", false, "filter builds by debug flag") + }) + flags.BindFlagCompletions(implantBuildsCmd, func(comp *carapace.ActionMap) { + (*comp)["os"] = OSCompleter(con) + (*comp)["arch"] = ArchCompleter(con) + (*comp)["format"] = FormatCompleter() + }) + + implantsRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove implant build", + Long: help.GetHelpFor([]string{consts.ImplantBuildsStr, consts.RmStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ImplantsRmCmd(cmd, con, args) + }, + } + carapace.Gen(implantsRmCmd).PositionalCompletion(ImplantBuildNameCompleter(con)) + implantBuildsCmd.AddCommand(implantsRmCmd) + + canariesCmd := &cobra.Command{ + Use: consts.CanariesStr, + Short: "List previously generated canaries", + Long: help.GetHelpFor([]string{consts.CanariesStr}), + Run: func(cmd *cobra.Command, args []string) { + CanariesCmd(cmd, con, args) + }, + GroupID: consts.PayloadsHelpGroup, + } + flags.Bind("canaries", false, canariesCmd, func(f *pflag.FlagSet) { + f.BoolP("burned", "b", false, "show only triggered/burned canaries") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{generateCmd, regenerateCmd, profilesCmd, implantBuildsCmd} +} + +// coreImplantFlags binds all flags common to all sliver implant types. +// This is used by all sliver compilation and profiles generation commands. +func coreImplantFlags(name string, cmd *cobra.Command) { + flags.Bind(name, false, cmd, func(f *pflag.FlagSet) { + // Core compile + f.StringP("os", "o", "windows", "operating system") + f.StringP("arch", "a", "amd64", "cpu architecture") + f.StringP("name", "N", "", "agent name") // + f.BoolP("debug", "d", false, "enable debug features") + f.StringP("debug-file", "O", "", "path to debug output") + f.BoolP("evasion", "e", false, "enable evasion features (e.g. overwrite user space hooks)") + f.BoolP("skip-symbols", "l", false, "skip symbol obfuscation") + f.BoolP("disable-sgn", "G", false, "disable shikata ga nai shellcode encoder") + + f.StringP("canary", "c", "", "canary domain(s)") + + // C2 channels + f.StringP("mtls", "m", "", "mtls connection strings") + f.StringP("wg", "g", "", "wg connection strings") + f.StringP("http", "b", "", "http(s) connection strings") + f.StringP("dns", "n", "", "dns connection strings") + f.StringP("named-pipe", "p", "", "named-pipe connection strings") + f.StringP("tcp-pivot", "i", "", "tcp-pivot connection strings") + + f.Uint32P("key-exchange", "X", DefaultWGKeyExPort, "wg key-exchange port") + f.Uint32P("tcp-comms", "T", DefaultWGNPort, "wg c2 comms port") + + f.BoolP("run-at-load", "R", false, "run the implant entrypoint from DllMain/Constructor (shared library only)") + f.BoolP("netgo", "q", false, "force the use of netgo") + f.StringP("traffic-encoders", "A", "", "comma separated list of traffic encoders to enable") + + f.StringP("strategy", "Z", "", "specify a connection strategy (r = random, rd = random domain, s = sequential)") + f.Int64P("reconnect", "j", DefaultReconnect, "attempt to reconnect every n second(s)") + f.Int64P("poll-timeout", "P", DefaultPollTimeout, "long poll request timeout") + f.Uint32P("max-errors", "k", DefaultMaxErrors, "max number of connection errors") + + // Limits + f.StringP("limit-datetime", "w", "", "limit execution to before datetime") + f.BoolP("limit-domainjoined", "x", false, "limit execution to domain joined machines") + f.StringP("limit-username", "y", "", "limit execution to specified username") + f.StringP("limit-hostname", "z", "", "limit execution to specified hostname") + f.StringP("limit-fileexists", "F", "", "limit execution to hosts with this file in the filesystem") + f.StringP("limit-locale", "L", "", "limit execution to hosts that match this locale") + + f.StringP("format", "f", "exe", "Specifies the output formats, valid values are: 'exe', 'shared' (for dynamic libraries), 'service' (see: `psexec` for more info) and 'shellcode' (windows only)") + }) +} + +// coreImplantFlagCompletions binds completions to flags registered in coreImplantFlags. +func coreImplantFlagCompletions(cmd *cobra.Command, con *console.SliverConsoleClient) { + flags.BindFlagCompletions(cmd, func(comp *carapace.ActionMap) { + (*comp)["debug-file"] = carapace.ActionFiles() + (*comp)["os"] = OSCompleter(con) + (*comp)["arch"] = ArchCompleter(con) + (*comp)["strategy"] = carapace.ActionValuesDescribed([]string{"r", "random", "rd", "random domain", "s", "sequential"}...).Tag("C2 strategy") + (*comp)["format"] = FormatCompleter() + (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") + }) +} + +// coreBeaconFlags binds all flags specific to beacon implants (profiles or compiled). +func coreBeaconFlags(name string, cmd *cobra.Command) { + flags.Bind(name, false, cmd, func(f *pflag.FlagSet) { + f.Int64P("days", "D", 0, "beacon interval days") + f.Int64P("hours", "H", 0, "beacon interval hours") + f.Int64P("minutes", "M", 0, "beacon interval minutes") + f.Int64P("seconds", "S", 60, "beacon interval seconds") + f.Int64P("jitter", "J", 30, "beacon interval jitter in seconds") + }) +} + +// compileImplantFlags binds all flags used when actually compiling an implant (not when creating a profile). +func compileImplantFlags(name string, cmd *cobra.Command) { + flags.Bind(name, false, cmd, func(f *pflag.FlagSet) { + f.StringP("name", "N", "", "agent name") + f.StringP("template", "I", "sliver", "implant code template") + f.BoolP("external-builder", "E", false, "use an external builder") + f.StringP("save", "s", "", "directory/file to the binary to") + }) +} diff --git a/client/command/hosts/commands.go b/client/command/hosts/commands.go new file mode 100644 index 0000000000..ca6573d325 --- /dev/null +++ b/client/command/hosts/commands.go @@ -0,0 +1,59 @@ +package hosts + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + hostsCmd := &cobra.Command{ + Use: consts.HostsStr, + Short: "Manage the database of hosts", + Long: help.GetHelpFor([]string{consts.HostsStr}), + Run: func(cmd *cobra.Command, args []string) { + HostsCmd(cmd, con, args) + }, + GroupID: consts.SliverHelpGroup, + } + flags.Bind("hosts", true, hostsCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + hostsRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a host from the database", + Long: help.GetHelpFor([]string{consts.HostsStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + HostsRmCmd(cmd, con, args) + }, + } + hostsCmd.AddCommand(hostsRmCmd) + + hostsIOCCmd := &cobra.Command{ + Use: consts.IOCStr, + Short: "Manage tracked IOCs on a given host", + Long: help.GetHelpFor([]string{consts.HostsStr, consts.IOCStr}), + Run: func(cmd *cobra.Command, args []string) { + HostsIOCCmd(cmd, con, args) + }, + } + hostsCmd.AddCommand(hostsIOCCmd) + + hostsIOCRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Delete IOCs from the database", + Long: help.GetHelpFor([]string{consts.HostsStr, consts.IOCStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + HostsIOCRmCmd(cmd, con, args) + }, + } + hostsIOCCmd.AddCommand(hostsIOCRmCmd) + + return []*cobra.Command{hostsCmd, hostsIOCCmd} +} diff --git a/client/command/info/commands.go b/client/command/info/commands.go new file mode 100644 index 0000000000..90472999d3 --- /dev/null +++ b/client/command/info/commands.go @@ -0,0 +1,32 @@ +package info + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/command/use" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + infoCmd := &cobra.Command{ + Use: consts.InfoStr, + Short: "Get info about session", + Long: help.GetHelpFor([]string{consts.InfoStr}), + Run: func(cmd *cobra.Command, args []string) { + InfoCmd(cmd, con, args) + }, + GroupID: consts.SliverHelpGroup, + } + flags.Bind("use", false, infoCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(infoCmd).PositionalCompletion(use.BeaconAndSessionIDCompleter(con)) + + return []*cobra.Command{infoCmd} +} diff --git a/client/command/licenses/commands.go b/client/command/licenses/commands.go new file mode 100644 index 0000000000..d0a9b18396 --- /dev/null +++ b/client/command/licenses/commands.go @@ -0,0 +1,25 @@ +package licenses + +import ( + "github.com/spf13/cobra" + + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" + "github.com/bishopfox/sliver/client/licenses" +) + +// Commands returns the `licences` command. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + licensesCmd := &cobra.Command{ + Use: consts.LicensesStr, + Short: "Open source licenses", + Long: help.GetHelpFor([]string{consts.LicensesStr}), + Run: func(cmd *cobra.Command, args []string) { + con.Println(licenses.All) + }, + GroupID: consts.GenericHelpGroup, + } + + return []*cobra.Command{licensesCmd} +} diff --git a/client/command/loot/commands.go b/client/command/loot/commands.go new file mode 100644 index 0000000000..4087ce6ed4 --- /dev/null +++ b/client/command/loot/commands.go @@ -0,0 +1,116 @@ +package loot + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + lootCmd := &cobra.Command{ + Use: consts.LootStr, + Short: "Manage the server's loot store", + Long: help.GetHelpFor([]string{consts.LootStr}), + Run: func(cmd *cobra.Command, args []string) { + LootCmd(cmd, con, args) + }, + GroupID: consts.SliverHelpGroup, + } + flags.Bind("loot", true, lootCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.Bind("loot", false, lootCmd, func(f *pflag.FlagSet) { + f.StringP("filter", "f", "", "filter based on loot type") + }) + + lootAddCmd := &cobra.Command{ + Use: consts.LootLocalStr, + Short: "Add a local file to the server's loot store", + Long: help.GetHelpFor([]string{consts.LootStr, consts.LootLocalStr}), + Run: func(cmd *cobra.Command, args []string) { + LootAddLocalCmd(cmd, con, args) + }, + Args: cobra.ExactArgs(1), + } + lootCmd.AddCommand(lootAddCmd) + flags.Bind("loot", false, lootAddCmd, func(f *pflag.FlagSet) { + f.StringP("name", "n", "", "name of this piece of loot") + f.StringP("type", "T", "", "force a specific loot type (file/cred)") + f.StringP("file-type", "F", "", "force a specific file type (binary/text)") + }) + flags.BindFlagCompletions(lootAddCmd, func(comp *carapace.ActionMap) { + (*comp)["type"] = carapace.ActionValues("file", "cred").Tag("loot type") + (*comp)["file-type"] = carapace.ActionValues("binary", "text").Tag("loot file type") + }) + carapace.Gen(lootAddCmd).PositionalCompletion( + carapace.ActionFiles().Tag("local loot file").Usage("The local file path to the loot")) + + lootRemoteCmd := &cobra.Command{ + Use: consts.LootRemoteStr, + Short: "Add a remote file from the current session to the server's loot store", + Long: help.GetHelpFor([]string{consts.LootStr, consts.LootRemoteStr}), + Run: func(cmd *cobra.Command, args []string) { + LootAddRemoteCmd(cmd, con, args) + }, + Args: cobra.ExactArgs(1), + } + lootCmd.AddCommand(lootRemoteCmd) + flags.Bind("loot", false, lootRemoteCmd, func(f *pflag.FlagSet) { + f.StringP("name", "n", "", "name of this piece of loot") + f.StringP("type", "T", "", "force a specific loot type (file/cred)") + f.StringP("file-type", "F", "", "force a specific file type (binary/text)") + }) + flags.BindFlagCompletions(lootRemoteCmd, func(comp *carapace.ActionMap) { + (*comp)["type"] = carapace.ActionValues("file", "cred").Tag("loot type") + (*comp)["file-type"] = carapace.ActionValues("binary", "text").Tag("loot file type") + }) + carapace.Gen(lootRemoteCmd).PositionalCompletion(carapace.ActionValues().Usage("The file path on the remote host to the loot")) + + lootRenameCmd := &cobra.Command{ + Use: consts.RenameStr, + Short: "Re-name a piece of existing loot", + Long: help.GetHelpFor([]string{consts.LootStr, consts.RenameStr}), + Run: func(cmd *cobra.Command, args []string) { + LootRenameCmd(cmd, con, args) + }, + } + lootCmd.AddCommand(lootRenameCmd) + + lootFetchCmd := &cobra.Command{ + Use: consts.FetchStr, + Short: "Fetch a piece of loot from the server's loot store", + Long: help.GetHelpFor([]string{consts.LootStr, consts.FetchStr}), + Run: func(cmd *cobra.Command, args []string) { + LootFetchCmd(cmd, con, args) + }, + } + lootCmd.AddCommand(lootFetchCmd) + flags.Bind("loot", false, lootFetchCmd, func(f *pflag.FlagSet) { + f.StringP("save", "s", "", "save loot to a local file") + f.StringP("filter", "f", "", "filter based on loot type") + }) + flags.BindFlagCompletions(lootFetchCmd, func(comp *carapace.ActionMap) { + (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save loot") + }) + + lootRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a piece of loot from the server's loot store", + Long: help.GetHelpFor([]string{consts.LootStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + LootRmCmd(cmd, con, args) + }, + } + lootCmd.AddCommand(lootRmCmd) + flags.Bind("loot", false, lootRmCmd, func(f *pflag.FlagSet) { + f.StringP("filter", "f", "", "filter based on loot type") + }) + + return []*cobra.Command{lootCmd} +} diff --git a/client/command/monitor/commands.go b/client/command/monitor/commands.go new file mode 100644 index 0000000000..3a3080ee5d --- /dev/null +++ b/client/command/monitor/commands.go @@ -0,0 +1,33 @@ +package monitor + +import ( + "github.com/spf13/cobra" + + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + monitorCmd := &cobra.Command{ + Use: consts.MonitorStr, + Short: "Monitor threat intel platforms for Sliver implants", + GroupID: consts.SliverHelpGroup, + } + monitorCmd.AddCommand(&cobra.Command{ + Use: "start", + Short: "Start the monitoring loops", + Run: func(cmd *cobra.Command, args []string) { + MonitorStartCmd(cmd, con, args) + }, + }) + monitorCmd.AddCommand(&cobra.Command{ + Use: "stop", + Short: "Stop the monitoring loops", + Run: func(cmd *cobra.Command, args []string) { + MonitorStopCmd(cmd, con, args) + }, + }) + + return []*cobra.Command{monitorCmd} +} diff --git a/client/command/operators/commands.go b/client/command/operators/commands.go index 03edb8b160..2713a124b3 100644 --- a/client/command/operators/commands.go +++ b/client/command/operators/commands.go @@ -11,7 +11,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) *cobra.Command { +func Commands(con *console.SliverConsoleClient) []*cobra.Command { operatorsCmd := &cobra.Command{ Use: consts.OperatorsStr, Short: "Manage operators", @@ -25,5 +25,5 @@ func Commands(con *console.SliverConsoleClient) *cobra.Command { f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") }) - return operatorsCmd + return []*cobra.Command{operatorsCmd} } diff --git a/client/command/prelude-operator/commands.go b/client/command/prelude-operator/commands.go new file mode 100644 index 0000000000..9167d3037b --- /dev/null +++ b/client/command/prelude-operator/commands.go @@ -0,0 +1,45 @@ +package operator + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + operatorCmd := &cobra.Command{ + Use: consts.PreludeOperatorStr, + Short: "Manage connection to Prelude's Operator", + Long: help.GetHelpFor([]string{consts.PreludeOperatorStr}), + GroupID: consts.GenericHelpGroup, + Run: func(cmd *cobra.Command, args []string) { + OperatorCmd(cmd, con, args) + }, + } + + operatorConnectCmd := &cobra.Command{ + Use: consts.ConnectStr, + Short: "Connect with Prelude's Operator", + Long: help.GetHelpFor([]string{consts.PreludeOperatorStr, consts.ConnectStr}), + Run: func(cmd *cobra.Command, args []string) { + ConnectCmd(cmd, con, args) + }, + Args: cobra.ExactArgs(1), + } + operatorCmd.AddCommand(operatorConnectCmd) + flags.Bind("operator", false, operatorConnectCmd, func(f *pflag.FlagSet) { + f.BoolP("skip-existing", "s", false, "Do not add existing sessions as Operator Agents") + f.StringP("aes-key", "a", "abcdefghijklmnopqrstuvwxyz012345", "AES key for communication encryption") + f.StringP("range", "r", "sliver", "Agents range") + }) + carapace.Gen(operatorConnectCmd).PositionalCompletion( + carapace.ActionValues().Usage("connection string to the Operator Host (e.g. 127.0.0.1:1234)")) + + return []*cobra.Command{operatorCmd} +} diff --git a/client/command/reaction/commands.go b/client/command/reaction/commands.go new file mode 100644 index 0000000000..5c8d215a30 --- /dev/null +++ b/client/command/reaction/commands.go @@ -0,0 +1,87 @@ +package reaction + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + reactionCmd := &cobra.Command{ + Use: consts.ReactionStr, + Short: "Manage automatic reactions to events", + Long: help.GetHelpFor([]string{consts.ReactionStr}), + Run: func(cmd *cobra.Command, args []string) { + ReactionCmd(cmd, con, args) + }, + GroupID: consts.SliverHelpGroup, + } + + reactionSetCmd := &cobra.Command{ + Use: consts.SetStr, + Short: "Set a reaction to an event", + Long: help.GetHelpFor([]string{consts.ReactionStr, consts.SetStr}), + Run: func(cmd *cobra.Command, args []string) { + ReactionSetCmd(cmd, con, args) + }, + } + reactionCmd.AddCommand(reactionSetCmd) + flags.Bind("reactions", false, reactionSetCmd, func(f *pflag.FlagSet) { + f.StringP("event", "e", "", "specify the event type to react to") + }) + + flags.BindFlagCompletions(reactionSetCmd, func(comp *carapace.ActionMap) { + (*comp)["event"] = carapace.ActionValues( + consts.SessionOpenedEvent, + consts.SessionClosedEvent, + consts.SessionUpdateEvent, + consts.BeaconRegisteredEvent, + consts.CanaryEvent, + consts.WatchtowerEvent, + ) + }) + + reactionUnsetCmd := &cobra.Command{ + Use: consts.UnsetStr, + Short: "Unset an existing reaction", + Long: help.GetHelpFor([]string{consts.ReactionStr, consts.UnsetStr}), + Run: func(cmd *cobra.Command, args []string) { + ReactionUnsetCmd(cmd, con, args) + }, + } + reactionCmd.AddCommand(reactionUnsetCmd) + flags.Bind("reactions", false, reactionUnsetCmd, func(f *pflag.FlagSet) { + f.IntP("id", "i", 0, "the id of the reaction to remove") + }) + flags.BindFlagCompletions(reactionUnsetCmd, func(comp *carapace.ActionMap) { + (*comp)["id"] = ReactionIDCompleter(con) + }) + + reactionSaveCmd := &cobra.Command{ + Use: consts.SaveStr, + Short: "Save current reactions to disk", + Long: help.GetHelpFor([]string{consts.ReactionStr, consts.SaveStr}), + Run: func(cmd *cobra.Command, args []string) { + ReactionSaveCmd(cmd, con, args) + }, + } + reactionCmd.AddCommand(reactionSaveCmd) + + reactionReloadCmd := &cobra.Command{ + Use: consts.ReloadStr, + Short: "Reload reactions from disk, replaces the running configuration", + Long: help.GetHelpFor([]string{consts.ReactionStr, consts.ReloadStr}), + Run: func(cmd *cobra.Command, args []string) { + ReactionReloadCmd(cmd, con, args) + }, + } + reactionCmd.AddCommand(reactionReloadCmd) + + return []*cobra.Command{reactionCmd} +} diff --git a/client/command/server.go b/client/command/server.go index 399e9a4c73..5ff9306a07 100644 --- a/client/command/server.go +++ b/client/command/server.go @@ -19,13 +19,8 @@ package command */ import ( - "os" - "github.com/reeflective/console" - "github.com/reeflective/console/commands/readline" - "github.com/rsteube/carapace" "github.com/spf13/cobra" - "github.com/spf13/pflag" "github.com/bishopfox/sliver/client/command/alias" "github.com/bishopfox/sliver/client/command/armory" @@ -35,10 +30,10 @@ import ( "github.com/bishopfox/sliver/client/command/creds" "github.com/bishopfox/sliver/client/command/exit" "github.com/bishopfox/sliver/client/command/generate" - "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/command/hosts" "github.com/bishopfox/sliver/client/command/info" "github.com/bishopfox/sliver/client/command/jobs" + "github.com/bishopfox/sliver/client/command/licenses" "github.com/bishopfox/sliver/client/command/loot" "github.com/bishopfox/sliver/client/command/monitor" "github.com/bishopfox/sliver/client/command/operators" @@ -53,7 +48,6 @@ import ( "github.com/bishopfox/sliver/client/command/wireguard" client "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" - "github.com/bishopfox/sliver/client/licenses" ) // ServerCommands returns all commands bound to the server menu, optionally @@ -67,1686 +61,69 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. }, } - // Load Reactions - n, err := reaction.LoadReactions() - if err != nil && !os.IsNotExist(err) { - con.PrintErrorf("Failed to load reactions: %s\n", err) - } else if n > 0 { - con.PrintInfof("Loaded %d reaction(s) from disk\n", n) - } - - // [ Groups ] ---------------------------------------------- - groups := []*cobra.Group{ - {ID: consts.GenericHelpGroup, Title: consts.GenericHelpGroup}, - {ID: consts.NetworkHelpGroup, Title: consts.NetworkHelpGroup}, - {ID: consts.PayloadsHelpGroup, Title: consts.PayloadsHelpGroup}, - {ID: consts.SliverHelpGroup, Title: consts.SliverHelpGroup}, - } - server.AddGroup(groups...) - - // [ Exit ] --------------------------------------------------------------- - exitCmd := &cobra.Command{ - Use: "exit", - Short: "Exit the program", - Run: func(cmd *cobra.Command, args []string) { - exit.ExitCmd(cmd, con, args) - }, - GroupID: consts.GenericHelpGroup, - } - server.AddCommand(exitCmd) - - // [ Aliases ] --------------------------------------------- - - aliasCmd := &cobra.Command{ - Use: consts.AliasesStr, - Short: "List current aliases", - Long: help.GetHelpFor([]string{consts.AliasesStr}), - Run: func(cmd *cobra.Command, args []string) { - alias.AliasesCmd(cmd, con, args) - }, - GroupID: consts.GenericHelpGroup, - } - server.AddCommand(aliasCmd) - - aliasLoadCmd := &cobra.Command{ - Use: consts.LoadStr + " [ALIAS]", - Short: "Load a command alias", - Long: help.GetHelpFor([]string{consts.AliasesStr, consts.LoadStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - alias.AliasesLoadCmd(cmd, con, args) - }, - } - carapace.Gen(aliasLoadCmd).PositionalCompletion( - carapace.ActionDirectories().Tag("alias directory").Usage("path to the alias directory")) - aliasCmd.AddCommand(aliasLoadCmd) - - aliasInstallCmd := &cobra.Command{ - Use: consts.InstallStr + " [ALIAS]", - Short: "Install a command alias", - Long: help.GetHelpFor([]string{consts.AliasesStr, consts.InstallStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - alias.AliasesInstallCmd(cmd, con, args) - }, - } - carapace.Gen(aliasInstallCmd).PositionalCompletion(carapace.ActionFiles().Tag("alias file")) - aliasCmd.AddCommand(aliasInstallCmd) - - aliasRemove := &cobra.Command{ - Use: consts.RmStr + " [ALIAS]", - Short: "Remove an alias", - Long: help.GetHelpFor([]string{consts.RmStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - alias.AliasesRemoveCmd(cmd, con, args) - }, - } - carapace.Gen(aliasRemove).PositionalCompletion(alias.AliasCompleter()) - aliasCmd.AddCommand(aliasRemove) - - // [ Armory ] --------------------------------------------- - - armoryCmd := &cobra.Command{ - Use: consts.ArmoryStr, - Short: "Automatically download and install extensions/aliases", - Long: help.GetHelpFor([]string{consts.ArmoryStr}), - Run: func(cmd *cobra.Command, args []string) { - armory.ArmoryCmd(cmd, con, args) - }, - GroupID: consts.GenericHelpGroup, - } - Flags("armory", true, armoryCmd, func(f *pflag.FlagSet) { - f.BoolP("insecure", "I", false, "skip tls certificate validation") - f.StringP("proxy", "p", "", "specify a proxy url (e.g. http://localhost:8080)") - f.BoolP("ignore-cache", "c", false, "ignore metadata cache, force refresh") - f.StringP("timeout", "t", "15m", "download timeout") - }) - server.AddCommand(armoryCmd) - - armoryInstallCmd := &cobra.Command{ - Use: consts.InstallStr, - Short: "Install an alias or extension", - Long: help.GetHelpFor([]string{consts.ArmoryStr, consts.InstallStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - armory.ArmoryInstallCmd(cmd, con, args) - }, - } - carapace.Gen(armoryInstallCmd).PositionalCompletion( - armory.AliasExtensionOrBundleCompleter().Usage("name of the extension or alias to install")) - armoryCmd.AddCommand(armoryInstallCmd) - - armoryUpdateCmd := &cobra.Command{ - Use: consts.UpdateStr, - Short: "Update installed an aliases and extensions", - Long: help.GetHelpFor([]string{consts.ArmoryStr, consts.UpdateStr}), - Run: func(cmd *cobra.Command, args []string) { - armory.ArmoryUpdateCmd(cmd, con, args) - }, - } - armoryCmd.AddCommand(armoryUpdateCmd) - - armorySearchCmd := &cobra.Command{ - Use: consts.SearchStr, - Short: "Search for aliases and extensions by name (regex)", - Long: help.GetHelpFor([]string{consts.ArmoryStr, consts.SearchStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - armory.ArmorySearchCmd(cmd, con, args) - }, - } - carapace.Gen(armorySearchCmd).PositionalCompletion(carapace.ActionValues().Usage("a name regular expression")) - armoryCmd.AddCommand(armorySearchCmd) - - // [ Update ] -------------------------------------------------------------- - - updateCmd := &cobra.Command{ - Use: consts.UpdateStr, - Short: "Check for updates", - Long: help.GetHelpFor([]string{consts.UpdateStr}), - Run: func(cmd *cobra.Command, args []string) { - update.UpdateCmd(cmd, con, args) - }, - GroupID: consts.GenericHelpGroup, - } - Flags("update", false, updateCmd, func(f *pflag.FlagSet) { - f.BoolP("prereleases", "P", false, "include pre-released (unstable) versions") - f.StringP("proxy", "p", "", "specify a proxy url (e.g. http://localhost:8080)") - f.StringP("save", "s", "", "save downloaded files to specific directory (default user home dir)") - f.BoolP("insecure", "I", false, "skip tls certificate validation") - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - server.AddCommand(updateCmd) - - versionCmd := &cobra.Command{ - Use: consts.VersionStr, - Short: "Display version information", - Long: help.GetHelpFor([]string{consts.VersionStr}), - Run: func(cmd *cobra.Command, args []string) { - update.VerboseVersionsCmd(cmd, con, args) - }, - GroupID: consts.GenericHelpGroup, - } - Flags("update", false, versionCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - server.AddCommand(versionCmd) - - // [ Jobs ] ----------------------------------------------------------------- - - jobsCmd := &cobra.Command{ - Use: consts.JobsStr, - Short: "Job control", - Long: help.GetHelpFor([]string{consts.JobsStr}), - Run: func(cmd *cobra.Command, args []string) { - jobs.JobsCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - Flags("jobs", true, jobsCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("jobs", false, jobsCmd, func(f *pflag.FlagSet) { - f.Int32P("kill", "k", -1, "kill a background job") - f.BoolP("kill-all", "K", false, "kill all jobs") - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - FlagComps(jobsCmd, func(comp *carapace.ActionMap) { - (*comp)["kill"] = jobs.JobsIDCompleter(con) - }) - server.AddCommand(jobsCmd) - - mtlsCmd := &cobra.Command{ - Use: consts.MtlsStr, - Short: "Start an mTLS listener", - Long: help.GetHelpFor([]string{consts.MtlsStr}), - Run: func(cmd *cobra.Command, args []string) { - jobs.MTLSListenerCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - Flags("mTLS listener", false, mtlsCmd, func(f *pflag.FlagSet) { - f.StringP("lhost", "L", "", "interface to bind server to") - f.Uint32P("lport", "l", generate.DefaultMTLSLPort, "tcp listen port") - f.BoolP("persistent", "p", false, "make persistent across restarts") - }) - server.AddCommand(mtlsCmd) - - wgCmd := &cobra.Command{ - Use: consts.WGStr, - Short: "Start a WireGuard listener", - Long: help.GetHelpFor([]string{consts.WGStr}), - Run: func(cmd *cobra.Command, args []string) { - jobs.WGListenerCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - Flags("WireGuard listener", false, wgCmd, func(f *pflag.FlagSet) { - f.StringP("lhost", "L", "", "interface to bind server to") - f.Uint32P("lport", "l", generate.DefaultWGLPort, "udp listen port") - f.Uint32P("nport", "n", generate.DefaultWGNPort, "virtual tun interface listen port") - f.Uint32P("key-port", "x", generate.DefaultWGKeyExPort, "virtual tun interface key exchange port") - f.BoolP("persistent", "p", false, "make persistent across restarts") - }) - server.AddCommand(wgCmd) - - dnsCmd := &cobra.Command{ - Use: consts.DnsStr, - Short: "Start a DNS listener", - Long: help.GetHelpFor([]string{consts.DnsStr}), - Run: func(cmd *cobra.Command, args []string) { - jobs.DNSListenerCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - Flags("DNS listener", false, dnsCmd, func(f *pflag.FlagSet) { - f.StringP("domains", "d", "", "parent domain(s) to use for DNS c2") - f.BoolP("no-canaries", "c", false, "disable dns canary detection") - f.StringP("lhost", "L", "", "interface to bind server to") - f.Uint32P("lport", "l", generate.DefaultDNSLPort, "udp listen port") - f.BoolP("disable-otp", "D", false, "disable otp authentication") - f.BoolP("persistent", "p", false, "make persistent across restarts") - }) - server.AddCommand(dnsCmd) - - httpCmd := &cobra.Command{ - Use: consts.HttpStr, - Short: "Start an HTTP listener", - Long: help.GetHelpFor([]string{consts.HttpStr}), - Run: func(cmd *cobra.Command, args []string) { - jobs.HTTPListenerCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - Flags("HTTP listener", false, httpCmd, func(f *pflag.FlagSet) { - f.StringP("domain", "d", "", "limit responses to specific domain") - f.StringP("website", "w", "", "website name (see websites cmd)") - f.StringP("lhost", "L", "", "interface to bind server to") - f.Uint32P("lport", "l", generate.DefaultHTTPLPort, "tcp listen port") - f.BoolP("disable-otp", "D", false, "disable otp authentication") - f.StringP("long-poll-timeout", "T", "1s", "server-side long poll timeout") - f.StringP("long-poll-jitter", "J", "2s", "server-side long poll jitter") - f.BoolP("persistent", "p", false, "make persistent across restarts") - }) - server.AddCommand(httpCmd) - - httpsCmd := &cobra.Command{ - Use: consts.HttpsStr, - Short: "Start an HTTPS listener", - Long: help.GetHelpFor([]string{consts.HttpsStr}), - Run: func(cmd *cobra.Command, args []string) { - jobs.HTTPSListenerCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - Flags("HTTPS listener", false, httpsCmd, func(f *pflag.FlagSet) { - f.StringP("domain", "d", "", "limit responses to specific domain") - f.StringP("website", "w", "", "website name (see websites cmd)") - f.StringP("lhost", "L", "", "interface to bind server to") - f.Uint32P("lport", "l", generate.DefaultHTTPSLPort, "tcp listen port") - f.BoolP("disable-otp", "D", false, "disable otp authentication") - f.StringP("long-poll-timeout", "T", "1s", "server-side long poll timeout") - f.StringP("long-poll-jitter", "J", "2s", "server-side long poll jitter") - - f.StringP("cert", "c", "", "PEM encoded certificate file") - f.StringP("key", "k", "", "PEM encoded private key file") - f.BoolP("lets-encrypt", "e", false, "attempt to provision a let's encrypt certificate") - f.BoolP("disable-randomized-jarm", "E", false, "disable randomized jarm fingerprints") - - f.BoolP("persistent", "p", false, "make persistent across restarts") - }) - server.AddCommand(httpsCmd) - - stageCmd := &cobra.Command{ - Use: consts.StageListenerStr, - Short: "Start a stager listener", - Long: help.GetHelpFor([]string{consts.StageListenerStr}), - Run: func(cmd *cobra.Command, args []string) { - jobs.StageListenerCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - Flags("stage listener", false, stageCmd, func(f *pflag.FlagSet) { - f.StringP("profile", "p", "", "implant profile name to link with the listener") - f.StringP("url", "u", "", "URL to which the stager will call back to") - f.StringP("cert", "c", "", "path to PEM encoded certificate file (HTTPS only)") - f.StringP("key", "k", "", "path to PEM encoded private key file (HTTPS only)") - f.BoolP("lets-encrypt", "e", false, "attempt to provision a let's encrypt certificate (HTTPS only)") - f.String("aes-encrypt-key", "", "encrypt stage with AES encryption key") - f.String("aes-encrypt-iv", "", "encrypt stage with AES encryption iv") - f.StringP("compress", "C", "none", "compress the stage before encrypting (zlib, gzip, deflate9, none)") - f.BoolP("prepend-size", "P", false, "prepend the size of the stage to the payload (to use with MSF stagers)") - }) - FlagComps(stageCmd, func(comp *carapace.ActionMap) { - (*comp)["profile"] = generate.ProfileNameCompleter(con) - (*comp)["cert"] = carapace.ActionFiles().Tag("certificate file") - (*comp)["key"] = carapace.ActionFiles().Tag("key file") - (*comp)["compress"] = carapace.ActionValues([]string{"zlib", "gzip", "deflate9", "none"}...).Tag("compression formats") - }) - server.AddCommand(stageCmd) - - // [ Operators ] -------------------------------------------------------------- - - operatorsCmd := &cobra.Command{ - Use: consts.OperatorsStr, - Short: "Manage operators", - Long: help.GetHelpFor([]string{consts.OperatorsStr}), - Run: func(cmd *cobra.Command, args []string) { - operators.OperatorsCmd(cmd, con, args) - }, - GroupID: consts.GenericHelpGroup, - } - Flags("operators", false, operatorsCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - server.AddCommand(operatorsCmd) - - // Server-only commands. + // [ Server-only ] if serverCmds != nil { server.AddGroup(&cobra.Group{ID: consts.MultiplayerHelpGroup, Title: consts.MultiplayerHelpGroup}) server.AddCommand(serverCmds()...) } - // [ Sessions ] -------------------------------------------------------------- - - sessionsCmd := &cobra.Command{ - Use: consts.SessionsStr, - Short: "Session management", - Long: help.GetHelpFor([]string{consts.SessionsStr}), - Run: func(cmd *cobra.Command, args []string) { - sessions.SessionsCmd(cmd, con, args) - }, - GroupID: consts.SliverHelpGroup, - } - Flags("sessions", true, sessionsCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("sessions", false, sessionsCmd, func(f *pflag.FlagSet) { - f.StringP("interact", "i", "", "interact with a session") - f.StringP("kill", "k", "", "kill the designated session") - f.BoolP("kill-all", "K", false, "kill all the sessions") - f.BoolP("clean", "C", false, "clean out any sessions marked as [DEAD]") - f.BoolP("force", "F", false, "force session action without waiting for results") - - f.StringP("filter", "f", "", "filter sessions by substring") - f.StringP("filter-re", "e", "", "filter sessions by regular expression") - }) - FlagComps(sessionsCmd, func(comp *carapace.ActionMap) { - (*comp)["interact"] = use.BeaconAndSessionIDCompleter(con) - (*comp)["kill"] = use.BeaconAndSessionIDCompleter(con) - }) - server.AddCommand(sessionsCmd) - - sessionsPruneCmd := &cobra.Command{ - Use: consts.PruneStr, - Short: "Kill all stale/dead sessions", - Long: help.GetHelpFor([]string{consts.SessionsStr, consts.PruneStr}), - Run: func(cmd *cobra.Command, args []string) { - sessions.SessionsPruneCmd(cmd, con, args) - }, - } - Flags("prune", false, sessionsPruneCmd, func(f *pflag.FlagSet) { - f.BoolP("force", "F", false, "Force the killing of stale/dead sessions") - }) - sessionsCmd.AddCommand(sessionsPruneCmd) - - // [ Use ] -------------------------------------------------------------- - - useCmd := &cobra.Command{ - Use: consts.UseStr, - Short: "Switch the active session or beacon", - Long: help.GetHelpFor([]string{consts.UseStr}), - Run: func(cmd *cobra.Command, args []string) { - use.UseCmd(cmd, con, args) - }, - GroupID: consts.SliverHelpGroup, - } - Flags("use", true, useCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(useCmd).PositionalCompletion(use.BeaconAndSessionIDCompleter(con)) - server.AddCommand(useCmd) - - useSessionCmd := &cobra.Command{ - Use: consts.SessionsStr, - Short: "Switch the active session", - Long: help.GetHelpFor([]string{consts.UseStr, consts.SessionsStr}), - Run: func(cmd *cobra.Command, args []string) { - use.UseSessionCmd(cmd, con, args) - }, - } - carapace.Gen(useSessionCmd).PositionalCompletion(use.SessionIDCompleter(con)) - useCmd.AddCommand(useSessionCmd) - - useBeaconCmd := &cobra.Command{ - Use: consts.BeaconsStr, - Short: "Switch the active beacon", - Long: help.GetHelpFor([]string{consts.UseStr, consts.BeaconsStr}), - Run: func(cmd *cobra.Command, args []string) { - use.UseBeaconCmd(cmd, con, args) - }, - } - carapace.Gen(useBeaconCmd).PositionalCompletion(use.BeaconIDCompleter(con)) - useCmd.AddCommand(useBeaconCmd) - - // [ Settings ] -------------------------------------------------------------- - - settingsCmd := &cobra.Command{ - Use: consts.SettingsStr, - Short: "Manage client settings", - Long: help.GetHelpFor([]string{consts.SettingsStr}), - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsCmd(cmd, con, args) - }, - GroupID: consts.GenericHelpGroup, - } - settingsCmd.AddCommand(&cobra.Command{ - Use: consts.SaveStr, - Short: "Save the current settings to disk", - Long: help.GetHelpFor([]string{consts.SettingsStr, consts.SaveStr}), - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsSaveCmd(cmd, con, args) - }, - }) - settingsCmd.AddCommand(&cobra.Command{ - Use: consts.TablesStr, - Short: "Modify tables setting (style)", - Long: help.GetHelpFor([]string{consts.SettingsStr, consts.TablesStr}), - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsTablesCmd(cmd, con, args) - }, - }) - settingsCmd.AddCommand(&cobra.Command{ - Use: "beacon-autoresults", - Short: "Automatically display beacon task results when completed", - Long: help.GetHelpFor([]string{consts.SettingsStr, "beacon-autoresults"}), - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsBeaconsAutoResultCmd(cmd, con, args) - }, - }) - settingsCmd.AddCommand(&cobra.Command{ - Use: "autoadult", - Short: "Automatically accept OPSEC warnings", - Long: help.GetHelpFor([]string{consts.SettingsStr, "autoadult"}), - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsAutoAdultCmd(cmd, con, args) - }, - }) - settingsCmd.AddCommand(&cobra.Command{ - Use: "always-overflow", - Short: "Disable table pagination", - Long: help.GetHelpFor([]string{consts.SettingsStr, "always-overflow"}), - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsAlwaysOverflow(cmd, con, args) - }, - }) - settingsCmd.AddCommand(&cobra.Command{ - Use: "small-terminal", - Short: "Set the small terminal width", - Long: help.GetHelpFor([]string{consts.SettingsStr, "small-terminal"}), - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsSmallTerm(cmd, con, args) - }, - }) - settingsCmd.AddCommand(&cobra.Command{ - Use: "user-connect", - Short: "Enable user connections/disconnections (can be very verbose when they use CLI)", - Run: func(cmd *cobra.Command, args []string) { - settings.SettingsUserConnect(cmd, con, args) - }, - }) - settingsCmd.AddCommand(&cobra.Command{ - Use: "console-logs", - Short: "Log console output (toggle)", - Long: help.GetHelpFor([]string{consts.SettingsStr, "console-logs"}), - Run: func(ctx *cobra.Command, args []string) { - settings.SettingsConsoleLogs(ctx, con) - }, - }) - server.AddCommand(settingsCmd) - - // [ Info ] -------------------------------------------------------------- - - infoCmd := &cobra.Command{ - Use: consts.InfoStr, - Short: "Get info about session", - Long: help.GetHelpFor([]string{consts.InfoStr}), - Run: func(cmd *cobra.Command, args []string) { - info.InfoCmd(cmd, con, args) - }, - GroupID: consts.SliverHelpGroup, - } - Flags("use", false, infoCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(infoCmd).PositionalCompletion(use.BeaconAndSessionIDCompleter(con)) - server.AddCommand(infoCmd) - - // [ Shellcode Encoders ] -------------------------------------------------------------- - - shikataGaNaiCmd := &cobra.Command{ - Use: consts.ShikataGaNai, - Short: "Polymorphic binary shellcode encoder (ノ ゜Д゜)ノ ︵ 仕方がない", - Long: help.GetHelpFor([]string{consts.ShikataGaNai}), - Run: func(cmd *cobra.Command, args []string) { - sgn.ShikataGaNaiCmd(cmd, con, args) - }, - Args: cobra.ExactArgs(1), - GroupID: consts.PayloadsHelpGroup, - } - server.AddCommand(shikataGaNaiCmd) - Flags("shikata ga nai", false, shikataGaNaiCmd, func(f *pflag.FlagSet) { - f.StringP("save", "s", "", "save output to local file") - f.StringP("arch", "a", "amd64", "architecture of shellcode") - f.IntP("iterations", "i", 1, "number of iterations") - f.StringP("bad-chars", "b", "", "hex encoded bad characters to avoid (e.g. 0001)") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - FlagComps(shikataGaNaiCmd, func(comp *carapace.ActionMap) { - (*comp)["arch"] = carapace.ActionValues("386", "amd64").Tag("shikata-ga-nai architectures") - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save shellcode") - }) - carapace.Gen(shikataGaNaiCmd).PositionalCompletion(carapace.ActionFiles().Tag("shellcode file")) - - // [ Generate ] -------------------------------------------------------------- - - generateCmd := &cobra.Command{ - Use: consts.GenerateStr, - Short: "Generate an implant binary", - Long: help.GetHelpFor([]string{consts.GenerateStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.GenerateCmd(cmd, con, args) - }, - GroupID: consts.PayloadsHelpGroup, - } - Flags("generate", true, generateCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("session", false, generateCmd, func(f *pflag.FlagSet) { - f.StringP("os", "o", "windows", "operating system") - f.StringP("arch", "a", "amd64", "cpu architecture") - f.StringP("name", "N", "", "agent name") - f.BoolP("debug", "d", false, "enable debug features") - f.StringP("debug-file", "O", "", "path to debug output") - f.BoolP("evasion", "e", false, "enable evasion features (e.g. overwrite user space hooks)") - f.BoolP("skip-symbols", "l", false, "skip symbol obfuscation") - f.StringP("template", "I", "sliver", "implant code template") - f.BoolP("external-builder", "E", false, "use an external builder") - f.BoolP("disable-sgn", "G", false, "disable shikata ga nai shellcode encoder") - - f.StringP("canary", "c", "", "canary domain(s)") - - f.StringP("mtls", "m", "", "mtls connection strings") - f.StringP("wg", "g", "", "wg connection strings") - f.StringP("http", "b", "", "http(s) connection strings") - f.StringP("dns", "n", "", "dns connection strings") - f.StringP("named-pipe", "p", "", "named-pipe connection strings") - f.StringP("tcp-pivot", "i", "", "tcp-pivot connection strings") - - f.Uint32P("key-exchange", "X", generate.DefaultWGKeyExPort, "wg key-exchange port") - f.Uint32P("tcp-comms", "T", generate.DefaultWGNPort, "wg c2 comms port") - - f.BoolP("run-at-load", "R", false, "run the implant entrypoint from DllMain/Constructor (shared library only)") - f.BoolP("netgo", "q", false, "force the use of netgo") - f.StringP("traffic-encoders", "A", "", "comma separated list of traffic encoders to enable") - - f.StringP("strategy", "Z", "", "specify a connection strategy (r = random, rd = random domain, s = sequential)") - f.Int64P("reconnect", "j", generate.DefaultReconnect, "attempt to reconnect every n second(s)") - f.Int64P("poll-timeout", "P", generate.DefaultPollTimeout, "long poll request timeout") - f.Uint32P("max-errors", "k", generate.DefaultMaxErrors, "max number of connection errors") - - f.StringP("limit-datetime", "w", "", "limit execution to before datetime") - f.BoolP("limit-domainjoined", "x", false, "limit execution to domain joined machines") - f.StringP("limit-username", "y", "", "limit execution to specified username") - f.StringP("limit-hostname", "z", "", "limit execution to specified hostname") - f.StringP("limit-fileexists", "F", "", "limit execution to hosts with this file in the filesystem") - f.StringP("limit-locale", "L", "", "limit execution to hosts that match this locale") - - f.StringP("format", "f", "exe", "Specifies the output formats, valid values are: 'exe', 'shared' (for dynamic libraries), 'service' (see: `psexec` for more info) and 'shellcode' (windows only)") - f.StringP("save", "s", "", "directory/file to the binary to") - }) - FlagComps(generateCmd, func(comp *carapace.ActionMap) { - (*comp)["debug-file"] = carapace.ActionFiles() - (*comp)["os"] = generate.OSCompleter(con) - (*comp)["arch"] = generate.ArchCompleter(con) - (*comp)["strategy"] = carapace.ActionValuesDescribed([]string{"r", "random", "rd", "random domain", "s", "sequential"}...).Tag("C2 strategy") - (*comp)["format"] = generate.FormatCompleter() - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") - }) - server.AddCommand(generateCmd) - - generateBeaconCmd := &cobra.Command{ - Use: consts.BeaconStr, - Short: "Generate a beacon binary", - Long: help.GetHelpFor([]string{consts.GenerateStr, consts.BeaconStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.GenerateBeaconCmd(cmd, con, args) - }, - } - Flags("beacon", false, generateBeaconCmd, func(f *pflag.FlagSet) { - f.Int64P("days", "D", 0, "beacon interval days") - f.Int64P("hours", "H", 0, "beacon interval hours") - f.Int64P("minutes", "M", 0, "beacon interval minutes") - f.Int64P("seconds", "S", 60, "beacon interval seconds") - f.Int64P("jitter", "J", 30, "beacon interval jitter in seconds") - - // Generate flags - f.StringP("os", "o", "windows", "operating system") - f.StringP("arch", "a", "amd64", "cpu architecture") - f.StringP("name", "N", "", "agent name") - f.BoolP("debug", "d", false, "enable debug features") - f.StringP("debug-file", "O", "", "path to debug output") - f.BoolP("evasion", "e", false, "enable evasion features (e.g. overwrite user space hooks)") - f.BoolP("skip-symbols", "l", false, "skip symbol obfuscation") - f.StringP("template", "I", "sliver", "implant code template") - f.BoolP("external-builder", "E", false, "use an external builder") - f.BoolP("disable-sgn", "G", false, "disable shikata ga nai shellcode encoder") - - f.StringP("canary", "c", "", "canary domain(s)") - - f.StringP("mtls", "m", "", "mtls connection strings") - f.StringP("wg", "g", "", "wg connection strings") - f.StringP("http", "b", "", "http(s) connection strings") - f.StringP("dns", "n", "", "dns connection strings") - f.StringP("named-pipe", "p", "", "named-pipe connection strings") - f.StringP("tcp-pivot", "i", "", "tcp-pivot connection strings") - - f.Uint32P("key-exchange", "X", generate.DefaultWGKeyExPort, "wg key-exchange port") - f.Uint32P("tcp-comms", "T", generate.DefaultWGNPort, "wg c2 comms port") - - f.BoolP("run-at-load", "R", false, "run the implant entrypoint from DllMain/Constructor (shared library only)") - f.BoolP("netgo", "q", false, "force the use of netgo") - f.StringP("traffic-encoders", "A", "", "comma separated list of traffic encoders to enable") - - f.StringP("strategy", "Z", "", "specify a connection strategy (r = random, rd = random domain, s = sequential)") - f.Int64P("reconnect", "j", generate.DefaultReconnect, "attempt to reconnect every n second(s)") - f.Int64P("poll-timeout", "P", generate.DefaultPollTimeout, "long poll request timeout") - f.Uint32P("max-errors", "k", generate.DefaultMaxErrors, "max number of connection errors") - - f.StringP("limit-datetime", "w", "", "limit execution to before datetime") - f.BoolP("limit-domainjoined", "x", false, "limit execution to domain joined machines") - f.StringP("limit-username", "y", "", "limit execution to specified username") - f.StringP("limit-hostname", "z", "", "limit execution to specified hostname") - f.StringP("limit-fileexists", "F", "", "limit execution to hosts with this file in the filesystem") - f.StringP("limit-locale", "L", "", "limit execution to hosts that match this locale") - - f.StringP("format", "f", "exe", "Specifies the output formats, valid values are: 'exe', 'shared' (for dynamic libraries), 'service' (see: `psexec` for more info) and 'shellcode' (windows only)") - f.StringP("save", "s", "", "directory/file to the binary to") - }) - FlagComps(generateBeaconCmd, func(comp *carapace.ActionMap) { - (*comp)["debug-file"] = carapace.ActionFiles() - (*comp)["os"] = generate.OSCompleter(con) - (*comp)["arch"] = generate.ArchCompleter(con) - (*comp)["strategy"] = carapace.ActionValuesDescribed([]string{"r", "random", "rd", "random domain", "s", "sequential"}...).Tag("C2 strategy") - (*comp)["format"] = generate.FormatCompleter() - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") - }) - generateCmd.AddCommand(generateBeaconCmd) - - generateStagerCmd := &cobra.Command{ - Use: consts.MsfStagerStr, - Short: "Generate a stager using Metasploit (requires local Metasploit installation)", - Long: help.GetHelpFor([]string{consts.MsfStagerStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.GenerateStagerCmd(cmd, con, args) - }, - } - Flags("stager", false, generateStagerCmd, func(f *pflag.FlagSet) { - f.StringP("os", "o", "windows", "operating system") - f.StringP("arch", "a", "amd64", "cpu architecture") - f.StringP("lhost", "L", "", "Listening host") - f.Uint32P("lport", "l", 8443, "Listening port") - f.StringP("protocol", "r", "tcp", "Staging protocol (tcp/http/https)") - f.StringP("format", "f", "raw", "Output format (msfvenom formats, see help generate msf-stager for the list)") - f.StringP("badchars", "b", "", "bytes to exclude from stage shellcode") - f.StringP("save", "s", "", "directory to save the generated stager to") - f.StringP("advanced", "d", "", "Advanced options for the stager using URI query syntax (option1=value1&option2=value2...)") - }) - generateCmd.AddCommand(generateStagerCmd) - - generateInfoCmd := &cobra.Command{ - Use: consts.CompilerInfoStr, - Short: "Get information about the server's compiler", - Long: help.GetHelpFor([]string{consts.CompilerInfoStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.GenerateInfoCmd(cmd, con, args) - }, - } - generateCmd.AddCommand(generateInfoCmd) - - // Traffic Encoder SubCommands - trafficEncodersCmd := &cobra.Command{ - Use: consts.TrafficEncodersStr, - Short: "Manage implant traffic encoders", - Long: help.GetHelpFor([]string{consts.GenerateStr, consts.TrafficEncodersStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.TrafficEncodersCmd(cmd, con, args) - }, - } - generateCmd.AddCommand(trafficEncodersCmd) - - trafficEncodersAddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add a new traffic encoder to the server from the local file system", - Long: help.GetHelpFor([]string{consts.GenerateStr, consts.TrafficEncodersStr, consts.AddStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - generate.TrafficEncodersAddCmd(cmd, con, args) - }, - } - Flags("", false, trafficEncodersAddCmd, func(f *pflag.FlagSet) { - f.BoolP("skip-tests", "s", false, "skip testing the traffic encoder (not recommended)") - }) - carapace.Gen(trafficEncodersAddCmd).PositionalCompletion(carapace.ActionFiles("wasm").Tag("wasm files").Usage("local file path (expects .wasm)")) - trafficEncodersCmd.AddCommand(trafficEncodersAddCmd) - - trafficEncodersRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a traffic encoder from the server", - Long: help.GetHelpFor([]string{consts.GenerateStr, consts.TrafficEncodersStr, consts.RmStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - generate.TrafficEncodersRemoveCmd(cmd, con, args) - }, - } - carapace.Gen(trafficEncodersRmCmd).PositionalCompletion(generate.TrafficEncodersCompleter(con).Usage("traffic encoder to remove")) - trafficEncodersCmd.AddCommand(trafficEncodersRmCmd) - - // [ Regenerate ] -------------------------------------------------------------- - - regenerateCmd := &cobra.Command{ - Use: consts.RegenerateStr, - Short: "Regenerate an implant", - Long: help.GetHelpFor([]string{consts.RegenerateStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - generate.RegenerateCmd(cmd, con, args) - }, - GroupID: consts.PayloadsHelpGroup, - } - Flags("regenerate", false, regenerateCmd, func(f *pflag.FlagSet) { - f.StringP("save", "s", "", "directory/file to the binary to") - }) - FlagComps(regenerateCmd, func(comp *carapace.ActionMap) { - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") - }) - carapace.Gen(regenerateCmd).PositionalCompletion(generate.ImplantBuildNameCompleter(con)) - server.AddCommand(regenerateCmd) - - // [ Profiles ] -------------------------------------------------------------- - - profilesCmd := &cobra.Command{ - Use: consts.ProfilesStr, - Short: "List existing profiles", - Long: help.GetHelpFor([]string{consts.ProfilesStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.ProfilesCmd(cmd, con, args) - }, - GroupID: consts.PayloadsHelpGroup, - } - Flags("profiles", true, profilesCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - server.AddCommand(profilesCmd) - - profilesGenerateCmd := &cobra.Command{ - Use: consts.GenerateStr, - Short: "Generate implant from a profile", - Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.GenerateStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - generate.ProfilesGenerateCmd(cmd, con, args) - }, - } - Flags("profiles", false, profilesGenerateCmd, func(f *pflag.FlagSet) { - f.StringP("save", "s", "", "directory/file to the binary to") - f.BoolP("disable-sgn", "G", false, "disable shikata ga nai shellcode encoder") - }) - FlagComps(profilesGenerateCmd, func(comp *carapace.ActionMap) { - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") - }) - carapace.Gen(profilesGenerateCmd).PositionalCompletion(generate.ProfileNameCompleter(con)) - profilesCmd.AddCommand(profilesGenerateCmd) - - profilesNewCmd := &cobra.Command{ - Use: consts.NewStr, - Short: "Create a new implant profile (interactive session)", - Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.NewStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.ProfilesNewCmd(cmd, con, args) - }, - } - Flags("session", false, profilesNewCmd, func(f *pflag.FlagSet) { - f.StringP("os", "o", "windows", "operating system") - f.StringP("arch", "a", "amd64", "cpu architecture") - - f.BoolP("debug", "d", false, "enable debug features") - f.StringP("debug-file", "O", "", "path to debug output") - f.BoolP("evasion", "e", false, "enable evasion features (e.g. overwrite user space hooks)") - f.BoolP("skip-symbols", "l", false, "skip symbol obfuscation") - f.BoolP("disable-sgn", "G", false, "disable shikata ga nai shellcode encoder") - - f.StringP("canary", "c", "", "canary domain(s)") - - f.StringP("name", "N", "", "agent name") - f.StringP("mtls", "m", "", "mtls connection strings") - f.StringP("wg", "g", "", "wg connection strings") - f.StringP("http", "b", "", "http(s) connection strings") - f.StringP("dns", "n", "", "dns connection strings") - f.StringP("named-pipe", "p", "", "named-pipe connection strings") - f.StringP("tcp-pivot", "i", "", "tcp-pivot connection strings") - - f.Uint32P("key-exchange", "X", generate.DefaultWGKeyExPort, "wg key-exchange port") - f.Uint32P("tcp-comms", "T", generate.DefaultWGNPort, "wg c2 comms port") - - f.BoolP("run-at-load", "R", false, "run the implant entrypoint from DllMain/Constructor (shared library only)") - f.StringP("strategy", "Z", "", "specify a connection strategy (r = random, rd = random domain, s = sequential)") - - f.BoolP("netgo", "q", false, "force the use of netgo") - f.StringP("traffic-encoders", "A", "", "comma separated list of traffic encoders to enable") - - f.StringP("template", "I", "sliver", "implant code template") - - f.Int64P("reconnect", "j", generate.DefaultReconnect, "attempt to reconnect every n second(s)") - f.Int64P("poll-timeout", "P", generate.DefaultPollTimeout, "long poll request timeout") - f.Uint32P("max-errors", "k", generate.DefaultMaxErrors, "max number of connection errors") - - f.StringP("limit-datetime", "w", "", "limit execution to before datetime") - f.BoolP("limit-domainjoined", "x", false, "limit execution to domain joined machines") - f.StringP("limit-username", "y", "", "limit execution to specified username") - f.StringP("limit-hostname", "z", "", "limit execution to specified hostname") - f.StringP("limit-fileexists", "F", "", "limit execution to hosts with this file in the filesystem") - f.StringP("limit-locale", "L", "", "limit execution to hosts that match this locale") - - f.StringP("format", "f", "exe", "Specifies the output formats, valid values are: 'exe', 'shared' (for dynamic libraries), 'service' (see: `psexec` for more info) and 'shellcode' (windows only)") - }) - FlagComps(profilesNewCmd, func(comp *carapace.ActionMap) { - (*comp)["debug-file"] = carapace.ActionFiles() - (*comp)["os"] = generate.OSCompleter(con) - (*comp)["arch"] = generate.ArchCompleter(con) - (*comp)["strategy"] = carapace.ActionValuesDescribed([]string{"r", "random", "rd", "random domain", "s", "sequential"}...).Tag("C2 strategy") - (*comp)["format"] = generate.FormatCompleter() - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") - }) - carapace.Gen(profilesNewCmd).PositionalCompletion(carapace.ActionValues().Usage("name of the session profile (optional)")) - profilesCmd.AddCommand(profilesNewCmd) - - // New Beacon Profile Command - profilesNewBeaconCmd := &cobra.Command{ - Use: consts.BeaconStr, - Short: "Create a new implant profile (beacon)", - Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.NewStr, consts.BeaconStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.ProfilesNewBeaconCmd(cmd, con, args) - }, - } - Flags("beacon", false, profilesNewBeaconCmd, func(f *pflag.FlagSet) { - f.Int64P("days", "D", 0, "beacon interval days") - f.Int64P("hours", "H", 0, "beacon interval hours") - f.Int64P("minutes", "M", 0, "beacon interval minutes") - f.Int64P("seconds", "S", 60, "beacon interval seconds") - f.Int64P("jitter", "J", 30, "beacon interval jitter in seconds") - f.BoolP("disable-sgn", "G", false, "disable shikata ga nai shellcode encoder") - - // Generate flags - f.StringP("os", "o", "windows", "operating system") - f.StringP("arch", "a", "amd64", "cpu architecture") - - f.BoolP("debug", "d", false, "enable debug features") - f.StringP("debug-file", "O", "", "path to debug output") - f.BoolP("evasion", "e", false, "enable evasion features (e.g. overwrite user space hooks)") - f.BoolP("skip-symbols", "l", false, "skip symbol obfuscation") - - f.StringP("canary", "c", "", "canary domain(s)") - - f.StringP("name", "N", "", "agent name") - f.StringP("mtls", "m", "", "mtls connection strings") - f.StringP("wg", "g", "", "wg connection strings") - f.StringP("http", "b", "", "http(s) connection strings") - f.StringP("dns", "n", "", "dns connection strings") - f.StringP("named-pipe", "p", "", "named-pipe connection strings") - f.StringP("tcp-pivot", "i", "", "tcp-pivot connection strings") - f.StringP("strategy", "Z", "", "specify a connection strategy (r = random, rd = random domain, s = sequential)") - - f.Uint32P("key-exchange", "X", generate.DefaultWGKeyExPort, "wg key-exchange port") - f.Uint32P("tcp-comms", "T", generate.DefaultWGNPort, "wg c2 comms port") - - f.BoolP("run-at-load", "R", false, "run the implant entrypoint from DllMain/Constructor (shared library only)") - f.BoolP("netgo", "q", false, "force the use of netgo") - f.StringP("traffic-encoders", "A", "", "comma separated list of traffic encoders to enable") - - f.StringP("template", "I", "sliver", "implant code template") - - f.Int64P("reconnect", "j", generate.DefaultReconnect, "attempt to reconnect every n second(s)") - f.Int64P("poll-timeout", "P", generate.DefaultPollTimeout, "long poll request timeout") - f.Uint32P("max-errors", "k", generate.DefaultMaxErrors, "max number of connection errors") - - f.StringP("limit-datetime", "w", "", "limit execution to before datetime") - f.BoolP("limit-domainjoined", "x", false, "limit execution to domain joined machines") - f.StringP("limit-username", "y", "", "limit execution to specified username") - f.StringP("limit-hostname", "z", "", "limit execution to specified hostname") - f.StringP("limit-fileexists", "F", "", "limit execution to hosts with this file in the filesystem") - f.StringP("limit-locale", "L", "", "limit execution to hosts that match this locale") - - f.StringP("format", "f", "exe", "Specifies the output formats, valid values are: 'exe', 'shared' (for dynamic libraries), 'service' (see: `psexec` for more info) and 'shellcode' (windows only)") - }) - FlagComps(profilesNewBeaconCmd, func(comp *carapace.ActionMap) { - (*comp)["debug-file"] = carapace.ActionFiles() - (*comp)["os"] = generate.OSCompleter(con) - (*comp)["arch"] = generate.ArchCompleter(con) - (*comp)["strategy"] = carapace.ActionValuesDescribed([]string{"r", "random", "rd", "random domain", "s", "sequential"}...).Tag("C2 strategy") - (*comp)["format"] = generate.FormatCompleter() - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") - }) - carapace.Gen(profilesNewBeaconCmd).PositionalCompletion(carapace.ActionValues().Usage("name of the beacon profile (optional)")) - profilesNewCmd.AddCommand(profilesNewBeaconCmd) - - profilesRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a profile", - Long: help.GetHelpFor([]string{consts.ProfilesStr, consts.RmStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - generate.ProfilesRmCmd(cmd, con, args) - }, - } - carapace.Gen(profilesRmCmd).PositionalCompletion(generate.ProfileNameCompleter(con)) - profilesCmd.AddCommand(profilesRmCmd) - - implantBuildsCmd := &cobra.Command{ - Use: consts.ImplantBuildsStr, - Short: "List implant builds", - Long: help.GetHelpFor([]string{consts.ImplantBuildsStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.ImplantsCmd(cmd, con, args) - }, - GroupID: consts.PayloadsHelpGroup, - } - Flags("implants", true, implantBuildsCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("implants", false, implantBuildsCmd, func(f *pflag.FlagSet) { - f.StringP("os", "o", "", "filter builds by operating system") - f.StringP("arch", "a", "", "filter builds by cpu architecture") - f.StringP("format", "f", "", "filter builds by artifact format") - f.BoolP("only-sessions", "s", false, "filter interactive sessions") - f.BoolP("only-beacons", "b", false, "filter beacons") - f.BoolP("no-debug", "d", false, "filter builds by debug flag") - }) - FlagComps(profilesNewBeaconCmd, func(comp *carapace.ActionMap) { - (*comp)["os"] = generate.OSCompleter(con) - (*comp)["arch"] = generate.ArchCompleter(con) - (*comp)["format"] = generate.FormatCompleter() - }) - server.AddCommand(implantBuildsCmd) - - implantsRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove implant build", - Long: help.GetHelpFor([]string{consts.ImplantBuildsStr, consts.RmStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - generate.ImplantsRmCmd(cmd, con, args) - }, - } - carapace.Gen(implantsRmCmd).PositionalCompletion(generate.ImplantBuildNameCompleter(con)) - implantBuildsCmd.AddCommand(implantsRmCmd) - - canariesCmd := &cobra.Command{ - Use: consts.CanariesStr, - Short: "List previously generated canaries", - Long: help.GetHelpFor([]string{consts.CanariesStr}), - Run: func(cmd *cobra.Command, args []string) { - generate.CanariesCmd(cmd, con, args) - }, - GroupID: consts.PayloadsHelpGroup, - } - Flags("canaries", false, canariesCmd, func(f *pflag.FlagSet) { - f.BoolP("burned", "b", false, "show only triggered/burned canaries") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Websites ] --------------------------------------------- - - websitesCmd := &cobra.Command{ - Use: consts.WebsitesStr, - Short: "Host static content (used with HTTP C2)", - Long: help.GetHelpFor([]string{consts.WebsitesStr}), - Run: func(cmd *cobra.Command, args []string) { - websites.WebsitesCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - server.AddCommand(websitesCmd) - Flags("websites", true, websitesCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(websitesCmd).PositionalCompletion(websites.WebsiteNameCompleter(con)) - - websitesRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove an entire website and all of its contents", - Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - websites.WebsiteRmCmd(cmd, con, args) - }, - } - carapace.Gen(websitesRmCmd).PositionalCompletion(websites.WebsiteNameCompleter(con)) - websitesCmd.AddCommand(websitesRmCmd) - - websitesRmWebContentCmd := &cobra.Command{ - Use: consts.RmWebContentStr, - Short: "Remove specific content from a website", - Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.RmWebContentStr}), - Run: func(cmd *cobra.Command, args []string) { - websites.WebsitesRmContent(cmd, con, args) - }, - } - Flags("websites", false, websitesRmWebContentCmd, func(f *pflag.FlagSet) { - f.BoolP("recursive", "r", false, "recursively add/rm content") - f.StringP("website", "w", "", "website name") - f.StringP("web-path", "p", "", "http path to host file at") - }) - websitesCmd.AddCommand(websitesRmWebContentCmd) - FlagComps(websitesRmWebContentCmd, func(comp *carapace.ActionMap) { - (*comp)["website"] = websites.WebsiteNameCompleter(con) - }) - - websitesContentCmd := &cobra.Command{ - Use: consts.AddWebContentStr, - Short: "Add content to a website", - Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.RmWebContentStr}), - Run: func(cmd *cobra.Command, args []string) { - websites.WebsitesAddContentCmd(cmd, con, args) - }, - } - Flags("websites", false, websitesContentCmd, func(f *pflag.FlagSet) { - f.StringP("website", "w", "", "website name") - f.StringP("content-type", "m", "", "mime content-type (if blank use file ext.)") - f.StringP("web-path", "p", "/", "http path to host file at") - f.StringP("content", "c", "", "local file path/dir (must use --recursive for dir)") - f.BoolP("recursive", "r", false, "recursively add/rm content") - }) - FlagComps(websitesContentCmd, func(comp *carapace.ActionMap) { - (*comp)["content"] = carapace.ActionFiles().Tag("content directory/files") - (*comp)["website"] = websites.WebsiteNameCompleter(con) - }) - websitesCmd.AddCommand(websitesContentCmd) - - websitesContentTypeCmd := &cobra.Command{ - Use: consts.WebContentTypeStr, - Short: "Update a path's content-type", - Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.WebContentTypeStr}), - Run: func(cmd *cobra.Command, args []string) { - websites.WebsitesUpdateContentCmd(cmd, con, args) - }, - } - Flags("websites", false, websitesContentTypeCmd, func(f *pflag.FlagSet) { - f.StringP("website", "w", "", "website name") - f.StringP("content-type", "m", "", "mime content-type (if blank use file ext.)") - f.StringP("web-path", "p", "/", "http path to host file at") - }) - websitesCmd.AddCommand(websitesContentTypeCmd) - FlagComps(websitesContentTypeCmd, func(comp *carapace.ActionMap) { - (*comp)["website"] = websites.WebsiteNameCompleter(con) - }) - - // [ Beacons ] --------------------------------------------- - - beaconsCmd := &cobra.Command{ - Use: consts.BeaconsStr, - Short: "Manage beacons", - Long: help.GetHelpFor([]string{consts.BeaconsStr}), - GroupID: consts.SliverHelpGroup, - Run: func(cmd *cobra.Command, args []string) { - beacons.BeaconsCmd(cmd, con, args) - }, - } - Flags("beacons", true, beaconsCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("beacons", false, beaconsCmd, func(f *pflag.FlagSet) { - f.StringP("kill", "k", "", "kill the designated beacon") - f.BoolP("kill-all", "K", false, "kill all beacons") - f.BoolP("force", "F", false, "force killing the beacon") - - f.StringP("filter", "f", "", "filter beacons by substring") - f.StringP("filter-re", "e", "", "filter beacons by regular expression") - }) - FlagComps(beaconsCmd, func(comp *carapace.ActionMap) { - (*comp)["kill"] = use.BeaconIDCompleter(con) - }) - beaconsRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a beacon", - Long: help.GetHelpFor([]string{consts.BeaconsStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - beacons.BeaconsRmCmd(cmd, con, args) - }, - } - carapace.Gen(beaconsRmCmd).PositionalCompletion(use.BeaconIDCompleter(con)) - beaconsCmd.AddCommand(beaconsRmCmd) - - beaconsWatchCmd := &cobra.Command{ - Use: consts.WatchStr, - Short: "Watch your beacons", - Long: help.GetHelpFor([]string{consts.BeaconsStr, consts.WatchStr}), - Run: func(cmd *cobra.Command, args []string) { - beacons.BeaconsWatchCmd(cmd, con, args) - }, - } - beaconsCmd.AddCommand(beaconsWatchCmd) - - beaconsPruneCmd := &cobra.Command{ - Use: consts.PruneStr, - Short: "Prune stale beacons automatically", - Long: help.GetHelpFor([]string{consts.BeaconsStr, consts.PruneStr}), - Run: func(cmd *cobra.Command, args []string) { - beacons.BeaconsPruneCmd(cmd, con, args) - }, - } - Flags("beacons", false, beaconsPruneCmd, func(f *pflag.FlagSet) { - f.StringP("duration", "d", "1h", "duration to prune beacons that have missed their last checkin") - }) - beaconsCmd.AddCommand(beaconsPruneCmd) - server.AddCommand(beaconsCmd) - - // [ Licenses ] --------------------------------------------- - - server.AddCommand(&cobra.Command{ - Use: consts.LicensesStr, - Short: "Open source licenses", - Long: help.GetHelpFor([]string{consts.LicensesStr}), - Run: func(cmd *cobra.Command, args []string) { - con.Println(licenses.All) - }, - GroupID: consts.GenericHelpGroup, - }) - - // [ WireGuard ] -------------------------------------------------------------- - - wgConfigCmd := &cobra.Command{ - Use: consts.WgConfigStr, - Short: "Generate a new WireGuard client config", - Long: help.GetHelpFor([]string{consts.WgConfigStr}), - Run: func(cmd *cobra.Command, args []string) { - wireguard.WGConfigCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - server.AddCommand(wgConfigCmd) - - Flags("wg-config", true, wgConfigCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("wg-config", false, wgConfigCmd, func(f *pflag.FlagSet) { - f.StringP("save", "s", "", "save configuration to file (.conf)") - }) - FlagComps(wgConfigCmd, func(comp *carapace.ActionMap) { - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save config") - }) - - // [ Monitor ] -------------------------------------------------------------- - - monitorCmd := &cobra.Command{ - Use: consts.MonitorStr, - Short: "Monitor threat intel platforms for Sliver implants", - GroupID: consts.SliverHelpGroup, - } - monitorCmd.AddCommand(&cobra.Command{ - Use: "start", - Short: "Start the monitoring loops", - Run: func(cmd *cobra.Command, args []string) { - monitor.MonitorStartCmd(cmd, con, args) - }, - }) - monitorCmd.AddCommand(&cobra.Command{ - Use: "stop", - Short: "Stop the monitoring loops", - Run: func(cmd *cobra.Command, args []string) { - monitor.MonitorStopCmd(cmd, con, args) - }, - }) - server.AddCommand(monitorCmd) - - // [ Loot ] -------------------------------------------------------------- - - lootCmd := &cobra.Command{ - Use: consts.LootStr, - Short: "Manage the server's loot store", - Long: help.GetHelpFor([]string{consts.LootStr}), - Run: func(cmd *cobra.Command, args []string) { - loot.LootCmd(cmd, con, args) - }, - GroupID: consts.SliverHelpGroup, - } - Flags("loot", true, lootCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("loot", false, lootCmd, func(f *pflag.FlagSet) { - f.StringP("filter", "f", "", "filter based on loot type") - }) - - lootAddCmd := &cobra.Command{ - Use: consts.LootLocalStr, - Short: "Add a local file to the server's loot store", - Long: help.GetHelpFor([]string{consts.LootStr, consts.LootLocalStr}), - Run: func(cmd *cobra.Command, args []string) { - loot.LootAddLocalCmd(cmd, con, args) - }, - Args: cobra.ExactArgs(1), - } - lootCmd.AddCommand(lootAddCmd) - Flags("loot", false, lootAddCmd, func(f *pflag.FlagSet) { - f.StringP("name", "n", "", "name of this piece of loot") - f.StringP("type", "T", "", "force a specific loot type (file/cred)") - f.StringP("file-type", "F", "", "force a specific file type (binary/text)") - }) - FlagComps(lootAddCmd, func(comp *carapace.ActionMap) { - (*comp)["type"] = carapace.ActionValues("file", "cred").Tag("loot type") - (*comp)["file-type"] = carapace.ActionValues("binary", "text").Tag("loot file type") - }) - carapace.Gen(lootAddCmd).PositionalCompletion( - carapace.ActionFiles().Tag("local loot file").Usage("The local file path to the loot")) - - lootRemoteCmd := &cobra.Command{ - Use: consts.LootRemoteStr, - Short: "Add a remote file from the current session to the server's loot store", - Long: help.GetHelpFor([]string{consts.LootStr, consts.LootRemoteStr}), - Run: func(cmd *cobra.Command, args []string) { - loot.LootAddRemoteCmd(cmd, con, args) - }, - Args: cobra.ExactArgs(1), - } - lootCmd.AddCommand(lootRemoteCmd) - Flags("loot", false, lootRemoteCmd, func(f *pflag.FlagSet) { - f.StringP("name", "n", "", "name of this piece of loot") - f.StringP("type", "T", "", "force a specific loot type (file/cred)") - f.StringP("file-type", "F", "", "force a specific file type (binary/text)") - }) - FlagComps(lootRemoteCmd, func(comp *carapace.ActionMap) { - (*comp)["type"] = carapace.ActionValues("file", "cred").Tag("loot type") - (*comp)["file-type"] = carapace.ActionValues("binary", "text").Tag("loot file type") - }) - carapace.Gen(lootRemoteCmd).PositionalCompletion(carapace.ActionValues().Usage("The file path on the remote host to the loot")) - - lootRenameCmd := &cobra.Command{ - Use: consts.RenameStr, - Short: "Re-name a piece of existing loot", - Long: help.GetHelpFor([]string{consts.LootStr, consts.RenameStr}), - Run: func(cmd *cobra.Command, args []string) { - loot.LootRenameCmd(cmd, con, args) - }, - } - lootCmd.AddCommand(lootRenameCmd) - - lootFetchCmd := &cobra.Command{ - Use: consts.FetchStr, - Short: "Fetch a piece of loot from the server's loot store", - Long: help.GetHelpFor([]string{consts.LootStr, consts.FetchStr}), - Run: func(cmd *cobra.Command, args []string) { - loot.LootFetchCmd(cmd, con, args) - }, - } - lootCmd.AddCommand(lootFetchCmd) - Flags("loot", false, lootFetchCmd, func(f *pflag.FlagSet) { - f.StringP("save", "s", "", "save loot to a local file") - f.StringP("filter", "f", "", "filter based on loot type") - }) - FlagComps(lootFetchCmd, func(comp *carapace.ActionMap) { - (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save loot") - }) - - lootRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a piece of loot from the server's loot store", - Long: help.GetHelpFor([]string{consts.LootStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - loot.LootRmCmd(cmd, con, args) - }, - } - lootCmd.AddCommand(lootRmCmd) - Flags("loot", false, lootRmCmd, func(f *pflag.FlagSet) { - f.StringP("filter", "f", "", "filter based on loot type") - }) - - server.AddCommand(lootCmd) - - // [ Credentials ] ------------------------------------------------------------ - credsCmd := &cobra.Command{ - Use: consts.CredsStr, - Short: "Manage the database of credentials", - Long: help.GetHelpFor([]string{consts.CredsStr}), - GroupID: consts.GenericHelpGroup, - Run: func(cmd *cobra.Command, args []string) { - creds.CredsCmd(cmd, con, args) - }, - } - Flags("creds", true, credsCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - server.AddCommand(credsCmd) - - credsAddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add a credential to the database", - Long: help.GetHelpFor([]string{consts.CredsStr, consts.AddStr}), - Run: func(cmd *cobra.Command, args []string) { - creds.CredsAddCmd(cmd, con, args) - }, - } - Flags("", false, credsAddCmd, func(f *pflag.FlagSet) { - f.StringP("collection", "c", "", "name of collection") - f.StringP("username", "u", "", "username for the credential") - f.StringP("plaintext", "p", "", "plaintext for the credential") - f.StringP("hash", "P", "", "hash of the credential") - f.StringP("hash-type", "H", "", "hash type of the credential") - }) - FlagComps(credsAddCmd, func(comp *carapace.ActionMap) { - (*comp)["hash-type"] = creds.CredsHashTypeCompleter(con) - }) - credsCmd.AddCommand(credsAddCmd) - - credsAddFileCmd := &cobra.Command{ - Use: consts.FileStr, - Short: "Add a credential to the database", - Long: help.GetHelpFor([]string{consts.CredsStr, consts.AddStr, consts.FileStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - creds.CredsAddHashFileCmd(cmd, con, args) - }, - } - Flags("", false, credsAddFileCmd, func(f *pflag.FlagSet) { - f.StringP("collection", "c", "", "name of collection") - f.StringP("file-format", "F", creds.HashNewlineFormat, "file format of the credential file") - f.StringP("hash-type", "H", "", "hash type of the credential") - }) - FlagComps(credsAddFileCmd, func(comp *carapace.ActionMap) { - (*comp)["collection"] = creds.CredsCollectionCompleter(con) - (*comp)["file-format"] = creds.CredsHashFileFormatCompleter(con) - (*comp)["hash-type"] = creds.CredsHashTypeCompleter(con) - }) - carapace.Gen(credsAddFileCmd).PositionalCompletion(carapace.ActionFiles().Tag("credential file")) - credsAddCmd.AddCommand(credsAddFileCmd) - - credsRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a credential to the database", - Long: help.GetHelpFor([]string{consts.CredsStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - creds.CredsRmCmd(cmd, con, args) - }, - } - carapace.Gen(credsRmCmd).PositionalCompletion(creds.CredsCredentialIDCompleter(con).Usage("id of credential to remove (leave empty to select)")) - credsCmd.AddCommand(credsRmCmd) - - // [ Hosts ] --------------------------------------------------------------------- - - hostsCmd := &cobra.Command{ - Use: consts.HostsStr, - Short: "Manage the database of hosts", - Long: help.GetHelpFor([]string{consts.HostsStr}), - Run: func(cmd *cobra.Command, args []string) { - hosts.HostsCmd(cmd, con, args) - }, - GroupID: consts.SliverHelpGroup, - } - server.AddCommand(hostsCmd) - Flags("hosts", true, hostsCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - hostsRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a host from the database", - Long: help.GetHelpFor([]string{consts.HostsStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - hosts.HostsRmCmd(cmd, con, args) - }, - } - hostsCmd.AddCommand(hostsRmCmd) - - hostsIOCCmd := &cobra.Command{ - Use: consts.IOCStr, - Short: "Manage tracked IOCs on a given host", - Long: help.GetHelpFor([]string{consts.HostsStr, consts.IOCStr}), - Run: func(cmd *cobra.Command, args []string) { - hosts.HostsIOCCmd(cmd, con, args) - }, - } - hostsCmd.AddCommand(hostsIOCCmd) - - hostsIOCRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Delete IOCs from the database", - Long: help.GetHelpFor([]string{consts.HostsStr, consts.IOCStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - hosts.HostsIOCRmCmd(cmd, con, args) - }, - } - hostsIOCCmd.AddCommand(hostsIOCRmCmd) - - // [ Reactions ] ----------------------------------------------------------------- - - reactionCmd := &cobra.Command{ - Use: consts.ReactionStr, - Short: "Manage automatic reactions to events", - Long: help.GetHelpFor([]string{consts.ReactionStr}), - Run: func(cmd *cobra.Command, args []string) { - reaction.ReactionCmd(cmd, con, args) - }, - GroupID: consts.SliverHelpGroup, - } - server.AddCommand(reactionCmd) - - reactionSetCmd := &cobra.Command{ - Use: consts.SetStr, - Short: "Set a reaction to an event", - Long: help.GetHelpFor([]string{consts.ReactionStr, consts.SetStr}), - Run: func(cmd *cobra.Command, args []string) { - reaction.ReactionSetCmd(cmd, con, args) - }, - } - reactionCmd.AddCommand(reactionSetCmd) - Flags("reactions", false, reactionSetCmd, func(f *pflag.FlagSet) { - f.StringP("event", "e", "", "specify the event type to react to") - }) - - FlagComps(reactionSetCmd, func(comp *carapace.ActionMap) { - (*comp)["event"] = carapace.ActionValues( - consts.SessionOpenedEvent, - consts.SessionClosedEvent, - consts.SessionUpdateEvent, - consts.BeaconRegisteredEvent, - consts.CanaryEvent, - consts.WatchtowerEvent, - ) - }) - - reactionUnsetCmd := &cobra.Command{ - Use: consts.UnsetStr, - Short: "Unset an existing reaction", - Long: help.GetHelpFor([]string{consts.ReactionStr, consts.UnsetStr}), - Run: func(cmd *cobra.Command, args []string) { - reaction.ReactionUnsetCmd(cmd, con, args) - }, - } - reactionCmd.AddCommand(reactionUnsetCmd) - Flags("reactions", false, reactionUnsetCmd, func(f *pflag.FlagSet) { - f.IntP("id", "i", 0, "the id of the reaction to remove") - }) - FlagComps(reactionUnsetCmd, func(comp *carapace.ActionMap) { - (*comp)["id"] = reaction.ReactionIDCompleter(con) - }) - - reactionSaveCmd := &cobra.Command{ - Use: consts.SaveStr, - Short: "Save current reactions to disk", - Long: help.GetHelpFor([]string{consts.ReactionStr, consts.SaveStr}), - Run: func(cmd *cobra.Command, args []string) { - reaction.ReactionSaveCmd(cmd, con, args) - }, - } - reactionCmd.AddCommand(reactionSaveCmd) - - reactionReloadCmd := &cobra.Command{ - Use: consts.ReloadStr, - Short: "Reload reactions from disk, replaces the running configuration", - Long: help.GetHelpFor([]string{consts.ReactionStr, consts.ReloadStr}), - Run: func(cmd *cobra.Command, args []string) { - reaction.ReactionReloadCmd(cmd, con, args) - }, - } - reactionCmd.AddCommand(reactionReloadCmd) - - // [ Prelude's Operator ] ------------------------------------------------------------ - operatorCmd := &cobra.Command{ - Use: consts.PreludeOperatorStr, - Short: "Manage connection to Prelude's Operator", - Long: help.GetHelpFor([]string{consts.PreludeOperatorStr}), - GroupID: consts.GenericHelpGroup, - Run: func(cmd *cobra.Command, args []string) { - operator.OperatorCmd(cmd, con, args) - }, - } - server.AddCommand(operatorCmd) - - operatorConnectCmd := &cobra.Command{ - Use: consts.ConnectStr, - Short: "Connect with Prelude's Operator", - Long: help.GetHelpFor([]string{consts.PreludeOperatorStr, consts.ConnectStr}), - Run: func(cmd *cobra.Command, args []string) { - operator.ConnectCmd(cmd, con, args) - }, - Args: cobra.ExactArgs(1), - } - operatorCmd.AddCommand(operatorConnectCmd) - Flags("operator", false, operatorConnectCmd, func(f *pflag.FlagSet) { - f.BoolP("skip-existing", "s", false, "Do not add existing sessions as Operator Agents") - f.StringP("aes-key", "a", "abcdefghijklmnopqrstuvwxyz012345", "AES key for communication encryption") - f.StringP("range", "r", "sliver", "Agents range") - }) - carapace.Gen(operatorConnectCmd).PositionalCompletion( - carapace.ActionValues().Usage("connection string to the Operator Host (e.g. 127.0.0.1:1234)")) - - // [ Builders ] --------------------------------------------- - - buildersCmd := &cobra.Command{ - Use: consts.BuildersStr, - Short: "List external builders", - Long: help.GetHelpFor([]string{consts.BuildersStr}), - Run: func(cmd *cobra.Command, args []string) { - builders.BuildersCmd(cmd, con, args) - }, - GroupID: consts.PayloadsHelpGroup, - } - server.AddCommand(buildersCmd) - Flags("builders", false, buildersCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Crack ] ------------------------------------------------------------ - crackCmd := &cobra.Command{ - Use: consts.CrackStr, - Short: "Crack: GPU password cracking", - Long: help.GetHelpFor([]string{consts.CrackStr}), - GroupID: consts.GenericHelpGroup, - Run: func(cmd *cobra.Command, args []string) { - crack.CrackCmd(cmd, con, args) - }, - } - Flags("", true, crackCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - server.AddCommand(crackCmd) - - crackStationsCmd := &cobra.Command{ - Use: consts.StationsStr, - Short: "Manage crackstations", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.StationsStr}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackStationsCmd(cmd, con, args) - }, - } - crackCmd.AddCommand(crackStationsCmd) - - wordlistsCmd := &cobra.Command{ - Use: consts.WordlistsStr, - Short: "Manage wordlists", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.WordlistsStr}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackWordlistsCmd(cmd, con, args) - }, - } - crackCmd.AddCommand(wordlistsCmd) - - wordlistsAddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add a wordlist", - Run: func(cmd *cobra.Command, args []string) { - crack.CrackWordlistsAddCmd(cmd, con, args) - }, - } - Flags("", false, wordlistsAddCmd, func(f *pflag.FlagSet) { - f.StringP("name", "n", "", "wordlist name (blank = filename)") - }) - carapace.Gen(wordlistsAddCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to local wordlist file")) - wordlistsCmd.AddCommand(wordlistsAddCmd) - - wordlistsRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a wordlist", - Run: func(cmd *cobra.Command, args []string) { - crack.CrackWordlistsRmCmd(cmd, con, args) - }, - } - wordlistsCmd.AddCommand(wordlistsRmCmd) - carapace.Gen(wordlistsRmCmd).PositionalCompletion(crack.CrackWordlistCompleter(con).Usage("wordlist to remove")) - - rulesCmd := &cobra.Command{ - Use: consts.RulesStr, - Short: "Manage rule files", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.RulesStr}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackRulesCmd(cmd, con, args) - }, - } - crackCmd.AddCommand(rulesCmd) - - rulesAddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add a rules file", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.RulesStr, consts.AddStr}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackRulesAddCmd(cmd, con, args) - }, - } - Flags("", false, rulesAddCmd, func(f *pflag.FlagSet) { - f.StringP("name", "n", "", "rules name (blank = filename)") - }) - carapace.Gen(rulesAddCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to local rules file")) - rulesCmd.AddCommand(rulesAddCmd) - - rulesRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove rules", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.RulesStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackRulesRmCmd(cmd, con, args) - }, - } - carapace.Gen(rulesRmCmd).PositionalCompletion(crack.CrackRulesCompleter(con).Usage("rules to remove")) - rulesCmd.AddCommand(rulesRmCmd) - - hcstat2Cmd := &cobra.Command{ - Use: consts.Hcstat2Str, - Short: "Manage markov hcstat2 files", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.Hcstat2Str}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackHcstat2Cmd(cmd, con, args) - }, - } - crackCmd.AddCommand(hcstat2Cmd) - - hcstat2AddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add a hcstat2 file", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.Hcstat2Str, consts.AddStr}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackHcstat2AddCmd(cmd, con, args) - }, - } - Flags("", false, hcstat2AddCmd, func(f *pflag.FlagSet) { - f.StringP("name", "n", "", "hcstat2 name (blank = filename)") - }) - carapace.Gen(hcstat2AddCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to local hcstat2 file")) - hcstat2Cmd.AddCommand(hcstat2AddCmd) - - hcstat2RmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove hcstat2 file", - Long: help.GetHelpFor([]string{consts.CrackStr, consts.Hcstat2Str, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - crack.CrackHcstat2RmCmd(cmd, con, args) - }, - } - carapace.Gen(hcstat2RmCmd).PositionalCompletion(crack.CrackHcstat2Completer(con).Usage("hcstat2 to remove")) - hcstat2Cmd.AddCommand(hcstat2RmCmd) + // [ Bind commands ] -------------------------------------------------------- + + // Below are bounds all commands of the server menu, gathered by the group + // under which they should be printed in help messages and/or completions. + // You can either add a new bindCommands() call with a new group (which will + // be automatically added to the command tree), or add your commands in one of + // the present calls. + + // Core + bindCommands(consts.GenericHelpGroup, server, con, + exit.Command, + licenses.Commands, + settings.Commands, + alias.Commands, + armory.Commands, + update.Commands, + operators.Commands, + operator.Commands, + creds.Commands, + crack.Commands, + ) + + // C2 Network + bindCommands(consts.NetworkHelpGroup, server, con, + jobs.Commands, + websites.Commands, + wireguard.Commands, + ) + + // Payloads + bindCommands(consts.PayloadsHelpGroup, server, con, + sgn.Commands, + generate.Commands, + builders.Commands, + ) + + // Slivers + bindCommands(consts.SliverHelpGroup, server, con, + use.Commands, + info.Commands, + sessions.Commands, + beacons.Commands, + monitor.Commands, + loot.Commands, + hosts.Commands, + reaction.Commands, + ) // [ Post-command declaration setup]----------------------------------------- // Everything below this line should preferably not be any command binding - // (unless you know what you're doing). If there are any final modifications - // to make to the sliver menu command tree, it time to do them here. + // (although you can do so without fear). If there are any final modifications + // to make to the server menu command tree, it time to do them here. server.InitDefaultHelpCmd() server.SetHelpCommandGroupID(consts.GenericHelpGroup) - // Bind a readline subcommand to the `settings` one, for allowing users to - // manipulate the shell instance keymaps, bindings, macros and global options. - settingsCmd.AddCommand(readline.Commands(con.App.Shell())) - return server } diff --git a/client/command/sessions/commands.go b/client/command/sessions/commands.go new file mode 100644 index 0000000000..0928b782d0 --- /dev/null +++ b/client/command/sessions/commands.go @@ -0,0 +1,85 @@ +package sessions + +import ( + "context" + "fmt" + "strings" + + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" + "github.com/bishopfox/sliver/protobuf/commonpb" +) + +// Commands returns the `sessions` command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + sessionsCmd := &cobra.Command{ + Use: consts.SessionsStr, + Short: "Session management", + Long: help.GetHelpFor([]string{consts.SessionsStr}), + Run: func(cmd *cobra.Command, args []string) { + SessionsCmd(cmd, con, args) + }, + GroupID: consts.SliverHelpGroup, + } + flags.Bind("sessions", true, sessionsCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.Bind("sessions", false, sessionsCmd, func(f *pflag.FlagSet) { + f.StringP("interact", "i", "", "interact with a session") + f.StringP("kill", "k", "", "kill the designated session") + f.BoolP("kill-all", "K", false, "kill all the sessions") + f.BoolP("clean", "C", false, "clean out any sessions marked as [DEAD]") + f.BoolP("force", "F", false, "force session action without waiting for results") + + f.StringP("filter", "f", "", "filter sessions by substring") + f.StringP("filter-re", "e", "", "filter sessions by regular expression") + }) + flags.BindFlagCompletions(sessionsCmd, func(comp *carapace.ActionMap) { + (*comp)["interact"] = SessionIDCompleter(con) + (*comp)["kill"] = SessionIDCompleter(con) + }) + + sessionsPruneCmd := &cobra.Command{ + Use: consts.PruneStr, + Short: "Kill all stale/dead sessions", + Long: help.GetHelpFor([]string{consts.SessionsStr, consts.PruneStr}), + Run: func(cmd *cobra.Command, args []string) { + SessionsPruneCmd(cmd, con, args) + }, + } + flags.Bind("prune", false, sessionsPruneCmd, func(f *pflag.FlagSet) { + f.BoolP("force", "F", false, "Force the killing of stale/dead sessions") + }) + sessionsCmd.AddCommand(sessionsPruneCmd) + + return []*cobra.Command{sessionsCmd} +} + +// SessionIDCompleter completes session IDs +func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { + callback := func(_ carapace.Context) carapace.Action { + results := make([]string, 0) + + sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) + if err == nil { + for _, s := range sessions.Sessions { + link := fmt.Sprintf("[%s <- %s]", s.ActiveC2, s.RemoteAddress) + id := fmt.Sprintf("%s (%d)", s.Name, s.PID) + userHost := fmt.Sprintf("%s@%s", s.Username, s.Hostname) + desc := strings.Join([]string{id, userHost, link}, " ") + + results = append(results, s.ID[:8]) + results = append(results, desc) + } + } + return carapace.ActionValuesDescribed(results...).Tag("sessions") + } + + return carapace.ActionCallback(callback) +} diff --git a/client/command/settings/commands.go b/client/command/settings/commands.go new file mode 100644 index 0000000000..c82e20bd38 --- /dev/null +++ b/client/command/settings/commands.go @@ -0,0 +1,92 @@ +package settings + +import ( + "github.com/reeflective/console/commands/readline" + "github.com/spf13/cobra" + + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + settingsCmd := &cobra.Command{ + Use: consts.SettingsStr, + Short: "Manage client settings", + Long: help.GetHelpFor([]string{consts.SettingsStr}), + Run: func(cmd *cobra.Command, args []string) { + SettingsCmd(cmd, con, args) + }, + GroupID: consts.GenericHelpGroup, + } + settingsCmd.AddCommand(&cobra.Command{ + Use: consts.SaveStr, + Short: "Save the current settings to disk", + Long: help.GetHelpFor([]string{consts.SettingsStr, consts.SaveStr}), + Run: func(cmd *cobra.Command, args []string) { + SettingsSaveCmd(cmd, con, args) + }, + }) + settingsCmd.AddCommand(&cobra.Command{ + Use: consts.TablesStr, + Short: "Modify tables setting (style)", + Long: help.GetHelpFor([]string{consts.SettingsStr, consts.TablesStr}), + Run: func(cmd *cobra.Command, args []string) { + SettingsTablesCmd(cmd, con, args) + }, + }) + settingsCmd.AddCommand(&cobra.Command{ + Use: "beacon-autoresults", + Short: "Automatically display beacon task results when completed", + Long: help.GetHelpFor([]string{consts.SettingsStr, "beacon-autoresults"}), + Run: func(cmd *cobra.Command, args []string) { + SettingsBeaconsAutoResultCmd(cmd, con, args) + }, + }) + settingsCmd.AddCommand(&cobra.Command{ + Use: "autoadult", + Short: "Automatically accept OPSEC warnings", + Long: help.GetHelpFor([]string{consts.SettingsStr, "autoadult"}), + Run: func(cmd *cobra.Command, args []string) { + SettingsAutoAdultCmd(cmd, con, args) + }, + }) + settingsCmd.AddCommand(&cobra.Command{ + Use: "always-overflow", + Short: "Disable table pagination", + Long: help.GetHelpFor([]string{consts.SettingsStr, "always-overflow"}), + Run: func(cmd *cobra.Command, args []string) { + SettingsAlwaysOverflow(cmd, con, args) + }, + }) + settingsCmd.AddCommand(&cobra.Command{ + Use: "small-terminal", + Short: "Set the small terminal width", + Long: help.GetHelpFor([]string{consts.SettingsStr, "small-terminal"}), + Run: func(cmd *cobra.Command, args []string) { + SettingsSmallTerm(cmd, con, args) + }, + }) + settingsCmd.AddCommand(&cobra.Command{ + Use: "user-connect", + Short: "Enable user connections/disconnections (can be very verbose when they use CLI)", + Run: func(cmd *cobra.Command, args []string) { + SettingsUserConnect(cmd, con, args) + }, + }) + settingsCmd.AddCommand(&cobra.Command{ + Use: "console-logs", + Short: "Log console output (toggle)", + Long: help.GetHelpFor([]string{consts.SettingsStr, "console-logs"}), + Run: func(ctx *cobra.Command, args []string) { + SettingsConsoleLogs(ctx, con) + }, + }) + + // Bind a readline subcommand to the `settings` one, for allowing users to + // manipulate the shell instance keymaps, bindings, macros and global options. + settingsCmd.AddCommand(readline.Commands(con.App.Shell())) + + return []*cobra.Command{settingsCmd} +} diff --git a/client/command/shikata-ga-nai/commands.go b/client/command/shikata-ga-nai/commands.go new file mode 100644 index 0000000000..2d81134c19 --- /dev/null +++ b/client/command/shikata-ga-nai/commands.go @@ -0,0 +1,40 @@ +package sgn + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + shikataGaNaiCmd := &cobra.Command{ + Use: consts.ShikataGaNai, + Short: "Polymorphic binary shellcode encoder (ノ ゜Д゜)ノ ︵ 仕方がない", + Long: help.GetHelpFor([]string{consts.ShikataGaNai}), + Run: func(cmd *cobra.Command, args []string) { + ShikataGaNaiCmd(cmd, con, args) + }, + Args: cobra.ExactArgs(1), + GroupID: consts.PayloadsHelpGroup, + } + flags.Bind("shikata ga nai", false, shikataGaNaiCmd, func(f *pflag.FlagSet) { + f.StringP("save", "s", "", "save output to local file") + f.StringP("arch", "a", "amd64", "architecture of shellcode") + f.IntP("iterations", "i", 1, "number of iterations") + f.StringP("bad-chars", "b", "", "hex encoded bad characters to avoid (e.g. 0001)") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.BindFlagCompletions(shikataGaNaiCmd, func(comp *carapace.ActionMap) { + (*comp)["arch"] = carapace.ActionValues("386", "amd64").Tag("shikata-ga-nai architectures") + (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save shellcode") + }) + carapace.Gen(shikataGaNaiCmd).PositionalCompletion(carapace.ActionFiles().Tag("shellcode file")) + + return []*cobra.Command{shikataGaNaiCmd} +} diff --git a/client/command/use/commands.go b/client/command/use/commands.go new file mode 100644 index 0000000000..d5c37a44c0 --- /dev/null +++ b/client/command/use/commands.go @@ -0,0 +1,53 @@ +package use + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + useCmd := &cobra.Command{ + Use: consts.UseStr, + Short: "Switch the active session or beacon", + Long: help.GetHelpFor([]string{consts.UseStr}), + Run: func(cmd *cobra.Command, args []string) { + UseCmd(cmd, con, args) + }, + GroupID: consts.SliverHelpGroup, + } + flags.Bind("use", true, useCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(useCmd).PositionalCompletion(BeaconAndSessionIDCompleter(con)) + + useSessionCmd := &cobra.Command{ + Use: consts.SessionsStr, + Short: "Switch the active session", + Long: help.GetHelpFor([]string{consts.UseStr, consts.SessionsStr}), + Run: func(cmd *cobra.Command, args []string) { + UseSessionCmd(cmd, con, args) + }, + } + carapace.Gen(useSessionCmd).PositionalCompletion(SessionIDCompleter(con)) + useCmd.AddCommand(useSessionCmd) + + useBeaconCmd := &cobra.Command{ + Use: consts.BeaconsStr, + Short: "Switch the active beacon", + Long: help.GetHelpFor([]string{consts.UseStr, consts.BeaconsStr}), + Run: func(cmd *cobra.Command, args []string) { + UseBeaconCmd(cmd, con, args) + }, + } + carapace.Gen(useBeaconCmd).PositionalCompletion(BeaconIDCompleter(con)) + useCmd.AddCommand(useBeaconCmd) + + return []*cobra.Command{useCmd} +} diff --git a/client/command/websites/commands.go b/client/command/websites/commands.go new file mode 100644 index 0000000000..862244b3cd --- /dev/null +++ b/client/command/websites/commands.go @@ -0,0 +1,99 @@ +package websites + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + websitesCmd := &cobra.Command{ + Use: consts.WebsitesStr, + Short: "Host static content (used with HTTP C2)", + Long: help.GetHelpFor([]string{consts.WebsitesStr}), + Run: func(cmd *cobra.Command, args []string) { + WebsitesCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("websites", true, websitesCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(websitesCmd).PositionalCompletion(WebsiteNameCompleter(con)) + + websitesRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove an entire website and all of its contents", + Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + WebsiteRmCmd(cmd, con, args) + }, + } + carapace.Gen(websitesRmCmd).PositionalCompletion(WebsiteNameCompleter(con)) + websitesCmd.AddCommand(websitesRmCmd) + + websitesRmWebContentCmd := &cobra.Command{ + Use: consts.RmWebContentStr, + Short: "Remove specific content from a website", + Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.RmWebContentStr}), + Run: func(cmd *cobra.Command, args []string) { + WebsitesRmContent(cmd, con, args) + }, + } + flags.Bind("websites", false, websitesRmWebContentCmd, func(f *pflag.FlagSet) { + f.BoolP("recursive", "r", false, "recursively add/rm content") + f.StringP("website", "w", "", "website name") + f.StringP("web-path", "p", "", "http path to host file at") + }) + websitesCmd.AddCommand(websitesRmWebContentCmd) + flags.BindFlagCompletions(websitesRmWebContentCmd, func(comp *carapace.ActionMap) { + (*comp)["website"] = WebsiteNameCompleter(con) + }) + + websitesContentCmd := &cobra.Command{ + Use: consts.AddWebContentStr, + Short: "Add content to a website", + Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.RmWebContentStr}), + Run: func(cmd *cobra.Command, args []string) { + WebsitesAddContentCmd(cmd, con, args) + }, + } + flags.Bind("websites", false, websitesContentCmd, func(f *pflag.FlagSet) { + f.StringP("website", "w", "", "website name") + f.StringP("content-type", "m", "", "mime content-type (if blank use file ext.)") + f.StringP("web-path", "p", "/", "http path to host file at") + f.StringP("content", "c", "", "local file path/dir (must use --recursive for dir)") + f.BoolP("recursive", "r", false, "recursively add/rm content") + }) + flags.BindFlagCompletions(websitesContentCmd, func(comp *carapace.ActionMap) { + (*comp)["content"] = carapace.ActionFiles().Tag("content directory/files") + (*comp)["website"] = WebsiteNameCompleter(con) + }) + websitesCmd.AddCommand(websitesContentCmd) + + websitesContentTypeCmd := &cobra.Command{ + Use: consts.WebContentTypeStr, + Short: "Update a path's content-type", + Long: help.GetHelpFor([]string{consts.WebsitesStr, consts.WebContentTypeStr}), + Run: func(cmd *cobra.Command, args []string) { + WebsitesUpdateContentCmd(cmd, con, args) + }, + } + flags.Bind("websites", false, websitesContentTypeCmd, func(f *pflag.FlagSet) { + f.StringP("website", "w", "", "website name") + f.StringP("content-type", "m", "", "mime content-type (if blank use file ext.)") + f.StringP("web-path", "p", "/", "http path to host file at") + }) + websitesCmd.AddCommand(websitesContentTypeCmd) + flags.BindFlagCompletions(websitesContentTypeCmd, func(comp *carapace.ActionMap) { + (*comp)["website"] = WebsiteNameCompleter(con) + }) + + return []*cobra.Command{websitesCmd} +} diff --git a/client/command/wireguard/commands.go b/client/command/wireguard/commands.go new file mode 100644 index 0000000000..dcbb9dc82d --- /dev/null +++ b/client/command/wireguard/commands.go @@ -0,0 +1,37 @@ +package wireguard + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + wgConfigCmd := &cobra.Command{ + Use: consts.WgConfigStr, + Short: "Generate a new WireGuard client config", + Long: help.GetHelpFor([]string{consts.WgConfigStr}), + Run: func(cmd *cobra.Command, args []string) { + WGConfigCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + + flags.Bind("wg-config", true, wgConfigCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.Bind("wg-config", false, wgConfigCmd, func(f *pflag.FlagSet) { + f.StringP("save", "s", "", "save configuration to file (.conf)") + }) + flags.BindFlagCompletions(wgConfigCmd, func(comp *carapace.ActionMap) { + (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save config") + }) + + return []*cobra.Command{wgConfigCmd} +} diff --git a/client/console/console.go b/client/console/console.go index fde4a37587..f523ca76da 100644 --- a/client/console/console.go +++ b/client/console/console.go @@ -40,6 +40,7 @@ import ( "google.golang.org/protobuf/proto" "github.com/bishopfox/sliver/client/assets" + "github.com/bishopfox/sliver/client/command/reaction" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/client/prelude" @@ -205,6 +206,16 @@ func StartClient(con *SliverConsoleClient, rpc rpcpb.SliverRPCClient, serverCmds con.setupAsciicastRecord(asciicastLog, asciicastStream) } + // Only load reactions when the console is going to be started. + if !con.IsCLI { + n, err := reaction.LoadReactions() + if err != nil && !os.IsNotExist(err) { + con.PrintErrorf("Failed to load reactions: %s\n", err) + } else if n > 0 { + con.PrintInfof("Loaded %d reaction(s) from disk\n", n) + } + } + if !con.IsCLI { return con.App.Start() } From e23f04096282ba7dff4e408af19922473094f248 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Thu, 22 Jun 2023 17:55:32 +0200 Subject: [PATCH 05/14] Split sliver commands in their files --- client/command/backdoor/commands.go | 38 + client/command/command.go | 4 +- client/command/completers/commands.go | 17 + client/command/cursed/commands.go | 149 ++ client/command/dllhijack/commands.go | 43 + client/command/environment/commands.go | 59 + client/command/exec/commands.go | 276 ++++ client/command/extensions/commands.go | 69 + client/command/filesystem/commands.go | 212 +++ client/command/help/commands.go | 17 + client/command/info/commands.go | 70 + client/command/kill/commands.go | 30 + client/command/network/commands.go | 49 + client/command/pivots/commands.go | 101 ++ client/command/portfwd/commands.go | 64 + client/command/privilege/commands.go | 175 +++ client/command/processes/commands.go | 73 + client/command/reconfig/commands.go | 47 + client/command/registry/commands.go | 129 ++ client/command/rportfwd/commands.go | 64 + client/command/screenshot/commands.go | 37 + client/command/server.go | 10 +- client/command/sessions/commands.go | 56 +- client/command/shell/commands.go | 33 + client/command/sliver.go | 1955 +----------------------- client/command/socks/commands.go | 65 + client/command/tasks/commands.go | 58 + client/command/wasm/commands.go | 54 + client/command/wireguard/commands.go | 85 ++ 29 files changed, 2141 insertions(+), 1898 deletions(-) create mode 100644 client/command/backdoor/commands.go create mode 100644 client/command/completers/commands.go create mode 100644 client/command/cursed/commands.go create mode 100644 client/command/dllhijack/commands.go create mode 100644 client/command/environment/commands.go create mode 100644 client/command/exec/commands.go create mode 100644 client/command/extensions/commands.go create mode 100644 client/command/filesystem/commands.go create mode 100644 client/command/help/commands.go create mode 100644 client/command/kill/commands.go create mode 100644 client/command/network/commands.go create mode 100644 client/command/pivots/commands.go create mode 100644 client/command/portfwd/commands.go create mode 100644 client/command/privilege/commands.go create mode 100644 client/command/processes/commands.go create mode 100644 client/command/reconfig/commands.go create mode 100644 client/command/registry/commands.go create mode 100644 client/command/rportfwd/commands.go create mode 100644 client/command/screenshot/commands.go create mode 100644 client/command/shell/commands.go create mode 100644 client/command/socks/commands.go create mode 100644 client/command/tasks/commands.go create mode 100644 client/command/wasm/commands.go diff --git a/client/command/backdoor/commands.go b/client/command/backdoor/commands.go new file mode 100644 index 0000000000..8fa7b4bbff --- /dev/null +++ b/client/command/backdoor/commands.go @@ -0,0 +1,38 @@ +package backdoor + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/generate" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + backdoorCmd := &cobra.Command{ + Use: consts.BackdoorStr, + Short: "Infect a remote file with a sliver shellcode", + Long: help.GetHelpFor([]string{consts.BackdoorStr}), + Args: cobra.ExactArgs(1), + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + Run: func(cmd *cobra.Command, args []string) { + BackdoorCmd(cmd, con, args) + }, + } + flags.Bind("", false, backdoorCmd, func(f *pflag.FlagSet) { + f.StringP("profile", "p", "", "profile to use for service binary") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.BindFlagCompletions(backdoorCmd, func(comp *carapace.ActionMap) { + (*comp)["profile"] = generate.ProfileNameCompleter(con) + }) + carapace.Gen(backdoorCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the remote file to backdoor")) + + return []*cobra.Command{backdoorCmd} +} diff --git a/client/command/command.go b/client/command/command.go index 9ba69ab42f..2afd028b3e 100644 --- a/client/command/command.go +++ b/client/command/command.go @@ -101,11 +101,11 @@ func RestrictTargets(filters ...string) map[string]string { // - double bind session commands // - don't bind readline command in CLI. -// bindCommands is a helper used to bind a list of root commands to a given menu, for a given "command help group". +// bind is a helper used to bind a list of root commands to a given menu, for a given "command help group". // @group - Name of the group under which the command should be shown. Preferably use a string in the constants package. // @menu - The command menu to which the commands should be bound (either server or implant menu). // @ cmds - A list of functions returning a list of root commands to bind. See any package's `commands.go` file and function. -func bindCommands(group string, menu *cobra.Command, con *client.SliverConsoleClient, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { +func bind(group string, menu *cobra.Command, con *client.SliverConsoleClient, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { found := false // Ensure the given command group is available in the menu. diff --git a/client/command/completers/commands.go b/client/command/completers/commands.go new file mode 100644 index 0000000000..a6c8864c7d --- /dev/null +++ b/client/command/completers/commands.go @@ -0,0 +1,17 @@ +package completers + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + return nil +} diff --git a/client/command/cursed/commands.go b/client/command/cursed/commands.go new file mode 100644 index 0000000000..6680df71e4 --- /dev/null +++ b/client/command/cursed/commands.go @@ -0,0 +1,149 @@ +package cursed + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + cursedCmd := &cobra.Command{ + Use: consts.Cursed, + Short: "Chrome/electron post-exploitation tool kit (∩`-´)⊃━☆゚.*・。゚", + Long: help.GetHelpFor([]string{consts.Cursed}), + GroupID: consts.ExecutionHelpGroup, + Run: func(cmd *cobra.Command, args []string) { + CursedCmd(cmd, con, args) + }, + } + flags.Bind("", true, cursedCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + cursedRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a Curse from a process", + Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedConsole}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + CursedRmCmd(cmd, con, args) + }, + } + cursedCmd.AddCommand(cursedRmCmd) + flags.Bind("", false, cursedRmCmd, func(f *pflag.FlagSet) { + f.BoolP("kill", "k", false, "kill the process after removing the curse") + }) + carapace.Gen(cursedRmCmd).PositionalCompletion(carapace.ActionValues().Usage("bind port of the Cursed process to stop")) + + cursedConsoleCmd := &cobra.Command{ + Use: consts.CursedConsole, + Short: "Start a JavaScript console connected to a debug target", + Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedConsole}), + Run: func(cmd *cobra.Command, args []string) { + CursedConsoleCmd(cmd, con, args) + }, + } + cursedCmd.AddCommand(cursedConsoleCmd) + flags.Bind("", false, cursedConsoleCmd, func(f *pflag.FlagSet) { + f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)`") + }) + + cursedChromeCmd := &cobra.Command{ + Use: consts.CursedChrome, + Short: "Automatically inject a Cursed Chrome payload into a remote Chrome extension", + Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedChrome}), + Run: func(cmd *cobra.Command, args []string) { + CursedChromeCmd(cmd, con, args) + }, + } + cursedCmd.AddCommand(cursedChromeCmd) + flags.Bind("", false, cursedChromeCmd, func(f *pflag.FlagSet) { + f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)") + f.BoolP("restore", "R", true, "restore the user's session after process termination") + f.StringP("exe", "e", "", "chrome/chromium browser executable path (blank string = auto)") + f.StringP("user-data", "u", "", "user data directory (blank string = auto)") + f.StringP("payload", "p", "", "cursed chrome payload file path (.js)") + f.BoolP("keep-alive", "k", false, "keeps browser alive after last browser window closes") + f.BoolP("headless", "H", false, "start browser process in headless mode") + }) + flags.BindFlagCompletions(cursedChromeCmd, func(comp *carapace.ActionMap) { + (*comp)["payload"] = carapace.ActionFiles("js").Tag("javascript files") + }) + cursedChromeCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + carapace.Gen(cursedChromeCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("additional Chrome CLI arguments")) + + cursedEdgeCmd := &cobra.Command{ + Use: consts.CursedEdge, + Short: "Automatically inject a Cursed Chrome payload into a remote Edge extension", + Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedEdge}), + Run: func(cmd *cobra.Command, args []string) { + CursedEdgeCmd(cmd, con, args) + }, + } + cursedCmd.AddCommand(cursedEdgeCmd) + flags.Bind("", false, cursedEdgeCmd, func(f *pflag.FlagSet) { + f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)") + f.BoolP("restore", "R", true, "restore the user's session after process termination") + f.StringP("exe", "e", "", "edge browser executable path (blank string = auto)") + f.StringP("user-data", "u", "", "user data directory (blank string = auto)") + f.StringP("payload", "p", "", "cursed chrome payload file path (.js)") + f.BoolP("keep-alive", "k", false, "keeps browser alive after last browser window closes") + f.BoolP("headless", "H", false, "start browser process in headless mode") + }) + flags.BindFlagCompletions(cursedEdgeCmd, func(comp *carapace.ActionMap) { + (*comp)["payload"] = carapace.ActionFiles("js").Tag("javascript files") + }) + cursedEdgeCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + carapace.Gen(cursedEdgeCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("additional Edge CLI arguments")) + + cursedElectronCmd := &cobra.Command{ + Use: consts.CursedElectron, + Short: "Curse a remote Electron application", + Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedElectron}), + Run: func(cmd *cobra.Command, args []string) { + CursedElectronCmd(cmd, con, args) + }, + } + cursedCmd.AddCommand(cursedElectronCmd) + flags.Bind("", false, cursedElectronCmd, func(f *pflag.FlagSet) { + f.StringP("exe", "e", "", "remote electron executable absolute path") + f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)") + }) + cursedElectronCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + carapace.Gen(cursedElectronCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("additional Electron CLI arguments")) + + CursedCookiesCmd := &cobra.Command{ + Use: consts.CursedCookies, + Short: "Dump all cookies from cursed process", + Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedCookies}), + Run: func(cmd *cobra.Command, args []string) { + CursedCookiesCmd(cmd, con, args) + }, + } + cursedCmd.AddCommand(CursedCookiesCmd) + flags.Bind("", false, CursedCookiesCmd, func(f *pflag.FlagSet) { + f.StringP("save", "s", "", "save to file") + }) + + cursedScreenshotCmd := &cobra.Command{ + Use: consts.ScreenshotStr, + Short: "Take a screenshot of a cursed process debug target", + Long: help.GetHelpFor([]string{consts.Cursed, consts.ScreenshotStr}), + Run: func(cmd *cobra.Command, args []string) { + CursedScreenshotCmd(cmd, con, args) + }, + } + cursedCmd.AddCommand(cursedScreenshotCmd) + flags.Bind("", false, cursedScreenshotCmd, func(f *pflag.FlagSet) { + f.Int64P("quality", "q", 100, "screenshot quality (1 - 100)") + f.StringP("save", "s", "", "save to file") + }) + + return []*cobra.Command{cursedCmd} +} diff --git a/client/command/dllhijack/commands.go b/client/command/dllhijack/commands.go new file mode 100644 index 0000000000..b9aae25f22 --- /dev/null +++ b/client/command/dllhijack/commands.go @@ -0,0 +1,43 @@ +package dllhijack + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/generate" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + dllhijackCmd := &cobra.Command{ + Use: consts.DLLHijackStr, + Short: "Plant a DLL for a hijack scenario", + Long: help.GetHelpFor([]string{consts.DLLHijackStr}), + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + DllHijackCmd(cmd, con, args) + }, + } + flags.Bind("", false, dllhijackCmd, func(f *pflag.FlagSet) { + f.StringP("reference-path", "r", "", "Path to the reference DLL on the remote system") + f.StringP("reference-file", "R", "", "Path to the reference DLL on the local system") + f.StringP("file", "f", "", "Local path to the DLL to plant for the hijack") + f.StringP("profile", "p", "", "Profile name to use as a base DLL") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.BindFlagCompletions(dllhijackCmd, func(comp *carapace.ActionMap) { + (*comp)["reference-file"] = carapace.ActionFiles() + (*comp)["file"] = carapace.ActionFiles() + (*comp)["profile"] = generate.ProfileNameCompleter(con) + }) + carapace.Gen(dllhijackCmd).PositionalCompletion(carapace.ActionValues().Usage("Path to upload the DLL to on the remote system")) + + return []*cobra.Command{dllhijackCmd} +} diff --git a/client/command/environment/commands.go b/client/command/environment/commands.go new file mode 100644 index 0000000000..ed72775b1f --- /dev/null +++ b/client/command/environment/commands.go @@ -0,0 +1,59 @@ +package environment + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + envCmd := &cobra.Command{ + Use: consts.EnvStr, + Short: "List environment variables", + Long: help.GetHelpFor([]string{consts.EnvStr}), + Args: cobra.RangeArgs(0, 1), + Run: func(cmd *cobra.Command, args []string) { + EnvGetCmd(cmd, con, args) + }, + GroupID: consts.InfoHelpGroup, + } + flags.Bind("", true, envCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(envCmd).PositionalCompletion(carapace.ActionValues().Usage("environment variable to fetch (optional)")) + + envSetCmd := &cobra.Command{ + Use: consts.SetStr, + Short: "Set environment variables", + Long: help.GetHelpFor([]string{consts.EnvStr, consts.SetStr}), + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + EnvSetCmd(cmd, con, args) + }, + } + envCmd.AddCommand(envSetCmd) + carapace.Gen(envSetCmd).PositionalCompletion( + carapace.ActionValues().Usage("environment variable name"), + carapace.ActionValues().Usage("value to assign"), + ) + + envUnsetCmd := &cobra.Command{ + Use: consts.UnsetStr, + Short: "Clear environment variables", + Long: help.GetHelpFor([]string{consts.EnvStr, consts.UnsetStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + EnvUnsetCmd(cmd, con, args) + }, + } + envCmd.AddCommand(envUnsetCmd) + carapace.Gen(envUnsetCmd).PositionalCompletion(carapace.ActionValues().Usage("environment variable name")) + + return []*cobra.Command{envCmd} +} diff --git a/client/command/exec/commands.go b/client/command/exec/commands.go new file mode 100644 index 0000000000..13edbe3de5 --- /dev/null +++ b/client/command/exec/commands.go @@ -0,0 +1,276 @@ +package exec + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + executeCmd := &cobra.Command{ + Use: consts.ExecuteStr, + Short: "Execute a program on the remote system", + Long: help.GetHelpFor([]string{consts.ExecuteStr}), + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ExecuteCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + } + flags.Bind("", false, executeCmd, func(f *pflag.FlagSet) { + 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") + f.BoolP("ignore-stderr", "S", false, "don't print STDERR output") + f.StringP("stdout", "O", "", "remote path to redirect STDOUT to") + 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.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + executeCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + + carapace.Gen(executeCmd).PositionalCompletion(carapace.ActionValues().Usage("command to execute (required)")) + carapace.Gen(executeCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to the command (optional)")) + + executeAssemblyCmd := &cobra.Command{ + Use: consts.ExecuteAssemblyStr, + Short: "Loads and executes a .NET assembly in a child process (Windows Only)", + Long: help.GetHelpFor([]string{consts.ExecuteAssemblyStr}), + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ExecuteAssemblyCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, executeAssemblyCmd, func(f *pflag.FlagSet) { + f.StringP("process", "p", "notepad.exe", "hosting process to inject into") + f.StringP("method", "m", "", "Optional method (a method is required for a .NET DLL)") + f.StringP("class", "c", "", "Optional class name (required for .NET DLL)") + f.StringP("app-domain", "d", "", "AppDomain name to create for .NET assembly. Generated randomly if not set.") + f.StringP("arch", "a", "x84", "Assembly target architecture: x86, x64, x84 (x86+x64)") + f.BoolP("in-process", "i", false, "Run in the current sliver process") + f.StringP("runtime", "r", "", "Runtime to use for running the assembly (only supported when used with --in-process)") + f.BoolP("save", "s", false, "save output to file") + f.BoolP("loot", "X", false, "save output as loot") + f.StringP("name", "n", "", "name to assign loot (optional)") + f.Uint32P("ppid", "P", 0, "parent process id (optional)") + f.StringP("process-arguments", "A", "", "arguments to pass to the hosting process") + f.BoolP("amsi-bypass", "M", false, "Bypass AMSI on Windows (only supported when used with --in-process)") + f.BoolP("etw-bypass", "E", false, "Bypass ETW on Windows (only supported when used with --in-process)") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + executeAssemblyCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + + carapace.Gen(executeAssemblyCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to assembly file (required)")) + carapace.Gen(executeAssemblyCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the assembly entrypoint (optional)")) + + executeShellcodeCmd := &cobra.Command{ + Use: consts.ExecuteShellcodeStr, + Short: "Executes the given shellcode in the sliver process", + Long: help.GetHelpFor([]string{consts.ExecuteShellcodeStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ExecuteShellcodeCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + } + flags.Bind("", false, executeShellcodeCmd, func(f *pflag.FlagSet) { + f.BoolP("rwx-pages", "r", false, "Use RWX permissions for memory pages") + f.Uint32P("pid", "p", 0, "Pid of process to inject into (0 means injection into ourselves)") + f.StringP("process", "n", `c:\windows\system32\notepad.exe`, "Process to inject into when running in interactive mode") + f.BoolP("interactive", "i", false, "Inject into a new process and interact with it") + f.BoolP("shikata-ga-nai", "S", false, "encode shellcode using shikata ga nai prior to execution") + f.StringP("architecture", "A", "amd64", "architecture of the shellcode: 386, amd64 (used with --shikata-ga-nai flag)") + f.Uint32P("iterations", "I", 1, "number of encoding iterations (used with --shikata-ga-nai flag)") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.BindFlagCompletions(executeShellcodeCmd, func(comp *carapace.ActionMap) { + (*comp)["shikata-ga-nai"] = carapace.ActionValues("386", "amd64").Tag("shikata-ga-nai architectures") + }) + carapace.Gen(executeShellcodeCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to shellcode file (required)")) + + sideloadCmd := &cobra.Command{ + Use: consts.SideloadStr, + Short: "Load and execute a shared object (shared library/DLL) in a remote process", + Long: help.GetHelpFor([]string{consts.SideloadStr}), + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + SideloadCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + } + flags.Bind("", false, sideloadCmd, func(f *pflag.FlagSet) { + f.StringP("entry-point", "e", "", "Entrypoint for the DLL (Windows only)") + f.StringP("process", "p", `c:\windows\system32\notepad.exe`, "Path to process to host the shellcode") + f.BoolP("unicode", "w", false, "Command line is passed to unmanaged DLL function in UNICODE format. (default is ANSI)") + f.BoolP("save", "s", false, "save output to file") + f.BoolP("loot", "X", false, "save output as loot") + f.StringP("name", "n", "", "name to assign loot (optional)") + f.BoolP("keep-alive", "k", false, "don't terminate host process once the execution completes") + f.Uint32P("ppid", "P", 0, "parent process id (optional)") + f.StringP("process-arguments", "A", "", "arguments to pass to the hosting process") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + sideloadCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + + carapace.Gen(sideloadCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to shared library file (required)")) + carapace.Gen(sideloadCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the binary (optional)")) + + spawnDllCmd := &cobra.Command{ + Use: consts.SpawnDllStr, + Short: "Load and execute a Reflective DLL in a remote process", + Long: help.GetHelpFor([]string{consts.SpawnDllStr}), + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + SpawnDllCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, spawnDllCmd, func(f *pflag.FlagSet) { + f.StringP("process", "p", `c:\windows\system32\notepad.exe`, "Path to process to host the shellcode") + f.StringP("export", "e", "ReflectiveLoader", "Entrypoint of the Reflective DLL") + f.BoolP("save", "s", false, "save output to file") + f.BoolP("loot", "X", false, "save output as loot") + f.StringP("name", "n", "", "name to assign loot (optional)") + f.BoolP("keep-alive", "k", false, "don't terminate host process once the execution completes") + f.UintP("ppid", "P", 0, "parent process id (optional)") + f.StringP("process-arguments", "A", "", "arguments to pass to the hosting process") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + spawnDllCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + + carapace.Gen(spawnDllCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to DLL file (required)")) + carapace.Gen(spawnDllCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the DLL entrypoint (optional)")) + + migrateCmd := &cobra.Command{ + Use: consts.MigrateStr, + Short: "Migrate into a remote process", + Long: help.GetHelpFor([]string{consts.MigrateStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + MigrateCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, migrateCmd, func(f *pflag.FlagSet) { + f.BoolP("disable-sgn", "S", true, "disable shikata ga nai shellcode encoder") + f.Uint32P("pid", "p", 0, "process id to migrate into") + f.StringP("process-name", "n", "", "name of the process to migrate into") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(migrateCmd).PositionalCompletion(carapace.ActionValues().Usage("PID of process to migrate into")) + + msfCmd := &cobra.Command{ + Use: consts.MsfStr, + Short: "Execute an MSF payload in the current process", + Long: help.GetHelpFor([]string{consts.MsfStr}), + Run: func(cmd *cobra.Command, args []string) { + MsfCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + } + flags.Bind("", false, msfCmd, func(f *pflag.FlagSet) { + f.StringP("payload", "m", "meterpreter_reverse_https", "msf payload") + f.StringP("lhost", "L", "", "listen host") + f.IntP("lport", "l", 4444, "listen port") + f.StringP("encoder", "e", "", "msf encoder") + f.IntP("iterations", "i", 1, "iterations of the encoder") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + msfInjectCmd := &cobra.Command{ + Use: consts.MsfInjectStr, + Short: "Inject an MSF payload into a process", + Long: help.GetHelpFor([]string{consts.MsfInjectStr}), + Run: func(cmd *cobra.Command, args []string) { + MsfInjectCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + } + flags.Bind("", false, msfInjectCmd, func(f *pflag.FlagSet) { + f.IntP("pid", "p", -1, "pid to inject into") + f.StringP("payload", "m", "meterpreter_reverse_https", "msf payload") + f.StringP("lhost", "L", "", "listen host") + f.IntP("lport", "l", 4444, "listen port") + f.StringP("encoder", "e", "", "msf encoder") + f.IntP("iterations", "i", 1, "iterations of the encoder") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + psExecCmd := &cobra.Command{ + Use: consts.PsExecStr, + Short: "Start a sliver service on a remote target", + Long: help.GetHelpFor([]string{consts.PsExecStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + PsExecCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, psExecCmd, func(f *pflag.FlagSet) { + f.StringP("service-name", "s", "Sliver", "name that will be used to register the service") + f.StringP("service-description", "d", "Sliver implant", "description of the service") + f.StringP("profile", "p", "", "profile to use for service binary") + f.StringP("binpath", "b", "c:\\windows\\temp", "directory to which the executable will be uploaded") + f.StringP("custom-exe", "c", "", "custom service executable to use instead of generating a new Sliver") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.BindFlagCompletions(psExecCmd, func(comp *carapace.ActionMap) { + (*comp)["custom-exe"] = carapace.ActionFiles() + }) + carapace.Gen(psExecCmd).PositionalCompletion(carapace.ActionValues().Usage("hostname (required)")) + + sshCmd := &cobra.Command{ + Use: consts.SSHStr, + Short: "Run a SSH command on a remote host", + Long: help.GetHelpFor([]string{consts.SSHStr}), + Args: cobra.MinimumNArgs(1), + Run: func(cmd *cobra.Command, args []string) { + SSHCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + } + flags.Bind("", false, sshCmd, func(f *pflag.FlagSet) { + f.UintP("port", "p", 22, "SSH port") + f.StringP("private-key", "i", "", "path to private key file") + f.StringP("password", "P", "", "SSH user password") + f.StringP("login", "l", "", "username to use to connect") + f.BoolP("skip-loot", "s", false, "skip the prompt to use loot credentials") + f.StringP("kerberos-config", "c", "/etc/krb5.conf", "path to remote Kerberos config file") + f.StringP("kerberos-keytab", "k", "", "path to Kerberos keytab file") + f.StringP("kerberos-realm", "r", "", "Kerberos realm") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + sshCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true + + flags.BindFlagCompletions(sshCmd, func(comp *carapace.ActionMap) { + (*comp)["private-key"] = carapace.ActionFiles() + (*comp)["kerberos-keytab"] = carapace.ActionFiles() + }) + + carapace.Gen(sshCmd).PositionalCompletion(carapace.ActionValues().Usage("remote host to SSH to (required)")) + carapace.Gen(sshCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("command line with arguments")) + + return []*cobra.Command{executeCmd, executeAssemblyCmd, executeShellcodeCmd, sideloadCmd, spawnDllCmd, migrateCmd, msfCmd, msfInjectCmd, psExecCmd, sshCmd} +} diff --git a/client/command/extensions/commands.go b/client/command/extensions/commands.go new file mode 100644 index 0000000000..7ee046d4c4 --- /dev/null +++ b/client/command/extensions/commands.go @@ -0,0 +1,69 @@ +package extensions + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + extensionCmd := &cobra.Command{ + Use: consts.ExtensionsStr, + Short: "Manage extensions", + Long: help.GetHelpFor([]string{consts.ExtensionsStr}), + GroupID: consts.ExtensionHelpGroup, + Run: func(cmd *cobra.Command, _ []string) { + ExtensionsCmd(cmd, con) + }, + } + + extensionCmd.AddCommand(&cobra.Command{ + Use: consts.ListStr, + Short: "List extensions loaded in the current session or beacon", + Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.ListStr}), + Run: func(cmd *cobra.Command, args []string) { + ExtensionsListCmd(cmd, con, args) + }, + }) + + extensionLoadCmd := &cobra.Command{ + Use: consts.LoadStr, + Short: "Temporarily load an extension from a local directory", + Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.LoadStr}), + Run: func(cmd *cobra.Command, args []string) { + ExtensionLoadCmd(cmd, con, args) + }, + } + extensionCmd.AddCommand(extensionLoadCmd) + carapace.Gen(extensionLoadCmd).PositionalCompletion(carapace.ActionDirectories().Usage("path to the extension directory")) + + extensionInstallCmd := &cobra.Command{ + Use: consts.InstallStr, + Short: "Install an extension from a local directory or .tar.gz file", + Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.InstallStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ExtensionsInstallCmd(cmd, con, args) + }, + } + extensionCmd.AddCommand(extensionInstallCmd) + carapace.Gen(extensionInstallCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to the extension .tar.gz or directory")) + + extensionRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove an installed extension", + Args: cobra.ExactArgs(1), + Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.RmStr}), + Run: func(cmd *cobra.Command, args []string) { + ExtensionsRemoveCmd(cmd, con, args) + }, + } + extensionCmd.AddCommand(extensionRmCmd) + carapace.Gen(extensionRmCmd).PositionalCompletion(ExtensionsCommandNameCompleter(con).Usage("the command name of the extension to remove")) + + return []*cobra.Command{extensionCmd} +} diff --git a/client/command/filesystem/commands.go b/client/command/filesystem/commands.go new file mode 100644 index 0000000000..425527704a --- /dev/null +++ b/client/command/filesystem/commands.go @@ -0,0 +1,212 @@ +package filesystem + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + mvCmd := &cobra.Command{ + Use: consts.MvStr, + Short: "Move or rename a file", + Long: help.GetHelpFor([]string{consts.MvStr}), + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + MvCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, mvCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(mvCmd).PositionalCompletion( + carapace.ActionValues().Usage("path to source file (required)"), + carapace.ActionValues().Usage("path to dest file (required)"), + ) + + lsCmd := &cobra.Command{ + Use: consts.LsStr, + Short: "List current directory", + Long: help.GetHelpFor([]string{consts.LsStr}), + Args: cobra.RangeArgs(0, 1), + Run: func(cmd *cobra.Command, args []string) { + LsCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, lsCmd, func(f *pflag.FlagSet) { + f.BoolP("reverse", "r", false, "reverse sort order") + f.BoolP("modified", "m", false, "sort by modified time") + f.BoolP("size", "s", false, "sort by size") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(lsCmd).PositionalCompletion(carapace.ActionValues().Usage("path to enumerate (optional)")) + + rmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a file or directory", + Long: help.GetHelpFor([]string{consts.RmStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + RmCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, rmCmd, func(f *pflag.FlagSet) { + f.BoolP("recursive", "r", false, "recursively remove files") + f.BoolP("force", "F", false, "ignore safety and forcefully remove files") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(rmCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the file to remove")) + + mkdirCmd := &cobra.Command{ + Use: consts.MkdirStr, + Short: "Make a directory", + Long: help.GetHelpFor([]string{consts.MkdirStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + MkdirCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, mkdirCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(mkdirCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the directory to create")) + + cdCmd := &cobra.Command{ + Use: consts.CdStr, + Short: "Change directory", + Long: help.GetHelpFor([]string{consts.CdStr}), + Args: cobra.RangeArgs(0, 1), + Run: func(cmd *cobra.Command, args []string) { + CdCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, cdCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(cdCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the directory")) + + pwdCmd := &cobra.Command{ + Use: consts.PwdStr, + Short: "Print working directory", + Long: help.GetHelpFor([]string{consts.PwdStr}), + Run: func(cmd *cobra.Command, args []string) { + PwdCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, pwdCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + catCmd := &cobra.Command{ + Use: consts.CatStr, + Short: "Dump file to stdout", + Long: help.GetHelpFor([]string{consts.CatStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + CatCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, catCmd, func(f *pflag.FlagSet) { + f.BoolP("colorize-output", "c", false, "colorize output") + f.BoolP("hex", "x", false, "display as a hex dump") + f.BoolP("loot", "X", false, "save output as loot") + f.StringP("name", "n", "", "name to assign loot (optional)") + f.StringP("type", "T", "", "force a specific loot type (file/cred) if looting (optional)") + f.StringP("file-type", "F", "", "force a specific file type (binary/text) if looting (optional)") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(catCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the file to print")) + + downloadCmd := &cobra.Command{ + Use: consts.DownloadStr, + Short: "Download a file", + Long: help.GetHelpFor([]string{consts.DownloadStr}), + Args: cobra.RangeArgs(1, 2), + Run: func(cmd *cobra.Command, args []string) { + DownloadCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, downloadCmd, func(f *pflag.FlagSet) { + f.BoolP("loot", "X", false, "save output as loot") + f.StringP("type", "T", "", "force a specific loot type (file/cred) if looting") + f.StringP("file-type", "F", "", "force a specific file type (binary/text) if looting") + f.StringP("name", "n", "", "name to assign the download if looting") + f.BoolP("recurse", "r", false, "recursively download all files in a directory") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(downloadCmd).PositionalCompletion( + carapace.ActionValues().Usage("path to the file or directory to download"), + carapace.ActionFiles().Usage("local path where the downloaded file will be saved (optional)"), + ) + + uploadCmd := &cobra.Command{ + Use: consts.UploadStr, + Short: "Upload a file", + Long: help.GetHelpFor([]string{consts.UploadStr}), + Args: cobra.RangeArgs(1, 2), + Run: func(cmd *cobra.Command, args []string) { + UploadCmd(cmd, con, args) + }, + GroupID: consts.FilesystemHelpGroup, + } + flags.Bind("", false, uploadCmd, func(f *pflag.FlagSet) { + f.BoolP("ioc", "i", false, "track uploaded file as an ioc") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(uploadCmd).PositionalCompletion( + carapace.ActionFiles().Usage("local path to the file to upload"), + carapace.ActionValues().Usage("path to the file or directory to upload to (optional)"), + ) + + memfilesCmd := &cobra.Command{ + Use: consts.MemfilesStr, + Short: "List current memfiles", + Long: help.GetHelpFor([]string{consts.MemfilesStr}), + GroupID: consts.FilesystemHelpGroup, + Run: func(cmd *cobra.Command, args []string) { + MemfilesListCmd(cmd, con, args) + }, + } + flags.Bind("", true, memfilesCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + memfilesAddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add a memfile", + Long: help.GetHelpFor([]string{consts.MemfilesStr, consts.AddStr}), + Run: func(cmd *cobra.Command, args []string) { + MemfilesAddCmd(cmd, con, args) + }, + } + memfilesCmd.AddCommand(memfilesAddCmd) + + memfilesRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a memfile", + Long: help.GetHelpFor([]string{consts.MemfilesStr, consts.RmStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + MemfilesRmCmd(cmd, con, args) + }, + } + memfilesCmd.AddCommand(memfilesRmCmd) + + carapace.Gen(memfilesRmCmd).PositionalCompletion(carapace.ActionValues().Usage("memfile file descriptor")) + + return []*cobra.Command{mvCmd, lsCmd, rmCmd, mkdirCmd, pwdCmd, catCmd, cdCmd, downloadCmd, uploadCmd, memfilesCmd} +} diff --git a/client/command/help/commands.go b/client/command/help/commands.go new file mode 100644 index 0000000000..3799c739aa --- /dev/null +++ b/client/command/help/commands.go @@ -0,0 +1,17 @@ +package help + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + return nil +} diff --git a/client/command/info/commands.go b/client/command/info/commands.go index 90472999d3..64582c6877 100644 --- a/client/command/info/commands.go +++ b/client/command/info/commands.go @@ -30,3 +30,73 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { return []*cobra.Command{infoCmd} } + +// SliverCommands returns all info commands working on an active target. +func SliverCommands(con *console.SliverConsoleClient) []*cobra.Command { + pingCmd := &cobra.Command{ + Use: consts.PingStr, + Short: "Send round trip message to implant (does not use ICMP)", + Long: help.GetHelpFor([]string{consts.PingStr}), + Run: func(cmd *cobra.Command, args []string) { + PingCmd(cmd, con, args) + }, + GroupID: consts.InfoHelpGroup, + } + flags.Bind("", false, pingCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + getPIDCmd := &cobra.Command{ + Use: consts.GetPIDStr, + Short: "Get session pid", + Long: help.GetHelpFor([]string{consts.GetPIDStr}), + Run: func(cmd *cobra.Command, args []string) { + PIDCmd(cmd, con, args) + }, + GroupID: consts.InfoHelpGroup, + } + flags.Bind("", false, getPIDCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + getUIDCmd := &cobra.Command{ + Use: consts.GetUIDStr, + Short: "Get session process UID", + Long: help.GetHelpFor([]string{consts.GetUIDStr}), + Run: func(cmd *cobra.Command, args []string) { + UIDCmd(cmd, con, args) + }, + GroupID: consts.InfoHelpGroup, + } + flags.Bind("", false, getUIDCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + getGIDCmd := &cobra.Command{ + Use: consts.GetGIDStr, + Short: "Get session process GID", + Long: help.GetHelpFor([]string{consts.GetGIDStr}), + Run: func(cmd *cobra.Command, args []string) { + GIDCmd(cmd, con, args) + }, + GroupID: consts.InfoHelpGroup, + } + flags.Bind("", false, getGIDCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + whoamiCmd := &cobra.Command{ + Use: consts.WhoamiStr, + Short: "Get session user execution context", + Long: help.GetHelpFor([]string{consts.WhoamiStr}), + Run: func(cmd *cobra.Command, args []string) { + WhoamiCmd(cmd, con, args) + }, + GroupID: consts.InfoHelpGroup, + } + flags.Bind("", false, whoamiCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{pingCmd, getPIDCmd, getUIDCmd, getGIDCmd, whoamiCmd} +} diff --git a/client/command/kill/commands.go b/client/command/kill/commands.go new file mode 100644 index 0000000000..e9b0bdac15 --- /dev/null +++ b/client/command/kill/commands.go @@ -0,0 +1,30 @@ +package kill + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + killCmd := &cobra.Command{ + Use: consts.KillStr, + Short: "Kill a session", + Long: help.GetHelpFor([]string{consts.KillStr}), + Run: func(cmd *cobra.Command, args []string) { + KillCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + } + flags.Bind("use", false, killCmd, func(f *pflag.FlagSet) { + f.BoolP("force", "F", false, "Force kill, does not clean up") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{killCmd} +} diff --git a/client/command/network/commands.go b/client/command/network/commands.go new file mode 100644 index 0000000000..31fd801e9f --- /dev/null +++ b/client/command/network/commands.go @@ -0,0 +1,49 @@ +package network + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + ifconfigCmd := &cobra.Command{ + Use: consts.IfconfigStr, + Short: "View network interface configurations", + Long: help.GetHelpFor([]string{consts.IfconfigStr}), + Run: func(cmd *cobra.Command, args []string) { + IfconfigCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("", false, ifconfigCmd, func(f *pflag.FlagSet) { + f.BoolP("all", "A", false, "show all network adapters (default only shows IPv4)") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + netstatCmd := &cobra.Command{ + Use: consts.NetstatStr, + Short: "Print network connection information", + Long: help.GetHelpFor([]string{consts.NetstatStr}), + Run: func(cmd *cobra.Command, args []string) { + NetstatCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("", false, netstatCmd, func(f *pflag.FlagSet) { + f.BoolP("tcp", "T", true, "display information about TCP sockets") + f.BoolP("udp", "u", false, "display information about UDP sockets") + f.BoolP("ip4", "4", true, "display information about IPv4 sockets") + f.BoolP("ip6", "6", false, "display information about IPv6 sockets") + f.BoolP("listen", "l", false, "display information about listening sockets") + f.BoolP("numeric", "n", false, "display numeric addresses (disable hostname resolution)") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{ifconfigCmd, netstatCmd} +} diff --git a/client/command/pivots/commands.go b/client/command/pivots/commands.go new file mode 100644 index 0000000000..9a3362da71 --- /dev/null +++ b/client/command/pivots/commands.go @@ -0,0 +1,101 @@ +package pivots + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/generate" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + pivotsCmd := &cobra.Command{ + Use: consts.PivotsStr, + Short: "List pivots for active session", + Long: help.GetHelpFor([]string{consts.PivotsStr}), + Run: func(cmd *cobra.Command, args []string) { + PivotsCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + } + flags.Bind("", true, pivotsCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + namedPipeCmd := &cobra.Command{ + Use: consts.NamedPipeStr, + Short: "Start a named pipe pivot listener", + Long: help.GetHelpFor([]string{consts.PivotsStr, consts.NamedPipeStr}), + Run: func(cmd *cobra.Command, args []string) { + StartNamedPipeListenerCmd(cmd, con, args) + }, + } + pivotsCmd.AddCommand(namedPipeCmd) + flags.Bind("", false, namedPipeCmd, func(f *pflag.FlagSet) { + f.StringP("bind", "b", "", "name of the named pipe to bind pivot listener") + f.BoolP("allow-all", "a", false, "allow all users to connect") + }) + + tcpListenerCmd := &cobra.Command{ + Use: consts.TCPListenerStr, + Short: "Start a TCP pivot listener", + Long: help.GetHelpFor([]string{consts.PivotsStr, consts.TCPListenerStr}), + Run: func(cmd *cobra.Command, args []string) { + StartTCPListenerCmd(cmd, con, args) + }, + } + pivotsCmd.AddCommand(tcpListenerCmd) + flags.Bind("", false, tcpListenerCmd, func(f *pflag.FlagSet) { + f.StringP("bind", "b", "", "remote interface to bind pivot listener") + f.Uint16P("lport", "l", generate.DefaultTCPPivotPort, "tcp pivot listener port") + }) + + pivotStopCmd := &cobra.Command{ + Use: consts.StopStr, + Short: "Stop a pivot listener", + Long: help.GetHelpFor([]string{consts.PivotsStr, consts.StopStr}), + Run: func(cmd *cobra.Command, args []string) { + StopPivotListenerCmd(cmd, con, args) + }, + } + pivotsCmd.AddCommand(pivotStopCmd) + flags.Bind("", false, pivotStopCmd, func(f *pflag.FlagSet) { + f.Uint32P("id", "i", 0, "id of the pivot listener to stop") + }) + flags.BindFlagCompletions(pivotStopCmd, func(comp *carapace.ActionMap) { + (*comp)["id"] = PivotIDCompleter(con) + }) + + pivotDetailsCmd := &cobra.Command{ + Use: consts.DetailsStr, + Short: "Get details of a pivot listener", + Long: help.GetHelpFor([]string{consts.PivotsStr, consts.StopStr}), + Run: func(cmd *cobra.Command, args []string) { + PivotDetailsCmd(cmd, con, args) + }, + } + pivotsCmd.AddCommand(pivotDetailsCmd) + flags.Bind("", false, pivotDetailsCmd, func(f *pflag.FlagSet) { + f.IntP("id", "i", 0, "id of the pivot listener to get details for") + }) + flags.BindFlagCompletions(pivotDetailsCmd, func(comp *carapace.ActionMap) { + (*comp)["id"] = PivotIDCompleter(con) + }) + + graphCmd := &cobra.Command{ + Use: consts.GraphStr, + Short: "Get pivot listeners graph", + Long: help.GetHelpFor([]string{consts.PivotsStr, "graph"}), + Run: func(cmd *cobra.Command, args []string) { + PivotsGraphCmd(cmd, con, args) + }, + } + pivotsCmd.AddCommand(graphCmd) + + return []*cobra.Command{pivotsCmd} +} diff --git a/client/command/portfwd/commands.go b/client/command/portfwd/commands.go new file mode 100644 index 0000000000..003c247443 --- /dev/null +++ b/client/command/portfwd/commands.go @@ -0,0 +1,64 @@ +package portfwd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/completers" + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + portfwdCmd := &cobra.Command{ + Use: consts.PortfwdStr, + Short: "In-band TCP port forwarding", + Long: help.GetHelpFor([]string{consts.PortfwdStr}), + Run: func(cmd *cobra.Command, args []string) { + PortfwdCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("", true, portfwdCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + addCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Create a new port forwarding tunnel", + Long: help.GetHelpFor([]string{consts.PortfwdStr}), + Run: func(cmd *cobra.Command, args []string) { + PortfwdAddCmd(cmd, con, args) + }, + } + portfwdCmd.AddCommand(addCmd) + flags.Bind("", false, addCmd, func(f *pflag.FlagSet) { + f.StringP("remote", "r", "", "remote target host:port (e.g., 10.0.0.1:445)") + f.StringP("bind", "b", "127.0.0.1:8080", "bind port forward to interface") + }) + flags.BindFlagCompletions(addCmd, func(comp *carapace.ActionMap) { + (*comp)["bind"] = completers.ClientInterfacesCompleter() + }) + + portfwdRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a port forwarding tunnel", + Long: help.GetHelpFor([]string{consts.PortfwdStr}), + Run: func(cmd *cobra.Command, args []string) { + PortfwdRmCmd(cmd, con, args) + }, + } + portfwdCmd.AddCommand(portfwdRmCmd) + flags.Bind("", false, portfwdRmCmd, func(f *pflag.FlagSet) { + f.IntP("id", "i", 0, "id of portfwd to remove") + }) + flags.BindFlagCompletions(portfwdRmCmd, func(comp *carapace.ActionMap) { + (*comp)["id"] = PortfwdIDCompleter(con) + }) + + return []*cobra.Command{portfwdCmd} +} diff --git a/client/command/privilege/commands.go b/client/command/privilege/commands.go new file mode 100644 index 0000000000..995fec1bc8 --- /dev/null +++ b/client/command/privilege/commands.go @@ -0,0 +1,175 @@ +package privilege + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/filesystem" + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + runAsCmd := &cobra.Command{ + Use: consts.RunAsStr, + Short: "Run a new process in the context of the designated user (Windows Only)", + Long: help.GetHelpFor([]string{consts.RunAsStr}), + Run: func(cmd *cobra.Command, args []string) { + RunAsCmd(cmd, con, args) + }, + GroupID: consts.PrivilegesHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, runAsCmd, func(f *pflag.FlagSet) { + f.StringP("username", "u", "", "user to impersonate") + f.StringP("process", "p", "", "process to start") + f.StringP("args", "a", "", "arguments for the process") + f.StringP("domain", "d", "", "domain of the user") + f.StringP("password", "P", "", "password of the user") + f.BoolP("show-window", "s", false, ` + Log on, but use the specified credentials on the network only. The new process uses the same token as the caller, but the system creates a new logon session within LSA, and the process uses the specified credentials as the default credentials.`) + f.BoolP("net-only", "n", false, "use ") + f.Int64P("timeout", "t", 30, "grpc timeout in seconds") + }) + + impersonateCmd := &cobra.Command{ + Use: consts.ImpersonateStr, + Short: "Impersonate a logged in user.", + Long: help.GetHelpFor([]string{consts.ImpersonateStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + ImpersonateCmd(cmd, con, args) + }, + GroupID: consts.PrivilegesHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, impersonateCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", 30, "grpc timeout in seconds") + }) + carapace.Gen(impersonateCmd).PositionalCompletion(carapace.ActionValues().Usage("name of the user account to impersonate")) + + revToSelfCmd := &cobra.Command{ + Use: consts.RevToSelfStr, + Short: "Revert to self: lose stolen Windows token", + Long: help.GetHelpFor([]string{consts.RevToSelfStr}), + Run: func(cmd *cobra.Command, args []string) { + RevToSelfCmd(cmd, con, args) + }, + GroupID: consts.PrivilegesHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, revToSelfCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", 30, "grpc timeout in seconds") + }) + + getSystemCmd := &cobra.Command{ + Use: consts.GetSystemStr, + Short: "Spawns a new sliver session as the NT AUTHORITY\\SYSTEM user (Windows Only)", + Long: help.GetHelpFor([]string{consts.GetSystemStr}), + Run: func(cmd *cobra.Command, args []string) { + GetSystemCmd(cmd, con, args) + }, + GroupID: consts.PrivilegesHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("", false, getSystemCmd, func(f *pflag.FlagSet) { + f.StringP("process", "p", "spoolsv.exe", "SYSTEM process to inject into") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + makeTokenCmd := &cobra.Command{ + Use: consts.MakeTokenStr, + Short: "Create a new Logon Session with the specified credentials", + Long: help.GetHelpFor([]string{consts.MakeTokenStr}), + GroupID: consts.PrivilegesHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + Run: func(cmd *cobra.Command, args []string) { + MakeTokenCmd(cmd, con, args) + }, + } + flags.Bind("", false, makeTokenCmd, func(f *pflag.FlagSet) { + f.StringP("username", "u", "", "username of the user to impersonate") + f.StringP("password", "p", "", "password of the user to impersonate") + f.StringP("domain", "d", "", "domain of the user to impersonate") + f.StringP("logon-type", "T", "LOGON_NEW_CREDENTIALS", "logon type to use") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + chmodCmd := &cobra.Command{ + Use: consts.ChmodStr, + Short: "Change permissions on a file or directory", + Long: help.GetHelpFor([]string{consts.ChmodStr}), + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + filesystem.ChmodCmd(cmd, con, args) + }, + GroupID: consts.PrivilegesHelpGroup, + } + flags.Bind("", false, chmodCmd, func(f *pflag.FlagSet) { + f.BoolP("recursive", "r", false, "recursively change permissions on files") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(chmodCmd).PositionalCompletion( + carapace.ActionValues().Usage("path to file to change mod perms"), + carapace.ActionValues().Usage("file permissions in octal (eg. 0644)"), + ) + + chownCmd := &cobra.Command{ + Use: consts.ChownStr, + Short: "Change owner on a file or directory", + Long: help.GetHelpFor([]string{consts.ChownStr}), + Args: cobra.ExactArgs(3), + Run: func(cmd *cobra.Command, args []string) { + filesystem.ChownCmd(cmd, con, args) + }, + GroupID: consts.PrivilegesHelpGroup, + } + flags.Bind("", false, chownCmd, func(f *pflag.FlagSet) { + f.BoolP("recursive", "r", false, "recursively change permissions on files") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(chownCmd).PositionalCompletion( + carapace.ActionValues().Usage("path to file to change owner for"), + carapace.ActionValues().Usage("user ID"), + carapace.ActionValues().Usage("group ID (required)"), + ) + + chtimesCmd := &cobra.Command{ + Use: consts.ChtimesStr, + Short: "Change access and modification times on a file (timestomp)", + Long: help.GetHelpFor([]string{consts.ChtimesStr}), + Args: cobra.ExactArgs(3), + Run: func(cmd *cobra.Command, args []string) { + filesystem.ChtimesCmd(cmd, con, args) + }, + GroupID: consts.PrivilegesHelpGroup, + } + flags.Bind("", false, chtimesCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(chtimesCmd).PositionalCompletion( + carapace.ActionValues().Usage("path to file to change access timestamps"), + carapace.ActionValues().Usage("last accessed time in DateTime format, i.e. 2006-01-02 15:04:05"), + carapace.ActionValues().Usage("last modified time in DateTime format, i.e. 2006-01-02 15:04:05"), + ) + + getprivsCmd := &cobra.Command{ + Use: consts.GetPrivsStr, + Short: "Get current privileges (Windows only)", + Long: help.GetHelpFor([]string{consts.GetPrivsStr}), + GroupID: consts.PrivilegesHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + Run: func(cmd *cobra.Command, args []string) { + GetPrivsCmd(cmd, con, args) + }, + } + flags.Bind("", false, getprivsCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{runAsCmd, impersonateCmd, revToSelfCmd, makeTokenCmd, getSystemCmd, chtimesCmd, chmodCmd, chownCmd, getprivsCmd} +} diff --git a/client/command/processes/commands.go b/client/command/processes/commands.go new file mode 100644 index 0000000000..f844894b70 --- /dev/null +++ b/client/command/processes/commands.go @@ -0,0 +1,73 @@ +package processes + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + psCmd := &cobra.Command{ + Use: consts.PsStr, + Short: "List remote processes", + Long: help.GetHelpFor([]string{consts.PsStr}), + Run: func(cmd *cobra.Command, args []string) { + PsCmd(cmd, con, args) + }, + GroupID: consts.ProcessHelpGroup, + } + flags.Bind("", false, psCmd, func(f *pflag.FlagSet) { + f.IntP("pid", "p", -1, "filter based on pid") + f.StringP("exe", "e", "", "filter based on executable name") + f.StringP("owner", "o", "", "filter based on owner") + f.BoolP("print-cmdline", "c", false, "print command line arguments") + f.BoolP("overflow", "O", false, "overflow terminal width (display truncated rows)") + f.IntP("skip-pages", "S", 0, "skip the first n page(s)") + f.BoolP("tree", "T", false, "print process tree") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + procdumpCmd := &cobra.Command{ + Use: consts.ProcdumpStr, + Short: "Dump process memory", + Long: help.GetHelpFor([]string{consts.ProcdumpStr}), + Run: func(cmd *cobra.Command, args []string) { + ProcdumpCmd(cmd, con, args) + }, + GroupID: consts.ProcessHelpGroup, + } + flags.Bind("", false, procdumpCmd, func(f *pflag.FlagSet) { + f.IntP("pid", "p", -1, "target pid") + f.StringP("name", "n", "", "target process name") + f.StringP("save", "s", "", "save to file (will overwrite if exists)") + f.BoolP("loot", "X", false, "save output as loot") + f.StringP("loot-name", "N", "", "name to assign when adding the memory dump to the loot store (optional)") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + terminateCmd := &cobra.Command{ + Use: consts.TerminateStr, + Short: "Terminate a process on the remote system", + Long: help.GetHelpFor([]string{consts.TerminateStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + TerminateCmd(cmd, con, args) + }, + GroupID: consts.ProcessHelpGroup, + } + flags.Bind("", false, terminateCmd, func(f *pflag.FlagSet) { + f.BoolP("force", "F", false, "disregard safety and kill the PID") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + carapace.Gen(terminateCmd).PositionalCompletion(carapace.ActionValues().Usage("process ID")) + + return []*cobra.Command{psCmd, procdumpCmd, terminateCmd} +} diff --git a/client/command/reconfig/commands.go b/client/command/reconfig/commands.go new file mode 100644 index 0000000000..5e52838177 --- /dev/null +++ b/client/command/reconfig/commands.go @@ -0,0 +1,47 @@ +package reconfig + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + reconfigCmd := &cobra.Command{ + Use: consts.ReconfigStr, + Short: "Reconfigure the active beacon/session", + Long: help.GetHelpFor([]string{consts.ReconfigStr}), + Run: func(cmd *cobra.Command, args []string) { + ReconfigCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + Annotations: flags.RestrictTargets(consts.BeaconCmdsFilter), + } + flags.Bind("reconfig", false, reconfigCmd, func(f *pflag.FlagSet) { + f.StringP("reconnect-interval", "r", "", "reconnect interval for implant") + f.StringP("beacon-interval", "i", "", "beacon callback interval") + f.StringP("beacon-jitter", "j", "", "beacon callback jitter (random up to)") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + renameCmd := &cobra.Command{ + Use: consts.RenameStr, + Short: "Rename the active beacon/session", + Long: help.GetHelpFor([]string{consts.RenameStr}), + Run: func(cmd *cobra.Command, args []string) { + RenameCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + } + flags.Bind("rename", false, renameCmd, func(f *pflag.FlagSet) { + f.StringP("name", "n", "", "change implant name to") + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{reconfigCmd, renameCmd} +} diff --git a/client/command/registry/commands.go b/client/command/registry/commands.go new file mode 100644 index 0000000000..228cf37e40 --- /dev/null +++ b/client/command/registry/commands.go @@ -0,0 +1,129 @@ +package registry + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + registryCmd := &cobra.Command{ + Use: consts.RegistryStr, + Short: "Windows registry operations", + Long: help.GetHelpFor([]string{consts.RegistryStr}), + GroupID: consts.InfoHelpGroup, + Annotations: flags.RestrictTargets(consts.WindowsCmdsFilter), + } + flags.Bind("registry", true, registryCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + registryReadCmd := &cobra.Command{ + Use: consts.RegistryReadStr, + Short: "Read values from the Windows registry", + Long: help.GetHelpFor([]string{consts.RegistryReadStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + RegReadCmd(cmd, con, args) + }, + } + registryCmd.AddCommand(registryReadCmd) + flags.Bind("", false, registryReadCmd, func(f *pflag.FlagSet) { + f.StringP("hive", "H", "HKCU", "registry hive") + f.StringP("hostname", "o", "", "remote host to read values from") + }) + carapace.Gen(registryReadCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) + + registryWriteCmd := &cobra.Command{ + Use: consts.RegistryWriteStr, + Short: "Write values to the Windows registry", + Long: help.GetHelpFor([]string{consts.RegistryWriteStr}), + Args: cobra.ExactArgs(2), + Run: func(cmd *cobra.Command, args []string) { + RegWriteCmd(cmd, con, args) + }, + } + registryCmd.AddCommand(registryWriteCmd) + flags.Bind("", false, registryWriteCmd, func(f *pflag.FlagSet) { + f.StringP("hive", "H", "HKCU", "registry hive") + f.StringP("hostname", "o", "", "remote host to write values to") + f.StringP("type", "T", "string", "type of the value to write (string, dword, qword, binary). If binary, you must provide a path to a file with --path") + f.StringP("path", "p", "", "path to the binary file to write") + }) + carapace.Gen(registryWriteCmd).PositionalCompletion( + carapace.ActionValues().Usage("registry path"), + carapace.ActionValues().Usage("value to write"), + ) + + registryCreateKeyCmd := &cobra.Command{ + Use: consts.RegistryCreateKeyStr, + Short: "Create a registry key", + Long: help.GetHelpFor([]string{consts.RegistryCreateKeyStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + RegCreateKeyCmd(cmd, con, args) + }, + } + registryCmd.AddCommand(registryCreateKeyCmd) + flags.Bind("", false, registryCreateKeyCmd, func(f *pflag.FlagSet) { + f.StringP("hive", "H", "HKCU", "registry hive") + f.StringP("hostname", "o", "", "remote host to write values to") + }) + carapace.Gen(registryCreateKeyCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) + + registryDeleteKeyCmd := &cobra.Command{ + Use: consts.RegistryDeleteKeyStr, + Short: "Remove a registry key", + Long: help.GetHelpFor([]string{consts.RegistryDeleteKeyStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + RegDeleteKeyCmd(cmd, con, args) + }, + } + registryCmd.AddCommand(registryDeleteKeyCmd) + flags.Bind("", false, registryDeleteKeyCmd, func(f *pflag.FlagSet) { + f.StringP("hive", "H", "HKCU", "registry hive") + f.StringP("hostname", "o", "", "remote host to remove value from") + }) + carapace.Gen(registryDeleteKeyCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) + + registryListSubCmd := &cobra.Command{ + Use: consts.RegistryListSubStr, + Short: "List the sub keys under a registry key", + Long: help.GetHelpFor([]string{consts.RegistryListSubStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + RegListSubKeysCmd(cmd, con, args) + }, + } + registryCmd.AddCommand(registryListSubCmd) + flags.Bind("", false, registryListSubCmd, func(f *pflag.FlagSet) { + f.StringP("hive", "H", "HKCU", "registry hive") + f.StringP("hostname", "o", "", "remote host to write values to") + }) + carapace.Gen(registryListSubCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) + + registryListValuesCmd := &cobra.Command{ + Use: consts.RegistryListValuesStr, + Short: "List the values for a registry key", + Long: help.GetHelpFor([]string{consts.RegistryListValuesStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + RegListValuesCmd(cmd, con, args) + }, + } + registryCmd.AddCommand(registryListValuesCmd) + flags.Bind("", false, registryListValuesCmd, func(f *pflag.FlagSet) { + f.StringP("hive", "H", "HKCU", "registry hive") + f.StringP("hostname", "o", "", "remote host to write values to") + }) + carapace.Gen(registryListValuesCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) + + return []*cobra.Command{registryCmd} +} diff --git a/client/command/rportfwd/commands.go b/client/command/rportfwd/commands.go new file mode 100644 index 0000000000..d2b35b6eb7 --- /dev/null +++ b/client/command/rportfwd/commands.go @@ -0,0 +1,64 @@ +package rportfwd + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/completers" + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + rportfwdCmd := &cobra.Command{ + Use: consts.RportfwdStr, + Short: "reverse port forwardings", + Long: help.GetHelpFor([]string{consts.RportfwdStr}), + Run: func(cmd *cobra.Command, args []string) { + RportFwdListenersCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("", true, rportfwdCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + rportfwdAddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add and start reverse port forwarding", + Long: help.GetHelpFor([]string{consts.RportfwdStr}), + Run: func(cmd *cobra.Command, args []string) { + StartRportFwdListenerCmd(cmd, con, args) + }, + } + rportfwdCmd.AddCommand(rportfwdAddCmd) + flags.Bind("", false, rportfwdAddCmd, func(f *pflag.FlagSet) { + f.StringP("remote", "r", "", "remote address : connection is forwarded to") + f.StringP("bind", "b", "", "bind address : for implants to listen on") + }) + flags.BindFlagCompletions(rportfwdAddCmd, func(comp *carapace.ActionMap) { + (*comp)["remote"] = completers.ClientInterfacesCompleter() + }) + + rportfwdRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Stop and remove reverse port forwarding", + Long: help.GetHelpFor([]string{consts.RportfwdStr}), + Run: func(cmd *cobra.Command, args []string) { + StopRportFwdListenerCmd(cmd, con, args) + }, + } + rportfwdCmd.AddCommand(rportfwdRmCmd) + flags.Bind("", false, rportfwdRmCmd, func(f *pflag.FlagSet) { + f.Uint32P("id", "i", 0, "id of portfwd to remove") + }) + flags.BindFlagCompletions(rportfwdRmCmd, func(comp *carapace.ActionMap) { + (*comp)["id"] = PortfwdIDCompleter(con) + }) + + return []*cobra.Command{rportfwdCmd} +} diff --git a/client/command/screenshot/commands.go b/client/command/screenshot/commands.go new file mode 100644 index 0000000000..85758509ae --- /dev/null +++ b/client/command/screenshot/commands.go @@ -0,0 +1,37 @@ +package screenshot + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + screenshotCmd := &cobra.Command{ + Use: consts.ScreenshotStr, + Short: "Take a screenshot", + Long: help.GetHelpFor([]string{consts.ScreenshotStr}), + Run: func(cmd *cobra.Command, args []string) { + ScreenshotCmd(cmd, con, args) + }, + GroupID: consts.InfoHelpGroup, + } + flags.Bind("", false, screenshotCmd, func(f *pflag.FlagSet) { + f.StringP("save", "s", "", "save to file (will overwrite if exists)") + f.BoolP("loot", "X", false, "save output as loot") + f.StringP("name", "n", "", "name to assign loot (optional)") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.BindFlagCompletions(screenshotCmd, func(comp *carapace.ActionMap) { + (*comp)["save"] = carapace.ActionFiles() + }) + + return []*cobra.Command{screenshotCmd} +} diff --git a/client/command/server.go b/client/command/server.go index 5ff9306a07..034ac242c7 100644 --- a/client/command/server.go +++ b/client/command/server.go @@ -76,7 +76,7 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. // the present calls. // Core - bindCommands(consts.GenericHelpGroup, server, con, + bind(consts.GenericHelpGroup, server, con, exit.Command, licenses.Commands, settings.Commands, @@ -90,21 +90,21 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. ) // C2 Network - bindCommands(consts.NetworkHelpGroup, server, con, + bind(consts.NetworkHelpGroup, server, con, jobs.Commands, websites.Commands, wireguard.Commands, ) // Payloads - bindCommands(consts.PayloadsHelpGroup, server, con, + bind(consts.PayloadsHelpGroup, server, con, sgn.Commands, generate.Commands, builders.Commands, ) // Slivers - bindCommands(consts.SliverHelpGroup, server, con, + bind(consts.SliverHelpGroup, server, con, use.Commands, info.Commands, sessions.Commands, @@ -115,7 +115,7 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. reaction.Commands, ) - // [ Post-command declaration setup]----------------------------------------- + // [ Post-command declaration setup ]----------------------------------------- // Everything below this line should preferably not be any command binding // (although you can do so without fear). If there are any final modifications diff --git a/client/command/sessions/commands.go b/client/command/sessions/commands.go index 0928b782d0..a550d43b9a 100644 --- a/client/command/sessions/commands.go +++ b/client/command/sessions/commands.go @@ -68,7 +68,7 @@ func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err == nil { - for _, s := range sessions.Sessions { + for _, s := range Sessions { link := fmt.Sprintf("[%s <- %s]", s.ActiveC2, s.RemoteAddress) id := fmt.Sprintf("%s (%d)", s.Name, s.PID) userHost := fmt.Sprintf("%s@%s", s.Username, s.Hostname) @@ -83,3 +83,57 @@ func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { return carapace.ActionCallback(callback) } + +// SliverCommands returns all session control commands for the active target. +func SliverCommands(con *console.SliverConsoleClient) []*cobra.Command { + backgroundCmd := &cobra.Command{ + Use: consts.BackgroundStr, + Short: "Background an active session", + Long: help.GetHelpFor([]string{consts.BackgroundStr}), + Run: func(cmd *cobra.Command, args []string) { + BackgroundCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + } + flags.Bind("use", false, backgroundCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + openSessionCmd := &cobra.Command{ + Use: consts.InteractiveStr, + Short: "Task a beacon to open an interactive session (Beacon only)", + Long: help.GetHelpFor([]string{consts.InteractiveStr}), + Run: func(cmd *cobra.Command, args []string) { + InteractiveCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + Annotations: flags.RestrictTargets(consts.BeaconCmdsFilter), + } + flags.Bind("interactive", false, openSessionCmd, func(f *pflag.FlagSet) { + f.StringP("mtls", "m", "", "mtls connection strings") + f.StringP("wg", "g", "", "wg connection strings") + f.StringP("http", "b", "", "http(s) connection strings") + f.StringP("dns", "n", "", "dns connection strings") + f.StringP("named-pipe", "p", "", "namedpipe connection strings") + f.StringP("tcp-pivot", "i", "", "tcppivot connection strings") + + f.StringP("delay", "d", "0s", "delay opening the session (after checkin) for a given period of time") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + closeSessionCmd := &cobra.Command{ + Use: consts.CloseStr, + Short: "Close an interactive session without killing the remote process", + Long: help.GetHelpFor([]string{consts.CloseStr}), + Run: func(cmd *cobra.Command, args []string) { + CloseSessionCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + } + flags.Bind("", false, closeSessionCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{backgroundCmd, openSessionCmd, closeSessionCmd} +} diff --git a/client/command/shell/commands.go b/client/command/shell/commands.go new file mode 100644 index 0000000000..4791cc8215 --- /dev/null +++ b/client/command/shell/commands.go @@ -0,0 +1,33 @@ +package shell + +import ( + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + shellCmd := &cobra.Command{ + Use: consts.ShellStr, + Short: "Start an interactive shell", + Long: help.GetHelpFor([]string{consts.ShellStr}), + Run: func(cmd *cobra.Command, args []string) { + ShellCmd(cmd, con, args) + }, + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.SessionCmdsFilter), + } + flags.Bind("", false, shellCmd, func(f *pflag.FlagSet) { + f.BoolP("no-pty", "y", false, "disable use of pty on macos/linux") + f.StringP("shell-path", "s", "", "path to shell interpreter") + + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + return []*cobra.Command{shellCmd} +} diff --git a/client/command/sliver.go b/client/command/sliver.go index f69bcd483e..15a3d32c91 100644 --- a/client/command/sliver.go +++ b/client/command/sliver.go @@ -20,22 +20,17 @@ package command import ( "github.com/reeflective/console" - "github.com/rsteube/carapace" "github.com/spf13/cobra" - "github.com/spf13/pflag" "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/command/alias" "github.com/bishopfox/sliver/client/command/backdoor" - "github.com/bishopfox/sliver/client/command/completers" "github.com/bishopfox/sliver/client/command/cursed" "github.com/bishopfox/sliver/client/command/dllhijack" "github.com/bishopfox/sliver/client/command/environment" "github.com/bishopfox/sliver/client/command/exec" "github.com/bishopfox/sliver/client/command/extensions" "github.com/bishopfox/sliver/client/command/filesystem" - "github.com/bishopfox/sliver/client/command/generate" - "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/command/info" "github.com/bishopfox/sliver/client/command/kill" "github.com/bishopfox/sliver/client/command/network" @@ -51,7 +46,6 @@ import ( "github.com/bishopfox/sliver/client/command/shell" "github.com/bishopfox/sliver/client/command/socks" "github.com/bishopfox/sliver/client/command/tasks" - "github.com/bishopfox/sliver/client/command/use" "github.com/bishopfox/sliver/client/command/wasm" "github.com/bishopfox/sliver/client/command/wireguard" client "github.com/bishopfox/sliver/client/console" @@ -68,18 +62,69 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { }, } - groups := []*cobra.Group{ - {ID: consts.SliverCoreHelpGroup, Title: consts.SliverCoreHelpGroup}, - {ID: consts.InfoHelpGroup, Title: consts.InfoHelpGroup}, - {ID: consts.FilesystemHelpGroup, Title: consts.FilesystemHelpGroup}, - {ID: consts.NetworkHelpGroup, Title: consts.NetworkHelpGroup}, - {ID: consts.ExecutionHelpGroup, Title: consts.ExecutionHelpGroup}, - {ID: consts.PrivilegesHelpGroup, Title: consts.PrivilegesHelpGroup}, - {ID: consts.ProcessHelpGroup, Title: consts.ProcessHelpGroup}, - {ID: consts.AliasHelpGroup, Title: consts.AliasHelpGroup}, - {ID: consts.ExtensionHelpGroup, Title: consts.ExtensionHelpGroup}, - } - sliver.AddGroup(groups...) + // [ Core ] + bind(consts.SliverCoreHelpGroup, sliver, con, + reconfig.Commands, + // sessions.Commands, + sessions.SliverCommands, + kill.Commands, + // use.Commands, + tasks.Commands, + pivots.Commands, + ) + + // [ Info ] + bind(consts.InfoHelpGroup, sliver, con, + // info.Commands, + info.SliverCommands, + screenshot.Commands, + environment.Commands, + registry.Commands, + ) + + // [ Filesystem ] + bind(consts.FilesystemHelpGroup, sliver, con, + filesystem.Commands, + ) + + // [ Network tools ] + bind(consts.NetworkHelpGroup, sliver, con, + network.Commands, + rportfwd.Commands, + portfwd.Commands, + socks.Commands, + wireguard.SliverCommands, + ) + + // [ Execution ] + bind(consts.ExecutionHelpGroup, sliver, con, + shell.Commands, + exec.Commands, + backdoor.Commands, + dllhijack.Commands, + cursed.Commands, + wasm.Commands, + ) + + // [ Privileges ] + bind(consts.PrivilegesHelpGroup, sliver, con, + privilege.Commands, + ) + + // [ Processes ] + bind(consts.ProcessHelpGroup, sliver, con, + processes.Commands, + ) + + // [ Aliases ] + bind(consts.AliasHelpGroup, sliver, con) + + // [ Extensions ] + bind(consts.ExtensionHelpGroup, sliver, con, + extensions.Commands, + ) + + // [ Post-command declaration setup ]---------------------------------------- // Load Aliases aliasManifests := assets.GetInstalledAliasManifests() @@ -103,1879 +148,9 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { extensions.ExtensionRegisterCommand(ext, sliver, con) } - // [ Reconfig ] --------------------------------------------------------------- - - reconfigCmd := &cobra.Command{ - Use: consts.ReconfigStr, - Short: "Reconfigure the active beacon/session", - Long: help.GetHelpFor([]string{consts.ReconfigStr}), - Run: func(cmd *cobra.Command, args []string) { - reconfig.ReconfigCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - Annotations: hideCommand(consts.BeaconCmdsFilter), - } - sliver.AddCommand(reconfigCmd) - Flags("reconfig", false, reconfigCmd, func(f *pflag.FlagSet) { - f.StringP("reconnect-interval", "r", "", "reconnect interval for implant") - f.StringP("beacon-interval", "i", "", "beacon callback interval") - f.StringP("beacon-jitter", "j", "", "beacon callback jitter (random up to)") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - renameCmd := &cobra.Command{ - Use: consts.RenameStr, - Short: "Rename the active beacon/session", - Long: help.GetHelpFor([]string{consts.RenameStr}), - Run: func(cmd *cobra.Command, args []string) { - reconfig.RenameCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - } - sliver.AddCommand(renameCmd) - Flags("rename", false, renameCmd, func(f *pflag.FlagSet) { - f.StringP("name", "n", "", "change implant name to") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Sessions ] -------------------------------------------------------------- - - sessionsCmd := &cobra.Command{ - Use: consts.SessionsStr, - Short: "Session management", - Long: help.GetHelpFor([]string{consts.SessionsStr}), - Run: func(cmd *cobra.Command, args []string) { - sessions.SessionsCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - } - Flags("sessions", true, sessionsCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("sessions", false, sessionsCmd, func(f *pflag.FlagSet) { - f.StringP("interact", "i", "", "interact with a session") - f.StringP("kill", "k", "", "kill the designated session") - f.BoolP("kill-all", "K", false, "kill all the sessions") - f.BoolP("clean", "C", false, "clean out any sessions marked as [DEAD]") - f.BoolP("force", "F", false, "force session action without waiting for results") - - f.StringP("filter", "f", "", "filter sessions by substring") - f.StringP("filter-re", "e", "", "filter sessions by regular expression") - }) - FlagComps(sessionsCmd, func(comp *carapace.ActionMap) { - (*comp)["interact"] = use.BeaconAndSessionIDCompleter(con) - (*comp)["kill"] = use.BeaconAndSessionIDCompleter(con) - }) - sliver.AddCommand(sessionsCmd) - - sessionsPruneCmd := &cobra.Command{ - Use: consts.PruneStr, - Short: "Kill all stale/dead sessions", - Long: help.GetHelpFor([]string{consts.SessionsStr, consts.PruneStr}), - Run: func(cmd *cobra.Command, args []string) { - sessions.SessionsPruneCmd(cmd, con, args) - }, - } - Flags("prune", false, sessionsPruneCmd, func(f *pflag.FlagSet) { - f.BoolP("force", "F", false, "Force the killing of stale/dead sessions") - }) - sessionsCmd.AddCommand(sessionsPruneCmd) - - backgroundCmd := &cobra.Command{ - Use: consts.BackgroundStr, - Short: "Background an active session", - Long: help.GetHelpFor([]string{consts.BackgroundStr}), - Run: func(cmd *cobra.Command, args []string) { - sessions.BackgroundCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - } - Flags("use", false, backgroundCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - sliver.AddCommand(backgroundCmd) - - killCmd := &cobra.Command{ - Use: consts.KillStr, - Short: "Kill a session", - Long: help.GetHelpFor([]string{consts.KillStr}), - Run: func(cmd *cobra.Command, args []string) { - kill.KillCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - } - sliver.AddCommand(killCmd) - Flags("use", false, backgroundCmd, func(f *pflag.FlagSet) { - f.BoolP("force", "F", false, "Force kill, does not clean up") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - openSessionCmd := &cobra.Command{ - Use: consts.InteractiveStr, - Short: "Task a beacon to open an interactive session (Beacon only)", - Long: help.GetHelpFor([]string{consts.InteractiveStr}), - Run: func(cmd *cobra.Command, args []string) { - sessions.InteractiveCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - Annotations: hideCommand(consts.BeaconCmdsFilter), - } - sliver.AddCommand(openSessionCmd) - Flags("interactive", false, openSessionCmd, func(f *pflag.FlagSet) { - f.StringP("mtls", "m", "", "mtls connection strings") - f.StringP("wg", "g", "", "wg connection strings") - f.StringP("http", "b", "", "http(s) connection strings") - f.StringP("dns", "n", "", "dns connection strings") - f.StringP("named-pipe", "p", "", "namedpipe connection strings") - f.StringP("tcp-pivot", "i", "", "tcppivot connection strings") - - f.StringP("delay", "d", "0s", "delay opening the session (after checkin) for a given period of time") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Use ] -------------------------------------------------------------- - - useCmd := &cobra.Command{ - Use: consts.UseStr, - Short: "Switch the active session or beacon", - Long: help.GetHelpFor([]string{consts.UseStr}), - Run: func(cmd *cobra.Command, args []string) { - use.UseCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - } - Flags("use", true, useCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(useCmd).PositionalCompletion(use.BeaconAndSessionIDCompleter(con)) - - if !con.IsCLI { - sliver.AddCommand(useCmd) - } - - useSessionCmd := &cobra.Command{ - Use: consts.SessionsStr, - Short: "Switch the active session", - Long: help.GetHelpFor([]string{consts.UseStr, consts.SessionsStr}), - Run: func(cmd *cobra.Command, args []string) { - use.UseSessionCmd(cmd, con, args) - }, - } - carapace.Gen(useSessionCmd).PositionalCompletion(use.SessionIDCompleter(con)) - useCmd.AddCommand(useSessionCmd) - - useBeaconCmd := &cobra.Command{ - Use: consts.BeaconsStr, - Short: "Switch the active beacon", - Long: help.GetHelpFor([]string{consts.UseStr, consts.BeaconsStr}), - Run: func(cmd *cobra.Command, args []string) { - use.UseBeaconCmd(cmd, con, args) - }, - } - carapace.Gen(useBeaconCmd).PositionalCompletion(use.BeaconIDCompleter(con)) - useCmd.AddCommand(useBeaconCmd) - - // [ Close ] -------------------------------------------------------------- - closeSessionCmd := &cobra.Command{ - Use: consts.CloseStr, - Short: "Close an interactive session without killing the remote process", - Long: help.GetHelpFor([]string{consts.CloseStr}), - Run: func(cmd *cobra.Command, args []string) { - sessions.CloseSessionCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - } - sliver.AddCommand(closeSessionCmd) - Flags("", false, closeSessionCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Tasks ] -------------------------------------------------------------- - - tasksCmd := &cobra.Command{ - Use: consts.TasksStr, - Short: "Beacon task management", - Long: help.GetHelpFor([]string{consts.TasksStr}), - Run: func(cmd *cobra.Command, args []string) { - tasks.TasksCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - Annotations: hideCommand(consts.BeaconCmdsFilter), - } - Flags("tasks", true, tasksCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - f.BoolP("overflow", "O", false, "overflow terminal width (display truncated rows)") - f.IntP("skip-pages", "S", 0, "skip the first n page(s)") - f.StringP("filter", "f", "", "filter based on task type (case-insensitive prefix matching)") - }) - sliver.AddCommand(tasksCmd) - - fetchCmd := &cobra.Command{ - Use: consts.FetchStr, - Short: "Fetch the details of a beacon task", - Long: help.GetHelpFor([]string{consts.TasksStr, consts.FetchStr}), - Args: cobra.RangeArgs(0, 1), - Run: func(cmd *cobra.Command, args []string) { - tasks.TasksFetchCmd(cmd, con, args) - }, - } - tasksCmd.AddCommand(fetchCmd) - carapace.Gen(fetchCmd).PositionalCompletion(tasks.BeaconTaskIDCompleter(con).Usage("beacon task ID")) - - cancelCmd := &cobra.Command{ - Use: consts.CancelStr, - Short: "Cancel a pending beacon task", - Long: help.GetHelpFor([]string{consts.TasksStr, consts.CancelStr}), - Args: cobra.RangeArgs(0, 1), - Run: func(cmd *cobra.Command, args []string) { - tasks.TasksCancelCmd(cmd, con, args) - }, - } - tasksCmd.AddCommand(cancelCmd) - carapace.Gen(cancelCmd).PositionalCompletion(tasks.BeaconPendingTasksCompleter(con).Usage("beacon task ID")) - - // [ Info ] -------------------------------------------------------------- - - infoCmd := &cobra.Command{ - Use: consts.InfoStr, - Short: "Get info about session", - Long: help.GetHelpFor([]string{consts.InfoStr}), - Run: func(cmd *cobra.Command, args []string) { - info.InfoCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - Flags("use", false, infoCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(infoCmd).PositionalCompletion(use.BeaconAndSessionIDCompleter(con)) - sliver.AddCommand(infoCmd) - - pingCmd := &cobra.Command{ - Use: consts.PingStr, - Short: "Send round trip message to implant (does not use ICMP)", - Long: help.GetHelpFor([]string{consts.PingStr}), - Run: func(cmd *cobra.Command, args []string) { - info.PingCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - sliver.AddCommand(pingCmd) - Flags("", false, pingCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - getPIDCmd := &cobra.Command{ - Use: consts.GetPIDStr, - Short: "Get session pid", - Long: help.GetHelpFor([]string{consts.GetPIDStr}), - Run: func(cmd *cobra.Command, args []string) { - info.PIDCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - sliver.AddCommand(getPIDCmd) - Flags("", false, getPIDCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - getUIDCmd := &cobra.Command{ - Use: consts.GetUIDStr, - Short: "Get session process UID", - Long: help.GetHelpFor([]string{consts.GetUIDStr}), - Run: func(cmd *cobra.Command, args []string) { - info.UIDCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - sliver.AddCommand(getUIDCmd) - Flags("", false, getUIDCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - getGIDCmd := &cobra.Command{ - Use: consts.GetGIDStr, - Short: "Get session process GID", - Long: help.GetHelpFor([]string{consts.GetGIDStr}), - Run: func(cmd *cobra.Command, args []string) { - info.GIDCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - sliver.AddCommand(getGIDCmd) - Flags("", false, getGIDCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - whoamiCmd := &cobra.Command{ - Use: consts.WhoamiStr, - Short: "Get session user execution context", - Long: help.GetHelpFor([]string{consts.WhoamiStr}), - Run: func(cmd *cobra.Command, args []string) { - info.WhoamiCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - sliver.AddCommand(whoamiCmd) - Flags("", false, whoamiCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Shell ] -------------------------------------------------------------- - - shellCmd := &cobra.Command{ - Use: consts.ShellStr, - Short: "Start an interactive shell", - Long: help.GetHelpFor([]string{consts.ShellStr}), - Run: func(cmd *cobra.Command, args []string) { - shell.ShellCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - Annotations: hideCommand(consts.SessionCmdsFilter), - } - sliver.AddCommand(shellCmd) - Flags("", false, shellCmd, func(f *pflag.FlagSet) { - f.BoolP("no-pty", "y", false, "disable use of pty on macos/linux") - f.StringP("shell-path", "s", "", "path to shell interpreter") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Exec ] -------------------------------------------------------------- - - executeCmd := &cobra.Command{ - Use: consts.ExecuteStr, - Short: "Execute a program on the remote system", - Long: help.GetHelpFor([]string{consts.ExecuteStr}), - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.ExecuteCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - } - sliver.AddCommand(executeCmd) - Flags("", false, executeCmd, func(f *pflag.FlagSet) { - 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") - f.BoolP("ignore-stderr", "S", false, "don't print STDERR output") - f.StringP("stdout", "O", "", "remote path to redirect STDOUT to") - 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.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - executeCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - - carapace.Gen(executeCmd).PositionalCompletion(carapace.ActionValues().Usage("command to execute (required)")) - carapace.Gen(executeCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to the command (optional)")) - - executeAssemblyCmd := &cobra.Command{ - Use: consts.ExecuteAssemblyStr, - Short: "Loads and executes a .NET assembly in a child process (Windows Only)", - Long: help.GetHelpFor([]string{consts.ExecuteAssemblyStr}), - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.ExecuteAssemblyCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(executeAssemblyCmd) - Flags("", false, executeAssemblyCmd, func(f *pflag.FlagSet) { - f.StringP("process", "p", "notepad.exe", "hosting process to inject into") - f.StringP("method", "m", "", "Optional method (a method is required for a .NET DLL)") - f.StringP("class", "c", "", "Optional class name (required for .NET DLL)") - f.StringP("app-domain", "d", "", "AppDomain name to create for .NET assembly. Generated randomly if not set.") - f.StringP("arch", "a", "x84", "Assembly target architecture: x86, x64, x84 (x86+x64)") - f.BoolP("in-process", "i", false, "Run in the current sliver process") - f.StringP("runtime", "r", "", "Runtime to use for running the assembly (only supported when used with --in-process)") - f.BoolP("save", "s", false, "save output to file") - f.BoolP("loot", "X", false, "save output as loot") - f.StringP("name", "n", "", "name to assign loot (optional)") - f.Uint32P("ppid", "P", 0, "parent process id (optional)") - f.StringP("process-arguments", "A", "", "arguments to pass to the hosting process") - f.BoolP("amsi-bypass", "M", false, "Bypass AMSI on Windows (only supported when used with --in-process)") - f.BoolP("etw-bypass", "E", false, "Bypass ETW on Windows (only supported when used with --in-process)") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - executeAssemblyCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - - carapace.Gen(executeAssemblyCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to assembly file (required)")) - carapace.Gen(executeAssemblyCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the assembly entrypoint (optional)")) - - executeShellcodeCmd := &cobra.Command{ - Use: consts.ExecuteShellcodeStr, - Short: "Executes the given shellcode in the sliver process", - Long: help.GetHelpFor([]string{consts.ExecuteShellcodeStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.ExecuteShellcodeCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - } - sliver.AddCommand(executeShellcodeCmd) - Flags("", false, executeShellcodeCmd, func(f *pflag.FlagSet) { - f.BoolP("rwx-pages", "r", false, "Use RWX permissions for memory pages") - f.Uint32P("pid", "p", 0, "Pid of process to inject into (0 means injection into ourselves)") - f.StringP("process", "n", `c:\windows\system32\notepad.exe`, "Process to inject into when running in interactive mode") - f.BoolP("interactive", "i", false, "Inject into a new process and interact with it") - f.BoolP("shikata-ga-nai", "S", false, "encode shellcode using shikata ga nai prior to execution") - f.StringP("architecture", "A", "amd64", "architecture of the shellcode: 386, amd64 (used with --shikata-ga-nai flag)") - f.Uint32P("iterations", "I", 1, "number of encoding iterations (used with --shikata-ga-nai flag)") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - FlagComps(executeShellcodeCmd, func(comp *carapace.ActionMap) { - (*comp)["shikata-ga-nai"] = carapace.ActionValues("386", "amd64").Tag("shikata-ga-nai architectures") - }) - carapace.Gen(executeShellcodeCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to shellcode file (required)")) - - sideloadCmd := &cobra.Command{ - Use: consts.SideloadStr, - Short: "Load and execute a shared object (shared library/DLL) in a remote process", - Long: help.GetHelpFor([]string{consts.SideloadStr}), - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.SideloadCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - } - sliver.AddCommand(sideloadCmd) - Flags("", false, sideloadCmd, func(f *pflag.FlagSet) { - f.StringP("entry-point", "e", "", "Entrypoint for the DLL (Windows only)") - f.StringP("process", "p", `c:\windows\system32\notepad.exe`, "Path to process to host the shellcode") - f.BoolP("unicode", "w", false, "Command line is passed to unmanaged DLL function in UNICODE format. (default is ANSI)") - f.BoolP("save", "s", false, "save output to file") - f.BoolP("loot", "X", false, "save output as loot") - f.StringP("name", "n", "", "name to assign loot (optional)") - f.BoolP("keep-alive", "k", false, "don't terminate host process once the execution completes") - f.Uint32P("ppid", "P", 0, "parent process id (optional)") - f.StringP("process-arguments", "A", "", "arguments to pass to the hosting process") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - sideloadCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - - carapace.Gen(sideloadCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to shared library file (required)")) - carapace.Gen(sideloadCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the binary (optional)")) - - spawnDllCmd := &cobra.Command{ - Use: consts.SpawnDllStr, - Short: "Load and execute a Reflective DLL in a remote process", - Long: help.GetHelpFor([]string{consts.SpawnDllStr}), - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.SpawnDllCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(spawnDllCmd) - Flags("", false, spawnDllCmd, func(f *pflag.FlagSet) { - f.StringP("process", "p", `c:\windows\system32\notepad.exe`, "Path to process to host the shellcode") - f.StringP("export", "e", "ReflectiveLoader", "Entrypoint of the Reflective DLL") - f.BoolP("save", "s", false, "save output to file") - f.BoolP("loot", "X", false, "save output as loot") - f.StringP("name", "n", "", "name to assign loot (optional)") - f.BoolP("keep-alive", "k", false, "don't terminate host process once the execution completes") - f.UintP("ppid", "P", 0, "parent process id (optional)") - f.StringP("process-arguments", "A", "", "arguments to pass to the hosting process") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - spawnDllCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - - carapace.Gen(spawnDllCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to DLL file (required)")) - carapace.Gen(spawnDllCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the DLL entrypoint (optional)")) - - migrateCmd := &cobra.Command{ - Use: consts.MigrateStr, - Short: "Migrate into a remote process", - Long: help.GetHelpFor([]string{consts.MigrateStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.MigrateCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(migrateCmd) - Flags("", false, migrateCmd, func(f *pflag.FlagSet) { - f.BoolP("disable-sgn", "S", true, "disable shikata ga nai shellcode encoder") - f.Uint32P("pid", "p", 0, "process id to migrate into") - f.StringP("process-name", "n", "", "name of the process to migrate into") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(migrateCmd).PositionalCompletion(carapace.ActionValues().Usage("PID of process to migrate into")) - - msfCmd := &cobra.Command{ - Use: consts.MsfStr, - Short: "Execute an MSF payload in the current process", - Long: help.GetHelpFor([]string{consts.MsfStr}), - Run: func(cmd *cobra.Command, args []string) { - exec.MsfCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - } - sliver.AddCommand(msfCmd) - Flags("", false, msfCmd, func(f *pflag.FlagSet) { - f.StringP("payload", "m", "meterpreter_reverse_https", "msf payload") - f.StringP("lhost", "L", "", "listen host") - f.IntP("lport", "l", 4444, "listen port") - f.StringP("encoder", "e", "", "msf encoder") - f.IntP("iterations", "i", 1, "iterations of the encoder") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - msfInjectCmd := &cobra.Command{ - Use: consts.MsfInjectStr, - Short: "Inject an MSF payload into a process", - Long: help.GetHelpFor([]string{consts.MsfInjectStr}), - Run: func(cmd *cobra.Command, args []string) { - exec.MsfInjectCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - } - sliver.AddCommand(msfInjectCmd) - Flags("", false, msfInjectCmd, func(f *pflag.FlagSet) { - f.IntP("pid", "p", -1, "pid to inject into") - f.StringP("payload", "m", "meterpreter_reverse_https", "msf payload") - f.StringP("lhost", "L", "", "listen host") - f.IntP("lport", "l", 4444, "listen port") - f.StringP("encoder", "e", "", "msf encoder") - f.IntP("iterations", "i", 1, "iterations of the encoder") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - psExecCmd := &cobra.Command{ - Use: consts.PsExecStr, - Short: "Start a sliver service on a remote target", - Long: help.GetHelpFor([]string{consts.PsExecStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.PsExecCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(psExecCmd) - Flags("", false, psExecCmd, func(f *pflag.FlagSet) { - f.StringP("service-name", "s", "Sliver", "name that will be used to register the service") - f.StringP("service-description", "d", "Sliver implant", "description of the service") - f.StringP("profile", "p", "", "profile to use for service binary") - f.StringP("binpath", "b", "c:\\windows\\temp", "directory to which the executable will be uploaded") - f.StringP("custom-exe", "c", "", "custom service executable to use instead of generating a new Sliver") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - FlagComps(psExecCmd, func(comp *carapace.ActionMap) { - (*comp)["custom-exe"] = carapace.ActionFiles() - }) - carapace.Gen(psExecCmd).PositionalCompletion(carapace.ActionValues().Usage("hostname (required)")) - - sshCmd := &cobra.Command{ - Use: consts.SSHStr, - Short: "Run a SSH command on a remote host", - Long: help.GetHelpFor([]string{consts.SSHStr}), - Args: cobra.MinimumNArgs(1), - Run: func(cmd *cobra.Command, args []string) { - exec.SSHCmd(cmd, con, args) - }, - GroupID: consts.ExecutionHelpGroup, - } - sliver.AddCommand(sshCmd) - Flags("", false, sshCmd, func(f *pflag.FlagSet) { - f.UintP("port", "p", 22, "SSH port") - f.StringP("private-key", "i", "", "path to private key file") - f.StringP("password", "P", "", "SSH user password") - f.StringP("login", "l", "", "username to use to connect") - f.BoolP("skip-loot", "s", false, "skip the prompt to use loot credentials") - f.StringP("kerberos-config", "c", "/etc/krb5.conf", "path to remote Kerberos config file") - f.StringP("kerberos-keytab", "k", "", "path to Kerberos keytab file") - f.StringP("kerberos-realm", "r", "", "Kerberos realm") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - sshCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - - FlagComps(sshCmd, func(comp *carapace.ActionMap) { - (*comp)["private-key"] = carapace.ActionFiles() - (*comp)["kerberos-keytab"] = carapace.ActionFiles() - }) - - carapace.Gen(sshCmd).PositionalCompletion(carapace.ActionValues().Usage("remote host to SSH to (required)")) - carapace.Gen(sshCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("command line with arguments")) - - // [ Extensions ] ----------------------------------------------------------------- - extensionCmd := &cobra.Command{ - Use: consts.ExtensionsStr, - Short: "Manage extensions", - Long: help.GetHelpFor([]string{consts.ExtensionsStr}), - GroupID: consts.ExtensionHelpGroup, - Run: func(cmd *cobra.Command, _ []string) { - extensions.ExtensionsCmd(cmd, con) - }, - } - sliver.AddCommand(extensionCmd) - - extensionCmd.AddCommand(&cobra.Command{ - Use: consts.ListStr, - Short: "List extensions loaded in the current session or beacon", - Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.ListStr}), - Run: func(cmd *cobra.Command, args []string) { - extensions.ExtensionsListCmd(cmd, con, args) - }, - }) - - extensionLoadCmd := &cobra.Command{ - Use: consts.LoadStr, - Short: "Temporarily load an extension from a local directory", - Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.LoadStr}), - Run: func(cmd *cobra.Command, args []string) { - extensions.ExtensionLoadCmd(cmd, con, args) - }, - } - extensionCmd.AddCommand(extensionLoadCmd) - carapace.Gen(extensionLoadCmd).PositionalCompletion(carapace.ActionDirectories().Usage("path to the extension directory")) - - extensionInstallCmd := &cobra.Command{ - Use: consts.InstallStr, - Short: "Install an extension from a local directory or .tar.gz file", - Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.InstallStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - extensions.ExtensionsInstallCmd(cmd, con, args) - }, - } - extensionCmd.AddCommand(extensionInstallCmd) - carapace.Gen(extensionInstallCmd).PositionalCompletion(carapace.ActionFiles().Usage("path to the extension .tar.gz or directory")) - - extensionRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove an installed extension", - Args: cobra.ExactArgs(1), - Long: help.GetHelpFor([]string{consts.ExtensionsStr, consts.RmStr}), - Run: func(cmd *cobra.Command, args []string) { - extensions.ExtensionsRemoveCmd(cmd, con, args) - }, - } - extensionCmd.AddCommand(extensionRmCmd) - carapace.Gen(extensionRmCmd).PositionalCompletion(extensions.ExtensionsCommandNameCompleter(con).Usage("the command name of the extension to remove")) - - // [ Filesystem ] --------------------------------------------- - - mvCmd := &cobra.Command{ - Use: consts.MvStr, - Short: "Move or rename a file", - Long: help.GetHelpFor([]string{consts.MvStr}), - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - filesystem.MvCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(mvCmd) - Flags("", false, mvCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(mvCmd).PositionalCompletion( - carapace.ActionValues().Usage("path to source file (required)"), - carapace.ActionValues().Usage("path to dest file (required)"), - ) - - lsCmd := &cobra.Command{ - Use: consts.LsStr, - Short: "List current directory", - Long: help.GetHelpFor([]string{consts.LsStr}), - Args: cobra.RangeArgs(0, 1), - Run: func(cmd *cobra.Command, args []string) { - filesystem.LsCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(lsCmd) - Flags("", false, lsCmd, func(f *pflag.FlagSet) { - f.BoolP("reverse", "r", false, "reverse sort order") - f.BoolP("modified", "m", false, "sort by modified time") - f.BoolP("size", "s", false, "sort by size") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(lsCmd).PositionalCompletion(carapace.ActionValues().Usage("path to enumerate (optional)")) - - rmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a file or directory", - Long: help.GetHelpFor([]string{consts.RmStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - filesystem.RmCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(rmCmd) - Flags("", false, rmCmd, func(f *pflag.FlagSet) { - f.BoolP("recursive", "r", false, "recursively remove files") - f.BoolP("force", "F", false, "ignore safety and forcefully remove files") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(rmCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the file to remove")) - - mkdirCmd := &cobra.Command{ - Use: consts.MkdirStr, - Short: "Make a directory", - Long: help.GetHelpFor([]string{consts.MkdirStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - filesystem.MkdirCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(mkdirCmd) - Flags("", false, mkdirCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(mkdirCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the directory to create")) - - cdCmd := &cobra.Command{ - Use: consts.CdStr, - Short: "Change directory", - Long: help.GetHelpFor([]string{consts.CdStr}), - Args: cobra.RangeArgs(0, 1), - Run: func(cmd *cobra.Command, args []string) { - filesystem.CdCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(cdCmd) - Flags("", false, cdCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(cdCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the directory")) - - pwdCmd := &cobra.Command{ - Use: consts.PwdStr, - Short: "Print working directory", - Long: help.GetHelpFor([]string{consts.PwdStr}), - Run: func(cmd *cobra.Command, args []string) { - filesystem.PwdCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(pwdCmd) - Flags("", false, pwdCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - catCmd := &cobra.Command{ - Use: consts.CatStr, - Short: "Dump file to stdout", - Long: help.GetHelpFor([]string{consts.CatStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - filesystem.CatCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(catCmd) - Flags("", false, catCmd, func(f *pflag.FlagSet) { - f.BoolP("colorize-output", "c", false, "colorize output") - f.BoolP("hex", "x", false, "display as a hex dump") - f.BoolP("loot", "X", false, "save output as loot") - f.StringP("name", "n", "", "name to assign loot (optional)") - f.StringP("type", "T", "", "force a specific loot type (file/cred) if looting (optional)") - f.StringP("file-type", "F", "", "force a specific file type (binary/text) if looting (optional)") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(catCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the file to print")) - - downloadCmd := &cobra.Command{ - Use: consts.DownloadStr, - Short: "Download a file", - Long: help.GetHelpFor([]string{consts.DownloadStr}), - Args: cobra.RangeArgs(1, 2), - Run: func(cmd *cobra.Command, args []string) { - filesystem.DownloadCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(downloadCmd) - Flags("", false, downloadCmd, func(f *pflag.FlagSet) { - f.BoolP("loot", "X", false, "save output as loot") - f.StringP("type", "T", "", "force a specific loot type (file/cred) if looting") - f.StringP("file-type", "F", "", "force a specific file type (binary/text) if looting") - f.StringP("name", "n", "", "name to assign the download if looting") - f.BoolP("recurse", "r", false, "recursively download all files in a directory") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(downloadCmd).PositionalCompletion( - carapace.ActionValues().Usage("path to the file or directory to download"), - carapace.ActionFiles().Usage("local path where the downloaded file will be saved (optional)"), - ) - - uploadCmd := &cobra.Command{ - Use: consts.UploadStr, - Short: "Upload a file", - Long: help.GetHelpFor([]string{consts.UploadStr}), - Args: cobra.RangeArgs(1, 2), - Run: func(cmd *cobra.Command, args []string) { - filesystem.UploadCmd(cmd, con, args) - }, - GroupID: consts.FilesystemHelpGroup, - } - sliver.AddCommand(uploadCmd) - Flags("", false, uploadCmd, func(f *pflag.FlagSet) { - f.BoolP("ioc", "i", false, "track uploaded file as an ioc") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(uploadCmd).PositionalCompletion( - carapace.ActionFiles().Usage("local path to the file to upload"), - carapace.ActionValues().Usage("path to the file or directory to upload to (optional)"), - ) - - memfilesCmd := &cobra.Command{ - Use: consts.MemfilesStr, - Short: "List current memfiles", - Long: help.GetHelpFor([]string{consts.MemfilesStr}), - GroupID: consts.FilesystemHelpGroup, - Run: func(cmd *cobra.Command, args []string) { - filesystem.MemfilesListCmd(cmd, con, args) - }, - } - Flags("", true, memfilesCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - sliver.AddCommand(memfilesCmd) - - memfilesAddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add a memfile", - Long: help.GetHelpFor([]string{consts.MemfilesStr, consts.AddStr}), - Run: func(cmd *cobra.Command, args []string) { - filesystem.MemfilesAddCmd(cmd, con, args) - }, - } - memfilesCmd.AddCommand(memfilesAddCmd) - - memfilesRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a memfile", - Long: help.GetHelpFor([]string{consts.MemfilesStr, consts.RmStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - filesystem.MemfilesRmCmd(cmd, con, args) - }, - } - memfilesCmd.AddCommand(memfilesRmCmd) - - carapace.Gen(memfilesRmCmd).PositionalCompletion(carapace.ActionValues().Usage("memfile file descriptor")) - - // [ Network ] --------------------------------------------- - - ifconfigCmd := &cobra.Command{ - Use: consts.IfconfigStr, - Short: "View network interface configurations", - Long: help.GetHelpFor([]string{consts.IfconfigStr}), - Run: func(cmd *cobra.Command, args []string) { - network.IfconfigCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - sliver.AddCommand(ifconfigCmd) - Flags("", false, ifconfigCmd, func(f *pflag.FlagSet) { - f.BoolP("all", "A", false, "show all network adapters (default only shows IPv4)") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - netstatCmd := &cobra.Command{ - Use: consts.NetstatStr, - Short: "Print network connection information", - Long: help.GetHelpFor([]string{consts.NetstatStr}), - Run: func(cmd *cobra.Command, args []string) { - network.NetstatCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - sliver.AddCommand(netstatCmd) - Flags("", false, netstatCmd, func(f *pflag.FlagSet) { - f.BoolP("tcp", "T", true, "display information about TCP sockets") - f.BoolP("udp", "u", false, "display information about UDP sockets") - f.BoolP("ip4", "4", true, "display information about IPv4 sockets") - f.BoolP("ip6", "6", false, "display information about IPv6 sockets") - f.BoolP("listen", "l", false, "display information about listening sockets") - f.BoolP("numeric", "n", false, "display numeric addresses (disable hostname resolution)") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - // [ Processes ] --------------------------------------------- - - psCmd := &cobra.Command{ - Use: consts.PsStr, - Short: "List remote processes", - Long: help.GetHelpFor([]string{consts.PsStr}), - Run: func(cmd *cobra.Command, args []string) { - processes.PsCmd(cmd, con, args) - }, - GroupID: consts.ProcessHelpGroup, - } - sliver.AddCommand(psCmd) - Flags("", false, psCmd, func(f *pflag.FlagSet) { - f.IntP("pid", "p", -1, "filter based on pid") - f.StringP("exe", "e", "", "filter based on executable name") - f.StringP("owner", "o", "", "filter based on owner") - f.BoolP("print-cmdline", "c", false, "print command line arguments") - f.BoolP("overflow", "O", false, "overflow terminal width (display truncated rows)") - f.IntP("skip-pages", "S", 0, "skip the first n page(s)") - f.BoolP("tree", "T", false, "print process tree") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - procdumpCmd := &cobra.Command{ - Use: consts.ProcdumpStr, - Short: "Dump process memory", - Long: help.GetHelpFor([]string{consts.ProcdumpStr}), - Run: func(cmd *cobra.Command, args []string) { - processes.ProcdumpCmd(cmd, con, args) - }, - GroupID: consts.ProcessHelpGroup, - } - sliver.AddCommand(procdumpCmd) - Flags("", false, procdumpCmd, func(f *pflag.FlagSet) { - f.IntP("pid", "p", -1, "target pid") - f.StringP("name", "n", "", "target process name") - f.StringP("save", "s", "", "save to file (will overwrite if exists)") - f.BoolP("loot", "X", false, "save output as loot") - f.StringP("loot-name", "N", "", "name to assign when adding the memory dump to the loot store (optional)") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - terminateCmd := &cobra.Command{ - Use: consts.TerminateStr, - Short: "Terminate a process on the remote system", - Long: help.GetHelpFor([]string{consts.TerminateStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - processes.TerminateCmd(cmd, con, args) - }, - GroupID: consts.ProcessHelpGroup, - } - sliver.AddCommand(terminateCmd) - Flags("", false, terminateCmd, func(f *pflag.FlagSet) { - f.BoolP("force", "F", false, "disregard safety and kill the PID") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(terminateCmd).PositionalCompletion(carapace.ActionValues().Usage("process ID")) - - // [ Privileges ] --------------------------------------------- - - runAsCmd := &cobra.Command{ - Use: consts.RunAsStr, - Short: "Run a new process in the context of the designated user (Windows Only)", - Long: help.GetHelpFor([]string{consts.RunAsStr}), - Run: func(cmd *cobra.Command, args []string) { - privilege.RunAsCmd(cmd, con, args) - }, - GroupID: consts.PrivilegesHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(runAsCmd) - Flags("", false, runAsCmd, func(f *pflag.FlagSet) { - f.StringP("username", "u", "", "user to impersonate") - f.StringP("process", "p", "", "process to start") - f.StringP("args", "a", "", "arguments for the process") - f.StringP("domain", "d", "", "domain of the user") - f.StringP("password", "P", "", "password of the user") - f.BoolP("show-window", "s", false, ` - Log on, but use the specified credentials on the network only. The new process uses the same token as the caller, but the system creates a new logon session within LSA, and the process uses the specified credentials as the default credentials.`) - f.BoolP("net-only", "n", false, "use ") - f.Int64P("timeout", "t", 30, "grpc timeout in seconds") - }) - - impersonateCmd := &cobra.Command{ - Use: consts.ImpersonateStr, - Short: "Impersonate a logged in user.", - Long: help.GetHelpFor([]string{consts.ImpersonateStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - privilege.ImpersonateCmd(cmd, con, args) - }, - GroupID: consts.PrivilegesHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(impersonateCmd) - Flags("", false, impersonateCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", 30, "grpc timeout in seconds") - }) - carapace.Gen(impersonateCmd).PositionalCompletion(carapace.ActionValues().Usage("name of the user account to impersonate")) - - revToSelfCmd := &cobra.Command{ - Use: consts.RevToSelfStr, - Short: "Revert to self: lose stolen Windows token", - Long: help.GetHelpFor([]string{consts.RevToSelfStr}), - Run: func(cmd *cobra.Command, args []string) { - privilege.RevToSelfCmd(cmd, con, args) - }, - GroupID: consts.PrivilegesHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(revToSelfCmd) - Flags("", false, revToSelfCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", 30, "grpc timeout in seconds") - }) - - getSystemCmd := &cobra.Command{ - Use: consts.GetSystemStr, - Short: "Spawns a new sliver session as the NT AUTHORITY\\SYSTEM user (Windows Only)", - Long: help.GetHelpFor([]string{consts.GetSystemStr}), - Run: func(cmd *cobra.Command, args []string) { - privilege.GetSystemCmd(cmd, con, args) - }, - GroupID: consts.PrivilegesHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(getSystemCmd) - Flags("", false, getSystemCmd, func(f *pflag.FlagSet) { - f.StringP("process", "p", "spoolsv.exe", "SYSTEM process to inject into") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - makeTokenCmd := &cobra.Command{ - Use: consts.MakeTokenStr, - Short: "Create a new Logon Session with the specified credentials", - Long: help.GetHelpFor([]string{consts.MakeTokenStr}), - GroupID: consts.PrivilegesHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - Run: func(cmd *cobra.Command, args []string) { - privilege.MakeTokenCmd(cmd, con, args) - }, - } - sliver.AddCommand(makeTokenCmd) - Flags("", false, makeTokenCmd, func(f *pflag.FlagSet) { - f.StringP("username", "u", "", "username of the user to impersonate") - f.StringP("password", "p", "", "password of the user to impersonate") - f.StringP("domain", "d", "", "domain of the user to impersonate") - f.StringP("logon-type", "T", "LOGON_NEW_CREDENTIALS", "logon type to use") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - chmodCmd := &cobra.Command{ - Use: consts.ChmodStr, - Short: "Change permissions on a file or directory", - Long: help.GetHelpFor([]string{consts.ChmodStr}), - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - filesystem.ChmodCmd(cmd, con, args) - }, - GroupID: consts.PrivilegesHelpGroup, - } - sliver.AddCommand(chmodCmd) - Flags("", false, chmodCmd, func(f *pflag.FlagSet) { - f.BoolP("recursive", "r", false, "recursively change permissions on files") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(chmodCmd).PositionalCompletion( - carapace.ActionValues().Usage("path to file to change mod perms"), - carapace.ActionValues().Usage("file permissions in octal (eg. 0644)"), - ) - - chownCmd := &cobra.Command{ - Use: consts.ChownStr, - Short: "Change owner on a file or directory", - Long: help.GetHelpFor([]string{consts.ChownStr}), - Args: cobra.ExactArgs(3), - Run: func(cmd *cobra.Command, args []string) { - filesystem.ChownCmd(cmd, con, args) - }, - GroupID: consts.PrivilegesHelpGroup, - } - sliver.AddCommand(chownCmd) - Flags("", false, chownCmd, func(f *pflag.FlagSet) { - f.BoolP("recursive", "r", false, "recursively change permissions on files") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(chownCmd).PositionalCompletion( - carapace.ActionValues().Usage("path to file to change owner for"), - carapace.ActionValues().Usage("user ID"), - carapace.ActionValues().Usage("group ID (required)"), - ) - - chtimesCmd := &cobra.Command{ - Use: consts.ChtimesStr, - Short: "Change access and modification times on a file (timestomp)", - Long: help.GetHelpFor([]string{consts.ChtimesStr}), - Args: cobra.ExactArgs(3), - Run: func(cmd *cobra.Command, args []string) { - filesystem.ChtimesCmd(cmd, con, args) - }, - GroupID: consts.PrivilegesHelpGroup, - } - sliver.AddCommand(chtimesCmd) - Flags("", false, chtimesCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(chtimesCmd).PositionalCompletion( - carapace.ActionValues().Usage("path to file to change access timestamps"), - carapace.ActionValues().Usage("last accessed time in DateTime format, i.e. 2006-01-02 15:04:05"), - carapace.ActionValues().Usage("last modified time in DateTime format, i.e. 2006-01-02 15:04:05"), - ) - - // [ Screenshot ] --------------------------------------------- - - screenshotCmd := &cobra.Command{ - Use: consts.ScreenshotStr, - Short: "Take a screenshot", - Long: help.GetHelpFor([]string{consts.ScreenshotStr}), - Run: func(cmd *cobra.Command, args []string) { - screenshot.ScreenshotCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - sliver.AddCommand(screenshotCmd) - Flags("", false, screenshotCmd, func(f *pflag.FlagSet) { - f.StringP("save", "s", "", "save to file (will overwrite if exists)") - f.BoolP("loot", "X", false, "save output as loot") - f.StringP("name", "n", "", "name to assign loot (optional)") - - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - FlagComps(screenshotCmd, func(comp *carapace.ActionMap) { - (*comp)["save"] = carapace.ActionFiles() - }) - - // [ Backdoor ] --------------------------------------------- - - backdoorCmd := &cobra.Command{ - Use: consts.BackdoorStr, - Short: "Infect a remote file with a sliver shellcode", - Long: help.GetHelpFor([]string{consts.BackdoorStr}), - Args: cobra.ExactArgs(1), - GroupID: consts.ExecutionHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - Run: func(cmd *cobra.Command, args []string) { - backdoor.BackdoorCmd(cmd, con, args) - }, - } - sliver.AddCommand(backdoorCmd) - Flags("", false, backdoorCmd, func(f *pflag.FlagSet) { - f.StringP("profile", "p", "", "profile to use for service binary") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - FlagComps(screenshotCmd, func(comp *carapace.ActionMap) { - (*comp)["profile"] = generate.ProfileNameCompleter(con) - }) - carapace.Gen(backdoorCmd).PositionalCompletion(carapace.ActionValues().Usage("path to the remote file to backdoor")) - - // // [ DLL Hijack ] ----------------------------------------------------------------- - - dllhijackCmd := &cobra.Command{ - Use: consts.DLLHijackStr, - Short: "Plant a DLL for a hijack scenario", - Long: help.GetHelpFor([]string{consts.DLLHijackStr}), - GroupID: consts.ExecutionHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - dllhijack.DllHijackCmd(cmd, con, args) - }, - } - sliver.AddCommand(dllhijackCmd) - Flags("", false, dllhijackCmd, func(f *pflag.FlagSet) { - f.StringP("reference-path", "r", "", "Path to the reference DLL on the remote system") - f.StringP("reference-file", "R", "", "Path to the reference DLL on the local system") - f.StringP("file", "f", "", "Local path to the DLL to plant for the hijack") - f.StringP("profile", "p", "", "Profile name to use as a base DLL") - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - FlagComps(dllhijackCmd, func(comp *carapace.ActionMap) { - (*comp)["reference-file"] = carapace.ActionFiles() - (*comp)["file"] = carapace.ActionFiles() - (*comp)["profile"] = generate.ProfileNameCompleter(con) - }) - carapace.Gen(dllhijackCmd).PositionalCompletion(carapace.ActionValues().Usage("Path to upload the DLL to on the remote system")) - - // [ Get Privs ] ----------------------------------------------------------------- - getprivsCmd := &cobra.Command{ - Use: consts.GetPrivsStr, - Short: "Get current privileges (Windows only)", - Long: help.GetHelpFor([]string{consts.GetPrivsStr}), - GroupID: consts.PrivilegesHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - Run: func(cmd *cobra.Command, args []string) { - privilege.GetPrivsCmd(cmd, con, args) - }, - } - sliver.AddCommand(getprivsCmd) - Flags("", false, getprivsCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - // - - // [ Environment ] --------------------------------------------- - - envCmd := &cobra.Command{ - Use: consts.EnvStr, - Short: "List environment variables", - Long: help.GetHelpFor([]string{consts.EnvStr}), - Args: cobra.RangeArgs(0, 1), - Run: func(cmd *cobra.Command, args []string) { - environment.EnvGetCmd(cmd, con, args) - }, - GroupID: consts.InfoHelpGroup, - } - sliver.AddCommand(envCmd) - Flags("", true, envCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - carapace.Gen(envCmd).PositionalCompletion(carapace.ActionValues().Usage("environment variable to fetch (optional)")) - - envSetCmd := &cobra.Command{ - Use: consts.SetStr, - Short: "Set environment variables", - Long: help.GetHelpFor([]string{consts.EnvStr, consts.SetStr}), - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - environment.EnvSetCmd(cmd, con, args) - }, - } - envCmd.AddCommand(envSetCmd) - carapace.Gen(envSetCmd).PositionalCompletion( - carapace.ActionValues().Usage("environment variable name"), - carapace.ActionValues().Usage("value to assign"), - ) - - envUnsetCmd := &cobra.Command{ - Use: consts.UnsetStr, - Short: "Clear environment variables", - Long: help.GetHelpFor([]string{consts.EnvStr, consts.UnsetStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - environment.EnvUnsetCmd(cmd, con, args) - }, - } - envCmd.AddCommand(envUnsetCmd) - carapace.Gen(envUnsetCmd).PositionalCompletion(carapace.ActionValues().Usage("environment variable name")) - - // [ Registry ] --------------------------------------------- - - registryCmd := &cobra.Command{ - Use: consts.RegistryStr, - Short: "Windows registry operations", - Long: help.GetHelpFor([]string{consts.RegistryStr}), - GroupID: consts.InfoHelpGroup, - Annotations: hideCommand(consts.WindowsCmdsFilter), - } - sliver.AddCommand(registryCmd) - Flags("registry", true, registryCmd, func(f *pflag.FlagSet) { - f.IntP("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - registryReadCmd := &cobra.Command{ - Use: consts.RegistryReadStr, - Short: "Read values from the Windows registry", - Long: help.GetHelpFor([]string{consts.RegistryReadStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - registry.RegReadCmd(cmd, con, args) - }, - } - registryCmd.AddCommand(registryReadCmd) - Flags("", false, registryReadCmd, func(f *pflag.FlagSet) { - f.StringP("hive", "H", "HKCU", "registry hive") - f.StringP("hostname", "o", "", "remote host to read values from") - }) - carapace.Gen(registryReadCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) - - registryWriteCmd := &cobra.Command{ - Use: consts.RegistryWriteStr, - Short: "Write values to the Windows registry", - Long: help.GetHelpFor([]string{consts.RegistryWriteStr}), - Args: cobra.ExactArgs(2), - Run: func(cmd *cobra.Command, args []string) { - registry.RegWriteCmd(cmd, con, args) - }, - } - registryCmd.AddCommand(registryWriteCmd) - Flags("", false, registryWriteCmd, func(f *pflag.FlagSet) { - f.StringP("hive", "H", "HKCU", "registry hive") - f.StringP("hostname", "o", "", "remote host to write values to") - f.StringP("type", "T", "string", "type of the value to write (string, dword, qword, binary). If binary, you must provide a path to a file with --path") - f.StringP("path", "p", "", "path to the binary file to write") - }) - carapace.Gen(registryWriteCmd).PositionalCompletion( - carapace.ActionValues().Usage("registry path"), - carapace.ActionValues().Usage("value to write"), - ) - - registryCreateKeyCmd := &cobra.Command{ - Use: consts.RegistryCreateKeyStr, - Short: "Create a registry key", - Long: help.GetHelpFor([]string{consts.RegistryCreateKeyStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - registry.RegCreateKeyCmd(cmd, con, args) - }, - } - registryCmd.AddCommand(registryCreateKeyCmd) - Flags("", false, registryCreateKeyCmd, func(f *pflag.FlagSet) { - f.StringP("hive", "H", "HKCU", "registry hive") - f.StringP("hostname", "o", "", "remote host to write values to") - }) - carapace.Gen(registryCreateKeyCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) - - registryDeleteKeyCmd := &cobra.Command{ - Use: consts.RegistryDeleteKeyStr, - Short: "Remove a registry key", - Long: help.GetHelpFor([]string{consts.RegistryDeleteKeyStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - registry.RegDeleteKeyCmd(cmd, con, args) - }, - } - registryCmd.AddCommand(registryDeleteKeyCmd) - Flags("", false, registryDeleteKeyCmd, func(f *pflag.FlagSet) { - f.StringP("hive", "H", "HKCU", "registry hive") - f.StringP("hostname", "o", "", "remote host to remove value from") - }) - carapace.Gen(registryDeleteKeyCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) - - registryListSubCmd := &cobra.Command{ - Use: consts.RegistryListSubStr, - Short: "List the sub keys under a registry key", - Long: help.GetHelpFor([]string{consts.RegistryListSubStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - registry.RegListSubKeysCmd(cmd, con, args) - }, - } - registryCmd.AddCommand(registryListSubCmd) - Flags("", false, registryListSubCmd, func(f *pflag.FlagSet) { - f.StringP("hive", "H", "HKCU", "registry hive") - f.StringP("hostname", "o", "", "remote host to write values to") - }) - carapace.Gen(registryListSubCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) - - registryListValuesCmd := &cobra.Command{ - Use: consts.RegistryListValuesStr, - Short: "List the values for a registry key", - Long: help.GetHelpFor([]string{consts.RegistryListValuesStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - registry.RegListValuesCmd(cmd, con, args) - }, - } - registryCmd.AddCommand(registryListValuesCmd) - Flags("", false, registryListValuesCmd, func(f *pflag.FlagSet) { - f.StringP("hive", "H", "HKCU", "registry hive") - f.StringP("hostname", "o", "", "remote host to write values to") - }) - carapace.Gen(registryListValuesCmd).PositionalCompletion(carapace.ActionValues().Usage("registry path")) - - // [ Reverse Port Forwarding ] -------------------------------------------------------------- - - rportfwdCmd := &cobra.Command{ - Use: consts.RportfwdStr, - Short: "reverse port forwardings", - Long: help.GetHelpFor([]string{consts.RportfwdStr}), - Run: func(cmd *cobra.Command, args []string) { - rportfwd.RportFwdListenersCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - sliver.AddCommand(rportfwdCmd) - Flags("", true, rportfwdCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - rportfwdAddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add and start reverse port forwarding", - Long: help.GetHelpFor([]string{consts.RportfwdStr}), - Run: func(cmd *cobra.Command, args []string) { - rportfwd.StartRportFwdListenerCmd(cmd, con, args) - }, - } - rportfwdCmd.AddCommand(rportfwdAddCmd) - Flags("", false, rportfwdAddCmd, func(f *pflag.FlagSet) { - f.StringP("remote", "r", "", "remote address : connection is forwarded to") - f.StringP("bind", "b", "", "bind address : for implants to listen on") - }) - FlagComps(rportfwdAddCmd, func(comp *carapace.ActionMap) { - (*comp)["remote"] = completers.ClientInterfacesCompleter() - }) - - rportfwdRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Stop and remove reverse port forwarding", - Long: help.GetHelpFor([]string{consts.RportfwdStr}), - Run: func(cmd *cobra.Command, args []string) { - rportfwd.StopRportFwdListenerCmd(cmd, con, args) - }, - } - rportfwdCmd.AddCommand(rportfwdRmCmd) - Flags("", false, rportfwdRmCmd, func(f *pflag.FlagSet) { - f.Uint32P("id", "i", 0, "id of portfwd to remove") - }) - FlagComps(rportfwdRmCmd, func(comp *carapace.ActionMap) { - (*comp)["id"] = rportfwd.PortfwdIDCompleter(con) - }) - - // [ Pivots ] -------------------------------------------------------------- - - pivotsCmd := &cobra.Command{ - Use: consts.PivotsStr, - Short: "List pivots for active session", - Long: help.GetHelpFor([]string{consts.PivotsStr}), - Run: func(cmd *cobra.Command, args []string) { - pivots.PivotsCmd(cmd, con, args) - }, - GroupID: consts.SliverCoreHelpGroup, - } - sliver.AddCommand(pivotsCmd) - Flags("", true, pivotsCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - namedPipeCmd := &cobra.Command{ - Use: consts.NamedPipeStr, - Short: "Start a named pipe pivot listener", - Long: help.GetHelpFor([]string{consts.PivotsStr, consts.NamedPipeStr}), - Run: func(cmd *cobra.Command, args []string) { - pivots.StartNamedPipeListenerCmd(cmd, con, args) - }, - } - pivotsCmd.AddCommand(namedPipeCmd) - Flags("", false, namedPipeCmd, func(f *pflag.FlagSet) { - f.StringP("bind", "b", "", "name of the named pipe to bind pivot listener") - f.BoolP("allow-all", "a", false, "allow all users to connect") - }) - - tcpListenerCmd := &cobra.Command{ - Use: consts.TCPListenerStr, - Short: "Start a TCP pivot listener", - Long: help.GetHelpFor([]string{consts.PivotsStr, consts.TCPListenerStr}), - Run: func(cmd *cobra.Command, args []string) { - pivots.StartTCPListenerCmd(cmd, con, args) - }, - } - pivotsCmd.AddCommand(tcpListenerCmd) - Flags("", false, tcpListenerCmd, func(f *pflag.FlagSet) { - f.StringP("bind", "b", "", "remote interface to bind pivot listener") - f.Uint16P("lport", "l", generate.DefaultTCPPivotPort, "tcp pivot listener port") - }) - - pivotStopCmd := &cobra.Command{ - Use: consts.StopStr, - Short: "Stop a pivot listener", - Long: help.GetHelpFor([]string{consts.PivotsStr, consts.StopStr}), - Run: func(cmd *cobra.Command, args []string) { - pivots.StopPivotListenerCmd(cmd, con, args) - }, - } - pivotsCmd.AddCommand(pivotStopCmd) - Flags("", false, pivotStopCmd, func(f *pflag.FlagSet) { - f.Uint32P("id", "i", 0, "id of the pivot listener to stop") - }) - FlagComps(pivotStopCmd, func(comp *carapace.ActionMap) { - (*comp)["id"] = pivots.PivotIDCompleter(con) - }) - - pivotDetailsCmd := &cobra.Command{ - Use: consts.DetailsStr, - Short: "Get details of a pivot listener", - Long: help.GetHelpFor([]string{consts.PivotsStr, consts.StopStr}), - Run: func(cmd *cobra.Command, args []string) { - pivots.PivotDetailsCmd(cmd, con, args) - }, - } - pivotsCmd.AddCommand(pivotDetailsCmd) - Flags("", false, pivotDetailsCmd, func(f *pflag.FlagSet) { - f.IntP("id", "i", 0, "id of the pivot listener to get details for") - }) - FlagComps(pivotDetailsCmd, func(comp *carapace.ActionMap) { - (*comp)["id"] = pivots.PivotIDCompleter(con) - }) - - graphCmd := &cobra.Command{ - Use: consts.GraphStr, - Short: "Get pivot listeners graph", - Long: help.GetHelpFor([]string{consts.PivotsStr, "graph"}), - Run: func(cmd *cobra.Command, args []string) { - pivots.PivotsGraphCmd(cmd, con, args) - }, - } - pivotsCmd.AddCommand(graphCmd) - - // [ Portfwd ] -------------------------------------------------------------- - - portfwdCmd := &cobra.Command{ - Use: consts.PortfwdStr, - Short: "In-band TCP port forwarding", - Long: help.GetHelpFor([]string{consts.PortfwdStr}), - Run: func(cmd *cobra.Command, args []string) { - portfwd.PortfwdCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - sliver.AddCommand(portfwdCmd) - Flags("", true, portfwdCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - addCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Create a new port forwarding tunnel", - Long: help.GetHelpFor([]string{consts.PortfwdStr}), - Run: func(cmd *cobra.Command, args []string) { - portfwd.PortfwdAddCmd(cmd, con, args) - }, - } - portfwdCmd.AddCommand(addCmd) - Flags("", false, addCmd, func(f *pflag.FlagSet) { - f.StringP("remote", "r", "", "remote target host:port (e.g., 10.0.0.1:445)") - f.StringP("bind", "b", "127.0.0.1:8080", "bind port forward to interface") - }) - FlagComps(addCmd, func(comp *carapace.ActionMap) { - (*comp)["bind"] = completers.ClientInterfacesCompleter() - }) - - portfwdRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a port forwarding tunnel", - Long: help.GetHelpFor([]string{consts.PortfwdStr}), - Run: func(cmd *cobra.Command, args []string) { - portfwd.PortfwdRmCmd(cmd, con, args) - }, - } - portfwdCmd.AddCommand(portfwdRmCmd) - Flags("", false, portfwdRmCmd, func(f *pflag.FlagSet) { - f.IntP("id", "i", 0, "id of portfwd to remove") - }) - FlagComps(portfwdRmCmd, func(comp *carapace.ActionMap) { - (*comp)["id"] = portfwd.PortfwdIDCompleter(con) - }) - - // [ Socks ] -------------------------------------------------------------- - - socksCmd := &cobra.Command{ - Use: consts.Socks5Str, - Short: "In-band SOCKS5 Proxy", - Long: help.GetHelpFor([]string{consts.Socks5Str}), - Run: func(cmd *cobra.Command, args []string) { - socks.SocksCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - } - sliver.AddCommand(socksCmd) - Flags("", true, socksCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - socksStartCmd := &cobra.Command{ - Use: consts.StartStr, - Short: "Start an in-band SOCKS5 proxy", - Long: help.GetHelpFor([]string{consts.Socks5Str}), - Run: func(cmd *cobra.Command, args []string) { - socks.SocksStartCmd(cmd, con, args) - }, - } - socksCmd.AddCommand(socksStartCmd) - Flags("", false, socksStartCmd, func(f *pflag.FlagSet) { - f.StringP("host", "H", "127.0.0.1", "Bind a Socks5 Host") - f.StringP("port", "P", "1081", "Bind a Socks5 Port") - f.StringP("user", "u", "", "socks5 auth username (will generate random password)") - }) - FlagComps(socksStartCmd, func(comp *carapace.ActionMap) { - (*comp)["host"] = completers.ClientInterfacesCompleter() - }) - - socksStopCmd := &cobra.Command{ - Use: consts.StopStr, - Short: "Stop a SOCKS5 proxy", - Long: help.GetHelpFor([]string{consts.Socks5Str}), - Run: func(cmd *cobra.Command, args []string) { - socks.SocksStopCmd(cmd, con, args) - }, - } - socksCmd.AddCommand(socksStopCmd) - Flags("", false, socksStopCmd, func(f *pflag.FlagSet) { - f.Uint64P("id", "i", 0, "id of portfwd to remove") - }) - FlagComps(socksStopCmd, func(comp *carapace.ActionMap) { - (*comp)["id"] = socks.SocksIDCompleter(con) - }) - - // [ WireGuard ] -------------------------------------------------------------- - - wgPortFwdCmd := &cobra.Command{ - Use: consts.WgPortFwdStr, - Short: "List ports forwarded by the WireGuard tun interface", - Long: help.GetHelpFor([]string{consts.WgPortFwdStr}), - Run: func(cmd *cobra.Command, args []string) { - wireguard.WGPortFwdListCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - Annotations: hideCommand(consts.WireguardCmdsFilter), - } - Flags("wg portforward", true, wgPortFwdCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - sliver.AddCommand(wgPortFwdCmd) - - wgPortFwdAddCmd := &cobra.Command{ - Use: consts.AddStr, - Short: "Add a port forward from the WireGuard tun interface to a host on the target network", - Long: help.GetHelpFor([]string{consts.WgPortFwdStr, consts.AddStr}), - Run: func(cmd *cobra.Command, args []string) { - wireguard.WGPortFwdAddCmd(cmd, con, args) - }, - } - Flags("wg portforward", false, wgPortFwdAddCmd, func(f *pflag.FlagSet) { - f.Int32P("bind", "b", 1080, "port to listen on the WireGuard tun interface") - f.StringP("remote", "r", "", "remote target host:port (e.g., 10.0.0.1:445)") - }) - wgPortFwdCmd.AddCommand(wgPortFwdAddCmd) - - wgPortFwdRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a port forward from the WireGuard tun interface", - Long: help.GetHelpFor([]string{consts.WgPortFwdStr, consts.RmStr}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - wireguard.WGPortFwdRmCmd(cmd, con, args) - }, - } - wgPortFwdCmd.AddCommand(wgPortFwdRmCmd) - - carapace.Gen(wgPortFwdRmCmd).PositionalCompletion(wireguard.PortfwdIDCompleter(con).Usage("forwarder ID")) - - wgSocksCmd := &cobra.Command{ - Use: consts.WgSocksStr, - Short: "List socks servers listening on the WireGuard tun interface", - Long: help.GetHelpFor([]string{consts.WgSocksStr}), - Run: func(cmd *cobra.Command, args []string) { - wireguard.WGSocksListCmd(cmd, con, args) - }, - GroupID: consts.NetworkHelpGroup, - Annotations: hideCommand(consts.WireguardCmdsFilter), - } - sliver.AddCommand(wgSocksCmd) - Flags("wg socks", true, wgSocksCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - wgSocksStartCmd := &cobra.Command{ - Use: consts.StartStr, - Short: "Start a socks5 listener on the WireGuard tun interface", - Long: help.GetHelpFor([]string{consts.WgSocksStr, consts.StartStr}), - Run: func(cmd *cobra.Command, args []string) { - wireguard.WGSocksStartCmd(cmd, con, args) - }, - } - wgSocksCmd.AddCommand(wgSocksStartCmd) - Flags("wg socks", false, wgSocksStartCmd, func(f *pflag.FlagSet) { - f.Int32P("bind", "b", 3090, "port to listen on the WireGuard tun interface") - }) - - wgSocksStopCmd := &cobra.Command{ - Use: consts.StopStr, - Short: "Stop a socks5 listener on the WireGuard tun interface", - Long: help.GetHelpFor([]string{consts.WgSocksStr, consts.StopStr}), - Run: func(cmd *cobra.Command, args []string) { - wireguard.WGSocksStopCmd(cmd, con, args) - }, - Args: cobra.ExactArgs(1), - } - wgSocksCmd.AddCommand(wgSocksStopCmd) - carapace.Gen(wgSocksStopCmd).PositionalCompletion(wireguard.SocksIDCompleter(con).Usage("Socks server ID")) - - // [ Curse Commands ] ------------------------------------------------------------ - - cursedCmd := &cobra.Command{ - Use: consts.Cursed, - Short: "Chrome/electron post-exploitation tool kit (∩`-´)⊃━☆゚.*・。゚", - Long: help.GetHelpFor([]string{consts.Cursed}), - GroupID: consts.ExecutionHelpGroup, - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedCmd(cmd, con, args) - }, - } - sliver.AddCommand(cursedCmd) - Flags("", true, cursedCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - - cursedRmCmd := &cobra.Command{ - Use: consts.RmStr, - Short: "Remove a Curse from a process", - Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedConsole}), - Args: cobra.ExactArgs(1), - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedRmCmd(cmd, con, args) - }, - } - cursedCmd.AddCommand(cursedRmCmd) - Flags("", false, cursedRmCmd, func(f *pflag.FlagSet) { - f.BoolP("kill", "k", false, "kill the process after removing the curse") - }) - carapace.Gen(cursedRmCmd).PositionalCompletion(carapace.ActionValues().Usage("bind port of the Cursed process to stop")) - - cursedConsoleCmd := &cobra.Command{ - Use: consts.CursedConsole, - Short: "Start a JavaScript console connected to a debug target", - Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedConsole}), - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedConsoleCmd(cmd, con, args) - }, - } - cursedCmd.AddCommand(cursedConsoleCmd) - Flags("", false, cursedConsoleCmd, func(f *pflag.FlagSet) { - f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)`") - }) - - cursedChromeCmd := &cobra.Command{ - Use: consts.CursedChrome, - Short: "Automatically inject a Cursed Chrome payload into a remote Chrome extension", - Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedChrome}), - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedChromeCmd(cmd, con, args) - }, - } - cursedCmd.AddCommand(cursedChromeCmd) - Flags("", false, cursedChromeCmd, func(f *pflag.FlagSet) { - f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)") - f.BoolP("restore", "R", true, "restore the user's session after process termination") - f.StringP("exe", "e", "", "chrome/chromium browser executable path (blank string = auto)") - f.StringP("user-data", "u", "", "user data directory (blank string = auto)") - f.StringP("payload", "p", "", "cursed chrome payload file path (.js)") - f.BoolP("keep-alive", "k", false, "keeps browser alive after last browser window closes") - f.BoolP("headless", "H", false, "start browser process in headless mode") - }) - FlagComps(cursedChromeCmd, func(comp *carapace.ActionMap) { - (*comp)["payload"] = carapace.ActionFiles("js").Tag("javascript files") - }) - cursedChromeCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - carapace.Gen(cursedChromeCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("additional Chrome CLI arguments")) - - cursedEdgeCmd := &cobra.Command{ - Use: consts.CursedEdge, - Short: "Automatically inject a Cursed Chrome payload into a remote Edge extension", - Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedEdge}), - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedEdgeCmd(cmd, con, args) - }, - } - cursedCmd.AddCommand(cursedEdgeCmd) - Flags("", false, cursedEdgeCmd, func(f *pflag.FlagSet) { - f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)") - f.BoolP("restore", "R", true, "restore the user's session after process termination") - f.StringP("exe", "e", "", "edge browser executable path (blank string = auto)") - f.StringP("user-data", "u", "", "user data directory (blank string = auto)") - f.StringP("payload", "p", "", "cursed chrome payload file path (.js)") - f.BoolP("keep-alive", "k", false, "keeps browser alive after last browser window closes") - f.BoolP("headless", "H", false, "start browser process in headless mode") - }) - FlagComps(cursedEdgeCmd, func(comp *carapace.ActionMap) { - (*comp)["payload"] = carapace.ActionFiles("js").Tag("javascript files") - }) - cursedEdgeCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - carapace.Gen(cursedEdgeCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("additional Edge CLI arguments")) - - cursedElectronCmd := &cobra.Command{ - Use: consts.CursedElectron, - Short: "Curse a remote Electron application", - Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedElectron}), - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedElectronCmd(cmd, con, args) - }, - } - cursedCmd.AddCommand(cursedElectronCmd) - Flags("", false, cursedElectronCmd, func(f *pflag.FlagSet) { - f.StringP("exe", "e", "", "remote electron executable absolute path") - f.IntP("remote-debugging-port", "r", 0, "remote debugging tcp port (0 = random)") - }) - cursedElectronCmd.Flags().ParseErrorsWhitelist.UnknownFlags = true - carapace.Gen(cursedElectronCmd).PositionalAnyCompletion(carapace.ActionValues().Usage("additional Electron CLI arguments")) - - CursedCookiesCmd := &cobra.Command{ - Use: consts.CursedCookies, - Short: "Dump all cookies from cursed process", - Long: help.GetHelpFor([]string{consts.Cursed, consts.CursedCookies}), - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedCookiesCmd(cmd, con, args) - }, - } - cursedCmd.AddCommand(CursedCookiesCmd) - Flags("", false, CursedCookiesCmd, func(f *pflag.FlagSet) { - f.StringP("save", "s", "", "save to file") - }) - - cursedScreenshotCmd := &cobra.Command{ - Use: consts.ScreenshotStr, - Short: "Take a screenshot of a cursed process debug target", - Long: help.GetHelpFor([]string{consts.Cursed, consts.ScreenshotStr}), - Run: func(cmd *cobra.Command, args []string) { - cursed.CursedScreenshotCmd(cmd, con, args) - }, - } - cursedCmd.AddCommand(cursedScreenshotCmd) - Flags("", false, cursedScreenshotCmd, func(f *pflag.FlagSet) { - f.Int64P("quality", "q", 100, "screenshot quality (1 - 100)") - f.StringP("save", "s", "", "save to file") - }) - - // [ Wasm ] ----------------------------------------------------------------- - - wasmCmd := &cobra.Command{ - Use: consts.WasmStr, - Short: "Execute a Wasm Module Extension", - Long: help.GetHelpFor([]string{consts.WasmStr}), - GroupID: consts.ExecutionHelpGroup, - Run: func(cmd *cobra.Command, args []string) { - wasm.WasmCmd(cmd, con, args) - }, - } - sliver.AddCommand(wasmCmd) - Flags("", true, wasmCmd, func(f *pflag.FlagSet) { - f.Int64P("timeout", "t", defaultTimeout, "grpc timeout in seconds") - }) - Flags("", false, wasmCmd, func(f *pflag.FlagSet) { - f.BoolP("pipe", "P", false, "pipe module stdin/stdout/stderr to the current terminal (session only)") - f.StringP("file", "f", "", "include local file(s) in wasm module's /memfs (glob pattern) ") - f.StringP("dir", "d", "", "recursively include local directory in wasm module's /memfs (glob pattern)") - f.BoolP("skip-registration", "s", false, "assume the extension is already registered") - f.BoolP("loot", "X", false, "save output as loot, incompatible with --pipe") - }) - FlagComps(wasmCmd, func(comp *carapace.ActionMap) { - (*comp)["file"] = carapace.ActionFiles() - (*comp)["dir"] = carapace.ActionDirectories() - }) - wasmComp := carapace.Gen(wasmCmd) - wasmComp.PositionalCompletion(carapace.ActionFiles().Usage("wasm/wasi module file (.wasm)")) - wasmComp.PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the wasm module (optional)")) - - wasmLsCmd := &cobra.Command{ - Use: consts.LsStr, - Short: "List registered wasm extensions with current session/beacon", - Long: help.GetHelpFor([]string{consts.WasmStr, consts.LsStr}), - Run: func(cmd *cobra.Command, args []string) { - wasm.WasmLsCmd(cmd, con, args) - }, - } - wasmCmd.AddCommand(wasmLsCmd) - - // [ Post-command declaration setup ]---------------------------------------- - // Everything below this line should preferably not be any command binding - // (unless you know what you're doing). If there are any final modifications - // to make to the sliver menu command tree, it time to do them here. + // (although you can do so without fear). If there are any final modifications + // to make to the server menu command tree, it time to do them here. sliver.InitDefaultHelpCmd() sliver.SetHelpCommandGroupID(consts.SliverCoreHelpGroup) diff --git a/client/command/socks/commands.go b/client/command/socks/commands.go new file mode 100644 index 0000000000..90f3571276 --- /dev/null +++ b/client/command/socks/commands.go @@ -0,0 +1,65 @@ +package socks + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/completers" + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + socksCmd := &cobra.Command{ + Use: consts.Socks5Str, + Short: "In-band SOCKS5 Proxy", + Long: help.GetHelpFor([]string{consts.Socks5Str}), + Run: func(cmd *cobra.Command, args []string) { + SocksCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + } + flags.Bind("", true, socksCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + socksStartCmd := &cobra.Command{ + Use: consts.StartStr, + Short: "Start an in-band SOCKS5 proxy", + Long: help.GetHelpFor([]string{consts.Socks5Str}), + Run: func(cmd *cobra.Command, args []string) { + SocksStartCmd(cmd, con, args) + }, + } + socksCmd.AddCommand(socksStartCmd) + flags.Bind("", false, socksStartCmd, func(f *pflag.FlagSet) { + f.StringP("host", "H", "127.0.0.1", "Bind a Socks5 Host") + f.StringP("port", "P", "1081", "Bind a Socks5 Port") + f.StringP("user", "u", "", "socks5 auth username (will generate random password)") + }) + flags.BindFlagCompletions(socksStartCmd, func(comp *carapace.ActionMap) { + (*comp)["host"] = completers.ClientInterfacesCompleter() + }) + + socksStopCmd := &cobra.Command{ + Use: consts.StopStr, + Short: "Stop a SOCKS5 proxy", + Long: help.GetHelpFor([]string{consts.Socks5Str}), + Run: func(cmd *cobra.Command, args []string) { + SocksStopCmd(cmd, con, args) + }, + } + socksCmd.AddCommand(socksStopCmd) + flags.Bind("", false, socksStopCmd, func(f *pflag.FlagSet) { + f.Uint64P("id", "i", 0, "id of portfwd to remove") + }) + flags.BindFlagCompletions(socksStopCmd, func(comp *carapace.ActionMap) { + (*comp)["id"] = SocksIDCompleter(con) + }) + + return []*cobra.Command{socksCmd} +} diff --git a/client/command/tasks/commands.go b/client/command/tasks/commands.go new file mode 100644 index 0000000000..2f5bc11259 --- /dev/null +++ b/client/command/tasks/commands.go @@ -0,0 +1,58 @@ +package tasks + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + tasksCmd := &cobra.Command{ + Use: consts.TasksStr, + Short: "Beacon task management", + Long: help.GetHelpFor([]string{consts.TasksStr}), + Run: func(cmd *cobra.Command, args []string) { + TasksCmd(cmd, con, args) + }, + GroupID: consts.SliverCoreHelpGroup, + Annotations: flags.RestrictTargets(consts.BeaconCmdsFilter), + } + flags.Bind("tasks", true, tasksCmd, func(f *pflag.FlagSet) { + f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + f.BoolP("overflow", "O", false, "overflow terminal width (display truncated rows)") + f.IntP("skip-pages", "S", 0, "skip the first n page(s)") + f.StringP("filter", "f", "", "filter based on task type (case-insensitive prefix matching)") + }) + + fetchCmd := &cobra.Command{ + Use: consts.FetchStr, + Short: "Fetch the details of a beacon task", + Long: help.GetHelpFor([]string{consts.TasksStr, consts.FetchStr}), + Args: cobra.RangeArgs(0, 1), + Run: func(cmd *cobra.Command, args []string) { + TasksFetchCmd(cmd, con, args) + }, + } + tasksCmd.AddCommand(fetchCmd) + carapace.Gen(fetchCmd).PositionalCompletion(BeaconTaskIDCompleter(con).Usage("beacon task ID")) + + cancelCmd := &cobra.Command{ + Use: consts.CancelStr, + Short: "Cancel a pending beacon task", + Long: help.GetHelpFor([]string{consts.TasksStr, consts.CancelStr}), + Args: cobra.RangeArgs(0, 1), + Run: func(cmd *cobra.Command, args []string) { + TasksCancelCmd(cmd, con, args) + }, + } + tasksCmd.AddCommand(cancelCmd) + carapace.Gen(cancelCmd).PositionalCompletion(BeaconPendingTasksCompleter(con).Usage("beacon task ID")) + + return []*cobra.Command{tasksCmd} +} diff --git a/client/command/wasm/commands.go b/client/command/wasm/commands.go new file mode 100644 index 0000000000..175eaed811 --- /dev/null +++ b/client/command/wasm/commands.go @@ -0,0 +1,54 @@ +package wasm + +import ( + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + + "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/console" + consts "github.com/bishopfox/sliver/client/constants" +) + +// Commands returns the “ command and its subcommands. +func Commands(con *console.SliverConsoleClient) []*cobra.Command { + wasmCmd := &cobra.Command{ + Use: consts.WasmStr, + Short: "Execute a Wasm Module Extension", + Long: help.GetHelpFor([]string{consts.WasmStr}), + GroupID: consts.ExecutionHelpGroup, + Run: func(cmd *cobra.Command, args []string) { + WasmCmd(cmd, con, args) + }, + } + flags.Bind("", true, wasmCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + flags.Bind("", false, wasmCmd, func(f *pflag.FlagSet) { + f.BoolP("pipe", "P", false, "pipe module stdin/stdout/stderr to the current terminal (session only)") + f.StringP("file", "f", "", "include local file(s) in wasm module's /memfs (glob pattern) ") + f.StringP("dir", "d", "", "recursively include local directory in wasm module's /memfs (glob pattern)") + f.BoolP("skip-registration", "s", false, "assume the extension is already registered") + f.BoolP("loot", "X", false, "save output as loot, incompatible with --pipe") + }) + flags.BindFlagCompletions(wasmCmd, func(comp *carapace.ActionMap) { + (*comp)["file"] = carapace.ActionFiles() + (*comp)["dir"] = carapace.ActionDirectories() + }) + wasmComp := carapace.Gen(wasmCmd) + wasmComp.PositionalCompletion(carapace.ActionFiles().Usage("wasm/wasi module file (.wasm)")) + wasmComp.PositionalAnyCompletion(carapace.ActionValues().Usage("arguments to pass to the wasm module (optional)")) + + wasmLsCmd := &cobra.Command{ + Use: consts.LsStr, + Short: "List registered wasm extensions with current session/beacon", + Long: help.GetHelpFor([]string{consts.WasmStr, consts.LsStr}), + Run: func(cmd *cobra.Command, args []string) { + WasmLsCmd(cmd, con, args) + }, + } + wasmCmd.AddCommand(wasmLsCmd) + + return []*cobra.Command{wasmCmd} +} diff --git a/client/command/wireguard/commands.go b/client/command/wireguard/commands.go index dcbb9dc82d..daa4460539 100644 --- a/client/command/wireguard/commands.go +++ b/client/command/wireguard/commands.go @@ -35,3 +35,88 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { return []*cobra.Command{wgConfigCmd} } + +// SliverCommands returns all Wireguard commands that can be used on an active target. +func SliverCommands(con *console.SliverConsoleClient) []*cobra.Command { + wgPortFwdCmd := &cobra.Command{ + Use: consts.WgPortFwdStr, + Short: "List ports forwarded by the WireGuard tun interface", + Long: help.GetHelpFor([]string{consts.WgPortFwdStr}), + Run: func(cmd *cobra.Command, args []string) { + WGPortFwdListCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + Annotations: flags.RestrictTargets(consts.WireguardCmdsFilter), + } + flags.Bind("wg portforward", true, wgPortFwdCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + wgPortFwdAddCmd := &cobra.Command{ + Use: consts.AddStr, + Short: "Add a port forward from the WireGuard tun interface to a host on the target network", + Long: help.GetHelpFor([]string{consts.WgPortFwdStr, consts.AddStr}), + Run: func(cmd *cobra.Command, args []string) { + WGPortFwdAddCmd(cmd, con, args) + }, + } + flags.Bind("wg portforward", false, wgPortFwdAddCmd, func(f *pflag.FlagSet) { + f.Int32P("bind", "b", 1080, "port to listen on the WireGuard tun interface") + f.StringP("remote", "r", "", "remote target host:port (e.g., 10.0.0.1:445)") + }) + wgPortFwdCmd.AddCommand(wgPortFwdAddCmd) + + wgPortFwdRmCmd := &cobra.Command{ + Use: consts.RmStr, + Short: "Remove a port forward from the WireGuard tun interface", + Long: help.GetHelpFor([]string{consts.WgPortFwdStr, consts.RmStr}), + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + WGPortFwdRmCmd(cmd, con, args) + }, + } + wgPortFwdCmd.AddCommand(wgPortFwdRmCmd) + + carapace.Gen(wgPortFwdRmCmd).PositionalCompletion(PortfwdIDCompleter(con).Usage("forwarder ID")) + + wgSocksCmd := &cobra.Command{ + Use: consts.WgSocksStr, + Short: "List socks servers listening on the WireGuard tun interface", + Long: help.GetHelpFor([]string{consts.WgSocksStr}), + Run: func(cmd *cobra.Command, args []string) { + WGSocksListCmd(cmd, con, args) + }, + GroupID: consts.NetworkHelpGroup, + Annotations: flags.RestrictTargets(consts.WireguardCmdsFilter), + } + flags.Bind("wg socks", true, wgSocksCmd, func(f *pflag.FlagSet) { + f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") + }) + + wgSocksStartCmd := &cobra.Command{ + Use: consts.StartStr, + Short: "Start a socks5 listener on the WireGuard tun interface", + Long: help.GetHelpFor([]string{consts.WgSocksStr, consts.StartStr}), + Run: func(cmd *cobra.Command, args []string) { + WGSocksStartCmd(cmd, con, args) + }, + } + wgSocksCmd.AddCommand(wgSocksStartCmd) + flags.Bind("wg socks", false, wgSocksStartCmd, func(f *pflag.FlagSet) { + f.Int32P("bind", "b", 3090, "port to listen on the WireGuard tun interface") + }) + + wgSocksStopCmd := &cobra.Command{ + Use: consts.StopStr, + Short: "Stop a socks5 listener on the WireGuard tun interface", + Long: help.GetHelpFor([]string{consts.WgSocksStr, consts.StopStr}), + Run: func(cmd *cobra.Command, args []string) { + WGSocksStopCmd(cmd, con, args) + }, + Args: cobra.ExactArgs(1), + } + wgSocksCmd.AddCommand(wgSocksStopCmd) + carapace.Gen(wgSocksStopCmd).PositionalCompletion(SocksIDCompleter(con).Usage("Socks server ID")) + + return []*cobra.Command{wgPortFwdCmd, wgSocksCmd} +} From 2da61c1e54e8d455bee3afeafb6e4de772098404 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Thu, 22 Jun 2023 19:29:04 +0200 Subject: [PATCH 06/14] Finish splits. Compiles --- client/command/alias/alias.go | 8 +++---- client/command/beacons/commands.go | 33 ++++++++++++++++++++++++--- client/command/completers/commands.go | 17 -------------- client/command/exit/commands.go | 17 -------------- client/command/help/commands.go | 17 -------------- client/command/help/long-help.go | 3 +-- client/command/server.go | 12 ++++++++++ client/command/sessions/commands.go | 2 +- client/command/use/commands.go | 3 ++- client/command/use/use.go | 26 ++------------------- client/console/console.go | 11 --------- client/constants/constants.go | 7 ++++++ 12 files changed, 59 insertions(+), 97 deletions(-) delete mode 100644 client/command/completers/commands.go delete mode 100644 client/command/exit/commands.go delete mode 100644 client/command/help/commands.go diff --git a/client/command/alias/alias.go b/client/command/alias/alias.go index c418427ba9..2ff708f858 100644 --- a/client/command/alias/alias.go +++ b/client/command/alias/alias.go @@ -24,14 +24,14 @@ import ( "io/ioutil" "strings" - "github.com/bishopfox/sliver/client/assets" - "github.com/bishopfox/sliver/client/command/settings" - "github.com/bishopfox/sliver/client/console" - "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" "github.com/rsteube/carapace" "github.com/spf13/cobra" + + "github.com/bishopfox/sliver/client/assets" + "github.com/bishopfox/sliver/client/command/settings" + "github.com/bishopfox/sliver/client/console" ) // AliasesCmd - The alias command diff --git a/client/command/beacons/commands.go b/client/command/beacons/commands.go index 433e204f2d..d526d7412d 100644 --- a/client/command/beacons/commands.go +++ b/client/command/beacons/commands.go @@ -1,15 +1,19 @@ package beacons import ( + "context" + "fmt" + "strings" + "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" - "github.com/bishopfox/sliver/client/command/use" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/bishopfox/sliver/protobuf/commonpb" ) // Commands returns the “ command and its subcommands. @@ -35,7 +39,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.StringP("filter-re", "e", "", "filter beacons by regular expression") }) flags.BindFlagCompletions(beaconsCmd, func(comp *carapace.ActionMap) { - (*comp)["kill"] = use.BeaconIDCompleter(con) + (*comp)["kill"] = BeaconIDCompleter(con) }) beaconsRmCmd := &cobra.Command{ Use: consts.RmStr, @@ -45,7 +49,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { BeaconsRmCmd(cmd, con, args) }, } - carapace.Gen(beaconsRmCmd).PositionalCompletion(use.BeaconIDCompleter(con)) + carapace.Gen(beaconsRmCmd).PositionalCompletion(BeaconIDCompleter(con)) beaconsCmd.AddCommand(beaconsRmCmd) beaconsWatchCmd := &cobra.Command{ @@ -73,3 +77,26 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { return []*cobra.Command{beaconsCmd} } + +// BeaconIDCompleter completes beacon IDs +func BeaconIDCompleter(con *console.SliverConsoleClient) carapace.Action { + callback := func(_ carapace.Context) carapace.Action { + results := make([]string, 0) + + beacons, err := con.Rpc.GetBeacons(context.Background(), &commonpb.Empty{}) + if err == nil { + for _, b := range beacons.Beacons { + link := fmt.Sprintf("[%s <- %s]", b.ActiveC2, b.RemoteAddress) + id := fmt.Sprintf("%s (%d)", b.Name, b.PID) + userHost := fmt.Sprintf("%s@%s", b.Username, b.Hostname) + desc := strings.Join([]string{id, userHost, link}, " ") + + results = append(results, b.ID[:8]) + results = append(results, desc) + } + } + return carapace.ActionValuesDescribed(results...).Tag("beacons") + } + + return carapace.ActionCallback(callback) +} diff --git a/client/command/completers/commands.go b/client/command/completers/commands.go deleted file mode 100644 index a6c8864c7d..0000000000 --- a/client/command/completers/commands.go +++ /dev/null @@ -1,17 +0,0 @@ -package completers - -import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - - "github.com/bishopfox/sliver/client/command/flags" - "github.com/bishopfox/sliver/client/command/help" - "github.com/bishopfox/sliver/client/console" - consts "github.com/bishopfox/sliver/client/constants" -) - -// Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { - return nil -} diff --git a/client/command/exit/commands.go b/client/command/exit/commands.go deleted file mode 100644 index 75b67ea3a6..0000000000 --- a/client/command/exit/commands.go +++ /dev/null @@ -1,17 +0,0 @@ -package exit - -import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - - "github.com/bishopfox/sliver/client/command/flags" - "github.com/bishopfox/sliver/client/command/help" - "github.com/bishopfox/sliver/client/console" - consts "github.com/bishopfox/sliver/client/constants" -) - -// Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { - return nil -} diff --git a/client/command/help/commands.go b/client/command/help/commands.go deleted file mode 100644 index 3799c739aa..0000000000 --- a/client/command/help/commands.go +++ /dev/null @@ -1,17 +0,0 @@ -package help - -import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - - "github.com/bishopfox/sliver/client/command/flags" - "github.com/bishopfox/sliver/client/command/help" - "github.com/bishopfox/sliver/client/console" - consts "github.com/bishopfox/sliver/client/constants" -) - -// Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { - return nil -} diff --git a/client/command/help/long-help.go b/client/command/help/long-help.go index 281167634c..fccb56c5a6 100644 --- a/client/command/help/long-help.go +++ b/client/command/help/long-help.go @@ -28,7 +28,6 @@ import ( "strings" "text/template" - "github.com/bishopfox/sliver/client/command/creds" consts "github.com/bishopfox/sliver/client/constants" ) @@ -1219,7 +1218,7 @@ Sliver uses the same hash identifiers as Hashcat (use the #): % 10s - One hash per line. % 10s - A file containing lines of 'username:hash' pairs. % 10s - A CSV file containing 'username,hash' pairs (additional columns ignored). -`, creds.HashNewlineFormat, creds.UserColonHashNewlineFormat, creds.CSVFormat) +`, consts.HashNewlineFormat, consts.UserColonHashNewlineFormat, consts.CSVFormat) ) const ( diff --git a/client/command/server.go b/client/command/server.go index 034ac242c7..1a2c035a63 100644 --- a/client/command/server.go +++ b/client/command/server.go @@ -19,6 +19,8 @@ package command */ import ( + "os" + "github.com/reeflective/console" "github.com/spf13/cobra" @@ -121,6 +123,16 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. // (although you can do so without fear). If there are any final modifications // to make to the server menu command tree, it time to do them here. + // Only load reactions when the console is going to be started. + if !con.IsCLI { + n, err := reaction.LoadReactions() + if err != nil && !os.IsNotExist(err) { + con.PrintErrorf("Failed to load reactions: %s\n", err) + } else if n > 0 { + con.PrintInfof("Loaded %d reaction(s) from disk\n", n) + } + } + server.InitDefaultHelpCmd() server.SetHelpCommandGroupID(consts.GenericHelpGroup) diff --git a/client/command/sessions/commands.go b/client/command/sessions/commands.go index a550d43b9a..65e4de8966 100644 --- a/client/command/sessions/commands.go +++ b/client/command/sessions/commands.go @@ -68,7 +68,7 @@ func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err == nil { - for _, s := range Sessions { + for _, s := range sessions.Sessions { link := fmt.Sprintf("[%s <- %s]", s.ActiveC2, s.RemoteAddress) id := fmt.Sprintf("%s (%d)", s.Name, s.PID) userHost := fmt.Sprintf("%s@%s", s.Username, s.Hostname) diff --git a/client/command/use/commands.go b/client/command/use/commands.go index d5c37a44c0..0dd4ce5a1f 100644 --- a/client/command/use/commands.go +++ b/client/command/use/commands.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/bishopfox/sliver/client/command/beacons" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" @@ -46,7 +47,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { UseBeaconCmd(cmd, con, args) }, } - carapace.Gen(useBeaconCmd).PositionalCompletion(BeaconIDCompleter(con)) + carapace.Gen(useBeaconCmd).PositionalCompletion(beacons.BeaconIDCompleter(con)) useCmd.AddCommand(useBeaconCmd) return []*cobra.Command{useCmd} diff --git a/client/command/use/use.go b/client/command/use/use.go index 14b1f6e2b4..1cacc26e7e 100644 --- a/client/command/use/use.go +++ b/client/command/use/use.go @@ -31,6 +31,7 @@ import ( "github.com/rsteube/carapace" "github.com/spf13/cobra" + "github.com/bishopfox/sliver/client/command/beacons" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" @@ -188,7 +189,7 @@ func BeaconAndSessionIDCompleter(con *console.SliverConsoleClient) carapace.Acti return action.Invoke(ctx).Merge( SessionIDCompleter(con).Invoke(ctx), - BeaconIDCompleter(con).Invoke(ctx), + beacons.BeaconIDCompleter(con).Invoke(ctx), ).ToA() } @@ -217,26 +218,3 @@ func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { return carapace.ActionCallback(callback) } - -// BeaconIDCompleter completes beacon IDs -func BeaconIDCompleter(con *console.SliverConsoleClient) carapace.Action { - callback := func(_ carapace.Context) carapace.Action { - results := make([]string, 0) - - beacons, err := con.Rpc.GetBeacons(context.Background(), &commonpb.Empty{}) - if err == nil { - for _, b := range beacons.Beacons { - link := fmt.Sprintf("[%s <- %s]", b.ActiveC2, b.RemoteAddress) - id := fmt.Sprintf("%s (%d)", b.Name, b.PID) - userHost := fmt.Sprintf("%s@%s", b.Username, b.Hostname) - desc := strings.Join([]string{id, userHost, link}, " ") - - results = append(results, b.ID[:8]) - results = append(results, desc) - } - } - return carapace.ActionValuesDescribed(results...).Tag("beacons") - } - - return carapace.ActionCallback(callback) -} diff --git a/client/console/console.go b/client/console/console.go index f523ca76da..fde4a37587 100644 --- a/client/console/console.go +++ b/client/console/console.go @@ -40,7 +40,6 @@ import ( "google.golang.org/protobuf/proto" "github.com/bishopfox/sliver/client/assets" - "github.com/bishopfox/sliver/client/command/reaction" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/client/prelude" @@ -206,16 +205,6 @@ func StartClient(con *SliverConsoleClient, rpc rpcpb.SliverRPCClient, serverCmds con.setupAsciicastRecord(asciicastLog, asciicastStream) } - // Only load reactions when the console is going to be started. - if !con.IsCLI { - n, err := reaction.LoadReactions() - if err != nil && !os.IsNotExist(err) { - con.PrintErrorf("Failed to load reactions: %s\n", err) - } else if n > 0 { - con.PrintInfof("Loaded %d reaction(s) from disk\n", n) - } - } - if !con.IsCLI { return con.App.Start() } diff --git a/client/constants/constants.go b/client/constants/constants.go index ef128ae7a3..645a357ac1 100644 --- a/client/constants/constants.go +++ b/client/constants/constants.go @@ -325,3 +325,10 @@ const ( WindowsCmdsFilter = "windows" WireguardCmdsFilter = "wireguard" ) + +// Creds (needed here to avoid recursive imports) +const ( + UserColonHashNewlineFormat = "user:hash" // username:hash\n + HashNewlineFormat = "hash" // hash\n + CSVFormat = "csv" // username,hash\n +) From 51473ec137992a40dace36d27d3dd73cd82b381a Mon Sep 17 00:00:00 2001 From: maxlandon Date: Thu, 22 Jun 2023 20:26:04 +0200 Subject: [PATCH 07/14] Add many missing completers --- client/command/armory/commands.go | 4 ++++ client/command/completers/completers.go | 29 +++++++++++++++++++++++++ client/command/exec/commands.go | 2 ++ client/command/extensions/commands.go | 2 +- client/command/filesystem/commands.go | 5 +++++ client/command/generate/commands.go | 4 ++++ client/command/hosts/commands.go | 2 +- client/command/jobs/commands.go | 4 ++++ client/command/loot/commands.go | 22 +++++++++++++++---- client/command/processes/commands.go | 3 +++ client/command/update/commands.go | 5 +++++ 11 files changed, 76 insertions(+), 6 deletions(-) diff --git a/client/command/armory/commands.go b/client/command/armory/commands.go index 5e59ef2a44..fe2649dd16 100644 --- a/client/command/armory/commands.go +++ b/client/command/armory/commands.go @@ -5,6 +5,7 @@ import ( "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/bishopfox/sliver/client/command/completers" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" @@ -28,6 +29,9 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.BoolP("ignore-cache", "c", false, "ignore metadata cache, force refresh") f.StringP("timeout", "t", "15m", "download timeout") }) + flags.BindFlagCompletions(armoryCmd, func(comp *carapace.ActionMap) { + (*comp)["proxy"] = completers.LocalProxyCompleter() + }) armoryInstallCmd := &cobra.Command{ Use: consts.InstallStr, diff --git a/client/command/completers/completers.go b/client/command/completers/completers.go index 6973751922..762b14b62f 100644 --- a/client/command/completers/completers.go +++ b/client/command/completers/completers.go @@ -55,3 +55,32 @@ func ClientInterfacesCompleter() carapace.Action { return carapace.ActionValues(results...).Tag("client interfaces").NoSpace(':') }) } + +// LocalProxyCompleter gives URL completion to all flags/arguments that accept a client proxy address. +func LocalProxyCompleter() carapace.Action { + return carapace.ActionCallback(func(c carapace.Context) carapace.Action { + prefix := "" + + hostPort := carapace.ActionMultiParts(":", func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return ClientInterfacesCompleter() + case 1: + return carapace.ActionMessage("server port") + default: + return carapace.ActionValues() + } + }) + + return carapace.ActionMultiParts("://", func(c carapace.Context) carapace.Action { + switch len(c.Parts) { + case 0: + return carapace.ActionValues("http", "https").Tag("proxy protocols").Suffix("://") + case 1: + return hostPort + default: + return carapace.ActionValues() + } + }).Invoke(c).Prefix(prefix).ToA() + }) +} diff --git a/client/command/exec/commands.go b/client/command/exec/commands.go index 13edbe3de5..a0cc0473e2 100644 --- a/client/command/exec/commands.go +++ b/client/command/exec/commands.go @@ -6,6 +6,7 @@ import ( "github.com/spf13/pflag" "github.com/bishopfox/sliver/client/command/flags" + "github.com/bishopfox/sliver/client/command/generate" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" @@ -237,6 +238,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { }) flags.BindFlagCompletions(psExecCmd, func(comp *carapace.ActionMap) { (*comp)["custom-exe"] = carapace.ActionFiles() + (*comp)["profile"] = generate.ProfileNameCompleter(con) }) carapace.Gen(psExecCmd).PositionalCompletion(carapace.ActionValues().Usage("hostname (required)")) diff --git a/client/command/extensions/commands.go b/client/command/extensions/commands.go index 7ee046d4c4..236f13e6ba 100644 --- a/client/command/extensions/commands.go +++ b/client/command/extensions/commands.go @@ -15,7 +15,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { Use: consts.ExtensionsStr, Short: "Manage extensions", Long: help.GetHelpFor([]string{consts.ExtensionsStr}), - GroupID: consts.ExtensionHelpGroup, + GroupID: consts.ExecutionHelpGroup, Run: func(cmd *cobra.Command, _ []string) { ExtensionsCmd(cmd, con) }, diff --git a/client/command/filesystem/commands.go b/client/command/filesystem/commands.go index 425527704a..78241cf6ce 100644 --- a/client/command/filesystem/commands.go +++ b/client/command/filesystem/commands.go @@ -7,6 +7,7 @@ import ( "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" + "github.com/bishopfox/sliver/client/command/loot" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" ) @@ -148,6 +149,10 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.BoolP("recurse", "r", false, "recursively download all files in a directory") f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") }) + flags.BindFlagCompletions(downloadCmd, func(comp *carapace.ActionMap) { + (*comp)["type"] = loot.LootTypeCompleter(con) + (*comp)["file-type"] = loot.FileTypeCompleter(con) + }) carapace.Gen(downloadCmd).PositionalCompletion( carapace.ActionValues().Usage("path to the file or directory to download"), carapace.ActionFiles().Usage("local path where the downloaded file will be saved (optional)"), diff --git a/client/command/generate/commands.go b/client/command/generate/commands.go index c30db8c28e..9bd4bdff95 100644 --- a/client/command/generate/commands.go +++ b/client/command/generate/commands.go @@ -67,6 +67,9 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.StringP("save", "s", "", "directory to save the generated stager to") f.StringP("advanced", "d", "", "Advanced options for the stager using URI query syntax (option1=value1&option2=value2...)") }) + flags.BindFlagCompletions(generateStagerCmd, func(comp *carapace.ActionMap) { + (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") + }) generateCmd.AddCommand(generateStagerCmd) generateInfoCmd := &cobra.Command{ @@ -327,6 +330,7 @@ func coreImplantFlagCompletions(cmd *cobra.Command, con *console.SliverConsoleCl (*comp)["strategy"] = carapace.ActionValuesDescribed([]string{"r", "random", "rd", "random domain", "s", "sequential"}...).Tag("C2 strategy") (*comp)["format"] = FormatCompleter() (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save implant") + (*comp)["traffic-encoders"] = TrafficEncodersCompleter(con).UniqueList(",") }) } diff --git a/client/command/hosts/commands.go b/client/command/hosts/commands.go index ca6573d325..e9a92634ef 100644 --- a/client/command/hosts/commands.go +++ b/client/command/hosts/commands.go @@ -55,5 +55,5 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { } hostsIOCCmd.AddCommand(hostsIOCRmCmd) - return []*cobra.Command{hostsCmd, hostsIOCCmd} + return []*cobra.Command{hostsCmd} } diff --git a/client/command/jobs/commands.go b/client/command/jobs/commands.go index d3564d2a2a..b5cb4f1bb3 100644 --- a/client/command/jobs/commands.go +++ b/client/command/jobs/commands.go @@ -136,6 +136,10 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.BoolP("persistent", "p", false, "make persistent across restarts") }) + flags.BindFlagCompletions(httpsCmd, func(comp *carapace.ActionMap) { + (*comp)["cert"] = carapace.ActionFiles().Tag("certificate file") + (*comp)["key"] = carapace.ActionFiles().Tag("key file") + }) // Staging listeners stageCmd := &cobra.Command{ diff --git a/client/command/loot/commands.go b/client/command/loot/commands.go index 4087ce6ed4..8b2368f4b5 100644 --- a/client/command/loot/commands.go +++ b/client/command/loot/commands.go @@ -45,8 +45,8 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.StringP("file-type", "F", "", "force a specific file type (binary/text)") }) flags.BindFlagCompletions(lootAddCmd, func(comp *carapace.ActionMap) { - (*comp)["type"] = carapace.ActionValues("file", "cred").Tag("loot type") - (*comp)["file-type"] = carapace.ActionValues("binary", "text").Tag("loot file type") + (*comp)["type"] = LootTypeCompleter(con) + (*comp)["file-type"] = FileTypeCompleter(con) }) carapace.Gen(lootAddCmd).PositionalCompletion( carapace.ActionFiles().Tag("local loot file").Usage("The local file path to the loot")) @@ -67,8 +67,8 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.StringP("file-type", "F", "", "force a specific file type (binary/text)") }) flags.BindFlagCompletions(lootRemoteCmd, func(comp *carapace.ActionMap) { - (*comp)["type"] = carapace.ActionValues("file", "cred").Tag("loot type") - (*comp)["file-type"] = carapace.ActionValues("binary", "text").Tag("loot file type") + (*comp)["type"] = LootTypeCompleter(con) + (*comp)["file-type"] = FileTypeCompleter(con) }) carapace.Gen(lootRemoteCmd).PositionalCompletion(carapace.ActionValues().Usage("The file path on the remote host to the loot")) @@ -97,6 +97,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { }) flags.BindFlagCompletions(lootFetchCmd, func(comp *carapace.ActionMap) { (*comp)["save"] = carapace.ActionFiles().Tag("directory/file to save loot") + (*comp)["filter"] = FileTypeCompleter(con) }) lootRmCmd := &cobra.Command{ @@ -111,6 +112,19 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { flags.Bind("loot", false, lootRmCmd, func(f *pflag.FlagSet) { f.StringP("filter", "f", "", "filter based on loot type") }) + flags.BindFlagCompletions(lootRmCmd, func(comp *carapace.ActionMap) { + (*comp)["filter"] = LootTypeCompleter(con) + }) return []*cobra.Command{lootCmd} } + +// FileTypeCompleter completes valid filetypes for loot. +func FileTypeCompleter(con *console.SliverConsoleClient) carapace.Action { + return carapace.ActionValues("binary", "text").Tag("loot file type") +} + +// LootTypeCompleter completes valid loot type for a loot. +func LootTypeCompleter(con *console.SliverConsoleClient) carapace.Action { + return carapace.ActionValues("file", "cred").Tag("loot type") +} diff --git a/client/command/processes/commands.go b/client/command/processes/commands.go index f844894b70..9fab3d63c5 100644 --- a/client/command/processes/commands.go +++ b/client/command/processes/commands.go @@ -52,6 +52,9 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") }) + flags.BindFlagCompletions(procdumpCmd, func(comp *carapace.ActionMap) { + (*comp)["save"] = carapace.ActionFiles() + }) terminateCmd := &cobra.Command{ Use: consts.TerminateStr, diff --git a/client/command/update/commands.go b/client/command/update/commands.go index 251d2c41f3..1f4f8cb0a9 100644 --- a/client/command/update/commands.go +++ b/client/command/update/commands.go @@ -1,9 +1,11 @@ package update import ( + "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" + "github.com/bishopfox/sliver/client/command/completers" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" @@ -28,6 +30,9 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { f.BoolP("insecure", "I", false, "skip tls certificate validation") f.IntP("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") }) + flags.BindFlagCompletions(updateCmd, func(comp *carapace.ActionMap) { + (*comp)["proxy"] = completers.LocalProxyCompleter() + }) versionCmd := &cobra.Command{ Use: consts.VersionStr, From 47a280cc165a3e2630600a633d8af274a305af4f Mon Sep 17 00:00:00 2001 From: maxlandon Date: Sun, 23 Jul 2023 19:04:20 +0200 Subject: [PATCH 08/14] Fix beacon compile flags + debug level for client asciicast --- client/command/generate/commands.go | 9 +++++---- server/rpc/rpc-client-logs.go | 6 +++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/client/command/generate/commands.go b/client/command/generate/commands.go index cd5b971859..089873f589 100644 --- a/client/command/generate/commands.go +++ b/client/command/generate/commands.go @@ -1,14 +1,13 @@ package generate import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. @@ -44,6 +43,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { // Beacon flags and completions. coreImplantFlags("beacon", generateBeaconCmd) compileImplantFlags("beacon", generateBeaconCmd) + coreBeaconFlags("beacon", generateBeaconCmd) coreImplantFlagCompletions(generateBeaconCmd, con) generateCmd.AddCommand(generateBeaconCmd) @@ -202,6 +202,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { // Beacon flags and completions. coreImplantFlags("beacon", profilesNewBeaconCmd) compileImplantFlags("beacon", profilesNewBeaconCmd) + coreBeaconFlags("beacon", profilesNewBeaconCmd) coreImplantFlagCompletions(profilesNewBeaconCmd, con) profilesRmCmd := &cobra.Command{ diff --git a/server/rpc/rpc-client-logs.go b/server/rpc/rpc-client-logs.go index 4f32302842..c12df0e731 100644 --- a/server/rpc/rpc-client-logs.go +++ b/server/rpc/rpc-client-logs.go @@ -114,7 +114,7 @@ func (rpc *Server) ClientLog(stream rpcpb.SliverRPC_ClientLogServer) error { return err } } - rpcClientLogs.Infof("Received %d bytes of client console log data for stream %s", len(fromClient.GetData()), streamName) + rpcClientLogs.Debugf("Received %d bytes of client console log data for stream %s", len(fromClient.GetData()), streamName) streams[streamName].Write(fromClient.GetData()) } return nil @@ -139,7 +139,7 @@ func openNewLogStream(logsDir string, stream string) (*LogStream, error) { } func randomSuffix(n int) string { - var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") + letterRunes := []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") buf := make([]rune, n) for i := range buf { buf[i] = letterRunes[insecureRand.Intn(len(letterRunes))] @@ -168,7 +168,7 @@ func gzipFile(filePath string) { return } defer inputFile.Close() - outFile, err := os.OpenFile(filePath+".gz", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600) + outFile, err := os.OpenFile(filePath+".gz", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600) if err != nil { rpcClientLogs.Errorf("Failed to open gz client console log file: %s", err) return From 163c11b60c5aeb1d00053fc8f9438de5b43aae86 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Sun, 23 Jul 2023 19:04:44 +0200 Subject: [PATCH 09/14] Fmt --- client/command/generate/canaries.go | 9 ++-- client/command/generate/generate-beacon.go | 5 +-- client/command/generate/generate-info.go | 5 +-- client/command/generate/generate-stager.go | 5 +-- client/command/generate/generate.go | 45 ++++++++++---------- client/command/generate/helpers.go | 11 +++-- client/command/generate/implants-rm.go | 5 +-- client/command/generate/implants.go | 17 ++++---- client/command/generate/profiles-generate.go | 5 +-- client/command/generate/profiles-new.go | 7 ++- client/command/generate/profiles-rm.go | 5 +-- client/command/generate/profiles.go | 19 ++++----- client/command/generate/regenerate.go | 5 +-- client/command/generate/traffic-encoders.go | 33 +++++++------- 14 files changed, 81 insertions(+), 95 deletions(-) diff --git a/client/command/generate/canaries.go b/client/command/generate/canaries.go index e2a9ff240f..8900e0dd1c 100644 --- a/client/command/generate/canaries.go +++ b/client/command/generate/canaries.go @@ -4,16 +4,15 @@ import ( "context" "fmt" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// CanariesCmd - Display canaries from the database and their status +// CanariesCmd - Display canaries from the database and their status. func CanariesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { canaries, err := con.Rpc.Canaries(context.Background(), &commonpb.Empty{}) if err != nil { @@ -28,7 +27,7 @@ func CanariesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -// PrintCanaries - Print the canaries tracked by the server +// PrintCanaries - Print the canaries tracked by the server. func PrintCanaries(con *console.SliverConsoleClient, canaries []*clientpb.DNSCanary, burnedOnly bool) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) diff --git a/client/command/generate/generate-beacon.go b/client/command/generate/generate-beacon.go index 43820aa7d4..40466d7335 100644 --- a/client/command/generate/generate-beacon.go +++ b/client/command/generate/generate-beacon.go @@ -5,10 +5,9 @@ import ( "os" "time" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) var ( @@ -16,7 +15,7 @@ var ( ErrBeaconIntervalTooShort = fmt.Errorf("beacon interval must be %v or greater", minBeaconInterval) ) -// GenerateBeaconCmd - The main command used to generate implant binaries +// GenerateBeaconCmd - The main command used to generate implant binaries. func GenerateBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { config := parseCompileFlags(cmd, con) if config == nil { diff --git a/client/command/generate/generate-info.go b/client/command/generate/generate-info.go index 9fe59c3321..9a9efe6d2a 100644 --- a/client/command/generate/generate-info.go +++ b/client/command/generate/generate-info.go @@ -3,13 +3,12 @@ package generate import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/spf13/cobra" ) -// GenerateInfoCmd - Display information about the Sliver server's compiler configuration +// GenerateInfoCmd - Display information about the Sliver server's compiler configuration. func GenerateInfoCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { compiler, err := con.Rpc.GetCompiler(context.Background(), &commonpb.Empty{}) if err != nil { diff --git a/client/command/generate/generate-stager.go b/client/command/generate/generate-stager.go index 6806ffb184..a6f99d7b08 100644 --- a/client/command/generate/generate-stager.go +++ b/client/command/generate/generate-stager.go @@ -27,13 +27,12 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// GenerateStagerCmd - Generate a stager using Metasploit +// GenerateStagerCmd - Generate a stager using Metasploit. func GenerateStagerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { var stageProto clientpb.StageProtocol lhost, _ := cmd.Flags().GetString("lhost") diff --git a/client/command/generate/generate.go b/client/command/generate/generate.go index 9e105e31bd..677e8a4a29 100644 --- a/client/command/generate/generate.go +++ b/client/command/generate/generate.go @@ -33,39 +33,38 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/client/spin" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" ) const ( - // DefaultMTLSLPort is the default port for mtls + // DefaultMTLSLPort is the default port for mtls. DefaultMTLSLPort = 8888 - // DefaultWGPort is the default port for wg + // DefaultWGPort is the default port for wg. DefaultWGLPort = 53 - // DefaultWGNPort is the default n port for wg + // DefaultWGNPort is the default n port for wg. DefaultWGNPort = 8888 - // DefaultWGKeyExPort is the default port for wg key exchange + // DefaultWGKeyExPort is the default port for wg key exchange. DefaultWGKeyExPort = 1337 - // DefaultHTTPLPort is the default port for http + // DefaultHTTPLPort is the default port for http. DefaultHTTPLPort = 80 - // DefaultHTTPSLPort is the default port for https + // DefaultHTTPSLPort is the default port for https. DefaultHTTPSLPort = 443 - // DefaultDNSLPortis the default port for dns + // DefaultDNSLPortis the default port for dns. DefaultDNSLPort = 53 - // DefaultTCPPivotPort is the default port for tcp pivots + // DefaultTCPPivotPort is the default port for tcp pivots. DefaultTCPPivotPort = 9898 - // DefaultReconnect is the default reconnect time + // DefaultReconnect is the default reconnect time. DefaultReconnect = 60 - // DefaultPollTimeout is the default poll timeout + // DefaultPollTimeout is the default poll timeout. DefaultPollTimeout = 360 // 6 minutes - // DefaultMaxErrors is the default max reconnection errors before giving up + // DefaultMaxErrors is the default max reconnection errors before giving up. DefaultMaxErrors = 1000 ) @@ -74,7 +73,7 @@ const ( ) var ( - // SupportedCompilerTargets - Supported compiler targets + // SupportedCompilerTargets - Supported compiler targets. SupportedCompilerTargets = map[string]bool{ "darwin/amd64": true, "darwin/arm64": true, @@ -88,7 +87,7 @@ var ( ErrNoValidBuilders = errors.New("no valid external builders for target") ) -// GenerateCmd - The main command used to generate implant binaries +// GenerateCmd - The main command used to generate implant binaries. func GenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { config := parseCompileFlags(cmd, con) if config == nil { @@ -181,7 +180,7 @@ func nameOfOutputFormat(value clientpb.OutputFormat) string { } } -// Shared function that extracts the compile flags from the grumble context +// Shared function that extracts the compile flags from the grumble context. func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *clientpb.ImplantConfig { var name string if nameF, _ := cmd.Flags().GetString("name"); nameF != "" { @@ -404,7 +403,7 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl return config } -// parseTrafficEncoderArgs - parses the traffic encoder args and returns a bool indicating if traffic encoders are enabled +// parseTrafficEncoderArgs - parses the traffic encoder args and returns a bool indicating if traffic encoders are enabled. func parseTrafficEncoderArgs(cmd *cobra.Command, httpC2Enabled bool, con *console.SliverConsoleClient) (bool, []*commonpb.File) { trafficEncoders, _ := cmd.Flags().GetString("traffic-encoders") encoders := []*commonpb.File{} @@ -461,7 +460,7 @@ func getTargets(targetOS string, targetArch string, con *console.SliverConsoleCl return targetOS, targetArch } -// ParseMTLSc2 - Parse mtls connection string arg +// ParseMTLSc2 - Parse mtls connection string arg. func ParseMTLSc2(args string) ([]*clientpb.ImplantC2, error) { c2s := []*clientpb.ImplantC2{} if args == "" { @@ -496,7 +495,7 @@ func ParseMTLSc2(args string) ([]*clientpb.ImplantC2, error) { return c2s, nil } -// ParseWGc2 - Parse wg connect string arg +// ParseWGc2 - Parse wg connect string arg. func ParseWGc2(args string) ([]*clientpb.ImplantC2, error) { c2s := []*clientpb.ImplantC2{} if args == "" { @@ -612,7 +611,7 @@ func uriWithoutProxyOptions(uri *url.URL) { uri.RawQuery = options.Encode() } -// ParseHTTPc2 - Parse HTTP connection string arg +// ParseHTTPc2 - Parse HTTP connection string arg. func ParseHTTPc2(args string) ([]*clientpb.ImplantC2, error) { c2s := []*clientpb.ImplantC2{} if args == "" { @@ -658,7 +657,7 @@ func ParseHTTPc2(args string) ([]*clientpb.ImplantC2, error) { return c2s, nil } -// ParseDNSc2 - Parse DNS connection string arg +// ParseDNSc2 - Parse DNS connection string arg. func ParseDNSc2(args string) ([]*clientpb.ImplantC2, error) { c2s := []*clientpb.ImplantC2{} if args == "" { @@ -693,7 +692,7 @@ func ParseDNSc2(args string) ([]*clientpb.ImplantC2, error) { return c2s, nil } -// ParseNamedPipec2 - Parse named pipe connection string arg +// ParseNamedPipec2 - Parse named pipe connection string arg. func ParseNamedPipec2(args string) ([]*clientpb.ImplantC2, error) { c2s := []*clientpb.ImplantC2{} if args == "" { @@ -740,7 +739,7 @@ func ParseNamedPipec2(args string) ([]*clientpb.ImplantC2, error) { return c2s, nil } -// ParseTCPPivotc2 - Parse tcp pivot connection string arg +// ParseTCPPivotc2 - Parse tcp pivot connection string arg. func ParseTCPPivotc2(args string) ([]*clientpb.ImplantC2, error) { c2s := []*clientpb.ImplantC2{} if args == "" { diff --git a/client/command/generate/helpers.go b/client/command/generate/helpers.go index f234c09159..554128bb2d 100644 --- a/client/command/generate/helpers.go +++ b/client/command/generate/helpers.go @@ -4,14 +4,13 @@ import ( "context" "fmt" - "github.com/rsteube/carapace" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/rsteube/carapace" ) -// GetSliverBinary - Get the binary of an implant based on it's profile +// GetSliverBinary - Get the binary of an implant based on it's profile. func GetSliverBinary(profile *clientpb.ImplantProfile, con *console.SliverConsoleClient) ([]byte, error) { var data []byte // get implant builds @@ -92,7 +91,7 @@ func ArchCompleter(con *console.SliverConsoleClient) carapace.Action { }) } -// FormatCompleter completes build operating systems +// FormatCompleter completes build operating systems. func OSCompleter(con *console.SliverConsoleClient) carapace.Action { return carapace.ActionCallback(func(_ carapace.Context) carapace.Action { compiler, err := con.Rpc.GetCompiler(context.Background(), &commonpb.Empty{}) @@ -126,7 +125,7 @@ func OSCompleter(con *console.SliverConsoleClient) carapace.Action { }) } -// FormatCompleter completes build formats +// FormatCompleter completes build formats. func FormatCompleter() carapace.Action { return carapace.ActionCallback(func(_ carapace.Context) carapace.Action { return carapace.ActionValues([]string{ @@ -135,7 +134,7 @@ func FormatCompleter() carapace.Action { }) } -// TrafficEncoderCompleter - Completes the names of traffic encoders +// TrafficEncoderCompleter - Completes the names of traffic encoders. func TrafficEncodersCompleter(con *console.SliverConsoleClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { grpcCtx, cancel := con.GrpcContext(nil) diff --git a/client/command/generate/implants-rm.go b/client/command/generate/implants-rm.go index acb6f6b92e..9a95a9f56c 100644 --- a/client/command/generate/implants-rm.go +++ b/client/command/generate/implants-rm.go @@ -5,13 +5,12 @@ import ( "fmt" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// ImplantsRmCmd - Deletes an archived implant build from the server +// ImplantsRmCmd - Deletes an archived implant build from the server. func ImplantsRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { name := args[0] // name := ctx.Args.String("name") diff --git a/client/command/generate/implants.go b/client/command/generate/implants.go index 5553188b0a..cc59a6bd75 100644 --- a/client/command/generate/implants.go +++ b/client/command/generate/implants.go @@ -23,17 +23,16 @@ import ( "fmt" "strings" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// ImplantBuildFilter - Filter implant builds +// ImplantBuildFilter - Filter implant builds. type ImplantBuildFilter struct { GOOS string GOARCH string @@ -43,7 +42,7 @@ type ImplantBuildFilter struct { Debug bool } -// ImplantsCmd - Displays archived implant builds +// ImplantsCmd - Displays archived implant builds. func ImplantsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { builds, err := con.Rpc.ImplantBuilds(context.Background(), &commonpb.Empty{}) if err != nil { @@ -59,7 +58,7 @@ func ImplantsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -// PrintImplantBuilds - Print the implant builds on the server +// PrintImplantBuilds - Print the implant builds on the server. func PrintImplantBuilds(configs map[string]*clientpb.ImplantConfig, filters ImplantBuildFilter, con *console.SliverConsoleClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) @@ -123,7 +122,7 @@ func PrintImplantBuilds(configs map[string]*clientpb.ImplantConfig, filters Impl con.Println("\n") } -// ImplantBuildNameCompleter - Completer for implant build names +// ImplantBuildNameCompleter - Completer for implant build names. func ImplantBuildNameCompleter(con *console.SliverConsoleClient) carapace.Action { comps := func(ctx carapace.Context) carapace.Action { var action carapace.Action @@ -193,7 +192,7 @@ func ImplantBuildNameCompleter(con *console.SliverConsoleClient) carapace.Action return carapace.ActionCallback(comps) } -// ImplantBuildByName - Get an implant build by name +// ImplantBuildByName - Get an implant build by name. func ImplantBuildByName(name string, con *console.SliverConsoleClient) *clientpb.ImplantConfig { builds, err := con.Rpc.ImplantBuilds(context.Background(), &commonpb.Empty{}) if err != nil { diff --git a/client/command/generate/profiles-generate.go b/client/command/generate/profiles-generate.go index f83ab231e2..7d127e7645 100644 --- a/client/command/generate/profiles-generate.go +++ b/client/command/generate/profiles-generate.go @@ -24,12 +24,11 @@ import ( "path/filepath" "strings" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) -// ProfilesGenerateCmd - Generate an implant binary based on a profile +// ProfilesGenerateCmd - Generate an implant binary based on a profile. func ProfilesGenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { var name string if len(args) > 0 { diff --git a/client/command/generate/profiles-new.go b/client/command/generate/profiles-new.go index 8d04ff0a85..c4a6448cb7 100644 --- a/client/command/generate/profiles-new.go +++ b/client/command/generate/profiles-new.go @@ -20,13 +20,12 @@ package generate import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// ProfilesNewCmd - Create a new implant profile +// ProfilesNewCmd - Create a new implant profile. func ProfilesNewCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { var name string if len(args) > 0 { @@ -49,7 +48,7 @@ func ProfilesNewCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } } -// ProfilesNewBeaconCmd - Create a new beacon profile +// ProfilesNewBeaconCmd - Create a new beacon profile. func ProfilesNewBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { var name string if len(args) > 0 { diff --git a/client/command/generate/profiles-rm.go b/client/command/generate/profiles-rm.go index 4015c4ea87..2df08c17a2 100644 --- a/client/command/generate/profiles-rm.go +++ b/client/command/generate/profiles-rm.go @@ -23,13 +23,12 @@ import ( "fmt" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// ProfilesRmCmd - Delete an implant profile +// ProfilesRmCmd - Delete an implant profile. func ProfilesRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { var name string if len(args) > 0 { diff --git a/client/command/generate/profiles.go b/client/command/generate/profiles.go index 2fc45faa77..5190127d53 100644 --- a/client/command/generate/profiles.go +++ b/client/command/generate/profiles.go @@ -24,18 +24,17 @@ import ( "math" "strings" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// ProfilesCmd - Display implant profiles +// ProfilesCmd - Display implant profiles. func ProfilesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { profiles := getImplantProfiles(con) if profiles == nil { @@ -49,7 +48,7 @@ func ProfilesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -// PrintProfiles - Print the profiles +// PrintProfiles - Print the profiles. func PrintProfiles(profiles []*clientpb.ImplantProfile, con *console.SliverConsoleClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) @@ -106,7 +105,7 @@ func getImplantProfiles(con *console.SliverConsoleClient) []*clientpb.ImplantPro return pbProfiles.Profiles } -// GetImplantProfileByName - Get an implant profile by a specific name +// GetImplantProfileByName - Get an implant profile by a specific name. func GetImplantProfileByName(name string, con *console.SliverConsoleClient) *clientpb.ImplantProfile { pbProfiles, err := con.Rpc.ImplantProfiles(context.Background(), &commonpb.Empty{}) if err != nil { @@ -263,7 +262,7 @@ func populateProfileProperties(config *clientpb.ImplantConfig) map[string]string return properties } -// PrintProfileInfo - Print detailed information about a given profile +// PrintProfileInfo - Print detailed information about a given profile. func PrintProfileInfo(name string, con *console.SliverConsoleClient) { profile := GetImplantProfileByName(name, con) if profile == nil { @@ -273,7 +272,7 @@ func PrintProfileInfo(name string, con *console.SliverConsoleClient) { config := profile.Config properties := populateProfileProperties(config) - //con.Printf("--- Details for profile %s ---\n", profile.Name) + tw := table.NewWriter() // Implant Basics @@ -420,7 +419,7 @@ func PrintProfileInfo(name string, con *console.SliverConsoleClient) { } } -// ProfileNameCompleter - Completer for implant build names +// ProfileNameCompleter - Completer for implant build names. func ProfileNameCompleter(con *console.SliverConsoleClient) carapace.Action { comps := func(ctx carapace.Context) carapace.Action { var action carapace.Action diff --git a/client/command/generate/regenerate.go b/client/command/generate/regenerate.go index 2720a383df..504bb044bd 100644 --- a/client/command/generate/regenerate.go +++ b/client/command/generate/regenerate.go @@ -22,13 +22,12 @@ import ( "context" "os" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// RegenerateCmd - Download an archived implant build/binary +// RegenerateCmd - Download an archived implant build/binary. func RegenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { save, _ := cmd.Flags().GetString("save") if save == "" { diff --git a/client/command/generate/traffic-encoders.go b/client/command/generate/traffic-encoders.go index 539d4dd3c0..c7cb27cf55 100644 --- a/client/command/generate/traffic-encoders.go +++ b/client/command/generate/traffic-encoders.go @@ -27,22 +27,21 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/gofrs/uuid" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "golang.org/x/text/cases" - "golang.org/x/text/language" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/util" + "github.com/gofrs/uuid" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" + "golang.org/x/text/cases" + "golang.org/x/text/language" + "google.golang.org/protobuf/proto" ) -// TrafficEncodersCmd - Generate traffic encoders command implementation +// TrafficEncodersCmd - Generate traffic encoders command implementation. func TrafficEncodersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { grpcCtx, cancel := con.GrpcContext(cmd) defer cancel() @@ -54,7 +53,7 @@ func TrafficEncodersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, ar DisplayTrafficEncoders(encoderMap, con) } -// DisplayTrafficEncoders - Display traffic encoders map from server +// DisplayTrafficEncoders - Display traffic encoders map from server. func DisplayTrafficEncoders(encoderMap *clientpb.TrafficEncoderMap, con *console.SliverConsoleClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) @@ -83,7 +82,7 @@ func DisplayTrafficEncoders(encoderMap *clientpb.TrafficEncoderMap, con *console con.Println(tw.Render()) } -// TrafficEncodersAddCmd - Add a new traffic encoder to the server +// TrafficEncodersAddCmd - Add a new traffic encoder to the server. func TrafficEncodersAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { grpcCtx, cancel := con.GrpcContext(cmd) defer cancel() @@ -138,7 +137,7 @@ func TrafficEncodersAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, con.PrintInfof("Successfully added traffic encoder: %s\n", trafficEncoder.Wasm.Name) } -// saveFailedSample - Save the sample the encoder failed to properly encode/decode +// saveFailedSample - Save the sample the encoder failed to properly encode/decode. func saveFailedSample(encoderName string, test *clientpb.TrafficEncoderTest) { confirm := false prompt := &survey.Confirm{ @@ -156,7 +155,7 @@ func saveFailedSample(encoderName string, test *clientpb.TrafficEncoderTest) { } } -// allTestsPassed - Check if all tests passed +// allTestsPassed - Check if all tests passed. func allTestsPassed(tests *clientpb.TrafficEncoderTests) bool { for _, test := range tests.Tests { if !test.Success { @@ -166,7 +165,7 @@ func allTestsPassed(tests *clientpb.TrafficEncoderTests) bool { return true } -// displayTrafficEncoderTests - Display traffic encoder tests in real time +// displayTrafficEncoderTests - Display traffic encoder tests in real time. func displayTrafficEncoderTestProgress(testID string, completed chan interface{}, con *console.SliverConsoleClient) { listenerID, events := con.CreateEventListener() defer con.RemoveEventListener(listenerID) @@ -191,7 +190,7 @@ func displayTrafficEncoderTestProgress(testID string, completed chan interface{} } } -// clearLines - Clear a number of lines from the console +// clearLines - Clear a number of lines from the console. func clearLines(count int, con *console.SliverConsoleClient) { for i := 0; i < count; i++ { con.Printf(console.Clearln + "\r") @@ -199,7 +198,7 @@ func clearLines(count int, con *console.SliverConsoleClient) { } } -// displayTrafficEncoderTests - Display the results of traffic encoder tests, return number of lines written +// displayTrafficEncoderTests - Display the results of traffic encoder tests, return number of lines written. func displayTrafficEncoderTests(running bool, tests *clientpb.TrafficEncoderTests, con *console.SliverConsoleClient) int { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) @@ -245,7 +244,7 @@ func displayTrafficEncoderTests(running bool, tests *clientpb.TrafficEncoderTest return lineCount } -// TrafficEncodersRemoveCmd - Remove a traffic encoder +// TrafficEncodersRemoveCmd - Remove a traffic encoder. func TrafficEncodersRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { _, cancel := con.GrpcContext(cmd) defer cancel() @@ -272,7 +271,7 @@ func TrafficEncodersRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClie con.PrintInfof("Successfully removed traffic encoder: %s\n", name) } -// SelectTrafficEncoder - Select a traffic encoder from a list +// SelectTrafficEncoder - Select a traffic encoder from a list. func SelectTrafficEncoder(con *console.SliverConsoleClient) string { grpcCtx, cancel := con.GrpcContext(nil) defer cancel() From be65f1ce58c47199126237bdbdad94aa1f9d751f Mon Sep 17 00:00:00 2001 From: maxlandon Date: Sun, 23 Jul 2023 19:23:13 +0200 Subject: [PATCH 10/14] Filter portfwd/socks commands out of beacons --- client/cli/cli.go | 9 ++- client/cli/config.go | 1 - client/cli/console.go | 7 +- client/cli/implant.go | 7 +- client/cli/import.go | 3 +- client/cli/version.go | 3 +- client/command/command.go | 3 +- client/command/cursed/commands.go | 16 ++--- client/command/cursed/cursed-chrome.go | 5 +- client/command/cursed/cursed-console.go | 5 +- client/command/cursed/cursed-cookies.go | 3 +- client/command/cursed/cursed-edge.go | 6 +- client/command/cursed/cursed-electron.go | 3 +- client/command/cursed/cursed-rm.go | 3 +- client/command/cursed/cursed-screenshot.go | 3 +- client/command/cursed/cursed.go | 9 ++- client/command/portfwd/commands.go | 16 ++--- client/command/portfwd/portfwd-add.go | 5 +- client/command/portfwd/portfwd-rm.go | 5 +- client/command/portfwd/portfwd.go | 15 ++-- client/command/rportfwd/commands.go | 16 ++--- client/command/rportfwd/portfwd-add.go | 5 +- client/command/rportfwd/portfwd-rm.go | 5 +- client/command/rportfwd/portfwd.go | 11 ++- client/command/server.go | 5 +- client/command/shell/commands.go | 15 ++-- client/command/shell/shell.go | 7 +- client/command/sliver.go | 6 +- client/command/socks/commands.go | 16 ++--- client/command/socks/socks-start.go | 8 +-- client/command/socks/socks-stop.go | 5 +- client/command/socks/socks.go | 13 ++-- client/command/wasm/commands.go | 7 +- client/command/wasm/wasm.go | 10 +-- client/command/wireguard/commands.go | 20 +++--- client/command/wireguard/wg-config.go | 5 +- client/command/wireguard/wg-portfwd-add.go | 5 +- client/command/wireguard/wg-portfwd-rm.go | 9 ++- client/command/wireguard/wg-portfwd.go | 7 +- client/command/wireguard/wg-socks-start.go | 5 +- client/command/wireguard/wg-socks-stop.go | 5 +- client/command/wireguard/wg-socks.go | 9 ++- client/constants/constants.go | 80 +++++++++++----------- 43 files changed, 183 insertions(+), 218 deletions(-) diff --git a/client/cli/cli.go b/client/cli/cli.go index b36a37af99..5ebb7bd0f8 100644 --- a/client/cli/cli.go +++ b/client/cli/cli.go @@ -24,11 +24,10 @@ import ( "os" "path" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/version" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) const ( @@ -37,7 +36,7 @@ const ( var sliverServerVersion = fmt.Sprintf("v%s", version.FullVersion()) -// Initialize logging +// Initialize logging. func initLogging(appDir string) *os.File { log.SetFlags(log.LstdFlags | log.Lshortfile) logFile, err := os.OpenFile(path.Join(appDir, logFileName), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0o600) @@ -88,7 +87,7 @@ var rootCmd = &cobra.Command{ Long: ``, } -// Execute - Execute root command +// Execute - Execute root command. func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Println(err) diff --git a/client/cli/config.go b/client/cli/config.go index 71d858d3b3..c8f510ae40 100644 --- a/client/cli/config.go +++ b/client/cli/config.go @@ -23,7 +23,6 @@ import ( "sort" "github.com/bishopfox/sliver/client/assets" - "gopkg.in/AlecAivazis/survey.v1" ) diff --git a/client/cli/console.go b/client/cli/console.go index 67e208a382..5b0a8549e5 100644 --- a/client/cli/console.go +++ b/client/cli/console.go @@ -3,17 +3,16 @@ package cli import ( "fmt" - "github.com/spf13/cobra" - "google.golang.org/grpc" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/command" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/transport" "github.com/bishopfox/sliver/protobuf/rpcpb" + "github.com/spf13/cobra" + "google.golang.org/grpc" ) -// consoleCmd generates the console with required pre/post runners +// consoleCmd generates the console with required pre/post runners. func consoleCmd(con *console.SliverConsoleClient) *cobra.Command { consoleCmd := &cobra.Command{ Use: "console", diff --git a/client/cli/implant.go b/client/cli/implant.go index 1f24db8ba8..1952df7de9 100644 --- a/client/cli/implant.go +++ b/client/cli/implant.go @@ -3,14 +3,13 @@ package cli import ( "errors" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command" "github.com/bishopfox/sliver/client/command/use" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) func implantCmd(con *console.SliverConsoleClient) *cobra.Command { diff --git a/client/cli/import.go b/client/cli/import.go index b953916b27..affb22be41 100644 --- a/client/cli/import.go +++ b/client/cli/import.go @@ -22,10 +22,9 @@ import ( "fmt" "os" + "github.com/bishopfox/sliver/client/assets" "github.com/rsteube/carapace" "github.com/spf13/cobra" - - "github.com/bishopfox/sliver/client/assets" ) func importCmd() *cobra.Command { diff --git a/client/cli/version.go b/client/cli/version.go index 24d640871a..89ad72e863 100644 --- a/client/cli/version.go +++ b/client/cli/version.go @@ -21,9 +21,8 @@ package cli import ( "fmt" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/version" + "github.com/spf13/cobra" ) var cmdVersion = &cobra.Command{ diff --git a/client/command/command.go b/client/command/command.go index 2afd028b3e..27831efe6a 100644 --- a/client/command/command.go +++ b/client/command/command.go @@ -21,12 +21,11 @@ package command import ( "strings" + client "github.com/bishopfox/sliver/client/console" "github.com/reeflective/console" "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" - - client "github.com/bishopfox/sliver/client/console" ) const defaultTimeout = 60 diff --git a/client/command/cursed/commands.go b/client/command/cursed/commands.go index 6680df71e4..a750f4632a 100644 --- a/client/command/cursed/commands.go +++ b/client/command/cursed/commands.go @@ -1,23 +1,23 @@ package cursed import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. func Commands(con *console.SliverConsoleClient) []*cobra.Command { cursedCmd := &cobra.Command{ - Use: consts.Cursed, - Short: "Chrome/electron post-exploitation tool kit (∩`-´)⊃━☆゚.*・。゚", - Long: help.GetHelpFor([]string{consts.Cursed}), - GroupID: consts.ExecutionHelpGroup, + Use: consts.Cursed, + Short: "Chrome/electron post-exploitation tool kit (∩`-´)⊃━☆゚.*・。゚", + Long: help.GetHelpFor([]string{consts.Cursed}), + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.SessionCmdsFilter), Run: func(cmd *cobra.Command, args []string) { CursedCmd(cmd, con, args) }, diff --git a/client/command/cursed/cursed-chrome.go b/client/command/cursed/cursed-chrome.go index 04cfa2146d..bc5ca88d7a 100644 --- a/client/command/cursed/cursed-chrome.go +++ b/client/command/cursed/cursed-chrome.go @@ -29,8 +29,6 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/client/overlord" @@ -38,6 +36,7 @@ import ( "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) var ( @@ -51,7 +50,7 @@ var ( cursedChromePermissionsAlt = []string{overlord.AllHTTP, overlord.AllHTTPS, overlord.WebRequest, overlord.WebRequestBlocking} ) -// CursedChromeCmd - Execute a .NET assembly in-memory +// CursedChromeCmd - Execute a .NET assembly in-memory. func CursedChromeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/cursed/cursed-console.go b/client/command/cursed/cursed-console.go index 046bb45308..a17862fd87 100644 --- a/client/command/cursed/cursed-console.go +++ b/client/command/cursed/cursed-console.go @@ -27,12 +27,11 @@ import ( "text/tabwriter" "github.com/AlecAivazis/survey/v2" - "github.com/reeflective/readline" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/client/overlord" + "github.com/reeflective/readline" + "github.com/spf13/cobra" ) func CursedConsoleCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { diff --git a/client/command/cursed/cursed-cookies.go b/client/command/cursed/cursed-cookies.go index 59859771d0..1e994a8b48 100644 --- a/client/command/cursed/cursed-cookies.go +++ b/client/command/cursed/cursed-cookies.go @@ -24,10 +24,9 @@ import ( "strings" "time" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/overlord" + "github.com/spf13/cobra" ) func CursedCookiesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { diff --git a/client/command/cursed/cursed-edge.go b/client/command/cursed/cursed-edge.go index a83da8c2f3..412a7d5f29 100644 --- a/client/command/cursed/cursed-edge.go +++ b/client/command/cursed/cursed-edge.go @@ -21,21 +21,19 @@ package cursed import ( "context" "os" - "strings" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/client/overlord" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// CursedChromeCmd - Execute a .NET assembly in-memory +// CursedChromeCmd - Execute a .NET assembly in-memory. func CursedEdgeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/cursed/cursed-electron.go b/client/command/cursed/cursed-electron.go index 1d11bc2422..caab611e7a 100644 --- a/client/command/cursed/cursed-electron.go +++ b/client/command/cursed/cursed-electron.go @@ -27,8 +27,6 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/client/overlord" @@ -36,6 +34,7 @@ import ( "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) func CursedElectronCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { diff --git a/client/command/cursed/cursed-rm.go b/client/command/cursed/cursed-rm.go index 3220557f23..c2e5dcee7f 100644 --- a/client/command/cursed/cursed-rm.go +++ b/client/command/cursed/cursed-rm.go @@ -23,11 +23,10 @@ import ( "strconv" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) func CursedRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { diff --git a/client/command/cursed/cursed-screenshot.go b/client/command/cursed/cursed-screenshot.go index d6cc8dc4ca..d851a0d449 100644 --- a/client/command/cursed/cursed-screenshot.go +++ b/client/command/cursed/cursed-screenshot.go @@ -23,10 +23,9 @@ import ( "os" "time" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/overlord" + "github.com/spf13/cobra" ) func CursedScreenshotCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { diff --git a/client/command/cursed/cursed.go b/client/command/cursed/cursed.go index fe81219f6d..df34b76964 100644 --- a/client/command/cursed/cursed.go +++ b/client/command/cursed/cursed.go @@ -27,15 +27,14 @@ import ( "text/tabwriter" "github.com/AlecAivazis/survey/v2" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// CursedChromeCmd - Execute a .NET assembly in-memory +// CursedChromeCmd - Execute a .NET assembly in-memory. func CursedCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { // Collect existing curses from core cursedProcesses := [][]string{} @@ -71,7 +70,7 @@ func CursedCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } } -// selectCursedProcess - Interactively select a cursed process from a list +// selectCursedProcess - Interactively select a cursed process from a list. func selectCursedProcess(con *console.SliverConsoleClient) *core.CursedProcess { cursedProcesses := []*core.CursedProcess{} core.CursedProcesses.Range(func(key, value interface{}) bool { diff --git a/client/command/portfwd/commands.go b/client/command/portfwd/commands.go index 003c247443..629e56cfe6 100644 --- a/client/command/portfwd/commands.go +++ b/client/command/portfwd/commands.go @@ -1,27 +1,27 @@ package portfwd import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/completers" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. func Commands(con *console.SliverConsoleClient) []*cobra.Command { portfwdCmd := &cobra.Command{ - Use: consts.PortfwdStr, - Short: "In-band TCP port forwarding", - Long: help.GetHelpFor([]string{consts.PortfwdStr}), + Use: consts.PortfwdStr, + Short: "In-band TCP port forwarding", + Long: help.GetHelpFor([]string{consts.PortfwdStr}), + GroupID: consts.NetworkHelpGroup, + Annotations: flags.RestrictTargets(consts.SessionCmdsFilter), Run: func(cmd *cobra.Command, args []string) { PortfwdCmd(cmd, con, args) }, - GroupID: consts.NetworkHelpGroup, } flags.Bind("", true, portfwdCmd, func(f *pflag.FlagSet) { f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") diff --git a/client/command/portfwd/portfwd-add.go b/client/command/portfwd/portfwd-add.go index 36559441df..2b494cb9c2 100644 --- a/client/command/portfwd/portfwd-add.go +++ b/client/command/portfwd/portfwd-add.go @@ -25,16 +25,15 @@ import ( "regexp" "time" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/client/tcpproxy" + "github.com/spf13/cobra" ) var portNumberOnlyRegexp = regexp.MustCompile("^[0-9]+$") -// PortfwdAddCmd - Add a new tunneled port forward +// PortfwdAddCmd - Add a new tunneled port forward. func PortfwdAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/portfwd/portfwd-rm.go b/client/command/portfwd/portfwd-rm.go index ebcc5f5bda..8f940e4abb 100644 --- a/client/command/portfwd/portfwd-rm.go +++ b/client/command/portfwd/portfwd-rm.go @@ -19,13 +19,12 @@ package portfwd */ import ( - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/spf13/cobra" ) -// PortfwdRmCmd - Remove an existing tunneled port forward +// PortfwdRmCmd - Remove an existing tunneled port forward. func PortfwdRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { portfwdID, _ := cmd.Flags().GetInt("id") if portfwdID < 1 { diff --git a/client/command/portfwd/portfwd.go b/client/command/portfwd/portfwd.go index 82c667168b..abbd7b660a 100644 --- a/client/command/portfwd/portfwd.go +++ b/client/command/portfwd/portfwd.go @@ -23,28 +23,27 @@ import ( "sort" "strconv" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// PortfwdCmd - Display information about tunneled port forward(s) +// PortfwdCmd - Display information about tunneled port forward(s). func PortfwdCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { PrintPortfwd(con) } -// PrintPortfwd - Print the port forward(s) +// PrintPortfwd - Print the port forward(s). func PrintPortfwd(con *console.SliverConsoleClient) { portfwds := core.Portfwds.List() if len(portfwds) == 0 { con.PrintInfof("No port forwards\n") return } - sort.Slice(portfwds[:], func(i, j int) bool { + sort.Slice(portfwds, func(i, j int) bool { return portfwds[i].ID < portfwds[j].ID }) @@ -67,7 +66,7 @@ func PrintPortfwd(con *console.SliverConsoleClient) { con.Printf("%s\n", tw.Render()) } -// PortfwdIDCompleter completes IDs of local portforwarders +// PortfwdIDCompleter completes IDs of local portforwarders. func PortfwdIDCompleter(_ *console.SliverConsoleClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/rportfwd/commands.go b/client/command/rportfwd/commands.go index d2b35b6eb7..0f87656dad 100644 --- a/client/command/rportfwd/commands.go +++ b/client/command/rportfwd/commands.go @@ -1,27 +1,27 @@ package rportfwd import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/completers" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. func Commands(con *console.SliverConsoleClient) []*cobra.Command { rportfwdCmd := &cobra.Command{ - Use: consts.RportfwdStr, - Short: "reverse port forwardings", - Long: help.GetHelpFor([]string{consts.RportfwdStr}), + Use: consts.RportfwdStr, + Short: "reverse port forwardings", + Long: help.GetHelpFor([]string{consts.RportfwdStr}), + GroupID: consts.NetworkHelpGroup, + Annotations: flags.RestrictTargets(consts.SessionCmdsFilter), Run: func(cmd *cobra.Command, args []string) { RportFwdListenersCmd(cmd, con, args) }, - GroupID: consts.NetworkHelpGroup, } flags.Bind("", true, rportfwdCmd, func(f *pflag.FlagSet) { f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") diff --git a/client/command/rportfwd/portfwd-add.go b/client/command/rportfwd/portfwd-add.go index 55d8b00119..930f3f3800 100644 --- a/client/command/rportfwd/portfwd-add.go +++ b/client/command/rportfwd/portfwd-add.go @@ -23,15 +23,14 @@ import ( "fmt" "regexp" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) var portNumberOnlyRegexp = regexp.MustCompile("^[0-9]+$") -// StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant +// StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant. func StartRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/rportfwd/portfwd-rm.go b/client/command/rportfwd/portfwd-rm.go index 0d10f9b706..445f048b94 100644 --- a/client/command/rportfwd/portfwd-rm.go +++ b/client/command/rportfwd/portfwd-rm.go @@ -21,13 +21,12 @@ package rportfwd import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant +// StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant. func StopRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/rportfwd/portfwd.go b/client/command/rportfwd/portfwd.go index 0afcdc7605..3cf929fcb7 100644 --- a/client/command/rportfwd/portfwd.go +++ b/client/command/rportfwd/portfwd.go @@ -23,17 +23,16 @@ import ( "fmt" "strconv" + "github.com/bishopfox/sliver/client/command/settings" + "github.com/bishopfox/sliver/client/console" + "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/jedib0t/go-pretty/v6/table" "github.com/rsteube/carapace" "github.com/spf13/cobra" "github.com/spf13/pflag" - - "github.com/bishopfox/sliver/client/command/settings" - "github.com/bishopfox/sliver/client/console" - "github.com/bishopfox/sliver/protobuf/sliverpb" ) -// StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant +// StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant. func RportFwdListenersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { @@ -78,7 +77,7 @@ func PrintRportFwdListeners(rportfwdListeners *sliverpb.RportFwdListeners, flags con.Printf("%s\n", tw.Render()) } -// PortfwdIDCompleter completes IDs of remote portforwarders +// PortfwdIDCompleter completes IDs of remote portforwarders. func PortfwdIDCompleter(con *console.SliverConsoleClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/server.go b/client/command/server.go index aca2735397..f30aebe52f 100644 --- a/client/command/server.go +++ b/client/command/server.go @@ -21,9 +21,6 @@ package command import ( "os" - "github.com/reeflective/console" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/alias" "github.com/bishopfox/sliver/client/command/armory" "github.com/bishopfox/sliver/client/command/beacons" @@ -51,6 +48,8 @@ import ( "github.com/bishopfox/sliver/client/command/wireguard" client "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/reeflective/console" + "github.com/spf13/cobra" ) // ServerCommands returns all commands bound to the server menu, optionally diff --git a/client/command/shell/commands.go b/client/command/shell/commands.go index 4791cc8215..954d647712 100644 --- a/client/command/shell/commands.go +++ b/client/command/shell/commands.go @@ -1,26 +1,25 @@ package shell import ( - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. func Commands(con *console.SliverConsoleClient) []*cobra.Command { shellCmd := &cobra.Command{ - Use: consts.ShellStr, - Short: "Start an interactive shell", - Long: help.GetHelpFor([]string{consts.ShellStr}), + Use: consts.ShellStr, + Short: "Start an interactive shell", + Long: help.GetHelpFor([]string{consts.ShellStr}), + GroupID: consts.ExecutionHelpGroup, + Annotations: flags.RestrictTargets(consts.SessionCmdsFilter), Run: func(cmd *cobra.Command, args []string) { ShellCmd(cmd, con, args) }, - GroupID: consts.ExecutionHelpGroup, - Annotations: flags.RestrictTargets(consts.SessionCmdsFilter), } flags.Bind("", false, shellCmd, func(f *pflag.FlagSet) { f.BoolP("no-pty", "y", false, "disable use of pty on macos/linux") diff --git a/client/command/shell/shell.go b/client/command/shell/shell.go index f7c03fea70..3775367c44 100644 --- a/client/command/shell/shell.go +++ b/client/command/shell/shell.go @@ -25,13 +25,12 @@ import ( "log" "os" - "github.com/spf13/cobra" - "golang.org/x/term" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "golang.org/x/term" ) const ( @@ -40,7 +39,7 @@ const ( linux = "linux" ) -// ShellCmd - Start an interactive shell on the remote system +// ShellCmd - Start an interactive shell on the remote system. func ShellCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/sliver.go b/client/command/sliver.go index 0b9446b13c..3c4161ab2e 100644 --- a/client/command/sliver.go +++ b/client/command/sliver.go @@ -19,9 +19,6 @@ package command */ import ( - "github.com/reeflective/console" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/command/alias" "github.com/bishopfox/sliver/client/command/backdoor" @@ -50,6 +47,8 @@ import ( "github.com/bishopfox/sliver/client/command/wireguard" client "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/reeflective/console" + "github.com/spf13/cobra" ) // SliverCommands returns all commands bound to the implant menu. @@ -145,6 +144,7 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { con.PrintErrorf("Failed to load extension: %s", err) continue } + extensions.ExtensionRegisterCommand(ext, sliver, con) } diff --git a/client/command/socks/commands.go b/client/command/socks/commands.go index 90f3571276..2768f24bbd 100644 --- a/client/command/socks/commands.go +++ b/client/command/socks/commands.go @@ -1,27 +1,27 @@ package socks import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/completers" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. func Commands(con *console.SliverConsoleClient) []*cobra.Command { socksCmd := &cobra.Command{ - Use: consts.Socks5Str, - Short: "In-band SOCKS5 Proxy", - Long: help.GetHelpFor([]string{consts.Socks5Str}), + Use: consts.Socks5Str, + Short: "In-band SOCKS5 Proxy", + Long: help.GetHelpFor([]string{consts.Socks5Str}), + GroupID: consts.NetworkHelpGroup, + Annotations: flags.RestrictTargets(consts.SessionCmdsFilter), Run: func(cmd *cobra.Command, args []string) { SocksCmd(cmd, con, args) }, - GroupID: consts.NetworkHelpGroup, } flags.Bind("", true, socksCmd, func(f *pflag.FlagSet) { f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") diff --git a/client/command/socks/socks-start.go b/client/command/socks/socks-start.go index 7922429305..9ecde46961 100644 --- a/client/command/socks/socks-start.go +++ b/client/command/socks/socks-start.go @@ -25,15 +25,13 @@ import ( "net" "time" - "gopkg.in/AlecAivazis/survey.v1" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/spf13/cobra" + "gopkg.in/AlecAivazis/survey.v1" ) -// SocksStartCmd - Add a new tunneled port forward +// SocksStartCmd - Add a new tunneled port forward. func SocksStartCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/socks/socks-stop.go b/client/command/socks/socks-stop.go index d6e21e2c13..00bd5f7868 100644 --- a/client/command/socks/socks-stop.go +++ b/client/command/socks/socks-stop.go @@ -21,14 +21,13 @@ package socks import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// SocksStopCmd - Remove an existing tunneled port forward +// SocksStopCmd - Remove an existing tunneled port forward. func SocksStopCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { socksID, _ := cmd.Flags().GetUint64("id") if socksID < 1 { diff --git a/client/command/socks/socks.go b/client/command/socks/socks.go index ae006d91b3..412f37acd7 100644 --- a/client/command/socks/socks.go +++ b/client/command/socks/socks.go @@ -23,23 +23,22 @@ import ( "sort" "strconv" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// SocksCmd - Display information about tunneled port forward(s) +// SocksCmd - Display information about tunneled port forward(s). func SocksCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { socks := core.SocksProxies.List() if len(socks) == 0 { con.PrintInfof("No socks5 proxies\n") return } - sort.Slice(socks[:], func(i, j int) bool { + sort.Slice(socks, func(i, j int) bool { return socks[i].ID < socks[j].ID }) @@ -59,7 +58,7 @@ func SocksCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin con.Printf("%s\n", tw.Render()) } -// SocksIDCompleter completes IDs of remote of socks proxy servers +// SocksIDCompleter completes IDs of remote of socks proxy servers. func SocksIDCompleter(_ *console.SliverConsoleClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/wasm/commands.go b/client/command/wasm/commands.go index 175eaed811..96fd6f29dc 100644 --- a/client/command/wasm/commands.go +++ b/client/command/wasm/commands.go @@ -1,14 +1,13 @@ package wasm import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. diff --git a/client/command/wasm/wasm.go b/client/command/wasm/wasm.go index 3abb990aa4..0b517ab97a 100644 --- a/client/command/wasm/wasm.go +++ b/client/command/wasm/wasm.go @@ -36,16 +36,16 @@ import ( ) // wasmMaxModuleSize - Arbitrary 1.5Gb limit to put us well under the 2Gb max gRPC message size -// this is also the *compressed size* limit, so it's pretty generous +// this is also the *compressed size* limit, so it's pretty generous. const ( gb = 1024 * 1024 * 1024 wasmMaxModuleSize = gb + (gb / 2) ) -// WasmCmd - session/beacon id -> list of loaded wasm extension names +// WasmCmd - session/beacon id -> list of loaded wasm extension names. var wasmRegistrationCache = make(map[string][]string) -// WasmCmd - Execute a WASM module extension +// WasmCmd - Execute a WASM module extension. func WasmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { @@ -120,7 +120,7 @@ func isRegistered(name string, cmd *cobra.Command, con *console.SliverConsoleCli return false } -// idOf - Quickly return the id of the current session or beacon +// idOf - Quickly return the id of the current session or beacon. func idOf(con *console.SliverConsoleClient) string { if con.ActiveTarget != nil { if session := con.ActiveTarget.GetSession(); session != nil { @@ -253,7 +253,7 @@ func registerWasmExtension(wasmFilePath string, cmd *cobra.Command, con *console return nil } -// WasmLsCmd - Execute a WASM module extension +// WasmLsCmd - Execute a WASM module extension. func WasmLsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { diff --git a/client/command/wireguard/commands.go b/client/command/wireguard/commands.go index daa4460539..dae1f74a09 100644 --- a/client/command/wireguard/commands.go +++ b/client/command/wireguard/commands.go @@ -1,14 +1,13 @@ package wireguard import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. @@ -39,14 +38,17 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { // SliverCommands returns all Wireguard commands that can be used on an active target. func SliverCommands(con *console.SliverConsoleClient) []*cobra.Command { wgPortFwdCmd := &cobra.Command{ - Use: consts.WgPortFwdStr, - Short: "List ports forwarded by the WireGuard tun interface", - Long: help.GetHelpFor([]string{consts.WgPortFwdStr}), + Use: consts.WgPortFwdStr, + Short: "List ports forwarded by the WireGuard tun interface", + Long: help.GetHelpFor([]string{consts.WgPortFwdStr}), + GroupID: consts.NetworkHelpGroup, + Annotations: flags.RestrictTargets( + consts.WireguardCmdsFilter, + consts.SessionCmdsFilter, + ), Run: func(cmd *cobra.Command, args []string) { WGPortFwdListCmd(cmd, con, args) }, - GroupID: consts.NetworkHelpGroup, - Annotations: flags.RestrictTargets(consts.WireguardCmdsFilter), } flags.Bind("wg portforward", true, wgPortFwdCmd, func(f *pflag.FlagSet) { f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds") diff --git a/client/command/wireguard/wg-config.go b/client/command/wireguard/wg-config.go index 1568b51f04..7f08d3ec0a 100644 --- a/client/command/wireguard/wg-config.go +++ b/client/command/wireguard/wg-config.go @@ -28,10 +28,9 @@ import ( "strings" "text/template" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/spf13/cobra" ) var wgQuickTemplate = `[Interface] @@ -52,7 +51,7 @@ type wgQuickConfig struct { AllowedSubnet string } -// WGConfigCmd - Generate a WireGuard client configuration +// WGConfigCmd - Generate a WireGuard client configuration. func WGConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { wgConfig, err := con.Rpc.GenerateWGClientConfig(context.Background(), &commonpb.Empty{}) if err != nil { diff --git a/client/command/wireguard/wg-portfwd-add.go b/client/command/wireguard/wg-portfwd-add.go index c6817e38de..28899c94da 100644 --- a/client/command/wireguard/wg-portfwd-add.go +++ b/client/command/wireguard/wg-portfwd-add.go @@ -22,13 +22,12 @@ import ( "context" "net" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// WGPortFwdAddCmd - Add a new WireGuard port forward +// WGPortFwdAddCmd - Add a new WireGuard port forward. func WGPortFwdAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/wireguard/wg-portfwd-rm.go b/client/command/wireguard/wg-portfwd-rm.go index b732719fdf..05ad176013 100644 --- a/client/command/wireguard/wg-portfwd-rm.go +++ b/client/command/wireguard/wg-portfwd-rm.go @@ -23,14 +23,13 @@ import ( "fmt" "strconv" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// WGPortFwdRmCmd - Remove a WireGuard port forward +// WGPortFwdRmCmd - Remove a WireGuard port forward. func WGPortFwdRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { @@ -66,7 +65,7 @@ func WGPortFwdRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } } -// PortfwdIDCompleter completes IDs of WireGuard remote portforwarders +// PortfwdIDCompleter completes IDs of WireGuard remote portforwarders. func PortfwdIDCompleter(con *console.SliverConsoleClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/wireguard/wg-portfwd.go b/client/command/wireguard/wg-portfwd.go index e7eabd8db4..55614532ad 100644 --- a/client/command/wireguard/wg-portfwd.go +++ b/client/command/wireguard/wg-portfwd.go @@ -21,15 +21,14 @@ package wireguard import ( "context" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// WGPortFwdListCmd - List WireGuard port forwards +// WGPortFwdListCmd - List WireGuard port forwards. func WGPortFwdListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/wireguard/wg-socks-start.go b/client/command/wireguard/wg-socks-start.go index a9062faff2..4c3df6fc31 100644 --- a/client/command/wireguard/wg-socks-start.go +++ b/client/command/wireguard/wg-socks-start.go @@ -21,13 +21,12 @@ package wireguard import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// WGSocksStartCmd - Start a WireGuard reverse SOCKS proxy +// WGSocksStartCmd - Start a WireGuard reverse SOCKS proxy. func WGSocksStartCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/wireguard/wg-socks-stop.go b/client/command/wireguard/wg-socks-stop.go index ef9da5a69d..6a808bc95b 100644 --- a/client/command/wireguard/wg-socks-stop.go +++ b/client/command/wireguard/wg-socks-stop.go @@ -22,13 +22,12 @@ import ( "context" "strconv" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// WGSocksStopCmd - Stop a WireGuard SOCKS proxy +// WGSocksStopCmd - Stop a WireGuard SOCKS proxy. func WGSocksStopCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSession() if session == nil { diff --git a/client/command/wireguard/wg-socks.go b/client/command/wireguard/wg-socks.go index 1bc1b13385..f0fe2e2ea2 100644 --- a/client/command/wireguard/wg-socks.go +++ b/client/command/wireguard/wg-socks.go @@ -22,16 +22,15 @@ import ( "context" "strconv" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// WGSocksListCmd - List WireGuard SOCKS proxies +// WGSocksListCmd - List WireGuard SOCKS proxies. func WGSocksListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/constants/constants.go b/client/constants/constants.go index 104b89a699..a906378154 100644 --- a/client/constants/constants.go +++ b/client/constants/constants.go @@ -18,105 +18,105 @@ package constants along with this program. If not, see . */ -// Meta +// Meta. const ( - // KeepAliveStr - Keep alive constant + // KeepAliveStr - Keep alive constant. KeepAliveStr = "keepalive" ) const ( - // LastUpdateCheckFileName - Last update check file name + // LastUpdateCheckFileName - Last update check file name. LastUpdateCheckFileName = "last_update_check" ) -// Console +// Console. const ( ImplantMenu = "implant" ServerMenu = "" ) -// Events +// Events. const ( - // UpdateStr - "update" + // UpdateStr - "update". UpdateStr = "update" - // VersionStr - "version" + // VersionStr - "version". VersionStr = "version" - // EventStr - "event" + // EventStr - "event". EventStr = "event" - // ServersStr - "server-error" + // ServersStr - "server-error". ServerErrorStr = "server-error" - // ConnectedEvent - Sliver Connected + // ConnectedEvent - Sliver Connected. SessionOpenedEvent = "session-connected" - // DisconnectedEvent - Sliver disconnected + // DisconnectedEvent - Sliver disconnected. SessionClosedEvent = "session-disconnected" - // UpdateEvent - Sliver updated + // UpdateEvent - Sliver updated. SessionUpdateEvent = "session-updated" - // JoinedEvent - Player joined the game + // JoinedEvent - Player joined the game. JoinedEvent = "client-joined" - // LeftEvent - Player left the game + // LeftEvent - Player left the game. LeftEvent = "client-left" - // CanaryEvent - A DNS canary was triggered + // CanaryEvent - A DNS canary was triggered. CanaryEvent = "canary" - // WatchtowerEvent - An implant hash has been identified on a threat intel platform + // WatchtowerEvent - An implant hash has been identified on a threat intel platform. WatchtowerEvent = "watchtower" - // StartedEvent - Job was started + // StartedEvent - Job was started. JobStartedEvent = "job-started" - // StoppedEvent - Job was stopped + // StoppedEvent - Job was stopped. JobStoppedEvent = "job-stopped" - // BuildEvent - Fires on change to builds + // BuildEvent - Fires on change to builds. BuildEvent = "build" - // BuildCompletedEvent - Fires when a build completes + // BuildCompletedEvent - Fires when a build completes. BuildCompletedEvent = "build-completed" - // ProfileEvent - Fires whenever there's a change to profiles + // ProfileEvent - Fires whenever there's a change to profiles. ProfileEvent = "profile" - // WebsiteEvent - Fires whenever there's a change to websites + // WebsiteEvent - Fires whenever there's a change to websites. WebsiteEvent = "website" - // LootAdded + // LootAdded. LootAddedEvent = "loot-added" - // LootRemoved + // LootRemoved. LootRemovedEvent = "loot-removed" - // BeaconRegisteredEvent - First connection from a new beacon + // BeaconRegisteredEvent - First connection from a new beacon. BeaconRegisteredEvent = "beacon-registered" - // BeaconTaskResult - Beacon task completed with a result + // BeaconTaskResult - Beacon task completed with a result. BeaconTaskResultEvent = "beacon-taskresult" - // ExternalBuildEvent + // ExternalBuildEvent. ExternalBuildEvent = "external-build" AcknowledgeBuildEvent = "external-acknowledge" ExternalBuildFailedEvent = "external-build-failed" ExternalBuildCompletedEvent = "external-build-completed" - // TrafficEncoder Events + // TrafficEncoder Events. TrafficEncoderTestProgressEvent = "traffic-encoder-test-progress" - // Crackstation Events + // Crackstation Events. CrackstationConnected = "crackstation-connected" CrackstationDisconnected = "crackstation-disconnected" - // Crack Events - Events consumed by crackstations + // Crack Events - Events consumed by crackstations. CrackBenchmark = "crack-benchmark" CrackStatusEvent = "crack-status" - // WireGuardNewPeer - New Wireguard peer added + // WireGuardNewPeer - New Wireguard peer added. WireGuardNewPeer = "wireguard-newpeer" ) -// Commands +// Commands. const ( OperatorsStr = "operators" NewOperatorStr = "new-operator" @@ -144,9 +144,9 @@ const ( SearchStr = "search" TrafficEncodersStr = "traffic-encoders" - // Generic + // Generic. - // NewStr - "new" + // NewStr - "new". NewStr = "new" AddStr = "add" StartStr = "start" @@ -294,16 +294,16 @@ const ( Hcstat2Str = "hcstat2" ) -// Groups +// Groups. const ( - // Server commands ===================== + // Server commands =====================. GenericHelpGroup = "Generic" NetworkHelpGroup = "Network" PayloadsHelpGroup = "Payload" DataHelpGroup = "Data" SliverHelpGroup = "Sliver" - // Sliver commands ===================== + // Sliver commands =====================. SliverCoreHelpGroup = "Core" InfoHelpGroup = "Info" FilesystemHelpGroup = "Filesystem" @@ -314,13 +314,13 @@ const ( AliasHelpGroup = "Sliver - 3rd Party macros" ExtensionHelpGroup = "Sliver - 3rd Party extensions" - // Useless + // Useless. SliverWinHelpGroup = "Sliver - Windows" MultiplayerHelpGroup = "Multiplayer" ) // Command types / filters (per OS/type/C2/etc) -// Should not be changed: extension.json artifact file (architecture/OS) rely on some of the values below, +// Should not be changed: extension.json artifact file (architecture/OS) rely on some of the values below,. const ( SessionCmdsFilter = "session" BeaconCmdsFilter = "beacon" @@ -328,7 +328,7 @@ const ( WireguardCmdsFilter = "wireguard" ) -// Creds (needed here to avoid recursive imports) +// Creds (needed here to avoid recursive imports). const ( UserColonHashNewlineFormat = "user:hash" // username:hash\n HashNewlineFormat = "hash" // hash\n From d5c1daaa480482efb94fb7108d3e160269fd6451 Mon Sep 17 00:00:00 2001 From: maxlandon Date: Sun, 23 Jul 2023 19:36:57 +0200 Subject: [PATCH 11/14] Simplify binding commands with groups --- client/command/command.go | 66 +++++++++++++++++++++------------------ client/command/server.go | 14 ++++++--- client/command/sliver.go | 24 ++++++++------ 3 files changed, 61 insertions(+), 43 deletions(-) diff --git a/client/command/command.go b/client/command/command.go index 27831efe6a..e9f2c66601 100644 --- a/client/command/command.go +++ b/client/command/command.go @@ -77,6 +77,42 @@ func RestrictTargets(filters ...string) map[string]string { } } +// makeBind returns a commandBinder helper function +// @menu - The command menu to which the commands should be bound (either server or implant menu). +func makeBind(cmd *cobra.Command, con *client.SliverConsoleClient) func(group string, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { + return func(group string, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { + found := false + + // Ensure the given command group is available in the menu. + if group != "" { + for _, grp := range cmd.Groups() { + if grp.Title == group { + found = true + break + } + } + + if !found { + cmd.AddGroup(&cobra.Group{ + ID: group, + Title: group, + }) + } + } + + // Bind the command to the root + for _, command := range cmds { + cmd.AddCommand(command(con)...) + } + } +} + +// commandBinder is a helper used to bind commands to a given menu, for a given "command help group". +// +// @group - Name of the group under which the command should be shown. Preferably use a string in the constants package. +// @ cmds - A list of functions returning a list of root commands to bind. See any package's `commands.go` file and function. +type commandBinder func(group string, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) + // [ Core ] // [ Sessions ] // [ Execution ] @@ -99,33 +135,3 @@ func RestrictTargets(filters ...string) map[string]string { // - double bind help command // - double bind session commands // - don't bind readline command in CLI. - -// bind is a helper used to bind a list of root commands to a given menu, for a given "command help group". -// @group - Name of the group under which the command should be shown. Preferably use a string in the constants package. -// @menu - The command menu to which the commands should be bound (either server or implant menu). -// @ cmds - A list of functions returning a list of root commands to bind. See any package's `commands.go` file and function. -func bind(group string, menu *cobra.Command, con *client.SliverConsoleClient, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { - found := false - - // Ensure the given command group is available in the menu. - if group != "" { - for _, grp := range menu.Groups() { - if grp.Title == group { - found = true - break - } - } - - if !found { - menu.AddGroup(&cobra.Group{ - ID: group, - Title: group, - }) - } - } - - // Bind the command to the root - for _, command := range cmds { - menu.AddCommand(command(con)...) - } -} diff --git a/client/command/server.go b/client/command/server.go index f30aebe52f..ce694d550c 100644 --- a/client/command/server.go +++ b/client/command/server.go @@ -63,6 +63,12 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. }, } + // Utility function to be used for binding new commands to + // the sliver menu: call the function with the name of the + // group under which this/these commands should be added, + // and the group will be automatically created if needed. + bind := makeBind(server, con) + if serverCmds != nil { server.AddGroup(&cobra.Group{ID: consts.MultiplayerHelpGroup, Title: consts.MultiplayerHelpGroup}) server.AddCommand(serverCmds()...) @@ -77,7 +83,7 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. // the present calls. // Core - bind(consts.GenericHelpGroup, server, con, + bind(consts.GenericHelpGroup, exit.Command, licenses.Commands, settings.Commands, @@ -91,21 +97,21 @@ func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra. ) // C2 Network - bind(consts.NetworkHelpGroup, server, con, + bind(consts.NetworkHelpGroup, jobs.Commands, websites.Commands, wireguard.Commands, ) // Payloads - bind(consts.PayloadsHelpGroup, server, con, + bind(consts.PayloadsHelpGroup, sgn.Commands, generate.Commands, builders.Commands, ) // Slivers - bind(consts.SliverHelpGroup, server, con, + bind(consts.SliverHelpGroup, use.Commands, info.Commands, sessions.Commands, diff --git a/client/command/sliver.go b/client/command/sliver.go index 3c4161ab2e..2ba0a8c68e 100644 --- a/client/command/sliver.go +++ b/client/command/sliver.go @@ -61,8 +61,14 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { }, } + // Utility function to be used for binding new commands to + // the sliver menu: call the function with the name of the + // group under which this/these commands should be added, + // and the group will be automatically created if needed. + bind := makeBind(sliver, con) + // [ Core ] - bind(consts.SliverCoreHelpGroup, sliver, con, + bind(consts.SliverCoreHelpGroup, reconfig.Commands, // sessions.Commands, sessions.SliverCommands, @@ -73,7 +79,7 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { ) // [ Info ] - bind(consts.InfoHelpGroup, sliver, con, + bind(consts.InfoHelpGroup, // info.Commands, info.SliverCommands, screenshot.Commands, @@ -82,12 +88,12 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { ) // [ Filesystem ] - bind(consts.FilesystemHelpGroup, sliver, con, + bind(consts.FilesystemHelpGroup, filesystem.Commands, ) // [ Network tools ] - bind(consts.NetworkHelpGroup, sliver, con, + bind(consts.NetworkHelpGroup, network.Commands, rportfwd.Commands, portfwd.Commands, @@ -96,7 +102,7 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { ) // [ Execution ] - bind(consts.ExecutionHelpGroup, sliver, con, + bind(consts.ExecutionHelpGroup, shell.Commands, exec.Commands, backdoor.Commands, @@ -106,20 +112,20 @@ func SliverCommands(con *client.SliverConsoleClient) console.Commands { ) // [ Privileges ] - bind(consts.PrivilegesHelpGroup, sliver, con, + bind(consts.PrivilegesHelpGroup, privilege.Commands, ) // [ Processes ] - bind(consts.ProcessHelpGroup, sliver, con, + bind(consts.ProcessHelpGroup, processes.Commands, ) // [ Aliases ] - bind(consts.AliasHelpGroup, sliver, con) + bind(consts.AliasHelpGroup) // [ Extensions ] - bind(consts.ExtensionHelpGroup, sliver, con, + bind(consts.ExtensionHelpGroup, extensions.Commands, ) From 12065fdb9950adb7c8562cd5534c9df0be005b6b Mon Sep 17 00:00:00 2001 From: maxlandon Date: Sun, 23 Jul 2023 19:48:38 +0200 Subject: [PATCH 12/14] Rename SliverConsoleClient to SliverClient --- client/cli/console.go | 4 +- client/cli/implant.go | 6 +- client/command/alias/alias.go | 21 ++-- client/command/alias/commands.go | 7 +- client/command/alias/install.go | 17 ++- client/command/alias/load.go | 43 ++++--- client/command/alias/remove.go | 9 +- client/command/armory/armory.go | 6 +- client/command/armory/commands.go | 2 +- client/command/armory/install.go | 16 +-- client/command/armory/search.go | 2 +- client/command/armory/update.go | 6 +- client/command/backdoor/backdoor.go | 7 +- client/command/backdoor/commands.go | 2 +- client/command/beacons/beacons.go | 6 +- client/command/beacons/commands.go | 4 +- client/command/beacons/helpers.go | 6 +- client/command/beacons/prune.go | 2 +- client/command/beacons/rm.go | 2 +- client/command/beacons/watch.go | 2 +- client/command/builders/builders.go | 11 +- client/command/builders/commands.go | 7 +- client/command/command.go | 6 +- client/command/crack/commands.go | 2 +- client/command/crack/crack-files.go | 49 ++++---- client/command/crack/crack.go | 14 +-- client/command/crack/helpers.go | 6 +- client/command/creds/add.go | 8 +- client/command/creds/commands.go | 9 +- client/command/creds/creds.go | 27 +++-- client/command/creds/rm.go | 4 +- client/command/creds/select.go | 5 +- client/command/cursed/commands.go | 2 +- client/command/cursed/cursed-chrome.go | 12 +- client/command/cursed/cursed-console.go | 6 +- client/command/cursed/cursed-cookies.go | 2 +- client/command/cursed/cursed-edge.go | 6 +- client/command/cursed/cursed-electron.go | 10 +- client/command/cursed/cursed-rm.go | 2 +- client/command/cursed/cursed-screenshot.go | 2 +- client/command/cursed/cursed.go | 4 +- client/command/dllhijack/commands.go | 2 +- client/command/dllhijack/dllhijack.go | 2 +- client/command/environment/commands.go | 2 +- client/command/environment/get.go | 4 +- client/command/environment/set.go | 4 +- client/command/environment/unset.go | 4 +- client/command/exec/commands.go | 9 +- client/command/exec/execute-assembly.go | 11 +- client/command/exec/execute-shellcode.go | 18 ++- client/command/exec/execute.go | 24 ++-- client/command/exec/migrate.go | 7 +- client/command/exec/msf-inject.go | 14 +-- client/command/exec/msf.go | 10 +- client/command/exec/psexec.go | 8 +- client/command/exec/sideload.go | 12 +- client/command/exec/spawndll.go | 12 +- client/command/exec/ssh.go | 15 ++- client/command/exit/exit.go | 6 +- client/command/extensions/commands.go | 7 +- client/command/extensions/extensions.go | 19 ++-- client/command/extensions/install.go | 17 ++- client/command/extensions/list.go | 7 +- client/command/extensions/load.go | 39 ++++--- client/command/extensions/remove.go | 11 +- client/command/filesystem/cat.go | 13 +-- client/command/filesystem/cd.go | 10 +- client/command/filesystem/chmod.go | 14 +-- client/command/filesystem/chown.go | 14 +-- client/command/filesystem/chtimes.go | 14 +-- client/command/filesystem/commands.go | 9 +- client/command/filesystem/cp.go | 10 +- client/command/filesystem/download.go | 11 +- client/command/filesystem/ls.go | 16 ++- client/command/filesystem/memfiles-add.go | 13 +-- client/command/filesystem/memfiles-list.go | 13 +-- client/command/filesystem/memfiles-rm.go | 13 +-- client/command/filesystem/mkdir.go | 14 +-- client/command/filesystem/mv.go | 12 +- client/command/filesystem/pwd.go | 14 +-- client/command/filesystem/rm.go | 14 +-- client/command/filesystem/upload.go | 14 +-- client/command/generate/canaries.go | 4 +- client/command/generate/commands.go | 4 +- client/command/generate/generate-beacon.go | 4 +- client/command/generate/generate-info.go | 2 +- client/command/generate/generate-stager.go | 2 +- client/command/generate/generate.go | 22 ++-- client/command/generate/helpers.go | 8 +- client/command/generate/implants-rm.go | 2 +- client/command/generate/implants.go | 8 +- client/command/generate/profiles-generate.go | 2 +- client/command/generate/profiles-new.go | 4 +- client/command/generate/profiles-rm.go | 2 +- client/command/generate/profiles.go | 12 +- client/command/generate/regenerate.go | 2 +- client/command/generate/traffic-encoders.go | 16 +-- client/command/hosts/commands.go | 7 +- client/command/hosts/hosts-ioc-rm.go | 7 +- client/command/hosts/hosts-ioc.go | 13 +-- client/command/hosts/hosts-rm.go | 7 +- client/command/hosts/hosts.go | 26 ++--- client/command/info/commands.go | 11 +- client/command/info/info.go | 27 +++-- client/command/info/ping.go | 7 +- client/command/jobs/commands.go | 9 +- client/command/jobs/dns.go | 7 +- client/command/jobs/http.go | 7 +- client/command/jobs/https.go | 7 +- client/command/jobs/jobs.go | 20 ++-- client/command/jobs/mtls.go | 7 +- client/command/jobs/stage.go | 10 +- client/command/jobs/wg.go | 7 +- client/command/kill/commands.go | 2 +- client/command/kill/kill.go | 6 +- client/command/licenses/commands.go | 2 +- client/command/loot/commands.go | 6 +- client/command/loot/fetch.go | 2 +- client/command/loot/local.go | 2 +- client/command/loot/loot.go | 6 +- client/command/loot/remote.go | 8 +- client/command/loot/rename.go | 2 +- client/command/loot/rm.go | 2 +- client/command/monitor/commands.go | 2 +- client/command/monitor/start.go | 2 +- client/command/monitor/stop.go | 2 +- client/command/network/commands.go | 2 +- client/command/network/ifconfig.go | 4 +- client/command/network/netstat.go | 4 +- client/command/operators/commands.go | 7 +- client/command/operators/operators.go | 10 +- client/command/pivots/commands.go | 2 +- client/command/pivots/details.go | 4 +- client/command/pivots/graph.go | 7 +- client/command/pivots/helpers.go | 9 +- client/command/pivots/pivots.go | 15 ++- client/command/pivots/start.go | 11 +- client/command/pivots/stop.go | 2 +- client/command/portfwd/commands.go | 2 +- client/command/portfwd/portfwd-add.go | 2 +- client/command/portfwd/portfwd-rm.go | 2 +- client/command/portfwd/portfwd.go | 6 +- client/command/prelude-operator/commands.go | 2 +- client/command/prelude-operator/connect.go | 2 +- client/command/prelude-operator/operator.go | 2 +- client/command/privilege/commands.go | 2 +- client/command/privilege/getprivs.go | 4 +- client/command/privilege/getsystem.go | 4 +- client/command/privilege/impersonate.go | 4 +- client/command/privilege/make-token.go | 4 +- client/command/privilege/rev2self.go | 4 +- client/command/privilege/runas.go | 4 +- client/command/processes/commands.go | 2 +- client/command/processes/procdump.go | 6 +- client/command/processes/ps.go | 8 +- client/command/processes/terminate.go | 4 +- client/command/reaction/commands.go | 9 +- client/command/reaction/helpers.go | 13 +-- client/command/reaction/reaction.go | 13 +-- client/command/reaction/reload.go | 7 +- client/command/reaction/save.go | 7 +- client/command/reaction/set.go | 13 +-- client/command/reaction/unset.go | 9 +- client/command/reconfig/commands.go | 7 +- client/command/reconfig/reconfig.go | 10 +- client/command/reconfig/rename.go | 7 +- client/command/registry/commands.go | 2 +- client/command/registry/reg-create.go | 4 +- client/command/registry/reg-delete.go | 4 +- client/command/registry/reg-list.go | 8 +- client/command/registry/reg-read.go | 4 +- client/command/registry/reg-write.go | 4 +- client/command/rportfwd/commands.go | 2 +- client/command/rportfwd/portfwd-add.go | 4 +- client/command/rportfwd/portfwd-rm.go | 4 +- client/command/rportfwd/portfwd.go | 6 +- client/command/screenshot/commands.go | 9 +- client/command/screenshot/screenshot.go | 16 ++- client/command/server.go | 2 +- client/command/sessions/background.go | 7 +- client/command/sessions/close.go | 7 +- client/command/sessions/commands.go | 15 ++- client/command/sessions/helpers.go | 9 +- client/command/sessions/interactive.go | 7 +- client/command/sessions/prune.go | 7 +- client/command/sessions/sessions.go | 17 ++- client/command/settings/beacons.go | 7 +- client/command/settings/commands.go | 7 +- client/command/settings/opsec.go | 15 ++- client/command/settings/settings.go | 33 +++--- client/command/settings/tables.go | 21 ++-- client/command/shell/commands.go | 2 +- client/command/shell/shell.go | 4 +- client/command/shikata-ga-nai/commands.go | 2 +- client/command/shikata-ga-nai/sgn.go | 2 +- client/command/sliver.go | 2 +- client/command/socks/commands.go | 2 +- client/command/socks/socks-start.go | 2 +- client/command/socks/socks-stop.go | 2 +- client/command/socks/socks.go | 4 +- client/command/taskmany/taskmany.go | 10 +- client/command/tasks/commands.go | 9 +- client/command/tasks/fetch.go | 25 ++-- client/command/tasks/helpers.go | 11 +- client/command/tasks/tasks-cancel.go | 7 +- client/command/tasks/tasks.go | 13 +-- client/command/update/commands.go | 9 +- client/command/update/update.go | 15 ++- client/command/use/beacons.go | 2 +- client/command/use/commands.go | 2 +- client/command/use/sessions.go | 2 +- client/command/use/use.go | 10 +- client/command/wasm/commands.go | 2 +- client/command/wasm/memfs.go | 2 +- client/command/wasm/wasm.go | 14 +-- client/command/websites/commands.go | 9 +- .../command/websites/websites-add-content.go | 7 +- .../command/websites/websites-rm-content.go | 7 +- client/command/websites/websites-rm.go | 7 +- .../websites/websites-update-content.go | 7 +- client/command/websites/websites.go | 23 ++-- client/command/wireguard/commands.go | 4 +- client/command/wireguard/wg-config.go | 2 +- client/command/wireguard/wg-portfwd-add.go | 2 +- client/command/wireguard/wg-portfwd-rm.go | 4 +- client/command/wireguard/wg-portfwd.go | 2 +- client/command/wireguard/wg-socks-start.go | 2 +- client/command/wireguard/wg-socks-stop.go | 2 +- client/command/wireguard/wg-socks.go | 4 +- client/console/console.go | 107 +++++++++--------- client/console/log.go | 37 +++--- 231 files changed, 935 insertions(+), 1066 deletions(-) diff --git a/client/cli/console.go b/client/cli/console.go index 5b0a8549e5..40a45e71be 100644 --- a/client/cli/console.go +++ b/client/cli/console.go @@ -13,7 +13,7 @@ import ( ) // consoleCmd generates the console with required pre/post runners. -func consoleCmd(con *console.SliverConsoleClient) *cobra.Command { +func consoleCmd(con *console.SliverClient) *cobra.Command { consoleCmd := &cobra.Command{ Use: "console", Short: "Start the sliver client console", @@ -24,7 +24,7 @@ func consoleCmd(con *console.SliverConsoleClient) *cobra.Command { return consoleCmd } -func consoleRunnerCmd(con *console.SliverConsoleClient, run bool) (pre, post func(cmd *cobra.Command, args []string) error) { +func consoleRunnerCmd(con *console.SliverClient, run bool) (pre, post func(cmd *cobra.Command, args []string) error) { var ln *grpc.ClientConn pre = func(_ *cobra.Command, _ []string) error { diff --git a/client/cli/implant.go b/client/cli/implant.go index 1952df7de9..98b7a4889a 100644 --- a/client/cli/implant.go +++ b/client/cli/implant.go @@ -12,7 +12,7 @@ import ( "github.com/spf13/pflag" ) -func implantCmd(con *console.SliverConsoleClient) *cobra.Command { +func implantCmd(con *console.SliverClient) *cobra.Command { con.IsCLI = true makeCommands := command.SliverCommands(con) @@ -33,7 +33,7 @@ func implantCmd(con *console.SliverConsoleClient) *cobra.Command { return cmd } -func makeRunners(implantCmd *cobra.Command, con *console.SliverConsoleClient) (pre, post func(cmd *cobra.Command, args []string) error) { +func makeRunners(implantCmd *cobra.Command, con *console.SliverClient) (pre, post func(cmd *cobra.Command, args []string) error) { startConsole, closeConsole := consoleRunnerCmd(con, false) // The pre-run function connects to the server and sets up a "fake" console, @@ -58,7 +58,7 @@ func makeRunners(implantCmd *cobra.Command, con *console.SliverConsoleClient) (p return pre, closeConsole } -func makeCompleters(cmd *cobra.Command, con *console.SliverConsoleClient) { +func makeCompleters(cmd *cobra.Command, con *console.SliverClient) { comps := carapace.Gen(cmd) comps.PreRun(func(cmd *cobra.Command, args []string) { diff --git a/client/command/alias/alias.go b/client/command/alias/alias.go index 2ff708f858..47bddfb9bb 100644 --- a/client/command/alias/alias.go +++ b/client/command/alias/alias.go @@ -24,18 +24,17 @@ import ( "io/ioutil" "strings" + "github.com/bishopfox/sliver/client/assets" + "github.com/bishopfox/sliver/client/command/settings" + "github.com/bishopfox/sliver/client/console" "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" "github.com/rsteube/carapace" "github.com/spf13/cobra" - - "github.com/bishopfox/sliver/client/assets" - "github.com/bishopfox/sliver/client/command/settings" - "github.com/bishopfox/sliver/client/console" ) -// AliasesCmd - The alias command -func AliasesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) error { +// AliasesCmd - The alias command. +func AliasesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) error { if 0 < len(loadedAliases) { PrintAliases(con) } else { @@ -45,8 +44,8 @@ func AliasesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str return nil } -// PrintAliases - Print a list of loaded aliases -func PrintAliases(con *console.SliverConsoleClient) { +// PrintAliases - Print a list of loaded aliases. +func PrintAliases(con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -88,8 +87,8 @@ func PrintAliases(con *console.SliverConsoleClient) { con.Println(tw.Render()) } -// AliasCommandNameCompleter - Completer for installed extensions command names -func AliasCommandNameCompleter(prefix string, args []string, con *console.SliverConsoleClient) []string { +// AliasCommandNameCompleter - Completer for installed extensions command names. +func AliasCommandNameCompleter(prefix string, args []string, con *console.SliverClient) []string { results := []string{} for name := range loadedAliases { if strings.HasPrefix(name, prefix) { @@ -129,7 +128,7 @@ func getInstalledManifests() map[string]*AliasManifest { return installedManifests } -// AliasCommandNameCompleter - Completer for installed extensions command names +// AliasCommandNameCompleter - Completer for installed extensions command names. func AliasCompleter() carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { results := []string{} diff --git a/client/command/alias/commands.go b/client/command/alias/commands.go index 5b7bff8727..d8b86be31f 100644 --- a/client/command/alias/commands.go +++ b/client/command/alias/commands.go @@ -1,17 +1,16 @@ package alias import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) // Commands returns the `alias` command and its child commands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { aliasCmd := &cobra.Command{ Use: consts.AliasesStr, Short: "List current aliases", diff --git a/client/command/alias/install.go b/client/command/alias/install.go index e63ea0f374..663e9c0ebd 100644 --- a/client/command/alias/install.go +++ b/client/command/alias/install.go @@ -26,15 +26,14 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" ) -// AliasesInstallCmd - Install an alias -func AliasesInstallCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// AliasesInstallCmd - Install an alias. +func AliasesInstallCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { aliasLocalPath := args[0] fi, err := os.Stat(aliasLocalPath) if os.IsNotExist(err) { @@ -48,8 +47,8 @@ func AliasesInstallCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg } } -// Install an extension from a directory -func installFromDir(aliasLocalPath string, con *console.SliverConsoleClient) { +// Install an extension from a directory. +func installFromDir(aliasLocalPath string, con *console.SliverClient) { manifestData, err := ioutil.ReadFile(filepath.Join(aliasLocalPath, ManifestFileName)) if err != nil { con.PrintErrorf("Error reading %s: %s", ManifestFileName, err) @@ -101,8 +100,8 @@ func installFromDir(aliasLocalPath string, con *console.SliverConsoleClient) { con.Printf("done!\n") } -// Install an extension from a .tar.gz file -func InstallFromFile(aliasGzFilePath string, autoOverwrite bool, con *console.SliverConsoleClient) *string { +// Install an extension from a .tar.gz file. +func InstallFromFile(aliasGzFilePath string, autoOverwrite bool, con *console.SliverClient) *string { manifestData, err := util.ReadFileFromTarGz(aliasGzFilePath, fmt.Sprintf("./%s", ManifestFileName)) if err != nil { con.PrintErrorf("Failed to read %s from '%s': %s\n", ManifestFileName, aliasGzFilePath, err) @@ -153,7 +152,7 @@ func InstallFromFile(aliasGzFilePath string, autoOverwrite bool, con *console.Sl return &installPath } -func installArtifact(aliasGzFilePath string, installPath, artifactPath string, con *console.SliverConsoleClient) error { +func installArtifact(aliasGzFilePath string, installPath, artifactPath string, con *console.SliverClient) error { data, err := util.ReadFileFromTarGz(aliasGzFilePath, fmt.Sprintf("./%s", strings.TrimPrefix(artifactPath, string(os.PathSeparator)))) if err != nil { return err diff --git a/client/command/alias/load.go b/client/command/alias/load.go index 4b6237267b..7c684f1bab 100644 --- a/client/command/alias/load.go +++ b/client/command/alias/load.go @@ -28,11 +28,6 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" - app "github.com/reeflective/console" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" @@ -40,6 +35,10 @@ import ( "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util" + app "github.com/reeflective/console" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "google.golang.org/protobuf/proto" ) const ( @@ -53,7 +52,7 @@ const ( ) var ( - // alias name -> manifest/command + // alias name -> manifest/command. loadedAliases = map[string]*loadedAlias{} defaultHostProc = map[string]string{ @@ -63,20 +62,20 @@ var ( } ) -// Ties the manifest struct to the command struct +// Ties the manifest struct to the command struct. type loadedAlias struct { Manifest *AliasManifest Command *cobra.Command } -// AliasFile - An OS/Arch specific file +// AliasFile - An OS/Arch specific file. type AliasFile struct { OS string `json:"os"` Arch string `json:"arch"` Path string `json:"path"` } -// AliasManifest - The manifest for an alias, contains metadata +// AliasManifest - The manifest for an alias, contains metadata. type AliasManifest struct { Name string `json:"name"` Version string `json:"version"` @@ -124,7 +123,7 @@ func (a *AliasManifest) getFileForTarget(cmdName string, targetOS string, target } // AliasesLoadCmd - Locally load a alias into the Sliver shell. -func AliasesLoadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func AliasesLoadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { dirPath := args[0] // dirPath := ctx.Args.String("dir-path") alias, err := LoadAlias(dirPath, cmd.Root(), con) @@ -135,8 +134,8 @@ func AliasesLoadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } } -// LoadAlias - Load an alias into the Sliver shell from a given directory -func LoadAlias(manifestPath string, cmd *cobra.Command, con *console.SliverConsoleClient) (*AliasManifest, error) { +// LoadAlias - Load an alias into the Sliver shell from a given directory. +func LoadAlias(manifestPath string, cmd *cobra.Command, con *console.SliverClient) (*AliasManifest, error) { // retrieve alias manifest var err error manifestPath, err = filepath.Abs(manifestPath) @@ -205,7 +204,7 @@ func LoadAlias(manifestPath string, cmd *cobra.Command, con *console.SliverConso return aliasManifest, nil } -// ParseAliasManifest - Parse an alias manifest +// ParseAliasManifest - Parse an alias manifest. func ParseAliasManifest(data []byte) (*AliasManifest, error) { // parse it alias := &AliasManifest{} @@ -241,7 +240,7 @@ func ParseAliasManifest(data []byte) (*AliasManifest, error) { return alias, nil } -func runAliasCommand(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func runAliasCommand(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -474,26 +473,26 @@ func runAliasCommand(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -// PrintSpawnDLLOutput - Prints the output of a spawn dll command -func PrintSpawnDLLOutput(cmdName string, spawnDllResp *sliverpb.SpawnDll, outFilePath *os.File, con *console.SliverConsoleClient) { +// PrintSpawnDLLOutput - Prints the output of a spawn dll command. +func PrintSpawnDLLOutput(cmdName string, spawnDllResp *sliverpb.SpawnDll, outFilePath *os.File, con *console.SliverClient) { con.PrintInfof("%s output:\n%s", cmdName, spawnDllResp.GetResult()) if outFilePath != nil { - outFilePath.Write([]byte(spawnDllResp.GetResult())) + outFilePath.WriteString(spawnDllResp.GetResult()) con.PrintInfof("Output saved to %s\n", outFilePath.Name()) } } -// PrintSideloadOutput - Prints the output of a sideload command -func PrintSideloadOutput(cmdName string, sideloadResp *sliverpb.Sideload, outFilePath *os.File, con *console.SliverConsoleClient) { +// PrintSideloadOutput - Prints the output of a sideload command. +func PrintSideloadOutput(cmdName string, sideloadResp *sliverpb.Sideload, outFilePath *os.File, con *console.SliverClient) { con.PrintInfof("%s output:\n%s", cmdName, sideloadResp.GetResult()) if outFilePath != nil { - outFilePath.Write([]byte(sideloadResp.GetResult())) + outFilePath.WriteString(sideloadResp.GetResult()) con.PrintInfof("Output saved to %s\n", outFilePath.Name()) } } -// PrintAssemblyOutput - Prints the output of an execute-assembly command -func PrintAssemblyOutput(cmdName string, execAsmResp *sliverpb.ExecuteAssembly, outFilePath *os.File, con *console.SliverConsoleClient) { +// PrintAssemblyOutput - Prints the output of an execute-assembly command. +func PrintAssemblyOutput(cmdName string, execAsmResp *sliverpb.ExecuteAssembly, outFilePath *os.File, con *console.SliverClient) { con.PrintInfof("%s output:\n%s", cmdName, string(execAsmResp.GetOutput())) if outFilePath != nil { outFilePath.Write(execAsmResp.GetOutput()) diff --git a/client/command/alias/remove.go b/client/command/alias/remove.go index 3a7fb7ab43..850b2cd292 100644 --- a/client/command/alias/remove.go +++ b/client/command/alias/remove.go @@ -25,14 +25,13 @@ import ( "path/filepath" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) // AliasesRemoveCmd - Locally load a alias into the Sliver shell. -func AliasesRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func AliasesRemoveCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name := args[0] // name := ctx.Args.String("name") if name == "" { @@ -54,8 +53,8 @@ func AliasesRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -// RemoveAliasByCommandName - Remove an alias by command name -func RemoveAliasByCommandName(commandName string, con *console.SliverConsoleClient) error { +// RemoveAliasByCommandName - Remove an alias by command name. +func RemoveAliasByCommandName(commandName string, con *console.SliverClient) error { if commandName == "" { return errors.New("command name is required") } diff --git a/client/command/armory/armory.go b/client/command/armory/armory.go index 14d55069f4..c32ef13fb2 100644 --- a/client/command/armory/armory.go +++ b/client/command/armory/armory.go @@ -105,7 +105,7 @@ var ( ) // ArmoryCmd - The main armory command -func ArmoryCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ArmoryCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { armoriesConfig := assets.GetArmoriesConfig() con.PrintInfof("Fetching %d armory index(es) ... ", len(armoriesConfig)) clientConfig := parseArmoryHTTPConfig(cmd) @@ -240,7 +240,7 @@ func AliasExtensionOrBundleCompleter() carapace.Action { } // PrintArmoryPackages - Prints the armory packages -func PrintArmoryPackages(aliases []*alias.AliasManifest, exts []*extensions.ExtensionManifest, con *console.SliverConsoleClient) { +func PrintArmoryPackages(aliases []*alias.AliasManifest, exts []*extensions.ExtensionManifest, con *console.SliverClient) { width, _, err := term.GetSize(0) if err != nil { width = 1 @@ -331,7 +331,7 @@ func PrintArmoryPackages(aliases []*alias.AliasManifest, exts []*extensions.Exte } // PrintArmoryBundles - Prints the armory bundles -func PrintArmoryBundles(bundles []*ArmoryBundle, con *console.SliverConsoleClient) { +func PrintArmoryBundles(bundles []*ArmoryBundle, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.SetTitle(console.Bold + "Bundles" + console.Normal) diff --git a/client/command/armory/commands.go b/client/command/armory/commands.go index fe2649dd16..80cb290e18 100644 --- a/client/command/armory/commands.go +++ b/client/command/armory/commands.go @@ -13,7 +13,7 @@ import ( ) // Commands returns the `armory` command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { armoryCmd := &cobra.Command{ Use: consts.ArmoryStr, Short: "Automatically download and install extensions/aliases", diff --git a/client/command/armory/install.go b/client/command/armory/install.go index 730b40ed34..8c53a093c2 100644 --- a/client/command/armory/install.go +++ b/client/command/armory/install.go @@ -39,7 +39,7 @@ import ( var ErrPackageNotFound = errors.New("package not found") // ArmoryInstallCmd - The armory install command -func ArmoryInstallCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ArmoryInstallCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name := args[0] // name := ctx.Args.String("name") if name == "" { @@ -77,7 +77,7 @@ func ArmoryInstallCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args con.PrintErrorf("No package or bundle named '%s' was found", name) } -func installBundle(bundle *ArmoryBundle, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) { +func installBundle(bundle *ArmoryBundle, clientConfig ArmoryHTTPConfig, con *console.SliverClient) { for _, pkgName := range bundle.Packages { err := installPackageByName(pkgName, clientConfig, con) if err != nil { @@ -86,7 +86,7 @@ func installBundle(bundle *ArmoryBundle, clientConfig ArmoryHTTPConfig, con *con } } -func installPackageByName(name string, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) error { +func installPackageByName(name string, clientConfig ArmoryHTTPConfig, con *console.SliverClient) error { aliases, extensions := packagesInCache() for _, alias := range aliases { if alias.CommandName == name || name == "all" { @@ -112,7 +112,7 @@ func installPackageByName(name string, clientConfig ArmoryHTTPConfig, con *conso return ErrPackageNotFound } -func installAlias(alias *alias.AliasManifest, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) { +func installAlias(alias *alias.AliasManifest, clientConfig ArmoryHTTPConfig, con *console.SliverClient) { err := installAliasPackageByName(alias.CommandName, clientConfig, con) if err != nil { con.PrintErrorf("Failed to install alias '%s': %s", alias.CommandName, err) @@ -120,7 +120,7 @@ func installAlias(alias *alias.AliasManifest, clientConfig ArmoryHTTPConfig, con } } -func installAliasPackageByName(name string, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) error { +func installAliasPackageByName(name string, clientConfig ArmoryHTTPConfig, con *console.SliverClient) error { var entry *pkgCacheEntry pkgCache.Range(func(key, value interface{}) bool { cacheEntry := value.(pkgCacheEntry) @@ -186,7 +186,7 @@ func installAliasPackageByName(name string, clientConfig ArmoryHTTPConfig, con * return nil } -func installExtension(ext *extensions.ExtensionManifest, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) { +func installExtension(ext *extensions.ExtensionManifest, clientConfig ArmoryHTTPConfig, con *console.SliverClient) { deps := make(map[string]struct{}) resolveExtensionPackageDependencies(ext.CommandName, deps, clientConfig, con) sliverMenu := con.App.Menu(constants.ImplantMenu) @@ -209,7 +209,7 @@ func installExtension(ext *extensions.ExtensionManifest, clientConfig ArmoryHTTP const maxDepDepth = 10 // Arbitrary recursive limit for dependencies -func resolveExtensionPackageDependencies(name string, deps map[string]struct{}, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) { +func resolveExtensionPackageDependencies(name string, deps map[string]struct{}, clientConfig ArmoryHTTPConfig, con *console.SliverClient) { var entry *pkgCacheEntry pkgCache.Range(func(key, value interface{}) bool { cacheEntry := value.(pkgCacheEntry) @@ -242,7 +242,7 @@ func resolveExtensionPackageDependencies(name string, deps map[string]struct{}, resolveExtensionPackageDependencies(entry.Extension.DependsOn, deps, clientConfig, con) } -func installExtensionPackageByName(name string, clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) error { +func installExtensionPackageByName(name string, clientConfig ArmoryHTTPConfig, con *console.SliverClient) error { var entry *pkgCacheEntry pkgCache.Range(func(key, value interface{}) bool { cacheEntry := value.(pkgCacheEntry) diff --git a/client/command/armory/search.go b/client/command/armory/search.go index b20a8967c3..dda619ac50 100644 --- a/client/command/armory/search.go +++ b/client/command/armory/search.go @@ -29,7 +29,7 @@ import ( ) // ArmorySearchCmd - Search for packages by name -func ArmorySearchCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ArmorySearchCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { con.PrintInfof("Refreshing package cache ... ") clientConfig := parseArmoryHTTPConfig(cmd) refresh(clientConfig) diff --git a/client/command/armory/update.go b/client/command/armory/update.go index 76676355e9..4f14d0006b 100644 --- a/client/command/armory/update.go +++ b/client/command/armory/update.go @@ -31,7 +31,7 @@ import ( ) // ArmoryUpdateCmd - Update all installed extensions/aliases -func ArmoryUpdateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ArmoryUpdateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { con.PrintInfof("Refreshing package cache ... ") clientConfig := parseArmoryHTTPConfig(cmd) refresh(clientConfig) @@ -66,7 +66,7 @@ func ArmoryUpdateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -func checkForAliasUpdates(clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) []string { +func checkForAliasUpdates(clientConfig ArmoryHTTPConfig, con *console.SliverClient) []string { cachedAliases, _ := packagesInCache() results := []string{} for _, aliasManifestPath := range assets.GetInstalledAliasManifests() { @@ -89,7 +89,7 @@ func checkForAliasUpdates(clientConfig ArmoryHTTPConfig, con *console.SliverCons return results } -func checkForExtensionUpdates(clientConfig ArmoryHTTPConfig, con *console.SliverConsoleClient) []string { +func checkForExtensionUpdates(clientConfig ArmoryHTTPConfig, con *console.SliverClient) []string { _, cachedExtensions := packagesInCache() results := []string{} for _, extManifestPath := range assets.GetInstalledExtensionManifests() { diff --git a/client/command/backdoor/backdoor.go b/client/command/backdoor/backdoor.go index 9cdc64de29..474903358d 100644 --- a/client/command/backdoor/backdoor.go +++ b/client/command/backdoor/backdoor.go @@ -21,14 +21,13 @@ package backdoor import ( "fmt" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// BackdoorCmd - Command to inject implant code into an existing binary -func BackdoorCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// BackdoorCmd - Command to inject implant code into an existing binary. +func BackdoorCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/backdoor/commands.go b/client/command/backdoor/commands.go index 8fa7b4bbff..615750479c 100644 --- a/client/command/backdoor/commands.go +++ b/client/command/backdoor/commands.go @@ -13,7 +13,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { backdoorCmd := &cobra.Command{ Use: consts.BackdoorStr, Short: "Infect a remote file with a sliver shellcode", diff --git a/client/command/beacons/beacons.go b/client/command/beacons/beacons.go index 409d8ee824..5abfa659c9 100644 --- a/client/command/beacons/beacons.go +++ b/client/command/beacons/beacons.go @@ -36,7 +36,7 @@ import ( ) // BeaconsCmd - Display/interact with beacons -func BeaconsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func BeaconsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { killFlag, _ := cmd.Flags().GetString("kill") killAll, _ := cmd.Flags().GetBool("kill-all") @@ -94,7 +94,7 @@ func BeaconsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str } // PrintBeacons - Display a list of beacons -func PrintBeacons(beacons []*clientpb.Beacon, filter string, filterRegex *regexp.Regexp, con *console.SliverConsoleClient) { +func PrintBeacons(beacons []*clientpb.Beacon, filter string, filterRegex *regexp.Regexp, con *console.SliverClient) { if len(beacons) == 0 { con.PrintInfof("No beacons 🙁\n") return @@ -103,7 +103,7 @@ func PrintBeacons(beacons []*clientpb.Beacon, filter string, filterRegex *regexp con.Printf("%s\n", tw.Render()) } -func renderBeacons(beacons []*clientpb.Beacon, filter string, filterRegex *regexp.Regexp, con *console.SliverConsoleClient) table.Writer { +func renderBeacons(beacons []*clientpb.Beacon, filter string, filterRegex *regexp.Regexp, con *console.SliverClient) table.Writer { width, _, err := term.GetSize(0) if err != nil { width = 999 diff --git a/client/command/beacons/commands.go b/client/command/beacons/commands.go index d526d7412d..9849017446 100644 --- a/client/command/beacons/commands.go +++ b/client/command/beacons/commands.go @@ -17,7 +17,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { beaconsCmd := &cobra.Command{ Use: consts.BeaconsStr, Short: "Manage beacons", @@ -79,7 +79,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { } // BeaconIDCompleter completes beacon IDs -func BeaconIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func BeaconIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/beacons/helpers.go b/client/command/beacons/helpers.go index e12b8f7183..37473b9975 100644 --- a/client/command/beacons/helpers.go +++ b/client/command/beacons/helpers.go @@ -43,7 +43,7 @@ var ( ) // SelectBeacon - Interactive menu for the user to select an session, optionally only display live sessions -func SelectBeacon(con *console.SliverConsoleClient) (*clientpb.Beacon, error) { +func SelectBeacon(con *console.SliverClient) (*clientpb.Beacon, error) { grpcCtx, cancel := con.GrpcContext(nil) defer cancel() beacons, err := con.Rpc.GetBeacons(grpcCtx, &commonpb.Empty{}) @@ -102,7 +102,7 @@ func SelectBeacon(con *console.SliverConsoleClient) (*clientpb.Beacon, error) { return nil, ErrNoSelection } -func GetBeacon(con *console.SliverConsoleClient, beaconID string) (*clientpb.Beacon, error) { +func GetBeacon(con *console.SliverClient, beaconID string) (*clientpb.Beacon, error) { grpcCtx, cancel := con.GrpcContext(nil) defer cancel() beacons, err := con.Rpc.GetBeacons(grpcCtx, &commonpb.Empty{}) @@ -120,7 +120,7 @@ func GetBeacon(con *console.SliverConsoleClient, beaconID string) (*clientpb.Bea return nil, ErrBeaconNotFound } -func GetBeacons(con *console.SliverConsoleClient) (*clientpb.Beacons, error) { +func GetBeacons(con *console.SliverClient) (*clientpb.Beacons, error) { grpcCtx, cancel := con.GrpcContext(nil) defer cancel() beacons, err := con.Rpc.GetBeacons(grpcCtx, &commonpb.Empty{}) diff --git a/client/command/beacons/prune.go b/client/command/beacons/prune.go index 8c0ea55078..b3e48cd0dd 100644 --- a/client/command/beacons/prune.go +++ b/client/command/beacons/prune.go @@ -30,7 +30,7 @@ import ( ) // BeaconsPruneCmd - Prune stale beacons automatically -func BeaconsPruneCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func BeaconsPruneCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { duration, _ := cmd.Flags().GetString("duration") pruneDuration, err := time.ParseDuration(duration) if err != nil { diff --git a/client/command/beacons/rm.go b/client/command/beacons/rm.go index f3d8ee77d4..c8974b5d92 100644 --- a/client/command/beacons/rm.go +++ b/client/command/beacons/rm.go @@ -25,7 +25,7 @@ import ( ) // BeaconsRmCmd - Display/interact with beacons -func BeaconsRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func BeaconsRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { beacon, err := SelectBeacon(con) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/beacons/watch.go b/client/command/beacons/watch.go index 210de23102..f5a6699b75 100644 --- a/client/command/beacons/watch.go +++ b/client/command/beacons/watch.go @@ -31,7 +31,7 @@ import ( ) // BeaconsWatchCmd - Watch your beacons in real-ish time -func BeaconsWatchCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func BeaconsWatchCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { done := waitForInput() defer func() { con.Printf(console.UpN+console.Clearln+"\r", 1) diff --git a/client/command/builders/builders.go b/client/command/builders/builders.go index ade5846ab4..d7049d7263 100644 --- a/client/command/builders/builders.go +++ b/client/command/builders/builders.go @@ -23,17 +23,16 @@ import ( "fmt" "strings" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// BuildersCmd - List external builders -func BuildersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// BuildersCmd - List external builders. +func BuildersCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { builders, err := con.Rpc.Builders(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s", err) @@ -46,7 +45,7 @@ func BuildersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -func PrintBuilders(externalBuilders []*clientpb.Builder, con *console.SliverConsoleClient) { +func PrintBuilders(externalBuilders []*clientpb.Builder, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ diff --git a/client/command/builders/commands.go b/client/command/builders/commands.go index 882cb50952..16478cd1fc 100644 --- a/client/command/builders/commands.go +++ b/client/command/builders/commands.go @@ -1,17 +1,16 @@ package builders import ( - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { buildersCmd := &cobra.Command{ Use: consts.BuildersStr, Short: "List external builders", diff --git a/client/command/command.go b/client/command/command.go index e9f2c66601..3e5cb16fff 100644 --- a/client/command/command.go +++ b/client/command/command.go @@ -79,8 +79,8 @@ func RestrictTargets(filters ...string) map[string]string { // makeBind returns a commandBinder helper function // @menu - The command menu to which the commands should be bound (either server or implant menu). -func makeBind(cmd *cobra.Command, con *client.SliverConsoleClient) func(group string, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { - return func(group string, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) { +func makeBind(cmd *cobra.Command, con *client.SliverClient) func(group string, cmds ...func(con *client.SliverClient) []*cobra.Command) { + return func(group string, cmds ...func(con *client.SliverClient) []*cobra.Command) { found := false // Ensure the given command group is available in the menu. @@ -111,7 +111,7 @@ func makeBind(cmd *cobra.Command, con *client.SliverConsoleClient) func(group st // // @group - Name of the group under which the command should be shown. Preferably use a string in the constants package. // @ cmds - A list of functions returning a list of root commands to bind. See any package's `commands.go` file and function. -type commandBinder func(group string, cmds ...func(con *client.SliverConsoleClient) []*cobra.Command) +type commandBinder func(group string, cmds ...func(con *client.SliverClient) []*cobra.Command) // [ Core ] // [ Sessions ] diff --git a/client/command/crack/commands.go b/client/command/crack/commands.go index 44b0982c0c..7fc4e08df0 100644 --- a/client/command/crack/commands.go +++ b/client/command/crack/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { crackCmd := &cobra.Command{ Use: consts.CrackStr, Short: "Crack: GPU password cracking", diff --git a/client/command/crack/crack-files.go b/client/command/crack/crack-files.go index cd7af7c7cd..c31383d1ff 100644 --- a/client/command/crack/crack-files.go +++ b/client/command/crack/crack-files.go @@ -25,18 +25,17 @@ import ( "io" "os" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/klauspost/compress/zstd" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/util" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/klauspost/compress/zstd" + "github.com/spf13/cobra" ) -// CrackWordlistsCmd - Manage GPU cracking stations -func CrackWordlistsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackWordlistsCmd - Manage GPU cracking stations. +func CrackWordlistsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { wordlists, err := con.Rpc.CrackFilesList(context.Background(), &clientpb.CrackFile{Type: clientpb.CrackFileType_WORDLIST}) if err != nil { con.PrintErrorf("%s\n", err) @@ -55,8 +54,8 @@ func CrackWordlistsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg } } -// CrackRulesCmd - Manage GPU cracking stations -func CrackRulesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackRulesCmd - Manage GPU cracking stations. +func CrackRulesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { rules, err := con.Rpc.CrackFilesList(context.Background(), &clientpb.CrackFile{Type: clientpb.CrackFileType_RULES}) if err != nil { con.PrintErrorf("%s\n", err) @@ -75,8 +74,8 @@ func CrackRulesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [] } } -// CrackHcstat2Cmd - Manage GPU cracking stations -func CrackHcstat2Cmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackHcstat2Cmd - Manage GPU cracking stations. +func CrackHcstat2Cmd(cmd *cobra.Command, con *console.SliverClient, args []string) { hcstat2, err := con.Rpc.CrackFilesList(context.Background(), &clientpb.CrackFile{Type: clientpb.CrackFileType_MARKOV_HCSTAT2}) if err != nil { con.PrintErrorf("%s\n", err) @@ -95,7 +94,7 @@ func CrackHcstat2Cmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -func PrintCrackFiles(crackFiles *clientpb.CrackFiles, con *console.SliverConsoleClient) { +func PrintCrackFiles(crackFiles *clientpb.CrackFiles, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{"Name", "Size"}) @@ -105,7 +104,7 @@ func PrintCrackFiles(crackFiles *clientpb.CrackFiles, con *console.SliverConsole con.Printf("%s\n", tw.Render()) } -func PrintCrackFilesByType(crackFiles *clientpb.CrackFiles, con *console.SliverConsoleClient) { +func PrintCrackFilesByType(crackFiles *clientpb.CrackFiles, con *console.SliverClient) { wordlistTable := table.NewWriter() wordlistTable.SetTitle(console.Bold + "Wordlists" + console.Normal) wordlistTable.SetStyle(settings.GetTableStyle(con)) @@ -162,8 +161,8 @@ func PrintCrackFilesByType(crackFiles *clientpb.CrackFiles, con *console.SliverC ) } -// CrackWordlistsAddCmd - Manage GPU cracking stations -func CrackWordlistsAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackWordlistsAddCmd - Manage GPU cracking stations. +func CrackWordlistsAddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name, _ := cmd.Flags().GetString("name") var localPath string @@ -206,8 +205,8 @@ func CrackWordlistsAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, addCrackFile(wordlist, crackFile, con) } -// CrackRulesAddCmd - add a rules file -func CrackRulesAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackRulesAddCmd - add a rules file. +func CrackRulesAddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name, _ := cmd.Flags().GetString("name") var localPath string @@ -250,8 +249,8 @@ func CrackRulesAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args addCrackFile(rules, crackFile, con) } -// CrackHcstat2AddCmd - add a hcstat2 file -func CrackHcstat2AddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackHcstat2AddCmd - add a hcstat2 file. +func CrackHcstat2AddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name, _ := cmd.Flags().GetString("name") var localPath string @@ -294,7 +293,7 @@ func CrackHcstat2AddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, ar addCrackFile(hcstat2, crackFile, con) } -func addCrackFile(localFile *os.File, crackFile *clientpb.CrackFile, con *console.SliverConsoleClient) { +func addCrackFile(localFile *os.File, crackFile *clientpb.CrackFile, con *console.SliverClient) { digest := sha256.New() wordlistReader := io.TeeReader(localFile, digest) @@ -402,8 +401,8 @@ func readChunkAt(tmpFile *os.File, offset int64, chunkSize int64) ([]byte, error return chunkBuf[:n], nil } -// CrackWordlistsRmCmd - Manage GPU cracking stations -func CrackWordlistsRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackWordlistsRmCmd - Manage GPU cracking stations. +func CrackWordlistsRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var wordlistName string if len(args) > 0 { wordlistName = args[0] @@ -436,8 +435,8 @@ func CrackWordlistsRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, a } } -// CrackRulesRmCmd - Manage GPU cracking stations -func CrackRulesRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackRulesRmCmd - Manage GPU cracking stations. +func CrackRulesRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var rulesName string if len(args) > 0 { rulesName = args[0] @@ -470,8 +469,8 @@ func CrackRulesRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -// CrackHcstat2RmCmd - remove a hcstat2 file -func CrackHcstat2RmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CrackHcstat2RmCmd - remove a hcstat2 file. +func CrackHcstat2RmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var hcstat2Name string if len(args) > 0 { hcstat2Name = args[0] diff --git a/client/command/crack/crack.go b/client/command/crack/crack.go index 829933e132..163f0d8e9a 100644 --- a/client/command/crack/crack.go +++ b/client/command/crack/crack.go @@ -33,7 +33,7 @@ import ( ) // CrackCmd - GPU password cracking interface -func CrackCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CrackCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { if !AreCrackersOnline(con) { PrintNoCrackstations(con) } else { @@ -58,7 +58,7 @@ func CrackCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin } // CrackStationsCmd - Manage GPU cracking stations -func CrackStationsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CrackStationsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { crackers, err := con.Rpc.Crackstations(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) @@ -71,11 +71,11 @@ func CrackStationsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -func PrintNoCrackstations(con *console.SliverConsoleClient) { +func PrintNoCrackstations(con *console.SliverClient) { con.PrintInfof("No crackstations connected to server\n") } -func AreCrackersOnline(con *console.SliverConsoleClient) bool { +func AreCrackersOnline(con *console.SliverClient) bool { crackers, err := con.Rpc.Crackstations(context.Background(), &commonpb.Empty{}) if err != nil { return false @@ -83,7 +83,7 @@ func AreCrackersOnline(con *console.SliverConsoleClient) bool { return len(crackers.Crackstations) > 0 } -func PrintCrackers(crackers []*clientpb.Crackstation, con *console.SliverConsoleClient) { +func PrintCrackers(crackers []*clientpb.Crackstation, con *console.SliverClient) { sort.Slice(crackers, func(i, j int) bool { return crackers[i].Name < crackers[j].Name }) @@ -96,7 +96,7 @@ func PrintCrackers(crackers []*clientpb.Crackstation, con *console.SliverConsole } } -func printCracker(cracker *clientpb.Crackstation, index int, con *console.SliverConsoleClient) { +func printCracker(cracker *clientpb.Crackstation, index int, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.SetTitle(console.Bold + console.Orange + fmt.Sprintf(">>> Crackstation %02d - %s (%s)", index+1, cracker.Name, cracker.OperatorName) + console.Normal + "\n") @@ -135,7 +135,7 @@ func printCracker(cracker *clientpb.Crackstation, index int, con *console.Sliver printBenchmarks(cracker, con) } -func printBenchmarks(cracker *clientpb.Crackstation, con *console.SliverConsoleClient) { +func printBenchmarks(cracker *clientpb.Crackstation, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.SetTitle(console.Bold + "Benchmarks" + console.Normal) diff --git a/client/command/crack/helpers.go b/client/command/crack/helpers.go index a5409a2637..7cc947348a 100644 --- a/client/command/crack/helpers.go +++ b/client/command/crack/helpers.go @@ -10,7 +10,7 @@ import ( "github.com/rsteube/carapace" ) -func CrackHcstat2Completer(con *console.SliverConsoleClient) carapace.Action { +func CrackHcstat2Completer(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { hcstat2, err := con.Rpc.CrackFilesList(context.Background(), &clientpb.CrackFile{Type: clientpb.CrackFileType_MARKOV_HCSTAT2}) if err != nil { @@ -33,7 +33,7 @@ func CrackHcstat2Completer(con *console.SliverConsoleClient) carapace.Action { }) } -func CrackWordlistCompleter(con *console.SliverConsoleClient) carapace.Action { +func CrackWordlistCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { hcstat2, err := con.Rpc.CrackFilesList(context.Background(), &clientpb.CrackFile{Type: clientpb.CrackFileType_MARKOV_HCSTAT2}) if err != nil { @@ -57,7 +57,7 @@ func CrackWordlistCompleter(con *console.SliverConsoleClient) carapace.Action { }) } -func CrackRulesCompleter(con *console.SliverConsoleClient) carapace.Action { +func CrackRulesCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { hcstat2, err := con.Rpc.CrackFilesList(context.Background(), &clientpb.CrackFile{Type: clientpb.CrackFileType_MARKOV_HCSTAT2}) if err != nil { diff --git a/client/command/creds/add.go b/client/command/creds/add.go index 3f7e4352e7..6c4fef924d 100644 --- a/client/command/creds/add.go +++ b/client/command/creds/add.go @@ -37,8 +37,8 @@ const ( CSVFormat = "csv" // username,hash\n ) -// CredsCmd - Add new credentials -func CredsAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CredsCmd - Add new credentials. +func CredsAddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { collection, _ := cmd.Flags().GetString("collection") username, _ := cmd.Flags().GetString("username") plaintext, _ := cmd.Flags().GetString("plaintext") @@ -76,8 +76,8 @@ func CredsAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st PrintCreds(creds.Credentials, con) } -// CredsCmd - Add new credentials -func CredsAddHashFileCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CredsCmd - Add new credentials. +func CredsAddHashFileCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { collection, _ := cmd.Flags().GetString("collection") filePath := args[0] fileFormat, _ := cmd.Flags().GetString("file-format") diff --git a/client/command/creds/commands.go b/client/command/creds/commands.go index 4ec0bfec49..65276e382b 100644 --- a/client/command/creds/commands.go +++ b/client/command/creds/commands.go @@ -1,18 +1,17 @@ package creds import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { credsCmd := &cobra.Command{ Use: consts.CredsStr, Short: "Manage the database of credentials", diff --git a/client/command/creds/creds.go b/client/command/creds/creds.go index 73cc5e70b3..63f36728b7 100644 --- a/client/command/creds/creds.go +++ b/client/command/creds/creds.go @@ -23,18 +23,17 @@ import ( "fmt" "strings" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// CredsCmd - Manage credentials -func CredsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CredsCmd - Manage credentials. +func CredsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { creds, err := con.Rpc.Creds(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) @@ -47,7 +46,7 @@ func CredsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin PrintCreds(creds.Credentials, con) } -func PrintCreds(creds []*clientpb.Credential, con *console.SliverConsoleClient) { +func PrintCreds(creds []*clientpb.Credential, con *console.SliverClient) { collections := make(map[string][]*clientpb.Credential) for _, cred := range creds { collections[cred.Collection] = append(collections[cred.Collection], cred) @@ -58,7 +57,7 @@ func PrintCreds(creds []*clientpb.Credential, con *console.SliverConsoleClient) } } -func printCollection(collection string, creds []*clientpb.Credential, con *console.SliverConsoleClient) { +func printCollection(collection string, creds []*clientpb.Credential, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) if collection != "" { @@ -88,7 +87,7 @@ func printCollection(collection string, creds []*clientpb.Credential, con *conso } // CredsHashTypeCompleter completes hash types. -func CredsHashTypeCompleter(con *console.SliverConsoleClient) carapace.Action { +func CredsHashTypeCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { results := make([]string, 0) @@ -101,8 +100,8 @@ func CredsHashTypeCompleter(con *console.SliverConsoleClient) carapace.Action { }) } -// CredsHashFileFormatCompleter completes file formats for hash-files -func CredsHashFileFormatCompleter(con *console.SliverConsoleClient) carapace.Action { +// CredsHashFileFormatCompleter completes file formats for hash-files. +func CredsHashFileFormatCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionValuesDescribed( UserColonHashNewlineFormat, "One hash per line.", HashNewlineFormat, "A file containing lines of 'username:hash' pairs.", @@ -110,8 +109,8 @@ func CredsHashFileFormatCompleter(con *console.SliverConsoleClient) carapace.Act ).Tag("hash file formats") } -// CredsCollectionCompleter completes existing creds collection names -func CredsCollectionCompleter(con *console.SliverConsoleClient) carapace.Action { +// CredsCollectionCompleter completes existing creds collection names. +func CredsCollectionCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { results := make([]string, 0) @@ -134,7 +133,7 @@ func CredsCollectionCompleter(con *console.SliverConsoleClient) carapace.Action } // CredsCredentialIDCompleter completes credential IDs. -func CredsCredentialIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func CredsCredentialIDCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/creds/rm.go b/client/command/creds/rm.go index c119f0efd1..fcb88d828a 100644 --- a/client/command/creds/rm.go +++ b/client/command/creds/rm.go @@ -27,8 +27,8 @@ import ( "github.com/spf13/cobra" ) -// CredsCmd - Add new credentials -func CredsRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CredsCmd - Add new credentials. +func CredsRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var id string if len(args) > 0 { id = args[0] diff --git a/client/command/creds/select.go b/client/command/creds/select.go index a375937aa0..80c3da1516 100644 --- a/client/command/creds/select.go +++ b/client/command/creds/select.go @@ -9,14 +9,13 @@ import ( "text/tabwriter" "github.com/AlecAivazis/survey/v2" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" ) -// SelectCredential - Interactive menu for the user to select a credentials from the database -func SelectCredential(plaintext bool, hashType clientpb.HashType, con *console.SliverConsoleClient) (*clientpb.Credential, error) { +// SelectCredential - Interactive menu for the user to select a credentials from the database. +func SelectCredential(plaintext bool, hashType clientpb.HashType, con *console.SliverClient) (*clientpb.Credential, error) { var creds *clientpb.Credentials var err error if hashType == clientpb.HashType_INVALID { diff --git a/client/command/cursed/commands.go b/client/command/cursed/commands.go index a750f4632a..15162998aa 100644 --- a/client/command/cursed/commands.go +++ b/client/command/cursed/commands.go @@ -11,7 +11,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { cursedCmd := &cobra.Command{ Use: consts.Cursed, Short: "Chrome/electron post-exploitation tool kit (∩`-´)⊃━☆゚.*・。゚", diff --git a/client/command/cursed/cursed-chrome.go b/client/command/cursed/cursed-chrome.go index bc5ca88d7a..cf76c83da3 100644 --- a/client/command/cursed/cursed-chrome.go +++ b/client/command/cursed/cursed-chrome.go @@ -51,7 +51,7 @@ var ( ) // CursedChromeCmd - Execute a .NET assembly in-memory. -func CursedChromeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedChromeCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -111,7 +111,7 @@ func CursedChromeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -func avadaKedavraChrome(session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient, cargs []string) *core.CursedProcess { +func avadaKedavraChrome(session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient, cargs []string) *core.CursedProcess { chromeProcess, err := getChromeProcess(session, cmd, con) if err != nil { con.PrintErrorf("%s\n", err) @@ -153,7 +153,7 @@ func avadaKedavraChrome(session *clientpb.Session, cmd *cobra.Command, con *cons return curse } -func startCursedChromeProcess(isEdge bool, session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient, cargs []string) (*core.CursedProcess, error) { +func startCursedChromeProcess(isEdge bool, session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient, cargs []string) (*core.CursedProcess, error) { name := "Chrome" if isEdge { name = "Edge" @@ -253,7 +253,7 @@ func startCursedChromeProcess(isEdge bool, session *clientpb.Session, cmd *cobra return curse, nil } -func findChromeUserDataDir(isEdge bool, session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient) (string, error) { +func findChromeUserDataDir(isEdge bool, session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient) (string, error) { userDataFlag, _ := cmd.Flags().GetString("user-data") if userDataFlag != "" { return userDataFlag, nil @@ -306,7 +306,7 @@ func findChromeUserDataDir(isEdge bool, session *clientpb.Session, cmd *cobra.Co } } -func findChromeExecutablePath(isEdge bool, session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient) (string, error) { +func findChromeExecutablePath(isEdge bool, session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient) (string, error) { exeFlag, _ := cmd.Flags().GetString("exe") if exeFlag != "" { return exeFlag, nil @@ -416,7 +416,7 @@ func isChromeProcess(executable string) bool { return false } -func getChromeProcess(session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient) (*commonpb.Process, error) { +func getChromeProcess(session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient) (*commonpb.Process, error) { ps, err := con.Rpc.Ps(context.Background(), &sliverpb.PsReq{ Request: con.ActiveTarget.Request(cmd), }) diff --git a/client/command/cursed/cursed-console.go b/client/command/cursed/cursed-console.go index a17862fd87..24fcc4cdc2 100644 --- a/client/command/cursed/cursed-console.go +++ b/client/command/cursed/cursed-console.go @@ -34,7 +34,7 @@ import ( "github.com/spf13/cobra" ) -func CursedConsoleCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedConsoleCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { curse := selectCursedProcess(con) if curse == nil { return @@ -55,7 +55,7 @@ func CursedConsoleCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args startCursedConsole(curse, true, target, con) } -func selectDebugTarget(targets []overlord.ChromeDebugTarget, con *console.SliverConsoleClient) *overlord.ChromeDebugTarget { +func selectDebugTarget(targets []overlord.ChromeDebugTarget, con *console.SliverClient) *overlord.ChromeDebugTarget { if len(targets) < 1 { con.PrintErrorf("No debug targets\n") return nil @@ -93,7 +93,7 @@ var helperHooks = []string{ "console.log = (...a) => {return a;}", // console.log } -func startCursedConsole(curse *core.CursedProcess, helpers bool, target *overlord.ChromeDebugTarget, con *console.SliverConsoleClient) { +func startCursedConsole(curse *core.CursedProcess, helpers bool, target *overlord.ChromeDebugTarget, con *console.SliverClient) { tmpFile, _ := os.CreateTemp("", "cursed") shell := readline.NewShell() shell.History.AddFromFile("cursed history", tmpFile.Name()) diff --git a/client/command/cursed/cursed-cookies.go b/client/command/cursed/cursed-cookies.go index 1e994a8b48..59c13d5e09 100644 --- a/client/command/cursed/cursed-cookies.go +++ b/client/command/cursed/cursed-cookies.go @@ -29,7 +29,7 @@ import ( "github.com/spf13/cobra" ) -func CursedCookiesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedCookiesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { curse := selectCursedProcess(con) if curse == nil { return diff --git a/client/command/cursed/cursed-edge.go b/client/command/cursed/cursed-edge.go index 412a7d5f29..19623f35ef 100644 --- a/client/command/cursed/cursed-edge.go +++ b/client/command/cursed/cursed-edge.go @@ -34,7 +34,7 @@ import ( ) // CursedChromeCmd - Execute a .NET assembly in-memory. -func CursedEdgeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedEdgeCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -94,7 +94,7 @@ func CursedEdgeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [] } } -func avadaKedavraEdge(session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient, cargs []string) *core.CursedProcess { +func avadaKedavraEdge(session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient, cargs []string) *core.CursedProcess { edgeProcess, err := getEdgeProcess(session, cmd, con) if err != nil { con.PrintErrorf("%s\n", err) @@ -151,7 +151,7 @@ func isEdgeProcess(executable string) bool { return false } -func getEdgeProcess(session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient) (*commonpb.Process, error) { +func getEdgeProcess(session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient) (*commonpb.Process, error) { ps, err := con.Rpc.Ps(context.Background(), &sliverpb.PsReq{ Request: con.ActiveTarget.Request(cmd), }) diff --git a/client/command/cursed/cursed-electron.go b/client/command/cursed/cursed-electron.go index caab611e7a..e9894315db 100644 --- a/client/command/cursed/cursed-electron.go +++ b/client/command/cursed/cursed-electron.go @@ -37,7 +37,7 @@ import ( "github.com/spf13/cobra" ) -func CursedElectronCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedElectronCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -67,7 +67,7 @@ func CursedElectronCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg con.PrintInfof("Found %d debug targets, good hunting!\n", len(targets)) } -func avadaKedavraElectron(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient, cargs []string) *core.CursedProcess { +func avadaKedavraElectron(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient, cargs []string) *core.CursedProcess { exists, err := checkElectronPath(electronExe, session, cmd, con) if err != nil { con.PrintErrorf("%s", err) @@ -118,7 +118,7 @@ func avadaKedavraElectron(electronExe string, session *clientpb.Session, cmd *co return curse } -func checkElectronPath(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient) (bool, error) { +func checkElectronPath(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient) (bool, error) { ls, err := con.Rpc.Ls(context.Background(), &sliverpb.LsReq{ Request: con.ActiveTarget.Request(cmd), Path: electronExe, @@ -129,7 +129,7 @@ func checkElectronPath(electronExe string, session *clientpb.Session, cmd *cobra return ls.GetExists(), nil } -func checkElectronProcess(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient) (*commonpb.Process, error) { +func checkElectronProcess(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient) (*commonpb.Process, error) { ps, err := con.Rpc.Ps(context.Background(), &sliverpb.PsReq{ Request: con.ActiveTarget.Request(cmd), }) @@ -147,7 +147,7 @@ func checkElectronProcess(electronExe string, session *clientpb.Session, cmd *co return nil, nil } -func startCursedElectronProcess(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient, cargs []string) (*core.CursedProcess, error) { +func startCursedElectronProcess(electronExe string, session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient, cargs []string) (*core.CursedProcess, error) { con.PrintInfof("Starting '%s' ... ", path.Base(electronExe)) debugPort := getRemoteDebuggerPort(cmd) args := []string{ diff --git a/client/command/cursed/cursed-rm.go b/client/command/cursed/cursed-rm.go index c2e5dcee7f..a2f47b1ad9 100644 --- a/client/command/cursed/cursed-rm.go +++ b/client/command/cursed/cursed-rm.go @@ -29,7 +29,7 @@ import ( "github.com/spf13/cobra" ) -func CursedRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/cursed/cursed-screenshot.go b/client/command/cursed/cursed-screenshot.go index d851a0d449..1b0ab936d5 100644 --- a/client/command/cursed/cursed-screenshot.go +++ b/client/command/cursed/cursed-screenshot.go @@ -28,7 +28,7 @@ import ( "github.com/spf13/cobra" ) -func CursedScreenshotCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedScreenshotCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { curse := selectCursedProcess(con) if curse == nil { return diff --git a/client/command/cursed/cursed.go b/client/command/cursed/cursed.go index df34b76964..da38a6eab6 100644 --- a/client/command/cursed/cursed.go +++ b/client/command/cursed/cursed.go @@ -35,7 +35,7 @@ import ( ) // CursedChromeCmd - Execute a .NET assembly in-memory. -func CursedCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CursedCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { // Collect existing curses from core cursedProcesses := [][]string{} core.CursedProcesses.Range(func(key, value interface{}) bool { @@ -71,7 +71,7 @@ func CursedCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } // selectCursedProcess - Interactively select a cursed process from a list. -func selectCursedProcess(con *console.SliverConsoleClient) *core.CursedProcess { +func selectCursedProcess(con *console.SliverClient) *core.CursedProcess { cursedProcesses := []*core.CursedProcess{} core.CursedProcesses.Range(func(key, value interface{}) bool { cursedProcesses = append(cursedProcesses, value.(*core.CursedProcess)) diff --git a/client/command/dllhijack/commands.go b/client/command/dllhijack/commands.go index b9aae25f22..54735cc958 100644 --- a/client/command/dllhijack/commands.go +++ b/client/command/dllhijack/commands.go @@ -13,7 +13,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { dllhijackCmd := &cobra.Command{ Use: consts.DLLHijackStr, Short: "Plant a DLL for a hijack scenario", diff --git a/client/command/dllhijack/dllhijack.go b/client/command/dllhijack/dllhijack.go index 48eb91dd19..5f9f40c8f0 100644 --- a/client/command/dllhijack/dllhijack.go +++ b/client/command/dllhijack/dllhijack.go @@ -34,7 +34,7 @@ import ( // dllhijack --ref-path c:\windows\system32\msasn1.dll --ref-file /tmp/ref.dll --profile dll TARGET_PATH // DllHijackCmd -- implements the dllhijack command -func DllHijackCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func DllHijackCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var ( localRefData []byte targetDLLData []byte diff --git a/client/command/environment/commands.go b/client/command/environment/commands.go index ed72775b1f..6c030ae77c 100644 --- a/client/command/environment/commands.go +++ b/client/command/environment/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { envCmd := &cobra.Command{ Use: consts.EnvStr, Short: "List environment variables", diff --git a/client/command/environment/get.go b/client/command/environment/get.go index cdf40aecc5..5cd630bfaf 100644 --- a/client/command/environment/get.go +++ b/client/command/environment/get.go @@ -31,7 +31,7 @@ import ( ) // EnvGetCmd - Get a remote environment variable -func EnvGetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func EnvGetCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -66,7 +66,7 @@ func EnvGetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } // PrintGetEnvInfo - Print the results of the env get command -func PrintGetEnvInfo(envInfo *sliverpb.EnvInfo, con *console.SliverConsoleClient) { +func PrintGetEnvInfo(envInfo *sliverpb.EnvInfo, con *console.SliverClient) { if envInfo.Response != nil && envInfo.Response.Err != "" { con.PrintErrorf("%s\n", envInfo.Response.Err) return diff --git a/client/command/environment/set.go b/client/command/environment/set.go index 395d5edbd3..7db6d4124f 100644 --- a/client/command/environment/set.go +++ b/client/command/environment/set.go @@ -32,7 +32,7 @@ import ( ) // EnvSetCmd - Set a remote environment variable -func EnvSetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func EnvSetCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -72,7 +72,7 @@ func EnvSetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } // PrintSetEnvInfo - Print the set environment info -func PrintSetEnvInfo(name string, value string, envInfo *sliverpb.SetEnv, con *console.SliverConsoleClient) { +func PrintSetEnvInfo(name string, value string, envInfo *sliverpb.SetEnv, con *console.SliverClient) { if envInfo.Response != nil && envInfo.Response.Err != "" { con.PrintErrorf("%s\n", envInfo.Response.Err) return diff --git a/client/command/environment/unset.go b/client/command/environment/unset.go index 664497f703..c5b7b2773a 100644 --- a/client/command/environment/unset.go +++ b/client/command/environment/unset.go @@ -31,7 +31,7 @@ import ( ) // EnvUnsetCmd - Unset a remote environment variable -func EnvUnsetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func EnvUnsetCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -67,7 +67,7 @@ func EnvUnsetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintUnsetEnvInfo - Print the set environment info -func PrintUnsetEnvInfo(name string, envInfo *sliverpb.UnsetEnv, con *console.SliverConsoleClient) { +func PrintUnsetEnvInfo(name string, envInfo *sliverpb.UnsetEnv, con *console.SliverClient) { if envInfo.Response != nil && envInfo.Response.Err != "" { con.PrintErrorf("%s\n", envInfo.Response.Err) return diff --git a/client/command/exec/commands.go b/client/command/exec/commands.go index 79b6174323..a2f913c25c 100644 --- a/client/command/exec/commands.go +++ b/client/command/exec/commands.go @@ -1,19 +1,18 @@ package exec import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/generate" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { executeCmd := &cobra.Command{ Use: consts.ExecuteStr, Short: "Execute a program on the remote system", diff --git a/client/command/exec/execute-assembly.go b/client/command/exec/execute-assembly.go index 34f16a03ce..69f649da90 100644 --- a/client/command/exec/execute-assembly.go +++ b/client/command/exec/execute-assembly.go @@ -25,16 +25,15 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// ExecuteAssemblyCmd - Execute a .NET assembly in-memory -func ExecuteAssemblyCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExecuteAssemblyCmd - Execute a .NET assembly in-memory. +func ExecuteAssemblyCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -132,7 +131,7 @@ func ExecuteAssemblyCmd(cmd *cobra.Command, con *console.SliverConsoleClient, ar } } -func HandleExecuteAssemblyResponse(execAssembly *sliverpb.ExecuteAssembly, assemblyPath string, hostName string, cmd *cobra.Command, con *console.SliverConsoleClient) { +func HandleExecuteAssemblyResponse(execAssembly *sliverpb.ExecuteAssembly, assemblyPath string, hostName string, cmd *cobra.Command, con *console.SliverClient) { saveLoot, _ := cmd.Flags().GetBool("loot") lootName, _ := cmd.Flags().GetString("name") diff --git a/client/command/exec/execute-shellcode.go b/client/command/exec/execute-shellcode.go index 7857a9383b..586136b079 100644 --- a/client/command/exec/execute-shellcode.go +++ b/client/command/exec/execute-shellcode.go @@ -26,19 +26,17 @@ import ( "log" "os" - "golang.org/x/term" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "golang.org/x/term" + "google.golang.org/protobuf/proto" ) -// ExecuteShellcodeCmd - Execute shellcode in-memory -func ExecuteShellcodeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExecuteShellcodeCmd - Execute shellcode in-memory. +func ExecuteShellcodeCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -128,8 +126,8 @@ func ExecuteShellcodeCmd(cmd *cobra.Command, con *console.SliverConsoleClient, a } } -// PrintExecuteShellcode - Display result of shellcode execution -func PrintExecuteShellcode(task *sliverpb.Task, con *console.SliverConsoleClient) { +// PrintExecuteShellcode - Display result of shellcode execution. +func PrintExecuteShellcode(task *sliverpb.Task, con *console.SliverClient) { if task.Response.GetErr() != "" { con.PrintErrorf("%s\n", task.Response.GetErr()) } else { @@ -137,7 +135,7 @@ func PrintExecuteShellcode(task *sliverpb.Task, con *console.SliverConsoleClient } } -func executeInteractive(cmd *cobra.Command, hostProc string, shellcode []byte, rwxPages bool, con *console.SliverConsoleClient) { +func executeInteractive(cmd *cobra.Command, hostProc string, shellcode []byte, rwxPages bool, con *console.SliverClient) { // Check active session session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/exec/execute.go b/client/command/exec/execute.go index fd45ab5aa6..0fd15d98a0 100644 --- a/client/command/exec/execute.go +++ b/client/command/exec/execute.go @@ -23,18 +23,16 @@ import ( "strings" "time" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/loot" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// ExecuteCmd - Run a command on the remote system -func ExecuteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExecuteCmd - Run a command on the remote system. +func ExecuteCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -113,7 +111,7 @@ func ExecuteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str } } -func HandleExecuteResponse(exec *sliverpb.Execute, cmdPath string, hostName string, cmd *cobra.Command, con *console.SliverConsoleClient) { +func HandleExecuteResponse(exec *sliverpb.Execute, cmdPath string, hostName string, cmd *cobra.Command, con *console.SliverClient) { var lootedOutput []byte stdout, _ := cmd.Flags().GetString("stdout") saveLoot, _ := cmd.Flags().GetBool("loot") @@ -136,8 +134,8 @@ func HandleExecuteResponse(exec *sliverpb.Execute, cmdPath string, hostName stri PrintExecute(exec, cmd, con) } -// PrintExecute - Print the output of an executed command -func PrintExecute(exec *sliverpb.Execute, cmd *cobra.Command, con *console.SliverConsoleClient) { +// PrintExecute - Print the output of an executed command. +func PrintExecute(exec *sliverpb.Execute, cmd *cobra.Command, con *console.SliverClient) { ignoreStderr, _ := cmd.Flags().GetBool("ignore-stderr") stdout, _ := cmd.Flags().GetString("stdout") stderr, _ := cmd.Flags().GetString("stderr") @@ -210,7 +208,7 @@ func combineCommandOutput(exec *sliverpb.Execute, combineStdOut bool, combineStd return []byte(outputString) } -func LootExecute(commandOutput []byte, lootName string, sliverCmdName string, cmdName string, hostName string, con *console.SliverConsoleClient) { +func LootExecute(commandOutput []byte, lootName string, sliverCmdName string, cmdName string, hostName string, con *console.SliverClient) { if len(commandOutput) == 0 { con.PrintInfof("There was no output from execution, so there is nothing to loot.\n") return @@ -229,7 +227,7 @@ func LootExecute(commandOutput []byte, lootName string, sliverCmdName string, cm loot.SendLootMessage(lootMessage, con) } -func PrintExecutionOutput(executionOutput string, saveOutput bool, commandName string, hostName string, con *console.SliverConsoleClient) { +func PrintExecutionOutput(executionOutput string, saveOutput bool, commandName string, hostName string, con *console.SliverClient) { con.PrintInfof("Output:\n%s", executionOutput) if saveOutput { @@ -237,7 +235,7 @@ func PrintExecutionOutput(executionOutput string, saveOutput bool, commandName s } } -func SaveExecutionOutput(executionOutput string, commandName string, hostName string, con *console.SliverConsoleClient) { +func SaveExecutionOutput(executionOutput string, commandName string, hostName string, con *console.SliverClient) { var outFilePath *os.File var err error @@ -258,7 +256,7 @@ func SaveExecutionOutput(executionOutput string, commandName string, hostName st } if outFilePath != nil { - outFilePath.Write([]byte(executionOutput)) + outFilePath.WriteString(executionOutput) con.PrintInfof("Output saved to %s\n", outFilePath.Name()) } } diff --git a/client/command/exec/migrate.go b/client/command/exec/migrate.go index 1a0e421ca5..66a02fdeb5 100644 --- a/client/command/exec/migrate.go +++ b/client/command/exec/migrate.go @@ -23,15 +23,14 @@ import ( "fmt" "strings" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// MigrateCmd - Windows only, inject an implant into another process -func MigrateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MigrateCmd - Windows only, inject an implant into another process. +func MigrateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSession() if session == nil { return diff --git a/client/command/exec/msf-inject.go b/client/command/exec/msf-inject.go index b8d274345a..4039a2dcc9 100644 --- a/client/command/exec/msf-inject.go +++ b/client/command/exec/msf-inject.go @@ -22,18 +22,16 @@ import ( "context" "fmt" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// MsfInjectCmd - Inject a metasploit payload into a remote process -func MsfInjectCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MsfInjectCmd - Inject a metasploit payload into a remote process. +func MsfInjectCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -99,8 +97,8 @@ func MsfInjectCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s } } -// PrintMsfRemote - Print the results of the remote injection attempt -func PrintMsfRemote(msfRemote *sliverpb.Task, con *console.SliverConsoleClient) { +// PrintMsfRemote - Print the results of the remote injection attempt. +func PrintMsfRemote(msfRemote *sliverpb.Task, con *console.SliverClient) { if msfRemote.Response == nil { con.PrintErrorf("Empty response from msf payload injection task") return diff --git a/client/command/exec/msf.go b/client/command/exec/msf.go index 9108478c66..1685b7de99 100644 --- a/client/command/exec/msf.go +++ b/client/command/exec/msf.go @@ -22,17 +22,15 @@ import ( "context" "fmt" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// MsfCmd - Inject a metasploit payload into the current remote process -func MsfCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MsfCmd - Inject a metasploit payload into the current remote process. +func MsfCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return diff --git a/client/command/exec/psexec.go b/client/command/exec/psexec.go index 69f08a3a51..790417a1ce 100644 --- a/client/command/exec/psexec.go +++ b/client/command/exec/psexec.go @@ -21,14 +21,11 @@ package exec import ( "context" "fmt" + insecureRand "math/rand" "os" "strings" "time" - insecureRand "math/rand" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/generate" "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" @@ -36,10 +33,11 @@ import ( "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util/encoders" + "github.com/spf13/cobra" ) // PsExecCmd - psexec command implementation. -func PsExecCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func PsExecCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/exec/sideload.go b/client/command/exec/sideload.go index b965c5385a..f64c9eeb96 100644 --- a/client/command/exec/sideload.go +++ b/client/command/exec/sideload.go @@ -25,17 +25,15 @@ import ( "path/filepath" "strings" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// SideloadCmd - Sideload a shared library on the remote system -func SideloadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SideloadCmd - Sideload a shared library on the remote system. +func SideloadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -96,7 +94,7 @@ func SideloadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -func HandleSideloadResponse(sideload *sliverpb.Sideload, binPath string, hostName string, cmd *cobra.Command, con *console.SliverConsoleClient) { +func HandleSideloadResponse(sideload *sliverpb.Sideload, binPath string, hostName string, cmd *cobra.Command, con *console.SliverClient) { saveLoot, _ := cmd.Flags().GetBool("loot") lootName, _ := cmd.Flags().GetString("name") diff --git a/client/command/exec/spawndll.go b/client/command/exec/spawndll.go index d522f100b4..ff281187d2 100644 --- a/client/command/exec/spawndll.go +++ b/client/command/exec/spawndll.go @@ -24,17 +24,15 @@ import ( "os" "strings" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// SpawnDllCmd - Spawn execution of a DLL on the remote system -func SpawnDllCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SpawnDllCmd - Spawn execution of a DLL on the remote system. +func SpawnDllCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -85,7 +83,7 @@ func SpawnDllCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -func HandleSpawnDLLResponse(spawndll *sliverpb.SpawnDll, binPath string, hostName string, cmd *cobra.Command, con *console.SliverConsoleClient) { +func HandleSpawnDLLResponse(spawndll *sliverpb.SpawnDll, binPath string, hostName string, cmd *cobra.Command, con *console.SliverClient) { saveLoot, _ := cmd.Flags().GetBool("loot") lootName, _ := cmd.Flags().GetString("name") diff --git a/client/command/exec/ssh.go b/client/command/exec/ssh.go index f7b8f4dbb9..5de8a37a6d 100644 --- a/client/command/exec/ssh.go +++ b/client/command/exec/ssh.go @@ -24,16 +24,15 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// SSHCmd - A built-in SSH client command for the remote system (doesn't shell out) -func SSHCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SSHCmd - A built-in SSH client command for the remote system (doesn't shell out). +func SSHCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var ( privKey []byte err error @@ -120,8 +119,8 @@ func SSHCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// PrintSSHCmd - Print the ssh command response -func PrintSSHCmd(sshCmd *sliverpb.SSHCommand, con *console.SliverConsoleClient) { +// PrintSSHCmd - Print the ssh command response. +func PrintSSHCmd(sshCmd *sliverpb.SSHCommand, con *console.SliverClient) { if sshCmd.Response != nil && sshCmd.Response.Err != "" { con.PrintErrorf("Error: %s\n", sshCmd.Response.Err) if sshCmd.StdErr != "" { @@ -139,7 +138,7 @@ func PrintSSHCmd(sshCmd *sliverpb.SSHCommand, con *console.SliverConsoleClient) } } -func tryCredsFromLoot(con *console.SliverConsoleClient) (string, string, []byte) { +func tryCredsFromLoot(con *console.SliverClient) (string, string, []byte) { var ( username string password string diff --git a/client/command/exit/exit.go b/client/command/exit/exit.go index ba0f1ee79b..af74dfc1eb 100644 --- a/client/command/exit/exit.go +++ b/client/command/exit/exit.go @@ -30,8 +30,8 @@ import ( "github.com/spf13/cobra" ) -// ExitCmd - Exit the console -func ExitCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExitCmd - Exit the console. +func ExitCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { fmt.Println("Exiting...") if con.IsServer { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) @@ -56,7 +56,7 @@ func ExitCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } // Commands returns the `exit` command. -func Command(con *console.SliverConsoleClient) []*cobra.Command { +func Command(con *console.SliverClient) []*cobra.Command { return []*cobra.Command{{ Use: "exit", Short: "Exit the program", diff --git a/client/command/extensions/commands.go b/client/command/extensions/commands.go index 236f13e6ba..5d5e5434ef 100644 --- a/client/command/extensions/commands.go +++ b/client/command/extensions/commands.go @@ -1,16 +1,15 @@ package extensions import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { extensionCmd := &cobra.Command{ Use: consts.ExtensionsStr, Short: "Manage extensions", diff --git a/client/command/extensions/extensions.go b/client/command/extensions/extensions.go index 980386150f..e47864a111 100644 --- a/client/command/extensions/extensions.go +++ b/client/command/extensions/extensions.go @@ -24,18 +24,17 @@ import ( "os" "strings" + "github.com/bishopfox/sliver/client/assets" + "github.com/bishopfox/sliver/client/command/settings" + "github.com/bishopfox/sliver/client/console" "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" "github.com/rsteube/carapace" "github.com/spf13/cobra" - - "github.com/bishopfox/sliver/client/assets" - "github.com/bishopfox/sliver/client/command/settings" - "github.com/bishopfox/sliver/client/console" ) -// ExtensionsCmd - List information about installed extensions -func ExtensionsCmd(cmd *cobra.Command, con *console.SliverConsoleClient) { +// ExtensionsCmd - List information about installed extensions. +func ExtensionsCmd(cmd *cobra.Command, con *console.SliverClient) { if 0 < len(getInstalledManifests()) { PrintExtensions(con) } else { @@ -43,8 +42,8 @@ func ExtensionsCmd(cmd *cobra.Command, con *console.SliverConsoleClient) { } } -// PrintExtensions - Print a list of loaded extensions -func PrintExtensions(con *console.SliverConsoleClient) { +// PrintExtensions - Print a list of loaded extensions. +func PrintExtensions(con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -114,8 +113,8 @@ func getInstalledManifests() map[string]*ExtensionManifest { return installedManifests } -// ExtensionsCommandNameCompleter - Completer for installed extensions command names -func ExtensionsCommandNameCompleter(con *console.SliverConsoleClient) carapace.Action { +// ExtensionsCommandNameCompleter - Completer for installed extensions command names. +func ExtensionsCommandNameCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { installedManifests := getInstalledManifests() results := []string{} diff --git a/client/command/extensions/install.go b/client/command/extensions/install.go index 66e240f549..b084feddcc 100644 --- a/client/command/extensions/install.go +++ b/client/command/extensions/install.go @@ -24,15 +24,14 @@ import ( "path/filepath" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" ) -// ExtensionsInstallCmd - Install an extension -func ExtensionsInstallCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExtensionsInstallCmd - Install an extension. +func ExtensionsInstallCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { extLocalPath := args[0] fi, err := os.Stat(extLocalPath) @@ -47,8 +46,8 @@ func ExtensionsInstallCmd(cmd *cobra.Command, con *console.SliverConsoleClient, } } -// Install an extension from a directory -func installFromDir(extLocalPath string, con *console.SliverConsoleClient) { +// Install an extension from a directory. +func installFromDir(extLocalPath string, con *console.SliverClient) { manifestData, err := os.ReadFile(filepath.Join(extLocalPath, ManifestFileName)) if err != nil { con.PrintErrorf("Error reading %s: %s", ManifestFileName, err) @@ -98,8 +97,8 @@ func installFromDir(extLocalPath string, con *console.SliverConsoleClient) { } } -// InstallFromFilePath - Install an extension from a .tar.gz file -func InstallFromFilePath(extLocalPath string, autoOverwrite bool, con *console.SliverConsoleClient) *string { +// InstallFromFilePath - Install an extension from a .tar.gz file. +func InstallFromFilePath(extLocalPath string, autoOverwrite bool, con *console.SliverClient) *string { manifestData, err := util.ReadFileFromTarGz(extLocalPath, fmt.Sprintf("./%s", ManifestFileName)) if err != nil { con.PrintErrorf("Failed to read %s from '%s': %s\n", ManifestFileName, extLocalPath, err) @@ -150,7 +149,7 @@ func InstallFromFilePath(extLocalPath string, autoOverwrite bool, con *console.S return &installPath } -func installArtifact(extGzFilePath string, installPath string, artifactPath string, con *console.SliverConsoleClient) error { +func installArtifact(extGzFilePath string, installPath string, artifactPath string, con *console.SliverClient) error { data, err := util.ReadFileFromTarGz(extGzFilePath, "."+filepath.ToSlash(artifactPath)) if err != nil { return err diff --git a/client/command/extensions/list.go b/client/command/extensions/list.go index afc479a75c..52de4a9760 100644 --- a/client/command/extensions/list.go +++ b/client/command/extensions/list.go @@ -21,14 +21,13 @@ package extensions import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// ExtensionsListCmd - List all extension loaded on the active session/beacon -func ExtensionsListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExtensionsListCmd - List all extension loaded on the active session/beacon. +func ExtensionsListCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/extensions/load.go b/client/command/extensions/load.go index 72b7d2fd29..b70d8f76d2 100644 --- a/client/command/extensions/load.go +++ b/client/command/extensions/load.go @@ -30,12 +30,6 @@ import ( "strconv" "strings" - appConsole "github.com/reeflective/console" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" @@ -44,12 +38,17 @@ import ( "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util" + appConsole "github.com/reeflective/console" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "google.golang.org/protobuf/proto" ) const ( defaultTimeout = 60 - // ManifestFileName - Extension manifest file name + // ManifestFileName - Extension manifest file name. ManifestFileName = "extension.json" ) @@ -105,8 +104,8 @@ func (e *ExtensionManifest) getFileForTarget(cmdName string, targetOS string, ta return filePath, nil } -// ExtensionLoadCmd - Load extension command -func ExtensionLoadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExtensionLoadCmd - Load extension command. +func ExtensionLoadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { dirPath := args[0] // dirPath := ctx.Args.String("dir-path") extCmd, err := LoadExtensionManifest(filepath.Join(dirPath, ManifestFileName)) @@ -123,7 +122,7 @@ func ExtensionLoadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args con.PrintInfof("Added %s command: %s\n", extCmd.CommandName, extCmd.Help) } -// LoadExtensionManifest - Parse extension files +// LoadExtensionManifest - Parse extension files. func LoadExtensionManifest(manifestPath string) (*ExtensionManifest, error) { data, err := os.ReadFile(manifestPath) if err != nil { @@ -138,7 +137,7 @@ func LoadExtensionManifest(manifestPath string) (*ExtensionManifest, error) { return extManifest, nil } -// ParseExtensionManifest - Parse extension manifest from buffer +// ParseExtensionManifest - Parse extension manifest from buffer. func ParseExtensionManifest(data []byte) (*ExtensionManifest, error) { extManifest := &ExtensionManifest{} err := json.Unmarshal(data, &extManifest) @@ -174,8 +173,8 @@ func ParseExtensionManifest(data []byte) (*ExtensionManifest, error) { return extManifest, nil } -// ExtensionRegisterCommand - Register a new extension command -func ExtensionRegisterCommand(extCmd *ExtensionManifest, cmd *cobra.Command, con *console.SliverConsoleClient) { +// ExtensionRegisterCommand - Register a new extension command. +func ExtensionRegisterCommand(extCmd *ExtensionManifest, cmd *cobra.Command, con *console.SliverClient) { if errInvalidArgs := checkExtensionArgs(extCmd); errInvalidArgs != nil { con.PrintErrorf(errInvalidArgs.Error()) return @@ -210,7 +209,7 @@ func ExtensionRegisterCommand(extCmd *ExtensionManifest, cmd *cobra.Command, con cmd.AddCommand(extensionCmd) } -func loadExtension(goos string, goarch string, checkCache bool, ext *ExtensionManifest, cmd *cobra.Command, con *console.SliverConsoleClient) error { +func loadExtension(goos string, goarch string, checkCache bool, ext *ExtensionManifest, cmd *cobra.Command, con *console.SliverClient) error { var extensionList []string binPath, err := ext.getFileForTarget(cmd.Name(), goos, goarch) if err != nil { @@ -261,7 +260,7 @@ func loadExtension(goos string, goarch string, checkCache bool, ext *ExtensionMa return nil } -func registerExtension(goos string, ext *ExtensionManifest, binData []byte, cmd *cobra.Command, con *console.SliverConsoleClient) error { +func registerExtension(goos string, ext *ExtensionManifest, binData []byte, cmd *cobra.Command, con *console.SliverClient) error { registerResp, err := con.Rpc.RegisterExtension(context.Background(), &sliverpb.RegisterExtensionReq{ Name: ext.CommandName, Data: binData, @@ -278,7 +277,7 @@ func registerExtension(goos string, ext *ExtensionManifest, binData []byte, cmd return nil } -func loadDep(goos string, goarch string, depName string, cmd *cobra.Command, con *console.SliverConsoleClient) error { +func loadDep(goos string, goarch string, depName string, cmd *cobra.Command, con *console.SliverClient) error { depExt, ok := loadedExtensions[depName] if ok { depBinPath, err := depExt.getFileForTarget(depExt.CommandName, goos, goarch) @@ -294,7 +293,7 @@ func loadDep(goos string, goarch string, depName string, cmd *cobra.Command, con return fmt.Errorf("missing dependency %s", depName) } -func runExtensionCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func runExtensionCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var ( err error extensionArgs []byte @@ -388,8 +387,8 @@ func runExtensionCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -// PrintExtOutput - Print the ext execution output -func PrintExtOutput(extName string, commandName string, callExtension *sliverpb.CallExtension, con *console.SliverConsoleClient) { +// PrintExtOutput - Print the ext execution output. +func PrintExtOutput(extName string, commandName string, callExtension *sliverpb.CallExtension, con *console.SliverClient) { if extName == commandName { con.PrintInfof("Successfully executed %s", extName) } else { @@ -509,7 +508,7 @@ func getBOFArgs(cmd *cobra.Command, args []string, binPath string, ext *Extensio return extensionArgs, nil } -// CmdExists - checks if a command exists +// CmdExists - checks if a command exists. func CmdExists(name string, cmd *cobra.Command) bool { for _, c := range cmd.Commands() { if name == c.Name() { diff --git a/client/command/extensions/remove.go b/client/command/extensions/remove.go index ceadf621c3..d64dc15334 100644 --- a/client/command/extensions/remove.go +++ b/client/command/extensions/remove.go @@ -25,15 +25,14 @@ import ( "path/filepath" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" ) -// ExtensionsRemoveCmd - Remove an extension -func ExtensionsRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ExtensionsRemoveCmd - Remove an extension. +func ExtensionsRemoveCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name := args[0] if name == "" { con.PrintErrorf("Extension name is required\n") @@ -54,8 +53,8 @@ func ExtensionsRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, a } } -// RemoveExtensionByCommandName - Remove an extension by command name -func RemoveExtensionByCommandName(commandName string, con *console.SliverConsoleClient) error { +// RemoveExtensionByCommandName - Remove an extension by command name. +func RemoveExtensionByCommandName(commandName string, con *console.SliverClient) error { if commandName == "" { return errors.New("command name is required") } diff --git a/client/command/filesystem/cat.go b/client/command/filesystem/cat.go index 5da4c0e730..7226f13977 100644 --- a/client/command/filesystem/cat.go +++ b/client/command/filesystem/cat.go @@ -27,18 +27,17 @@ import ( "github.com/alecthomas/chroma/formatters" "github.com/alecthomas/chroma/lexers" "github.com/alecthomas/chroma/styles" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/command/loot" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util/encoders" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// CatCmd - Display the contents of a remote file -func CatCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CatCmd - Display the contents of a remote file. +func CatCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -80,8 +79,8 @@ func CatCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// PrintCat - Print the download to stdout -func PrintCat(download *sliverpb.Download, cmd *cobra.Command, con *console.SliverConsoleClient) { +// PrintCat - Print the download to stdout. +func PrintCat(download *sliverpb.Download, cmd *cobra.Command, con *console.SliverClient) { var ( lootDownload bool = true err error diff --git a/client/command/filesystem/cd.go b/client/command/filesystem/cd.go index 02fcf5ff69..58f2bc2c39 100644 --- a/client/command/filesystem/cd.go +++ b/client/command/filesystem/cd.go @@ -21,17 +21,15 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// CdCmd - Change directory on the remote system -func CdCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CdCmd - Change directory on the remote system. +func CdCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return diff --git a/client/command/filesystem/chmod.go b/client/command/filesystem/chmod.go index 083c2feab1..5485bb08f2 100644 --- a/client/command/filesystem/chmod.go +++ b/client/command/filesystem/chmod.go @@ -20,17 +20,15 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// ChmodCmd - Change the permissions of a file on the remote file system -func ChmodCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ChmodCmd - Change the permissions of a file on the remote file system. +func ChmodCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -77,8 +75,8 @@ func ChmodCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin } } -// PrintChmod - Print the chmod response -func PrintChmod(chmod *sliverpb.Chmod, con *console.SliverConsoleClient) { +// PrintChmod - Print the chmod response. +func PrintChmod(chmod *sliverpb.Chmod, con *console.SliverClient) { if chmod.Response != nil && chmod.Response.Err != "" { con.PrintErrorf("%s\n", chmod.Response.Err) return diff --git a/client/command/filesystem/chown.go b/client/command/filesystem/chown.go index 1a95be6255..5ea6d199cb 100644 --- a/client/command/filesystem/chown.go +++ b/client/command/filesystem/chown.go @@ -20,17 +20,15 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// ChownCmd - Change the owner of a file on the remote file system -func ChownCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ChownCmd - Change the owner of a file on the remote file system. +func ChownCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -85,8 +83,8 @@ func ChownCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin } } -// PrintChown - Print the chown response -func PrintChown(chown *sliverpb.Chown, con *console.SliverConsoleClient) { +// PrintChown - Print the chown response. +func PrintChown(chown *sliverpb.Chown, con *console.SliverClient) { if chown.Response != nil && chown.Response.Err != "" { con.PrintErrorf("%s\n", chown.Response.Err) return diff --git a/client/command/filesystem/chtimes.go b/client/command/filesystem/chtimes.go index eee6b4f503..2cf75b0dcb 100644 --- a/client/command/filesystem/chtimes.go +++ b/client/command/filesystem/chtimes.go @@ -21,17 +21,15 @@ import ( "context" "time" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// ChtimesCmd - Change the access and modified time of a file on the remote file system -func ChtimesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ChtimesCmd - Change the access and modified time of a file on the remote file system. +func ChtimesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -98,8 +96,8 @@ func ChtimesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str } } -// PrintChtimes - Print the Chtimes response -func PrintChtimes(chtimes *sliverpb.Chtimes, con *console.SliverConsoleClient) { +// PrintChtimes - Print the Chtimes response. +func PrintChtimes(chtimes *sliverpb.Chtimes, con *console.SliverClient) { if chtimes.Response != nil && chtimes.Response.Err != "" { con.PrintErrorf("%s\n", chtimes.Response.Err) return diff --git a/client/command/filesystem/commands.go b/client/command/filesystem/commands.go index 3c1c64d713..caa8f8c9c7 100644 --- a/client/command/filesystem/commands.go +++ b/client/command/filesystem/commands.go @@ -1,19 +1,18 @@ package filesystem import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/command/loot" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { mvCmd := &cobra.Command{ Use: consts.MvStr, Short: "Move or rename a file", diff --git a/client/command/filesystem/cp.go b/client/command/filesystem/cp.go index 9d0fe895a9..3f9724f1a0 100644 --- a/client/command/filesystem/cp.go +++ b/client/command/filesystem/cp.go @@ -21,16 +21,14 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -func CpCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) (err error) { +func CpCmd(cmd *cobra.Command, con *console.SliverClient, args []string) (err error) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -72,7 +70,7 @@ func CpCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) return } -func PrintCp(cp *sliverpb.Cp, con *console.SliverConsoleClient) { +func PrintCp(cp *sliverpb.Cp, con *console.SliverClient) { if cp.Response != nil && cp.Response.Err != "" { con.PrintErrorf("%s\n", cp.Response.Err) return diff --git a/client/command/filesystem/download.go b/client/command/filesystem/download.go index 6192a9fa5e..5cf74140e4 100644 --- a/client/command/filesystem/download.go +++ b/client/command/filesystem/download.go @@ -28,18 +28,17 @@ import ( "strings" "time" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "gopkg.in/AlecAivazis/survey.v1" - "github.com/bishopfox/sliver/client/command/loot" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util/encoders" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" + "gopkg.in/AlecAivazis/survey.v1" ) -func DownloadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func DownloadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -104,7 +103,7 @@ func prettifyDownloadName(path string) string { return filteredString } -func HandleDownloadResponse(download *sliverpb.Download, cmd *cobra.Command, args []string, con *console.SliverConsoleClient) { +func HandleDownloadResponse(download *sliverpb.Download, cmd *cobra.Command, args []string, con *console.SliverClient) { var err error if download.Response != nil && download.Response.Err != "" { con.PrintErrorf("%s\n", download.Response.Err) diff --git a/client/command/filesystem/ls.go b/client/command/filesystem/ls.go index 28e56348f4..84480548b8 100644 --- a/client/command/filesystem/ls.go +++ b/client/command/filesystem/ls.go @@ -27,19 +27,17 @@ import ( "text/tabwriter" "time" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "google.golang.org/protobuf/proto" ) -// LsCmd - List the contents of a remote directory -func LsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// LsCmd - List the contents of a remote directory. +func LsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -75,8 +73,8 @@ func LsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// PrintLs - Display an sliverpb.Ls object -func PrintLs(ls *sliverpb.Ls, flags *pflag.FlagSet, con *console.SliverConsoleClient) { +// PrintLs - Display an sliverpb.Ls object. +func PrintLs(ls *sliverpb.Ls, flags *pflag.FlagSet, con *console.SliverClient) { if ls.Response != nil && ls.Response.Err != "" { con.PrintErrorf("%s\n", ls.Response.Err) return diff --git a/client/command/filesystem/memfiles-add.go b/client/command/filesystem/memfiles-add.go index 2183298574..dfed97a4bb 100644 --- a/client/command/filesystem/memfiles-add.go +++ b/client/command/filesystem/memfiles-add.go @@ -20,16 +20,15 @@ package filesystem import ( "context" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// MemfilesAddCmd - Add memfile -func MemfilesAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MemfilesAddCmd - Add memfile. +func MemfilesAddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -57,8 +56,8 @@ func MemfilesAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } } -// PrintAddMemfile - Print the memfiles response -func PrintAddMemfile(memfilesAdd *sliverpb.MemfilesAdd, con *console.SliverConsoleClient) { +// PrintAddMemfile - Print the memfiles response. +func PrintAddMemfile(memfilesAdd *sliverpb.MemfilesAdd, con *console.SliverClient) { if memfilesAdd.Response != nil && memfilesAdd.Response.Err != "" { con.PrintErrorf("%s\n", memfilesAdd.Response.Err) return diff --git a/client/command/filesystem/memfiles-list.go b/client/command/filesystem/memfiles-list.go index e868a440c4..a4bb45d8bc 100644 --- a/client/command/filesystem/memfiles-list.go +++ b/client/command/filesystem/memfiles-list.go @@ -25,17 +25,16 @@ import ( "text/tabwriter" "time" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// MemfilesListCmd - List memfiles -func MemfilesListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MemfilesListCmd - List memfiles. +func MemfilesListCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -63,8 +62,8 @@ func MemfilesListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -// PrintMemfiles - Display an sliverpb.Ls object -func PrintMemfiles(ls *sliverpb.Ls, con *console.SliverConsoleClient) { +// PrintMemfiles - Display an sliverpb.Ls object. +func PrintMemfiles(ls *sliverpb.Ls, con *console.SliverClient) { if ls.Response != nil && ls.Response.Err != "" { con.PrintErrorf("%s\n", ls.Response.Err) return diff --git a/client/command/filesystem/memfiles-rm.go b/client/command/filesystem/memfiles-rm.go index 169b3ec0ad..9c90b46354 100644 --- a/client/command/filesystem/memfiles-rm.go +++ b/client/command/filesystem/memfiles-rm.go @@ -21,16 +21,15 @@ import ( "context" "strconv" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// MemfilesRmCmd - Remove a memfile -func MemfilesRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MemfilesRmCmd - Remove a memfile. +func MemfilesRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -67,8 +66,8 @@ func MemfilesRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [] } } -// PrintRmMemfile - Remove a memfile -func PrintRmMemfile(memfilesList *sliverpb.MemfilesRm, con *console.SliverConsoleClient) { +// PrintRmMemfile - Remove a memfile. +func PrintRmMemfile(memfilesList *sliverpb.MemfilesRm, con *console.SliverClient) { if memfilesList.Response != nil && memfilesList.Response.Err != "" { con.PrintErrorf("%s\n", memfilesList.Response.Err) return diff --git a/client/command/filesystem/mkdir.go b/client/command/filesystem/mkdir.go index e759f56f28..0699fe1ff5 100644 --- a/client/command/filesystem/mkdir.go +++ b/client/command/filesystem/mkdir.go @@ -21,17 +21,15 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// MkdirCmd - Make a remote directory -func MkdirCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MkdirCmd - Make a remote directory. +func MkdirCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -68,8 +66,8 @@ func MkdirCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin } } -// PrintMkdir - Print make directory -func PrintMkdir(mkdir *sliverpb.Mkdir, con *console.SliverConsoleClient) { +// PrintMkdir - Print make directory. +func PrintMkdir(mkdir *sliverpb.Mkdir, con *console.SliverClient) { if mkdir.Response != nil && mkdir.Response.Err != "" { con.PrintErrorf("%s\n", mkdir.Response.Err) return diff --git a/client/command/filesystem/mv.go b/client/command/filesystem/mv.go index 61aa523f70..9e0b46e874 100644 --- a/client/command/filesystem/mv.go +++ b/client/command/filesystem/mv.go @@ -21,16 +21,14 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -func MvCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) (err error) { +func MvCmd(cmd *cobra.Command, con *console.SliverClient, args []string) (err error) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -77,8 +75,8 @@ func MvCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) return } -// PrintMv - Print the renamed file -func PrintMv(mv *sliverpb.Mv, con *console.SliverConsoleClient) { +// PrintMv - Print the renamed file. +func PrintMv(mv *sliverpb.Mv, con *console.SliverClient) { if mv.Response != nil && mv.Response.Err != "" { con.PrintErrorf("%s\n", mv.Response.Err) return diff --git a/client/command/filesystem/pwd.go b/client/command/filesystem/pwd.go index 865de3bd8c..5ed2b019b9 100644 --- a/client/command/filesystem/pwd.go +++ b/client/command/filesystem/pwd.go @@ -21,17 +21,15 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// PwdCmd - Print the remote working directory -func PwdCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// PwdCmd - Print the remote working directory. +func PwdCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -58,8 +56,8 @@ func PwdCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// PrintPwd - Print the remote working directory -func PrintPwd(pwd *sliverpb.Pwd, con *console.SliverConsoleClient) { +// PrintPwd - Print the remote working directory. +func PrintPwd(pwd *sliverpb.Pwd, con *console.SliverClient) { if pwd.Response != nil && pwd.Response.Err != "" { con.PrintErrorf("%s\n", pwd.Response.Err) return diff --git a/client/command/filesystem/rm.go b/client/command/filesystem/rm.go index 72fc88b40d..7701c5a840 100644 --- a/client/command/filesystem/rm.go +++ b/client/command/filesystem/rm.go @@ -21,17 +21,15 @@ package filesystem import ( "context" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// RmCmd - Remove a directory from the remote file system -func RmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// RmCmd - Remove a directory from the remote file system. +func RmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -73,8 +71,8 @@ func RmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// PrintRm - Print the rm response -func PrintRm(rm *sliverpb.Rm, con *console.SliverConsoleClient) { +// PrintRm - Print the rm response. +func PrintRm(rm *sliverpb.Rm, con *console.SliverClient) { if rm.Response != nil && rm.Response.Err != "" { con.PrintErrorf("%s\n", rm.Response.Err) return diff --git a/client/command/filesystem/upload.go b/client/command/filesystem/upload.go index 9e163699dc..86daef51bc 100644 --- a/client/command/filesystem/upload.go +++ b/client/command/filesystem/upload.go @@ -25,18 +25,16 @@ import ( "os" "path/filepath" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util/encoders" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// UploadCmd - Upload a file to the remote system -func UploadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// UploadCmd - Upload a file to the remote system. +func UploadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -110,8 +108,8 @@ func UploadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } } -// PrintUpload - Print the result of the upload command -func PrintUpload(upload *sliverpb.Upload, con *console.SliverConsoleClient) { +// PrintUpload - Print the result of the upload command. +func PrintUpload(upload *sliverpb.Upload, con *console.SliverClient) { if upload.Response != nil && upload.Response.Err != "" { con.PrintErrorf("%s\n", upload.Response.Err) return diff --git a/client/command/generate/canaries.go b/client/command/generate/canaries.go index 8900e0dd1c..e8588eeb47 100644 --- a/client/command/generate/canaries.go +++ b/client/command/generate/canaries.go @@ -13,7 +13,7 @@ import ( ) // CanariesCmd - Display canaries from the database and their status. -func CanariesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func CanariesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { canaries, err := con.Rpc.Canaries(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("Failed to list canaries %s", err) @@ -28,7 +28,7 @@ func CanariesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintCanaries - Print the canaries tracked by the server. -func PrintCanaries(con *console.SliverConsoleClient, canaries []*clientpb.DNSCanary, burnedOnly bool) { +func PrintCanaries(con *console.SliverClient, canaries []*clientpb.DNSCanary, burnedOnly bool) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ diff --git a/client/command/generate/commands.go b/client/command/generate/commands.go index 089873f589..83e54fabd9 100644 --- a/client/command/generate/commands.go +++ b/client/command/generate/commands.go @@ -11,7 +11,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { // [ Generate ] -------------------------------------------------------------- generateCmd := &cobra.Command{ Use: consts.GenerateStr, @@ -335,7 +335,7 @@ func coreImplantFlags(name string, cmd *cobra.Command) { } // coreImplantFlagCompletions binds completions to flags registered in coreImplantFlags. -func coreImplantFlagCompletions(cmd *cobra.Command, con *console.SliverConsoleClient) { +func coreImplantFlagCompletions(cmd *cobra.Command, con *console.SliverClient) { flags.BindFlagCompletions(cmd, func(comp *carapace.ActionMap) { (*comp)["debug-file"] = carapace.ActionFiles() (*comp)["os"] = OSCompleter(con) diff --git a/client/command/generate/generate-beacon.go b/client/command/generate/generate-beacon.go index 40466d7335..80add10c58 100644 --- a/client/command/generate/generate-beacon.go +++ b/client/command/generate/generate-beacon.go @@ -16,7 +16,7 @@ var ( ) // GenerateBeaconCmd - The main command used to generate implant binaries. -func GenerateBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func GenerateBeaconCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { config := parseCompileFlags(cmd, con) if config == nil { return @@ -38,7 +38,7 @@ func GenerateBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg } } -func parseBeaconFlags(cmd *cobra.Command, con *console.SliverConsoleClient, config *clientpb.ImplantConfig) error { +func parseBeaconFlags(cmd *cobra.Command, con *console.SliverClient, config *clientpb.ImplantConfig) error { days, _ := cmd.Flags().GetInt64("days") hours, _ := cmd.Flags().GetInt64("hours") minutes, _ := cmd.Flags().GetInt64("minutes") diff --git a/client/command/generate/generate-info.go b/client/command/generate/generate-info.go index 9a9efe6d2a..f9b2a3901a 100644 --- a/client/command/generate/generate-info.go +++ b/client/command/generate/generate-info.go @@ -9,7 +9,7 @@ import ( ) // GenerateInfoCmd - Display information about the Sliver server's compiler configuration. -func GenerateInfoCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func GenerateInfoCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { compiler, err := con.Rpc.GetCompiler(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("Failed to get compiler information: %s\n", err) diff --git a/client/command/generate/generate-stager.go b/client/command/generate/generate-stager.go index a6f99d7b08..b30831c1dd 100644 --- a/client/command/generate/generate-stager.go +++ b/client/command/generate/generate-stager.go @@ -33,7 +33,7 @@ import ( ) // GenerateStagerCmd - Generate a stager using Metasploit. -func GenerateStagerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func GenerateStagerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var stageProto clientpb.StageProtocol lhost, _ := cmd.Flags().GetString("lhost") if lhost == "" { diff --git a/client/command/generate/generate.go b/client/command/generate/generate.go index 677e8a4a29..a4c1fd29d6 100644 --- a/client/command/generate/generate.go +++ b/client/command/generate/generate.go @@ -88,7 +88,7 @@ var ( ) // GenerateCmd - The main command used to generate implant binaries. -func GenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func GenerateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { config := parseCompileFlags(cmd, con) if config == nil { return @@ -126,7 +126,7 @@ func expandPath(path string) string { return filepath.Join(os.Getenv("HOME"), path[1:]) } -func saveLocation(save, DefaultName string, con *console.SliverConsoleClient) (string, error) { +func saveLocation(save, DefaultName string, con *console.SliverClient) (string, error) { var saveTo string if save == "" { save, _ = os.Getwd() @@ -181,7 +181,7 @@ func nameOfOutputFormat(value clientpb.OutputFormat) string { } // Shared function that extracts the compile flags from the grumble context. -func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *clientpb.ImplantConfig { +func parseCompileFlags(cmd *cobra.Command, con *console.SliverClient) *clientpb.ImplantConfig { var name string if nameF, _ := cmd.Flags().GetString("name"); nameF != "" { name = strings.ToLower(nameF) @@ -404,7 +404,7 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl } // parseTrafficEncoderArgs - parses the traffic encoder args and returns a bool indicating if traffic encoders are enabled. -func parseTrafficEncoderArgs(cmd *cobra.Command, httpC2Enabled bool, con *console.SliverConsoleClient) (bool, []*commonpb.File) { +func parseTrafficEncoderArgs(cmd *cobra.Command, httpC2Enabled bool, con *console.SliverClient) (bool, []*commonpb.File) { trafficEncoders, _ := cmd.Flags().GetString("traffic-encoders") encoders := []*commonpb.File{} if trafficEncoders != "" { @@ -424,7 +424,7 @@ func parseTrafficEncoderArgs(cmd *cobra.Command, httpC2Enabled bool, con *consol return false, encoders } -func getTargets(targetOS string, targetArch string, con *console.SliverConsoleClient) (string, string) { +func getTargets(targetOS string, targetArch string, con *console.SliverClient) (string, string) { /* For UX we convert some synonymous terms */ if targetOS == "darwin" || targetOS == "mac" || targetOS == "macos" || targetOS == "osx" { targetOS = "darwin" @@ -777,7 +777,7 @@ func ParseTCPPivotc2(args string) ([]*clientpb.ImplantC2, error) { return c2s, nil } -func externalBuild(config *clientpb.ImplantConfig, save string, con *console.SliverConsoleClient) (*commonpb.File, error) { +func externalBuild(config *clientpb.ImplantConfig, save string, con *console.SliverClient) (*commonpb.File, error) { potentialBuilders, err := findExternalBuilders(config, con) if err != nil { return nil, err @@ -900,7 +900,7 @@ func externalBuild(config *clientpb.ImplantConfig, save string, con *console.Sli return nil, nil } -func compile(config *clientpb.ImplantConfig, save string, con *console.SliverConsoleClient) (*commonpb.File, error) { +func compile(config *clientpb.ImplantConfig, save string, con *console.SliverClient) (*commonpb.File, error) { if config.IsBeacon { interval := time.Duration(config.BeaconInterval) con.PrintInfof("Generating new %s/%s beacon implant binary (%v)\n", config.GOOS, config.GOARCH, interval) @@ -993,7 +993,7 @@ func getLimitsString(config *clientpb.ImplantConfig) string { return strings.Join(limits, "; ") } -func checkBuildTargetCompatibility(format clientpb.OutputFormat, targetOS string, targetArch string, con *console.SliverConsoleClient) bool { +func checkBuildTargetCompatibility(format clientpb.OutputFormat, targetOS string, targetArch string, con *console.SliverClient) bool { if format == clientpb.OutputFormat_EXECUTABLE { return true // We don't need cross-compilers when targeting EXECUTABLE formats } @@ -1034,7 +1034,7 @@ func hasCC(targetOS string, targetArch string, crossCompilers []*clientpb.CrossC return false } -func warnMissingCrossCompiler(format clientpb.OutputFormat, targetOS string, targetArch string, con *console.SliverConsoleClient) bool { +func warnMissingCrossCompiler(format clientpb.OutputFormat, targetOS string, targetArch string, con *console.SliverClient) bool { con.PrintWarnf("Missing cross-compiler for %s on %s/%s\n", nameOfOutputFormat(format), targetOS, targetArch) switch targetOS { case "windows": @@ -1052,7 +1052,7 @@ func warnMissingCrossCompiler(format clientpb.OutputFormat, targetOS string, tar return confirm } -func findExternalBuilders(config *clientpb.ImplantConfig, con *console.SliverConsoleClient) ([]*clientpb.Builder, error) { +func findExternalBuilders(config *clientpb.ImplantConfig, con *console.SliverClient) ([]*clientpb.Builder, error) { builders, err := con.Rpc.Builders(context.Background(), &commonpb.Empty{}) if err != nil { return nil, err @@ -1078,7 +1078,7 @@ func findExternalBuilders(config *clientpb.ImplantConfig, con *console.SliverCon return validBuilders, nil } -func selectExternalBuilder(builders []*clientpb.Builder, con *console.SliverConsoleClient) (*clientpb.Builder, error) { +func selectExternalBuilder(builders []*clientpb.Builder, con *console.SliverClient) (*clientpb.Builder, error) { choices := []string{} for _, builder := range builders { choices = append(choices, builder.Name) diff --git a/client/command/generate/helpers.go b/client/command/generate/helpers.go index 554128bb2d..b545768661 100644 --- a/client/command/generate/helpers.go +++ b/client/command/generate/helpers.go @@ -11,7 +11,7 @@ import ( ) // GetSliverBinary - Get the binary of an implant based on it's profile. -func GetSliverBinary(profile *clientpb.ImplantProfile, con *console.SliverConsoleClient) ([]byte, error) { +func GetSliverBinary(profile *clientpb.ImplantProfile, con *console.SliverClient) ([]byte, error) { var data []byte // get implant builds builds, err := con.Rpc.ImplantBuilds(context.Background(), &commonpb.Empty{}) @@ -58,7 +58,7 @@ func GetSliverBinary(profile *clientpb.ImplantProfile, con *console.SliverConsol } // FormatCompleter completes builds' architectures. -func ArchCompleter(con *console.SliverConsoleClient) carapace.Action { +func ArchCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(_ carapace.Context) carapace.Action { compiler, err := con.Rpc.GetCompiler(context.Background(), &commonpb.Empty{}) if err != nil { @@ -92,7 +92,7 @@ func ArchCompleter(con *console.SliverConsoleClient) carapace.Action { } // FormatCompleter completes build operating systems. -func OSCompleter(con *console.SliverConsoleClient) carapace.Action { +func OSCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(_ carapace.Context) carapace.Action { compiler, err := con.Rpc.GetCompiler(context.Background(), &commonpb.Empty{}) if err != nil { @@ -135,7 +135,7 @@ func FormatCompleter() carapace.Action { } // TrafficEncoderCompleter - Completes the names of traffic encoders. -func TrafficEncodersCompleter(con *console.SliverConsoleClient) carapace.Action { +func TrafficEncodersCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { grpcCtx, cancel := con.GrpcContext(nil) defer cancel() diff --git a/client/command/generate/implants-rm.go b/client/command/generate/implants-rm.go index 9a95a9f56c..edf09a9c46 100644 --- a/client/command/generate/implants-rm.go +++ b/client/command/generate/implants-rm.go @@ -11,7 +11,7 @@ import ( ) // ImplantsRmCmd - Deletes an archived implant build from the server. -func ImplantsRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ImplantsRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name := args[0] // name := ctx.Args.String("name") if name == "" { diff --git a/client/command/generate/implants.go b/client/command/generate/implants.go index cc59a6bd75..4f69ea5c48 100644 --- a/client/command/generate/implants.go +++ b/client/command/generate/implants.go @@ -43,7 +43,7 @@ type ImplantBuildFilter struct { } // ImplantsCmd - Displays archived implant builds. -func ImplantsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ImplantsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { builds, err := con.Rpc.ImplantBuilds(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) @@ -59,7 +59,7 @@ func ImplantsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintImplantBuilds - Print the implant builds on the server. -func PrintImplantBuilds(configs map[string]*clientpb.ImplantConfig, filters ImplantBuildFilter, con *console.SliverConsoleClient) { +func PrintImplantBuilds(configs map[string]*clientpb.ImplantConfig, filters ImplantBuildFilter, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -123,7 +123,7 @@ func PrintImplantBuilds(configs map[string]*clientpb.ImplantConfig, filters Impl } // ImplantBuildNameCompleter - Completer for implant build names. -func ImplantBuildNameCompleter(con *console.SliverConsoleClient) carapace.Action { +func ImplantBuildNameCompleter(con *console.SliverClient) carapace.Action { comps := func(ctx carapace.Context) carapace.Action { var action carapace.Action @@ -193,7 +193,7 @@ func ImplantBuildNameCompleter(con *console.SliverConsoleClient) carapace.Action } // ImplantBuildByName - Get an implant build by name. -func ImplantBuildByName(name string, con *console.SliverConsoleClient) *clientpb.ImplantConfig { +func ImplantBuildByName(name string, con *console.SliverClient) *clientpb.ImplantConfig { builds, err := con.Rpc.ImplantBuilds(context.Background(), &commonpb.Empty{}) if err != nil { return nil diff --git a/client/command/generate/profiles-generate.go b/client/command/generate/profiles-generate.go index 7d127e7645..f0f2cf229d 100644 --- a/client/command/generate/profiles-generate.go +++ b/client/command/generate/profiles-generate.go @@ -29,7 +29,7 @@ import ( ) // ProfilesGenerateCmd - Generate an implant binary based on a profile. -func ProfilesGenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ProfilesGenerateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var name string if len(args) > 0 { name = args[0] diff --git a/client/command/generate/profiles-new.go b/client/command/generate/profiles-new.go index c4a6448cb7..4a481bf49c 100644 --- a/client/command/generate/profiles-new.go +++ b/client/command/generate/profiles-new.go @@ -26,7 +26,7 @@ import ( ) // ProfilesNewCmd - Create a new implant profile. -func ProfilesNewCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ProfilesNewCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var name string if len(args) > 0 { name = args[0] @@ -49,7 +49,7 @@ func ProfilesNewCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } // ProfilesNewBeaconCmd - Create a new beacon profile. -func ProfilesNewBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ProfilesNewBeaconCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var name string if len(args) > 0 { name = args[0] diff --git a/client/command/generate/profiles-rm.go b/client/command/generate/profiles-rm.go index 2df08c17a2..f0ab60b5b1 100644 --- a/client/command/generate/profiles-rm.go +++ b/client/command/generate/profiles-rm.go @@ -29,7 +29,7 @@ import ( ) // ProfilesRmCmd - Delete an implant profile. -func ProfilesRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ProfilesRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var name string if len(args) > 0 { name = args[0] diff --git a/client/command/generate/profiles.go b/client/command/generate/profiles.go index 5190127d53..dd0f7ef925 100644 --- a/client/command/generate/profiles.go +++ b/client/command/generate/profiles.go @@ -35,7 +35,7 @@ import ( ) // ProfilesCmd - Display implant profiles. -func ProfilesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ProfilesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { profiles := getImplantProfiles(con) if profiles == nil { return @@ -49,7 +49,7 @@ func ProfilesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintProfiles - Print the profiles. -func PrintProfiles(profiles []*clientpb.ImplantProfile, con *console.SliverConsoleClient) { +func PrintProfiles(profiles []*clientpb.ImplantProfile, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -96,7 +96,7 @@ func PrintProfiles(profiles []*clientpb.ImplantProfile, con *console.SliverConso con.Printf("%s\n", tw.Render()) } -func getImplantProfiles(con *console.SliverConsoleClient) []*clientpb.ImplantProfile { +func getImplantProfiles(con *console.SliverClient) []*clientpb.ImplantProfile { pbProfiles, err := con.Rpc.ImplantProfiles(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) @@ -106,7 +106,7 @@ func getImplantProfiles(con *console.SliverConsoleClient) []*clientpb.ImplantPro } // GetImplantProfileByName - Get an implant profile by a specific name. -func GetImplantProfileByName(name string, con *console.SliverConsoleClient) *clientpb.ImplantProfile { +func GetImplantProfileByName(name string, con *console.SliverClient) *clientpb.ImplantProfile { pbProfiles, err := con.Rpc.ImplantProfiles(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) @@ -263,7 +263,7 @@ func populateProfileProperties(config *clientpb.ImplantConfig) map[string]string } // PrintProfileInfo - Print detailed information about a given profile. -func PrintProfileInfo(name string, con *console.SliverConsoleClient) { +func PrintProfileInfo(name string, con *console.SliverClient) { profile := GetImplantProfileByName(name, con) if profile == nil { con.PrintErrorf("Could not find a profile with the name \"%s\"", name) @@ -420,7 +420,7 @@ func PrintProfileInfo(name string, con *console.SliverConsoleClient) { } // ProfileNameCompleter - Completer for implant build names. -func ProfileNameCompleter(con *console.SliverConsoleClient) carapace.Action { +func ProfileNameCompleter(con *console.SliverClient) carapace.Action { comps := func(ctx carapace.Context) carapace.Action { var action carapace.Action diff --git a/client/command/generate/regenerate.go b/client/command/generate/regenerate.go index 504bb044bd..4cf1105a3e 100644 --- a/client/command/generate/regenerate.go +++ b/client/command/generate/regenerate.go @@ -28,7 +28,7 @@ import ( ) // RegenerateCmd - Download an archived implant build/binary. -func RegenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RegenerateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { save, _ := cmd.Flags().GetString("save") if save == "" { save, _ = os.Getwd() diff --git a/client/command/generate/traffic-encoders.go b/client/command/generate/traffic-encoders.go index c7cb27cf55..c1ec8530d0 100644 --- a/client/command/generate/traffic-encoders.go +++ b/client/command/generate/traffic-encoders.go @@ -42,7 +42,7 @@ import ( ) // TrafficEncodersCmd - Generate traffic encoders command implementation. -func TrafficEncodersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func TrafficEncodersCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { grpcCtx, cancel := con.GrpcContext(cmd) defer cancel() encoderMap, err := con.Rpc.TrafficEncoderMap(grpcCtx, &commonpb.Empty{}) @@ -54,7 +54,7 @@ func TrafficEncodersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, ar } // DisplayTrafficEncoders - Display traffic encoders map from server. -func DisplayTrafficEncoders(encoderMap *clientpb.TrafficEncoderMap, con *console.SliverConsoleClient) { +func DisplayTrafficEncoders(encoderMap *clientpb.TrafficEncoderMap, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -83,7 +83,7 @@ func DisplayTrafficEncoders(encoderMap *clientpb.TrafficEncoderMap, con *console } // TrafficEncodersAddCmd - Add a new traffic encoder to the server. -func TrafficEncodersAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func TrafficEncodersAddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { grpcCtx, cancel := con.GrpcContext(cmd) defer cancel() @@ -166,7 +166,7 @@ func allTestsPassed(tests *clientpb.TrafficEncoderTests) bool { } // displayTrafficEncoderTests - Display traffic encoder tests in real time. -func displayTrafficEncoderTestProgress(testID string, completed chan interface{}, con *console.SliverConsoleClient) { +func displayTrafficEncoderTestProgress(testID string, completed chan interface{}, con *console.SliverClient) { listenerID, events := con.CreateEventListener() defer con.RemoveEventListener(listenerID) lineCount := 0 @@ -191,7 +191,7 @@ func displayTrafficEncoderTestProgress(testID string, completed chan interface{} } // clearLines - Clear a number of lines from the console. -func clearLines(count int, con *console.SliverConsoleClient) { +func clearLines(count int, con *console.SliverClient) { for i := 0; i < count; i++ { con.Printf(console.Clearln + "\r") con.Printf(console.UpN, 1) @@ -199,7 +199,7 @@ func clearLines(count int, con *console.SliverConsoleClient) { } // displayTrafficEncoderTests - Display the results of traffic encoder tests, return number of lines written. -func displayTrafficEncoderTests(running bool, tests *clientpb.TrafficEncoderTests, con *console.SliverConsoleClient) int { +func displayTrafficEncoderTests(running bool, tests *clientpb.TrafficEncoderTests, con *console.SliverClient) int { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -245,7 +245,7 @@ func displayTrafficEncoderTests(running bool, tests *clientpb.TrafficEncoderTest } // TrafficEncodersRemoveCmd - Remove a traffic encoder. -func TrafficEncodersRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func TrafficEncodersRemoveCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { _, cancel := con.GrpcContext(cmd) defer cancel() @@ -272,7 +272,7 @@ func TrafficEncodersRemoveCmd(cmd *cobra.Command, con *console.SliverConsoleClie } // SelectTrafficEncoder - Select a traffic encoder from a list. -func SelectTrafficEncoder(con *console.SliverConsoleClient) string { +func SelectTrafficEncoder(con *console.SliverClient) string { grpcCtx, cancel := con.GrpcContext(nil) defer cancel() encoders, err := con.Rpc.TrafficEncoderMap(grpcCtx, &commonpb.Empty{}) diff --git a/client/command/hosts/commands.go b/client/command/hosts/commands.go index e9a92634ef..49f1906872 100644 --- a/client/command/hosts/commands.go +++ b/client/command/hosts/commands.go @@ -1,17 +1,16 @@ package hosts import ( - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { hostsCmd := &cobra.Command{ Use: consts.HostsStr, Short: "Manage the database of hosts", diff --git a/client/command/hosts/hosts-ioc-rm.go b/client/command/hosts/hosts-ioc-rm.go index b8b2ad47fc..f009e3ee92 100644 --- a/client/command/hosts/hosts-ioc-rm.go +++ b/client/command/hosts/hosts-ioc-rm.go @@ -21,13 +21,12 @@ package hosts import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) -// HostsIOCRmCmd - Remove a host from the database -func HostsIOCRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// HostsIOCRmCmd - Remove a host from the database. +func HostsIOCRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { host, err := SelectHost(con) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/hosts/hosts-ioc.go b/client/command/hosts/hosts-ioc.go index b52d409995..4bc5657899 100644 --- a/client/command/hosts/hosts-ioc.go +++ b/client/command/hosts/hosts-ioc.go @@ -26,15 +26,14 @@ import ( "text/tabwriter" "github.com/AlecAivazis/survey/v2" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// HostsIOCCmd - Remove a host from the database -func HostsIOCCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// HostsIOCCmd - Remove a host from the database. +func HostsIOCCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { host, err := SelectHost(con) if err != nil { con.PrintErrorf("%s\n", err) @@ -48,7 +47,7 @@ func HostsIOCCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -func hostIOCsTable(host *clientpb.Host, con *console.SliverConsoleClient) string { +func hostIOCsTable(host *clientpb.Host, con *console.SliverClient) string { tw := table.NewWriter() tw.SetStyle(table.StyleBold) tw.AppendHeader(table.Row{"File Path", "SHA-256"}) @@ -61,7 +60,7 @@ func hostIOCsTable(host *clientpb.Host, con *console.SliverConsoleClient) string return tw.Render() } -func SelectHostIOC(host *clientpb.Host, con *console.SliverConsoleClient) (*clientpb.IOC, error) { +func SelectHostIOC(host *clientpb.Host, con *console.SliverClient) (*clientpb.IOC, error) { // Sort the keys because maps have a randomized order, these keys must be ordered for the selection // to work properly since we rely on the index of the user's selection to find the session in the map var keys []string diff --git a/client/command/hosts/hosts-rm.go b/client/command/hosts/hosts-rm.go index 0066ed5305..77a052f93c 100644 --- a/client/command/hosts/hosts-rm.go +++ b/client/command/hosts/hosts-rm.go @@ -21,13 +21,12 @@ package hosts import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) -// HostsRmCmd - Remove a host from the database -func HostsRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// HostsRmCmd - Remove a host from the database. +func HostsRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { host, err := SelectHost(con) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/hosts/hosts.go b/client/command/hosts/hosts.go index 5655183884..c694bc1d61 100644 --- a/client/command/hosts/hosts.go +++ b/client/command/hosts/hosts.go @@ -29,25 +29,23 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" - "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) var ( - // ErrNoHosts - No hosts in database + // ErrNoHosts - No hosts in database. ErrNoHosts = errors.New("no hosts") - // ErrNoSelection - No selection made + // ErrNoSelection - No selection made. ErrNoSelection = errors.New("no selection") ) -// HostsCmd - Main hosts command -func HostsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// HostsCmd - Main hosts command. +func HostsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { allHosts, err := con.Rpc.Hosts(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s", err) @@ -60,7 +58,7 @@ func HostsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin } } -func hostsTable(hosts []*clientpb.Host, con *console.SliverConsoleClient) string { +func hostsTable(hosts []*clientpb.Host, con *console.SliverClient) string { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -96,7 +94,7 @@ func hostsTable(hosts []*clientpb.Host, con *console.SliverConsoleClient) string return tw.Render() } -func hostSessions(hostUUID string, con *console.SliverConsoleClient) string { +func hostSessions(hostUUID string, con *console.SliverClient) string { hostSessions := SessionsForHost(hostUUID, con) if len(hostSessions) == 0 { return "None" @@ -108,7 +106,7 @@ func hostSessions(hostUUID string, con *console.SliverConsoleClient) string { return fmt.Sprintf("%d", len(sessionIDs)) } -func hostBeacons(hostUUID string, con *console.SliverConsoleClient) string { +func hostBeacons(hostUUID string, con *console.SliverClient) string { beacons, err := con.Rpc.GetBeacons(context.Background(), &commonpb.Empty{}) if err != nil { return "Error" @@ -126,8 +124,8 @@ func hostBeacons(hostUUID string, con *console.SliverConsoleClient) string { } } -// SessionsForHost - Find session for a given host by id -func SessionsForHost(hostUUID string, con *console.SliverConsoleClient) []*clientpb.Session { +// SessionsForHost - Find session for a given host by id. +func SessionsForHost(hostUUID string, con *console.SliverClient) []*clientpb.Session { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { return []*clientpb.Session{} @@ -141,8 +139,8 @@ func SessionsForHost(hostUUID string, con *console.SliverConsoleClient) []*clien return hostSessions } -// SelectHost - Interactively select a host from the database -func SelectHost(con *console.SliverConsoleClient) (*clientpb.Host, error) { +// SelectHost - Interactively select a host from the database. +func SelectHost(con *console.SliverClient) (*clientpb.Host, error) { allHosts, err := con.Rpc.Hosts(context.Background(), &commonpb.Empty{}) if err != nil { return nil, err diff --git a/client/command/info/commands.go b/client/command/info/commands.go index 64582c6877..98f919dd28 100644 --- a/client/command/info/commands.go +++ b/client/command/info/commands.go @@ -1,19 +1,18 @@ package info import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/command/use" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { infoCmd := &cobra.Command{ Use: consts.InfoStr, Short: "Get info about session", @@ -32,7 +31,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { } // SliverCommands returns all info commands working on an active target. -func SliverCommands(con *console.SliverConsoleClient) []*cobra.Command { +func SliverCommands(con *console.SliverClient) []*cobra.Command { pingCmd := &cobra.Command{ Use: consts.PingStr, Short: "Send round trip message to implant (does not use ICMP)", diff --git a/client/command/info/info.go b/client/command/info/info.go index b49083ab02..6910370fd4 100644 --- a/client/command/info/info.go +++ b/client/command/info/info.go @@ -22,18 +22,17 @@ import ( "context" "time" - "github.com/spf13/cobra" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/command/use" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// InfoCmd - Display information about the active session -func InfoCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// InfoCmd - Display information about the active session. +func InfoCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error // Check if we have an active target via 'use' @@ -110,8 +109,8 @@ func InfoCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } } -// PIDCmd - Get the active session's PID -func PIDCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// PIDCmd - Get the active session's PID. +func PIDCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -123,8 +122,8 @@ func PIDCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// UIDCmd - Get the active session's UID -func UIDCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// UIDCmd - Get the active session's UID. +func UIDCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -136,8 +135,8 @@ func UIDCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// GIDCmd - Get the active session's GID -func GIDCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// GIDCmd - Get the active session's GID. +func GIDCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -149,8 +148,8 @@ func GIDCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } } -// WhoamiCmd - Displays the current user of the active session -func WhoamiCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// WhoamiCmd - Displays the current user of the active session. +func WhoamiCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -195,7 +194,7 @@ func WhoamiCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } } -func PrintTokenOwner(cto *sliverpb.CurrentTokenOwner, con *console.SliverConsoleClient) { +func PrintTokenOwner(cto *sliverpb.CurrentTokenOwner, con *console.SliverClient) { if cto.Response != nil && cto.Response.Err != "" { con.PrintErrorf("%s\n", cto.Response.Err) return diff --git a/client/command/info/ping.go b/client/command/info/ping.go index e09ae18410..3dd75e1652 100644 --- a/client/command/info/ping.go +++ b/client/command/info/ping.go @@ -4,14 +4,13 @@ import ( "context" insecureRand "math/rand" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// PingCmd - Send a round trip C2 message to an implant (does not use ICMP) -func PingCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// PingCmd - Send a round trip C2 message to an implant (does not use ICMP). +func PingCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/jobs/commands.go b/client/command/jobs/commands.go index 17f255a77c..5de76356a8 100644 --- a/client/command/jobs/commands.go +++ b/client/command/jobs/commands.go @@ -1,19 +1,18 @@ package jobs import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/generate" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { // Job control jobsCmd := &cobra.Command{ Use: consts.JobsStr, diff --git a/client/command/jobs/dns.go b/client/command/jobs/dns.go index fc447adab6..4cbf4e8479 100644 --- a/client/command/jobs/dns.go +++ b/client/command/jobs/dns.go @@ -22,14 +22,13 @@ import ( "context" "strings" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// DNSListenerCmd - Start a DNS lisenter -func DNSListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// DNSListenerCmd - Start a DNS lisenter. +func DNSListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { domainsF, _ := cmd.Flags().GetString("domains") domains := strings.Split(domainsF, ",") for index, domain := range domains { diff --git a/client/command/jobs/http.go b/client/command/jobs/http.go index f4ac3941f6..10ea0bb6bb 100644 --- a/client/command/jobs/http.go +++ b/client/command/jobs/http.go @@ -22,14 +22,13 @@ import ( "context" "time" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// HTTPListenerCmd - Start an HTTP listener -func HTTPListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// HTTPListenerCmd - Start an HTTP listener. +func HTTPListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { domain, _ := cmd.Flags().GetString("domain") lhost, _ := cmd.Flags().GetString("lhost") lport, _ := cmd.Flags().GetUint32("lport") diff --git a/client/command/jobs/https.go b/client/command/jobs/https.go index 474c32b799..cbba4450a4 100644 --- a/client/command/jobs/https.go +++ b/client/command/jobs/https.go @@ -25,14 +25,13 @@ import ( "io/ioutil" "time" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// HTTPSListenerCmd - Start an HTTPS listener -func HTTPSListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// HTTPSListenerCmd - Start an HTTPS listener. +func HTTPSListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { domain, _ := cmd.Flags().GetString("domain") lhost, _ := cmd.Flags().GetString("lhost") lport, _ := cmd.Flags().GetUint32("lport") diff --git a/client/command/jobs/jobs.go b/client/command/jobs/jobs.go index e65ff66911..9522bc4642 100644 --- a/client/command/jobs/jobs.go +++ b/client/command/jobs/jobs.go @@ -25,19 +25,17 @@ import ( "strconv" "strings" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" - "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) -// JobsCmd - Manage server jobs (listeners, etc) -func JobsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// JobsCmd - Manage server jobs (listeners, etc). +func JobsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { if pid, _ := cmd.Flags().GetInt32("kill"); pid != -1 { jobKill(uint32(pid), con) } else if all, _ := cmd.Flags().GetBool("kill-all"); all { @@ -61,8 +59,8 @@ func JobsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } } -// PrintJobs - Prints a list of active jobs -func PrintJobs(jobs map[uint32]*clientpb.Job, con *console.SliverConsoleClient) { +// PrintJobs - Prints a list of active jobs. +func PrintJobs(jobs map[uint32]*clientpb.Job, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -91,7 +89,7 @@ func PrintJobs(jobs map[uint32]*clientpb.Job, con *console.SliverConsoleClient) } // JobsIDCompleter completes jobs IDs with descriptions. -func JobsIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func JobsIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { jobs, err := con.Rpc.GetJobs(context.Background(), &commonpb.Empty{}) if err != nil { @@ -112,7 +110,7 @@ func JobsIDCompleter(con *console.SliverConsoleClient) carapace.Action { return carapace.ActionCallback(callback) } -func jobKill(jobID uint32, con *console.SliverConsoleClient) { +func jobKill(jobID uint32, con *console.SliverClient) { con.PrintInfof("Killing job #%d ...\n", jobID) jobKill, err := con.Rpc.KillJob(context.Background(), &clientpb.KillJobReq{ ID: jobID, @@ -124,7 +122,7 @@ func jobKill(jobID uint32, con *console.SliverConsoleClient) { } } -func killAllJobs(con *console.SliverConsoleClient) { +func killAllJobs(con *console.SliverClient) { jobs, err := con.Rpc.GetJobs(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/jobs/mtls.go b/client/command/jobs/mtls.go index 89f87cbe34..4c918e2914 100644 --- a/client/command/jobs/mtls.go +++ b/client/command/jobs/mtls.go @@ -21,14 +21,13 @@ package jobs import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// MTLSListenerCmd - Start an mTLS listener -func MTLSListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// MTLSListenerCmd - Start an mTLS listener. +func MTLSListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { lhost, _ := cmd.Flags().GetString("lhost") lport, _ := cmd.Flags().GetUint32("lport") persistent, _ := cmd.Flags().GetBool("persistent") diff --git a/client/command/jobs/stage.go b/client/command/jobs/stage.go index d14b29df91..bd779139cd 100644 --- a/client/command/jobs/stage.go +++ b/client/command/jobs/stage.go @@ -27,18 +27,16 @@ import ( "strconv" "strings" - "github.com/spf13/cobra" - - "github.com/bishopfox/sliver/util/encoders" - "github.com/bishopfox/sliver/client/command/generate" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/util" + "github.com/bishopfox/sliver/util/encoders" + "github.com/spf13/cobra" ) -// StageListenerCmd --url [tcp://ip:port | http://ip:port ] --profile name -func StageListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// StageListenerCmd --url [tcp://ip:port | http://ip:port ] --profile name. +func StageListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { profileName, _ := cmd.Flags().GetString("profile") listenerURL, _ := cmd.Flags().GetString("url") aesEncryptKey, _ := cmd.Flags().GetString("aes-encrypt-key") diff --git a/client/command/jobs/wg.go b/client/command/jobs/wg.go index 9cc244be1c..1f7ae6d8cd 100644 --- a/client/command/jobs/wg.go +++ b/client/command/jobs/wg.go @@ -21,14 +21,13 @@ package jobs import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// WGListenerCmd - Start a WireGuard listener -func WGListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// WGListenerCmd - Start a WireGuard listener. +func WGListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { lport, _ := cmd.Flags().GetUint32("lport") nport, _ := cmd.Flags().GetUint32("nport") keyExchangePort, _ := cmd.Flags().GetUint32("key-port") diff --git a/client/command/kill/commands.go b/client/command/kill/commands.go index e9b0bdac15..2128351edc 100644 --- a/client/command/kill/commands.go +++ b/client/command/kill/commands.go @@ -11,7 +11,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { killCmd := &cobra.Command{ Use: consts.KillStr, Short: "Kill a session", diff --git a/client/command/kill/kill.go b/client/command/kill/kill.go index 4c982d855d..250a104e95 100644 --- a/client/command/kill/kill.go +++ b/client/command/kill/kill.go @@ -32,7 +32,7 @@ import ( ) // KillCmd - Kill the active session (not to be confused with TerminateCmd) -func KillCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func KillCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() // Confirm with the user, just in case they confused kill with terminate confirm := false @@ -67,7 +67,7 @@ func KillCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string con.PrintErrorf("No active session or beacon\n") } -func KillSession(session *clientpb.Session, cmd *cobra.Command, con *console.SliverConsoleClient) error { +func KillSession(session *clientpb.Session, cmd *cobra.Command, con *console.SliverClient) error { if session == nil { return errors.New("session does not exist") } @@ -84,7 +84,7 @@ func KillSession(session *clientpb.Session, cmd *cobra.Command, con *console.Sli return err } -func KillBeacon(beacon *clientpb.Beacon, cmd *cobra.Command, con *console.SliverConsoleClient) error { +func KillBeacon(beacon *clientpb.Beacon, cmd *cobra.Command, con *console.SliverClient) error { if beacon == nil { return errors.New("session does not exist") } diff --git a/client/command/licenses/commands.go b/client/command/licenses/commands.go index d0a9b18396..e1ade622e5 100644 --- a/client/command/licenses/commands.go +++ b/client/command/licenses/commands.go @@ -10,7 +10,7 @@ import ( ) // Commands returns the `licences` command. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { licensesCmd := &cobra.Command{ Use: consts.LicensesStr, Short: "Open source licenses", diff --git a/client/command/loot/commands.go b/client/command/loot/commands.go index 8b2368f4b5..dd22b06216 100644 --- a/client/command/loot/commands.go +++ b/client/command/loot/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { lootCmd := &cobra.Command{ Use: consts.LootStr, Short: "Manage the server's loot store", @@ -120,11 +120,11 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { } // FileTypeCompleter completes valid filetypes for loot. -func FileTypeCompleter(con *console.SliverConsoleClient) carapace.Action { +func FileTypeCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionValues("binary", "text").Tag("loot file type") } // LootTypeCompleter completes valid loot type for a loot. -func LootTypeCompleter(con *console.SliverConsoleClient) carapace.Action { +func LootTypeCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionValues("file", "cred").Tag("loot type") } diff --git a/client/command/loot/fetch.go b/client/command/loot/fetch.go index 0688fe0630..5f778da404 100644 --- a/client/command/loot/fetch.go +++ b/client/command/loot/fetch.go @@ -27,7 +27,7 @@ import ( ) // LootFetchCmd - Display the contents of or download a piece of loot -func LootFetchCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func LootFetchCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { loot, err := SelectLoot(cmd, con.Rpc) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/loot/local.go b/client/command/loot/local.go index 696cf44301..446a595f71 100644 --- a/client/command/loot/local.go +++ b/client/command/loot/local.go @@ -33,7 +33,7 @@ import ( ) // LootAddLocalCmd - Add a local file to the server as loot -func LootAddLocalCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func LootAddLocalCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { localPath := args[0] if _, err := os.Stat(localPath); os.IsNotExist(err) { con.PrintErrorf("Path '%s' not found\n", localPath) diff --git a/client/command/loot/loot.go b/client/command/loot/loot.go index 0fbf41a3c9..faf48d9fdb 100644 --- a/client/command/loot/loot.go +++ b/client/command/loot/loot.go @@ -38,7 +38,7 @@ import ( ) // LootCmd - The loot root command -func LootCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func LootCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { allLoot, err := con.Rpc.LootAll(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("Failed to fetch loot %s\n", err) @@ -48,7 +48,7 @@ func LootCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } // PrintAllFileLootTable - Displays a table of all file loot -func PrintAllFileLootTable(allLoot *clientpb.AllLoot, con *console.SliverConsoleClient) { +func PrintAllFileLootTable(allLoot *clientpb.AllLoot, con *console.SliverClient) { if allLoot == nil || len(allLoot.Loot) == 0 { con.PrintInfof("No loot 🙁\n") return @@ -77,7 +77,7 @@ func PrintAllFileLootTable(allLoot *clientpb.AllLoot, con *console.SliverConsole } // PrintLootFile - Display the contents of a piece of loot -func PrintLootFile(loot *clientpb.Loot, con *console.SliverConsoleClient) { +func PrintLootFile(loot *clientpb.Loot, con *console.SliverClient) { if loot.File == nil { return } diff --git a/client/command/loot/remote.go b/client/command/loot/remote.go index 3b8460a504..940fbc4f25 100644 --- a/client/command/loot/remote.go +++ b/client/command/loot/remote.go @@ -55,7 +55,7 @@ func ValidateLootFileType(lootFileTypeInput string, data []byte) clientpb.FileTy Eventually this function needs to be refactored out, but we made the decision to duplicate it for now */ -func PerformDownload(remotePath string, fileName string, cmd *cobra.Command, con *console.SliverConsoleClient) (*sliverpb.Download, error) { +func PerformDownload(remotePath string, fileName string, cmd *cobra.Command, con *console.SliverClient) (*sliverpb.Download, error) { ctrl := make(chan bool) con.SpinUntil(fmt.Sprintf("%s -> %s", fileName, "loot"), ctrl) download, err := con.Rpc.Download(context.Background(), &sliverpb.DownloadReq{ @@ -107,7 +107,7 @@ func CreateLootMessage(fileName string, lootName string, lootFileType clientpb.F return lootMessage } -func SendLootMessage(loot *clientpb.Loot, con *console.SliverConsoleClient) { +func SendLootMessage(loot *clientpb.Loot, con *console.SliverClient) { control := make(chan bool) con.SpinUntil(fmt.Sprintf("Sending looted file (%s) to the server...", loot.Name), control) @@ -125,7 +125,7 @@ func SendLootMessage(loot *clientpb.Loot, con *console.SliverConsoleClient) { } } -func LootDownload(download *sliverpb.Download, lootName string, fileType clientpb.FileType, cmd *cobra.Command, con *console.SliverConsoleClient) { +func LootDownload(download *sliverpb.Download, lootName string, fileType clientpb.FileType, cmd *cobra.Command, con *console.SliverClient) { // Was the download successful? if download.Response != nil && download.Response.Err != "" { con.PrintErrorf("%s\n", download.Response.Err) @@ -198,7 +198,7 @@ func LootDownload(download *sliverpb.Download, lootName string, fileType clientp } // LootAddRemoteCmd - Add a file from the remote system to the server as loot -func LootAddRemoteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func LootAddRemoteCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/loot/rename.go b/client/command/loot/rename.go index ad45133016..0666870d67 100644 --- a/client/command/loot/rename.go +++ b/client/command/loot/rename.go @@ -29,7 +29,7 @@ import ( ) // LootRenameCmd - Rename a piece of loot -func LootRenameCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func LootRenameCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { loot, err := SelectLoot(cmd, con.Rpc) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/loot/rm.go b/client/command/loot/rm.go index fef220e102..7377fba9d4 100644 --- a/client/command/loot/rm.go +++ b/client/command/loot/rm.go @@ -26,7 +26,7 @@ import ( "github.com/bishopfox/sliver/client/console" ) -func LootRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func LootRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { loot, err := SelectLoot(cmd, con.Rpc) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/monitor/commands.go b/client/command/monitor/commands.go index 3a3080ee5d..da7c962e0c 100644 --- a/client/command/monitor/commands.go +++ b/client/command/monitor/commands.go @@ -8,7 +8,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { monitorCmd := &cobra.Command{ Use: consts.MonitorStr, Short: "Monitor threat intel platforms for Sliver implants", diff --git a/client/command/monitor/start.go b/client/command/monitor/start.go index d9133591e1..bafb59b16e 100644 --- a/client/command/monitor/start.go +++ b/client/command/monitor/start.go @@ -28,7 +28,7 @@ import ( ) // MonitorStartCmd - Start monitoring threat intel for implants -func MonitorStartCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func MonitorStartCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { resp, err := con.Rpc.MonitorStart(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/monitor/stop.go b/client/command/monitor/stop.go index d4b553ea23..5857750e60 100644 --- a/client/command/monitor/stop.go +++ b/client/command/monitor/stop.go @@ -28,7 +28,7 @@ import ( ) // MonitorStopCmd - Stop monitoring threat intel for implants -func MonitorStopCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func MonitorStopCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { _, err := con.Rpc.MonitorStop(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/network/commands.go b/client/command/network/commands.go index 31fd801e9f..137e5f68c5 100644 --- a/client/command/network/commands.go +++ b/client/command/network/commands.go @@ -11,7 +11,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { ifconfigCmd := &cobra.Command{ Use: consts.IfconfigStr, Short: "View network interface configurations", diff --git a/client/command/network/ifconfig.go b/client/command/network/ifconfig.go index 529b17d314..d72969cc5a 100644 --- a/client/command/network/ifconfig.go +++ b/client/command/network/ifconfig.go @@ -36,7 +36,7 @@ import ( ) // IfconfigCmd - Display network interfaces on the remote system -func IfconfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func IfconfigCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -65,7 +65,7 @@ func IfconfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintIfconfig - Print the ifconfig response -func PrintIfconfig(ifconfig *sliverpb.Ifconfig, all bool, con *console.SliverConsoleClient) { +func PrintIfconfig(ifconfig *sliverpb.Ifconfig, all bool, con *console.SliverClient) { var err error interfaces := ifconfig.NetInterfaces sort.Slice(interfaces, func(i, j int) bool { diff --git a/client/command/network/netstat.go b/client/command/network/netstat.go index e576c6e543..452c6d672f 100644 --- a/client/command/network/netstat.go +++ b/client/command/network/netstat.go @@ -34,7 +34,7 @@ import ( ) // NetstatCmd - Display active network connections on the remote system -func NetstatCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func NetstatCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -77,7 +77,7 @@ func NetstatCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str } } -func PrintNetstat(netstat *sliverpb.Netstat, implantPID int32, activeC2 string, numeric bool, con *console.SliverConsoleClient) { +func PrintNetstat(netstat *sliverpb.Netstat, implantPID int32, activeC2 string, numeric bool, con *console.SliverClient) { lookup := func(skaddr *sliverpb.SockTabEntry_SockAddr) string { addr := skaddr.Ip names, err := net.LookupAddr(addr) diff --git a/client/command/operators/commands.go b/client/command/operators/commands.go index 2713a124b3..f1da25a801 100644 --- a/client/command/operators/commands.go +++ b/client/command/operators/commands.go @@ -1,17 +1,16 @@ package operators import ( - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { operatorsCmd := &cobra.Command{ Use: consts.OperatorsStr, Short: "Manage operators", diff --git a/client/command/operators/operators.go b/client/command/operators/operators.go index 792d227ca9..6fac8d9d8f 100644 --- a/client/command/operators/operators.go +++ b/client/command/operators/operators.go @@ -21,18 +21,16 @@ package operators import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" - "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// OperatorsCmd - Display operators and current online status -func OperatorsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// OperatorsCmd - Display operators and current online status. +func OperatorsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { operators, err := con.Rpc.GetOperators(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) @@ -43,7 +41,7 @@ func OperatorsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s } } -func displayOperators(operators []*clientpb.Operator, con *console.SliverConsoleClient) { +func displayOperators(operators []*clientpb.Operator, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ diff --git a/client/command/pivots/commands.go b/client/command/pivots/commands.go index 9a3362da71..92a0b7db73 100644 --- a/client/command/pivots/commands.go +++ b/client/command/pivots/commands.go @@ -13,7 +13,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { pivotsCmd := &cobra.Command{ Use: consts.PivotsStr, Short: "List pivots for active session", diff --git a/client/command/pivots/details.go b/client/command/pivots/details.go index db21e9dde2..c7ab12571b 100644 --- a/client/command/pivots/details.go +++ b/client/command/pivots/details.go @@ -31,7 +31,7 @@ import ( ) // PivotDetailsCmd - Display pivots for all sessions -func PivotDetailsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func PivotDetailsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -71,7 +71,7 @@ func PivotDetailsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } // PrintPivotListenerDetails - Print details of a single pivot listener -func PrintPivotListenerDetails(listener *sliverpb.PivotListener, con *console.SliverConsoleClient) { +func PrintPivotListenerDetails(listener *sliverpb.PivotListener, con *console.SliverClient) { con.Printf("\n") con.Printf(" ID: %d\n", listener.ID) con.Printf(" Protocol: %s\n", PivotTypeToString(listener.Type)) diff --git a/client/command/pivots/graph.go b/client/command/pivots/graph.go index 0c8ad0f3ce..8872cd631a 100644 --- a/client/command/pivots/graph.go +++ b/client/command/pivots/graph.go @@ -23,14 +23,13 @@ import ( "encoding/json" "fmt" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/spf13/cobra" ) -// PivotsGraphCmd - Display pivots for all sessions -func PivotsGraphCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// PivotsGraphCmd - Display pivots for all sessions. +func PivotsGraphCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { graph, err := con.Rpc.PivotGraph(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/pivots/helpers.go b/client/command/pivots/helpers.go index b83f27a9b2..328043d0c6 100644 --- a/client/command/pivots/helpers.go +++ b/client/command/pivots/helpers.go @@ -28,14 +28,13 @@ import ( "text/tabwriter" "github.com/AlecAivazis/survey/v2" - "github.com/rsteube/carapace" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/rsteube/carapace" ) -// SelectPivotListener - Interactive menu to select a pivot listener -func SelectPivotListener(listeners []*sliverpb.PivotListener, con *console.SliverConsoleClient) (*sliverpb.PivotListener, error) { +// SelectPivotListener - Interactive menu to select a pivot listener. +func SelectPivotListener(listeners []*sliverpb.PivotListener, con *console.SliverClient) (*sliverpb.PivotListener, error) { // Render selection table buf := bytes.NewBufferString("") table := tabwriter.NewWriter(buf, 0, 2, 2, ' ', 0) @@ -67,7 +66,7 @@ func SelectPivotListener(listeners []*sliverpb.PivotListener, con *console.Slive } // PivotIDCompleter completes pivot listeners' IDs. -func PivotIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func PivotIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/pivots/pivots.go b/client/command/pivots/pivots.go index a883bdbdab..60de8dec39 100644 --- a/client/command/pivots/pivots.go +++ b/client/command/pivots/pivots.go @@ -21,16 +21,15 @@ package pivots import ( "context" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// PivotsCmd - Display pivots for all sessions -func PivotsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// PivotsCmd - Display pivots for all sessions. +func PivotsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -54,8 +53,8 @@ func PivotsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } } -// PrintPivotListeners - Print a table of pivot listeners -func PrintPivotListeners(pivotListeners []*sliverpb.PivotListener, con *console.SliverConsoleClient) { +// PrintPivotListeners - Print a table of pivot listeners. +func PrintPivotListeners(pivotListeners []*sliverpb.PivotListener, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ @@ -75,7 +74,7 @@ func PrintPivotListeners(pivotListeners []*sliverpb.PivotListener, con *console. con.Printf("%s\n", tw.Render()) } -// PivotTypeToString - Convert a pivot type to a human string +// PivotTypeToString - Convert a pivot type to a human string. func PivotTypeToString(pivotType sliverpb.PivotType) string { switch pivotType { case sliverpb.PivotType_TCP: diff --git a/client/command/pivots/start.go b/client/command/pivots/start.go index 34658b9eea..67e00e9041 100644 --- a/client/command/pivots/start.go +++ b/client/command/pivots/start.go @@ -22,14 +22,13 @@ import ( "context" "fmt" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// StartTCPListenerCmd - Start a TCP pivot listener on the remote system -func StartTCPListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// StartTCPListenerCmd - Start a TCP pivot listener on the remote system. +func StartTCPListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -52,8 +51,8 @@ func StartTCPListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, a con.PrintInfof("Started tcp pivot listener %s with id %d\n", listener.BindAddress, listener.ID) } -// StartNamedPipeListenerCmd - Start a TCP pivot listener on the remote system -func StartNamedPipeListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// StartNamedPipeListenerCmd - Start a TCP pivot listener on the remote system. +func StartNamedPipeListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/pivots/stop.go b/client/command/pivots/stop.go index 39caac33ab..6487d08e4d 100644 --- a/client/command/pivots/stop.go +++ b/client/command/pivots/stop.go @@ -28,7 +28,7 @@ import ( ) // StopPivotListenerCmd - Start a TCP pivot listener on the remote system -func StopPivotListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func StopPivotListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/portfwd/commands.go b/client/command/portfwd/commands.go index 629e56cfe6..15c9b0a0b9 100644 --- a/client/command/portfwd/commands.go +++ b/client/command/portfwd/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { portfwdCmd := &cobra.Command{ Use: consts.PortfwdStr, Short: "In-band TCP port forwarding", diff --git a/client/command/portfwd/portfwd-add.go b/client/command/portfwd/portfwd-add.go index 2b494cb9c2..42c481ea2d 100644 --- a/client/command/portfwd/portfwd-add.go +++ b/client/command/portfwd/portfwd-add.go @@ -34,7 +34,7 @@ import ( var portNumberOnlyRegexp = regexp.MustCompile("^[0-9]+$") // PortfwdAddCmd - Add a new tunneled port forward. -func PortfwdAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func PortfwdAddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/portfwd/portfwd-rm.go b/client/command/portfwd/portfwd-rm.go index 8f940e4abb..ab648b3f24 100644 --- a/client/command/portfwd/portfwd-rm.go +++ b/client/command/portfwd/portfwd-rm.go @@ -25,7 +25,7 @@ import ( ) // PortfwdRmCmd - Remove an existing tunneled port forward. -func PortfwdRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func PortfwdRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { portfwdID, _ := cmd.Flags().GetInt("id") if portfwdID < 1 { con.PrintErrorf("Must specify a valid portfwd id\n") diff --git a/client/command/portfwd/portfwd.go b/client/command/portfwd/portfwd.go index abbd7b660a..b8daedfd39 100644 --- a/client/command/portfwd/portfwd.go +++ b/client/command/portfwd/portfwd.go @@ -32,12 +32,12 @@ import ( ) // PortfwdCmd - Display information about tunneled port forward(s). -func PortfwdCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func PortfwdCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { PrintPortfwd(con) } // PrintPortfwd - Print the port forward(s). -func PrintPortfwd(con *console.SliverConsoleClient) { +func PrintPortfwd(con *console.SliverClient) { portfwds := core.Portfwds.List() if len(portfwds) == 0 { con.PrintInfof("No port forwards\n") @@ -67,7 +67,7 @@ func PrintPortfwd(con *console.SliverConsoleClient) { } // PortfwdIDCompleter completes IDs of local portforwarders. -func PortfwdIDCompleter(_ *console.SliverConsoleClient) carapace.Action { +func PortfwdIDCompleter(_ *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/prelude-operator/commands.go b/client/command/prelude-operator/commands.go index 9167d3037b..f152788fdf 100644 --- a/client/command/prelude-operator/commands.go +++ b/client/command/prelude-operator/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { operatorCmd := &cobra.Command{ Use: consts.PreludeOperatorStr, Short: "Manage connection to Prelude's Operator", diff --git a/client/command/prelude-operator/connect.go b/client/command/prelude-operator/connect.go index 93e9ee9c10..be07ff9aba 100644 --- a/client/command/prelude-operator/connect.go +++ b/client/command/prelude-operator/connect.go @@ -29,7 +29,7 @@ import ( "github.com/bishopfox/sliver/protobuf/commonpb" ) -func ConnectCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ConnectCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { url := args[0] aesKey, _ := cmd.Flags().GetString("aes-key") agentRange, _ := cmd.Flags().GetString("range") diff --git a/client/command/prelude-operator/operator.go b/client/command/prelude-operator/operator.go index af91ba9d4f..f36a692150 100644 --- a/client/command/prelude-operator/operator.go +++ b/client/command/prelude-operator/operator.go @@ -25,7 +25,7 @@ import ( "github.com/bishopfox/sliver/client/prelude" ) -func OperatorCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func OperatorCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { if prelude.ImplantMapper != nil { con.PrintInfof("Connected to Operator at %s\n", prelude.ImplantMapper.GetConfig().OperatorURL) return diff --git a/client/command/privilege/commands.go b/client/command/privilege/commands.go index 995fec1bc8..32095e4a7d 100644 --- a/client/command/privilege/commands.go +++ b/client/command/privilege/commands.go @@ -13,7 +13,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { runAsCmd := &cobra.Command{ Use: consts.RunAsStr, Short: "Run a new process in the context of the designated user (Windows Only)", diff --git a/client/command/privilege/getprivs.go b/client/command/privilege/getprivs.go index 13baa95a01..6dcc14307e 100644 --- a/client/command/privilege/getprivs.go +++ b/client/command/privilege/getprivs.go @@ -32,7 +32,7 @@ import ( ) // GetPrivsCmd - Get the current process privileges (Windows only) -func GetPrivsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func GetPrivsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -67,7 +67,7 @@ func GetPrivsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintGetPrivs - Print the results of the get privs command -func PrintGetPrivs(privs *sliverpb.GetPrivs, pid int32, con *console.SliverConsoleClient) { +func PrintGetPrivs(privs *sliverpb.GetPrivs, pid int32, con *console.SliverClient) { // Response is the Envelope (see RPC API), Err is part of it. if privs.Response != nil && privs.Response.Err != "" { con.PrintErrorf("NOTE: Information may be incomplete due to an error:\n") diff --git a/client/command/privilege/getsystem.go b/client/command/privilege/getsystem.go index 42771d77ba..20b862760b 100644 --- a/client/command/privilege/getsystem.go +++ b/client/command/privilege/getsystem.go @@ -31,7 +31,7 @@ import ( ) // GetSystemCmd - Windows only, attempt to get SYSTEM on the remote system -func GetSystemCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func GetSystemCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -75,7 +75,7 @@ func GetSystemCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s } // PrintGetSystem - Print the results of get system -func PrintGetSystem(getsystemResp *sliverpb.GetSystem, con *console.SliverConsoleClient) { +func PrintGetSystem(getsystemResp *sliverpb.GetSystem, con *console.SliverClient) { if getsystemResp.Response != nil && getsystemResp.Response.GetErr() != "" { con.PrintErrorf("%s\n", getsystemResp.GetResponse().GetErr()) return diff --git a/client/command/privilege/impersonate.go b/client/command/privilege/impersonate.go index 5fb3290726..95d764e81f 100644 --- a/client/command/privilege/impersonate.go +++ b/client/command/privilege/impersonate.go @@ -31,7 +31,7 @@ import ( ) // ImpersonateCmd - Windows only, impersonate a user token -func ImpersonateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ImpersonateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -63,7 +63,7 @@ func ImpersonateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } // PrintImpersonate - Print the results of the attempted impersonation -func PrintImpersonate(impersonate *sliverpb.Impersonate, username string, con *console.SliverConsoleClient) { +func PrintImpersonate(impersonate *sliverpb.Impersonate, username string, con *console.SliverClient) { if impersonate.Response != nil && impersonate.Response.GetErr() != "" { con.PrintErrorf("%s\n", impersonate.Response.GetErr()) return diff --git a/client/command/privilege/make-token.go b/client/command/privilege/make-token.go index ae1ee3fcc1..f3b02aad01 100644 --- a/client/command/privilege/make-token.go +++ b/client/command/privilege/make-token.go @@ -41,7 +41,7 @@ var logonTypes = map[string]uint32{ } // MakeTokenCmd - Windows only, create a token using "valid" credentails -func MakeTokenCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func MakeTokenCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -95,7 +95,7 @@ func MakeTokenCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s } // PrintMakeToken - Print the results of attempting to make a token -func PrintMakeToken(makeToken *sliverpb.MakeToken, domain string, username string, con *console.SliverConsoleClient) { +func PrintMakeToken(makeToken *sliverpb.MakeToken, domain string, username string, con *console.SliverClient) { if makeToken.Response != nil && makeToken.Response.GetErr() != "" { con.PrintErrorf("%s\n", makeToken.Response.GetErr()) return diff --git a/client/command/privilege/rev2self.go b/client/command/privilege/rev2self.go index 2b5dea324a..069b8b329a 100644 --- a/client/command/privilege/rev2self.go +++ b/client/command/privilege/rev2self.go @@ -31,7 +31,7 @@ import ( ) // RevToSelfCmd - Drop any impersonated tokens -func RevToSelfCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RevToSelfCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -61,7 +61,7 @@ func RevToSelfCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s } // PrintRev2Self - Print the result of revert to self -func PrintRev2Self(revert *sliverpb.RevToSelf, con *console.SliverConsoleClient) { +func PrintRev2Self(revert *sliverpb.RevToSelf, con *console.SliverClient) { if revert.Response != nil && revert.Response.GetErr() != "" { con.PrintErrorf("%s\n", revert.Response.GetErr()) return diff --git a/client/command/privilege/runas.go b/client/command/privilege/runas.go index a83e6c5576..ade8aa8768 100644 --- a/client/command/privilege/runas.go +++ b/client/command/privilege/runas.go @@ -31,7 +31,7 @@ import ( ) // RunAsCmd - Run a command as another user on the remote system -func RunAsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RunAsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -87,7 +87,7 @@ func RunAsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin } // PrintRunAs - Print the result of run as -func PrintRunAs(runAs *sliverpb.RunAs, process string, args string, name string, con *console.SliverConsoleClient) { +func PrintRunAs(runAs *sliverpb.RunAs, process string, args string, name string, con *console.SliverClient) { if runAs.Response != nil && runAs.Response.GetErr() != "" { con.PrintErrorf("%s\n", runAs.Response.GetErr()) return diff --git a/client/command/processes/commands.go b/client/command/processes/commands.go index 9fab3d63c5..b473d89648 100644 --- a/client/command/processes/commands.go +++ b/client/command/processes/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { psCmd := &cobra.Command{ Use: consts.PsStr, Short: "List remote processes", diff --git a/client/command/processes/procdump.go b/client/command/processes/procdump.go index 904de72bab..bd3f59d75e 100644 --- a/client/command/processes/procdump.go +++ b/client/command/processes/procdump.go @@ -36,7 +36,7 @@ import ( ) // ProcdumpCmd - Dump the memory of a remote process -func ProcdumpCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ProcdumpCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -107,7 +107,7 @@ func ProcdumpCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintProcessDump - Handle the results of a process dump -func PrintProcessDump(dump *sliverpb.ProcessDump, saveTo string, hostname string, pid int, con *console.SliverConsoleClient) { +func PrintProcessDump(dump *sliverpb.ProcessDump, saveTo string, hostname string, pid int, con *console.SliverClient) { var err error var saveToFile *os.File if saveTo == "" { @@ -139,7 +139,7 @@ func getHostname(session *clientpb.Session, beacon *clientpb.Beacon) string { return "" } -func LootProcessDump(dump *sliverpb.ProcessDump, lootName string, hostName string, pid int, con *console.SliverConsoleClient) { +func LootProcessDump(dump *sliverpb.ProcessDump, lootName string, hostName string, pid int, con *console.SliverClient) { timeNow := time.Now().UTC() dumpFileName := fmt.Sprintf("procdump_%s_%d_%s.dmp", hostName, pid, timeNow.Format("20060102150405")) diff --git a/client/command/processes/ps.go b/client/command/processes/ps.go index 73d7da514b..dbea16aa30 100644 --- a/client/command/processes/ps.go +++ b/client/command/processes/ps.go @@ -89,7 +89,7 @@ var knownSecurityTools = map[string][]string{ } // PsCmd - List processes on the remote system -func PsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func PsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -137,7 +137,7 @@ func getOS(session *clientpb.Session, beacon *clientpb.Beacon) string { } // PrintPS - Prints the process list -func PrintPS(os string, ps *sliverpb.Ps, interactive bool, flags *pflag.FlagSet, con *console.SliverConsoleClient) { +func PrintPS(os string, ps *sliverpb.Ps, interactive bool, flags *pflag.FlagSet, con *console.SliverClient) { pidFilter, _ := flags.GetInt("pid") exeFilter, _ := flags.GetString("exe") ownerFilter, _ := flags.GetString("owner") @@ -212,7 +212,7 @@ func findKnownSecurityProducts(ps *sliverpb.Ps) []string { } // procRow - Stylizes the process information -func procRow(tw table.Writer, proc *commonpb.Process, cmdLine bool, con *console.SliverConsoleClient) table.Row { +func procRow(tw table.Writer, proc *commonpb.Process, cmdLine bool, con *console.SliverClient) table.Row { session, beacon := con.ActiveTarget.GetInteractive() color := console.Normal @@ -287,7 +287,7 @@ func procRow(tw table.Writer, proc *commonpb.Process, cmdLine bool, con *console } // GetPIDByName - Get a PID by name from the active session -func GetPIDByName(cmd *cobra.Command, name string, con *console.SliverConsoleClient) int { +func GetPIDByName(cmd *cobra.Command, name string, con *console.SliverClient) int { ps, err := con.Rpc.Ps(context.Background(), &sliverpb.PsReq{ Request: con.ActiveTarget.Request(cmd), }) diff --git a/client/command/processes/terminate.go b/client/command/processes/terminate.go index b00f35f804..f7b91d9983 100644 --- a/client/command/processes/terminate.go +++ b/client/command/processes/terminate.go @@ -31,7 +31,7 @@ import ( ) // TerminateCmd - Terminate a process on the remote system -func TerminateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func TerminateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { con.PrintErrorf("No active session or beacon\n") @@ -72,7 +72,7 @@ func TerminateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s } // PrintTerminate - Print the results of the terminate command -func PrintTerminate(terminated *sliverpb.Terminate, con *console.SliverConsoleClient) { +func PrintTerminate(terminated *sliverpb.Terminate, con *console.SliverClient) { if terminated.Response != nil && terminated.Response.GetErr() != "" { con.PrintErrorf("%s\n", terminated.Response.GetErr()) } else { diff --git a/client/command/reaction/commands.go b/client/command/reaction/commands.go index 5c8d215a30..4e4e9c7929 100644 --- a/client/command/reaction/commands.go +++ b/client/command/reaction/commands.go @@ -1,18 +1,17 @@ package reaction import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { reactionCmd := &cobra.Command{ Use: consts.ReactionStr, Short: "Manage automatic reactions to events", diff --git a/client/command/reaction/helpers.go b/client/command/reaction/helpers.go index 0e7d22b247..85787b8d1d 100644 --- a/client/command/reaction/helpers.go +++ b/client/command/reaction/helpers.go @@ -26,23 +26,22 @@ import ( "strconv" "strings" - "github.com/rsteube/carapace" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/rsteube/carapace" ) const ( ReactionFileName = "reactions.json" ) -// GetReactionFilePath - Get the +// GetReactionFilePath - Get the. func GetReactionFilePath() string { return path.Join(assets.GetRootAppDir(), ReactionFileName) } -// SaveReactions - Save the reactions to the reaction file +// SaveReactions - Save the reactions to the reaction file. func SaveReactions(reactions []core.Reaction) error { reactionFilePath := GetReactionFilePath() data, err := json.MarshalIndent(reactions, "", " ") @@ -52,7 +51,7 @@ func SaveReactions(reactions []core.Reaction) error { return ioutil.WriteFile(reactionFilePath, data, 0o600) } -// LoadReactions - Save the reactions to the reaction file +// LoadReactions - Save the reactions to the reaction file. func LoadReactions() (int, error) { reactionFilePath := GetReactionFilePath() data, err := ioutil.ReadFile(reactionFilePath) @@ -85,8 +84,8 @@ func isReactable(reaction core.Reaction) bool { return false } -// ReactionIDCompleter completes saved/available reaction IDs -func ReactionIDCompleter(_ *console.SliverConsoleClient) carapace.Action { +// ReactionIDCompleter completes saved/available reaction IDs. +func ReactionIDCompleter(_ *console.SliverClient) carapace.Action { results := make([]string, 0) for _, reaction := range core.Reactions.All() { diff --git a/client/command/reaction/reaction.go b/client/command/reaction/reaction.go index 2cd3cf0fa7..9caa2cf448 100644 --- a/client/command/reaction/reaction.go +++ b/client/command/reaction/reaction.go @@ -22,17 +22,16 @@ import ( "fmt" "strings" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/client/core" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// ReactionCmd - Manage reactions to events -func ReactionCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ReactionCmd - Manage reactions to events. +func ReactionCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { totalReactions := 0 for _, eventType := range core.ReactableEvents { reactions := core.Reactions.On(eventType) @@ -49,7 +48,7 @@ func ReactionCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -func displayReactionsTable(eventType string, reactions []core.Reaction, con *console.SliverConsoleClient) { +func displayReactionsTable(eventType string, reactions []core.Reaction, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.SetTitle(fmt.Sprintf(console.Bold+"%s"+console.Normal, EventTypeToTitle(eventType))) @@ -71,7 +70,7 @@ func displayReactionsTable(eventType string, reactions []core.Reaction, con *con con.Printf("%s\n", tw.Render()) } -// EventTypeToTitle - Convert an eventType to a more human friendly string +// EventTypeToTitle - Convert an eventType to a more human friendly string. func EventTypeToTitle(eventType string) string { switch eventType { diff --git a/client/command/reaction/reload.go b/client/command/reaction/reload.go index 37444ff854..ff0d5553bc 100644 --- a/client/command/reaction/reload.go +++ b/client/command/reaction/reload.go @@ -22,13 +22,12 @@ import ( "os" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) -// ReactionSaveCmd - Manage reactions to events -func ReactionReloadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ReactionSaveCmd - Manage reactions to events. +func ReactionReloadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { if _, err := os.Stat(GetReactionFilePath()); os.IsNotExist(err) { con.PrintErrorf("Missing reaction file %s\n", GetReactionFilePath()) return diff --git a/client/command/reaction/save.go b/client/command/reaction/save.go index b98687bc8f..79ed192ad9 100644 --- a/client/command/reaction/save.go +++ b/client/command/reaction/save.go @@ -23,14 +23,13 @@ import ( "os" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/spf13/cobra" ) -// ReactionSaveCmd - Manage reactions to events -func ReactionSaveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ReactionSaveCmd - Manage reactions to events. +func ReactionSaveCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { reactionPath := GetReactionFilePath() if _, err := os.Stat(reactionPath); !os.IsNotExist(err) { confirm := false diff --git a/client/command/reaction/set.go b/client/command/reaction/set.go index eb104615ce..cf74c44e5e 100644 --- a/client/command/reaction/set.go +++ b/client/command/reaction/set.go @@ -23,17 +23,16 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/spf13/cobra" ) -// ErrNonReactableEvent - Event does not exist or is not supported by reactions +// ErrNonReactableEvent - Event does not exist or is not supported by reactions. var ErrNonReactableEvent = errors.New("non-reactable event type") -// ReactionSetCmd - Set a reaction upon an event -func ReactionSetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ReactionSetCmd - Set a reaction upon an event. +func ReactionSetCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { eventType, err := getEventType(cmd, con) if err != nil { con.PrintErrorf("%s\n", err) @@ -63,7 +62,7 @@ func ReactionSetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ con.PrintInfof("Set reaction to %s (id: %d)\n", eventType, reaction.ID) } -func getEventType(cmd *cobra.Command, con *console.SliverConsoleClient) (string, error) { +func getEventType(cmd *cobra.Command, con *console.SliverClient) (string, error) { rawEventType, _ := cmd.Flags().GetString("event") if rawEventType == "" { return selectEventType(con) @@ -77,7 +76,7 @@ func getEventType(cmd *cobra.Command, con *console.SliverConsoleClient) (string, } } -func selectEventType(con *console.SliverConsoleClient) (string, error) { +func selectEventType(con *console.SliverClient) (string, error) { prompt := &survey.Select{ Message: "Select an event:", Options: core.ReactableEvents, diff --git a/client/command/reaction/unset.go b/client/command/reaction/unset.go index 7ffe541060..a95e7d5f27 100644 --- a/client/command/reaction/unset.go +++ b/client/command/reaction/unset.go @@ -26,14 +26,13 @@ import ( "text/tabwriter" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/client/core" + "github.com/spf13/cobra" ) -// ReactionUnsetCmd - Unset a reaction upon an event -func ReactionUnsetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ReactionUnsetCmd - Unset a reaction upon an event. +func ReactionUnsetCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { reactionID, _ := cmd.Flags().GetInt("id") if reactionID == 0 { reaction, err := selectReaction(con) @@ -53,7 +52,7 @@ func ReactionUnsetCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args con.Println() } -func selectReaction(con *console.SliverConsoleClient) (*core.Reaction, error) { +func selectReaction(con *console.SliverClient) (*core.Reaction, error) { outputBuf := bytes.NewBufferString("") table := tabwriter.NewWriter(outputBuf, 0, 2, 2, ' ', 0) allReactions := core.Reactions.All() diff --git a/client/command/reconfig/commands.go b/client/command/reconfig/commands.go index 5e52838177..cc5178fd5b 100644 --- a/client/command/reconfig/commands.go +++ b/client/command/reconfig/commands.go @@ -1,17 +1,16 @@ package reconfig import ( - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { reconfigCmd := &cobra.Command{ Use: consts.ReconfigStr, Short: "Reconfigure the active beacon/session", diff --git a/client/command/reconfig/reconfig.go b/client/command/reconfig/reconfig.go index 2800d345f4..f0b5343aef 100644 --- a/client/command/reconfig/reconfig.go +++ b/client/command/reconfig/reconfig.go @@ -22,17 +22,15 @@ import ( "context" "time" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// ReconfigCmd - Reconfigure metadata about a sessions -func ReconfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ReconfigCmd - Reconfigure metadata about a sessions. +func ReconfigCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return diff --git a/client/command/reconfig/rename.go b/client/command/reconfig/rename.go index 7866036a50..ba4cb518a9 100644 --- a/client/command/reconfig/rename.go +++ b/client/command/reconfig/rename.go @@ -21,15 +21,14 @@ package reconfig import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" ) -// RecnameCmd - Reconfigure metadata about a sessions -func RenameCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// RecnameCmd - Reconfigure metadata about a sessions. +func RenameCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return diff --git a/client/command/registry/commands.go b/client/command/registry/commands.go index 228cf37e40..fec21cf040 100644 --- a/client/command/registry/commands.go +++ b/client/command/registry/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { registryCmd := &cobra.Command{ Use: consts.RegistryStr, Short: "Windows registry operations", diff --git a/client/command/registry/reg-create.go b/client/command/registry/reg-create.go index 275b2eed09..1791e8c018 100644 --- a/client/command/registry/reg-create.go +++ b/client/command/registry/reg-create.go @@ -32,7 +32,7 @@ import ( ) // RegCreateKeyCmd - Create a new Windows registry key -func RegCreateKeyCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RegCreateKeyCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -98,7 +98,7 @@ func RegCreateKeyCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } // PrintCreateKey - Print the results of the create key command -func PrintCreateKey(createKey *sliverpb.RegistryCreateKey, regPath string, key string, con *console.SliverConsoleClient) { +func PrintCreateKey(createKey *sliverpb.RegistryCreateKey, regPath string, key string, con *console.SliverClient) { if createKey.Response != nil && createKey.Response.Err != "" { con.PrintErrorf("%s", createKey.Response.Err) return diff --git a/client/command/registry/reg-delete.go b/client/command/registry/reg-delete.go index 7f846433db..80f80c484c 100644 --- a/client/command/registry/reg-delete.go +++ b/client/command/registry/reg-delete.go @@ -32,7 +32,7 @@ import ( ) // RegDeleteKeyCmd - Remove a Windows registry key -func RegDeleteKeyCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RegDeleteKeyCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -98,7 +98,7 @@ func RegDeleteKeyCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } // PrintDeleteKey - Print the results of the delete key command -func PrintDeleteKey(deleteKey *sliverpb.RegistryDeleteKey, regPath string, key string, con *console.SliverConsoleClient) { +func PrintDeleteKey(deleteKey *sliverpb.RegistryDeleteKey, regPath string, key string, con *console.SliverClient) { if deleteKey.Response != nil && deleteKey.Response.Err != "" { con.PrintErrorf("%s", deleteKey.Response.Err) return diff --git a/client/command/registry/reg-list.go b/client/command/registry/reg-list.go index a25c00f29f..3bafb2a571 100644 --- a/client/command/registry/reg-list.go +++ b/client/command/registry/reg-list.go @@ -31,7 +31,7 @@ import ( ) // RegListSubKeysCmd - List sub registry keys -func RegListSubKeysCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RegListSubKeysCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -73,7 +73,7 @@ func RegListSubKeysCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg } // PrintListSubKeys - Print the list sub keys command result -func PrintListSubKeys(regList *sliverpb.RegistrySubKeyList, hive string, regPath string, con *console.SliverConsoleClient) { +func PrintListSubKeys(regList *sliverpb.RegistrySubKeyList, hive string, regPath string, con *console.SliverClient) { if regList.Response != nil && regList.Response.Err != "" { con.PrintErrorf("%s\n", regList.Response.Err) return @@ -87,7 +87,7 @@ func PrintListSubKeys(regList *sliverpb.RegistrySubKeyList, hive string, regPath } // RegListValuesCmd - List registry values -func RegListValuesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RegListValuesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -124,7 +124,7 @@ func RegListValuesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } // PrintListValues - Print the registry list values -func PrintListValues(regList *sliverpb.RegistryValuesList, hive string, regPath string, con *console.SliverConsoleClient) { +func PrintListValues(regList *sliverpb.RegistryValuesList, hive string, regPath string, con *console.SliverClient) { if regList.Response != nil && regList.Response.Err != "" { con.PrintErrorf("%s\n", regList.Response.Err) return diff --git a/client/command/registry/reg-read.go b/client/command/registry/reg-read.go index 62df3b7117..3109b32e8c 100644 --- a/client/command/registry/reg-read.go +++ b/client/command/registry/reg-read.go @@ -75,7 +75,7 @@ func getType(t string) (uint32, error) { } // RegReadCmd - Read a windows registry key: registry read --hostname aa.bc.local --hive HKCU "software\google\chrome\blbeacon\version" -func RegReadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RegReadCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var ( finalPath string key string @@ -146,7 +146,7 @@ func RegReadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []str } // PrintRegRead - Print the results of the registry read command -func PrintRegRead(regRead *sliverpb.RegistryRead, con *console.SliverConsoleClient) { +func PrintRegRead(regRead *sliverpb.RegistryRead, con *console.SliverClient) { if regRead.Response != nil && regRead.Response.Err != "" { con.PrintErrorf("%s\n", regRead.Response.Err) return diff --git a/client/command/registry/reg-write.go b/client/command/registry/reg-write.go index e477b5682e..542f258544 100644 --- a/client/command/registry/reg-write.go +++ b/client/command/registry/reg-write.go @@ -35,7 +35,7 @@ import ( ) // RegWriteCmd - Write to a Windows registry key: registry write --hive HKCU --type dword "software\google\chrome\blbeacon\hello" 32 -func RegWriteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RegWriteCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -160,7 +160,7 @@ func RegWriteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } // PrintRegWrite - Print the registry write operation -func PrintRegWrite(regWrite *sliverpb.RegistryWrite, con *console.SliverConsoleClient) { +func PrintRegWrite(regWrite *sliverpb.RegistryWrite, con *console.SliverClient) { if regWrite.Response != nil && regWrite.Response.Err != "" { con.PrintErrorf("%s", regWrite.Response.Err) return diff --git a/client/command/rportfwd/commands.go b/client/command/rportfwd/commands.go index 0f87656dad..06a7b642a6 100644 --- a/client/command/rportfwd/commands.go +++ b/client/command/rportfwd/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { rportfwdCmd := &cobra.Command{ Use: consts.RportfwdStr, Short: "reverse port forwardings", diff --git a/client/command/rportfwd/portfwd-add.go b/client/command/rportfwd/portfwd-add.go index 930f3f3800..8dc20f2be9 100644 --- a/client/command/rportfwd/portfwd-add.go +++ b/client/command/rportfwd/portfwd-add.go @@ -31,7 +31,7 @@ import ( var portNumberOnlyRegexp = regexp.MustCompile("^[0-9]+$") // StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant. -func StartRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func StartRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -65,7 +65,7 @@ func StartRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClie printStartedRportFwdListener(rportfwdListener, con) } -func printStartedRportFwdListener(rportfwdListener *sliverpb.RportFwdListener, con *console.SliverConsoleClient) { +func printStartedRportFwdListener(rportfwdListener *sliverpb.RportFwdListener, con *console.SliverClient) { if rportfwdListener.Response != nil && rportfwdListener.Response.Err != "" { con.PrintErrorf("%s", rportfwdListener.Response.Err) return diff --git a/client/command/rportfwd/portfwd-rm.go b/client/command/rportfwd/portfwd-rm.go index 445f048b94..ac428a7b9b 100644 --- a/client/command/rportfwd/portfwd-rm.go +++ b/client/command/rportfwd/portfwd-rm.go @@ -27,7 +27,7 @@ import ( ) // StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant. -func StopRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func StopRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -45,7 +45,7 @@ func StopRportFwdListenerCmd(cmd *cobra.Command, con *console.SliverConsoleClien printStoppedRportFwdListener(rportfwdListener, con) } -func printStoppedRportFwdListener(rportfwdListener *sliverpb.RportFwdListener, con *console.SliverConsoleClient) { +func printStoppedRportFwdListener(rportfwdListener *sliverpb.RportFwdListener, con *console.SliverClient) { if rportfwdListener.Response != nil && rportfwdListener.Response.Err != "" { con.PrintErrorf("%s", rportfwdListener.Response.Err) return diff --git a/client/command/rportfwd/portfwd.go b/client/command/rportfwd/portfwd.go index 3cf929fcb7..2970812d8b 100644 --- a/client/command/rportfwd/portfwd.go +++ b/client/command/rportfwd/portfwd.go @@ -33,7 +33,7 @@ import ( ) // StartRportFwdListenerCmd - Start listener for reverse port forwarding on implant. -func RportFwdListenersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func RportFwdListenersCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -49,7 +49,7 @@ func RportFwdListenersCmd(cmd *cobra.Command, con *console.SliverConsoleClient, PrintRportFwdListeners(rportfwdListeners, cmd.Flags(), con) } -func PrintRportFwdListeners(rportfwdListeners *sliverpb.RportFwdListeners, flags *pflag.FlagSet, con *console.SliverConsoleClient) { +func PrintRportFwdListeners(rportfwdListeners *sliverpb.RportFwdListeners, flags *pflag.FlagSet, con *console.SliverClient) { if rportfwdListeners.Response != nil && rportfwdListeners.Response.Err != "" { con.PrintErrorf("%s\n", rportfwdListeners.Response.Err) return @@ -78,7 +78,7 @@ func PrintRportFwdListeners(rportfwdListeners *sliverpb.RportFwdListeners, flags } // PortfwdIDCompleter completes IDs of remote portforwarders. -func PortfwdIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func PortfwdIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/screenshot/commands.go b/client/command/screenshot/commands.go index 85758509ae..993cd8dcf7 100644 --- a/client/command/screenshot/commands.go +++ b/client/command/screenshot/commands.go @@ -1,18 +1,17 @@ package screenshot import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { screenshotCmd := &cobra.Command{ Use: consts.ScreenshotStr, Short: "Take a screenshot", diff --git a/client/command/screenshot/screenshot.go b/client/command/screenshot/screenshot.go index f15a884a41..0741237c8c 100644 --- a/client/command/screenshot/screenshot.go +++ b/client/command/screenshot/screenshot.go @@ -26,19 +26,17 @@ import ( "path/filepath" "time" - "google.golang.org/protobuf/proto" - - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/loot" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util" + "github.com/spf13/cobra" + "google.golang.org/protobuf/proto" ) -// ScreenshotCmd - Take a screenshot of the remote system -func ScreenshotCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ScreenshotCmd - Take a screenshot of the remote system. +func ScreenshotCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -98,8 +96,8 @@ func ScreenshotCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [] } } -// PrintScreenshot - Handle the screenshot command response -func PrintScreenshot(screenshot *sliverpb.Screenshot, hostname string, cmd *cobra.Command, con *console.SliverConsoleClient) { +// PrintScreenshot - Handle the screenshot command response. +func PrintScreenshot(screenshot *sliverpb.Screenshot, hostname string, cmd *cobra.Command, con *console.SliverClient) { timestamp := time.Now().Format("20060102150405") saveTo, _ := cmd.Flags().GetString("save") @@ -130,7 +128,7 @@ func PrintScreenshot(screenshot *sliverpb.Screenshot, hostname string, cmd *cobr con.PrintInfof("Screenshot written to %s (%s)\n", saveToFile.Name(), util.ByteCountBinary(int64(n))) } -func LootScreenshot(screenshot *sliverpb.Screenshot, lootName string, hostName string, con *console.SliverConsoleClient) { +func LootScreenshot(screenshot *sliverpb.Screenshot, lootName string, hostName string, con *console.SliverClient) { timeNow := time.Now().UTC() screenshotFileName := fmt.Sprintf("screenshot_%s_%s.png", hostName, timeNow.Format("20060102150405")) diff --git a/client/command/server.go b/client/command/server.go index ce694d550c..4ccadf8530 100644 --- a/client/command/server.go +++ b/client/command/server.go @@ -54,7 +54,7 @@ import ( // ServerCommands returns all commands bound to the server menu, optionally // accepting a function returning a list of additional (admin) commands. -func ServerCommands(con *client.SliverConsoleClient, serverCmds func() []*cobra.Command) console.Commands { +func ServerCommands(con *client.SliverClient, serverCmds func() []*cobra.Command) console.Commands { serverCommands := func() *cobra.Command { server := &cobra.Command{ Short: "Server commands", diff --git a/client/command/sessions/background.go b/client/command/sessions/background.go index a0e2b49c3b..bc2449578c 100644 --- a/client/command/sessions/background.go +++ b/client/command/sessions/background.go @@ -1,13 +1,12 @@ package sessions import ( - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) -// BackgroundCmd - Background the active session -func BackgroundCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// BackgroundCmd - Background the active session. +func BackgroundCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { con.ActiveTarget.Background() con.PrintInfof("Background ...\n") } diff --git a/client/command/sessions/close.go b/client/command/sessions/close.go index e630276989..3968a1c11f 100644 --- a/client/command/sessions/close.go +++ b/client/command/sessions/close.go @@ -21,14 +21,13 @@ package sessions import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// CloseSessionCmd - Close an interactive session but do not kill the remote process -func CloseSessionCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// CloseSessionCmd - Close an interactive session but do not kill the remote process. +func CloseSessionCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { // Get the active session session := con.ActiveTarget.GetSessionInteractive() if session == nil { diff --git a/client/command/sessions/commands.go b/client/command/sessions/commands.go index 65e4de8966..3e14771fc1 100644 --- a/client/command/sessions/commands.go +++ b/client/command/sessions/commands.go @@ -5,19 +5,18 @@ import ( "fmt" "strings" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the `sessions` command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { sessionsCmd := &cobra.Command{ Use: consts.SessionsStr, Short: "Session management", @@ -61,8 +60,8 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { return []*cobra.Command{sessionsCmd} } -// SessionIDCompleter completes session IDs -func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { +// SessionIDCompleter completes session IDs. +func SessionIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) @@ -85,7 +84,7 @@ func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { } // SliverCommands returns all session control commands for the active target. -func SliverCommands(con *console.SliverConsoleClient) []*cobra.Command { +func SliverCommands(con *console.SliverClient) []*cobra.Command { backgroundCmd := &cobra.Command{ Use: consts.BackgroundStr, Short: "Background an active session", diff --git a/client/command/sessions/helpers.go b/client/command/sessions/helpers.go index 0946336fe3..399fb19822 100644 --- a/client/command/sessions/helpers.go +++ b/client/command/sessions/helpers.go @@ -28,21 +28,20 @@ import ( "text/tabwriter" "github.com/AlecAivazis/survey/v2" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" ) var ( - // ErrNoSessions - No sessions available + // ErrNoSessions - No sessions available. ErrNoSessions = errors.New("no sessions") - // ErrNoSelection - No selection made + // ErrNoSelection - No selection made. ErrNoSelection = errors.New("no selection") ) -// SelectSession - Interactive menu for the user to select an session, optionally only display live sessions -func SelectSession(onlyAlive bool, con *console.SliverConsoleClient) (*clientpb.Session, error) { +// SelectSession - Interactive menu for the user to select an session, optionally only display live sessions. +func SelectSession(onlyAlive bool, con *console.SliverClient) (*clientpb.Session, error) { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { return nil, err diff --git a/client/command/sessions/interactive.go b/client/command/sessions/interactive.go index 7ba31e90e7..8b44007757 100644 --- a/client/command/sessions/interactive.go +++ b/client/command/sessions/interactive.go @@ -23,16 +23,15 @@ import ( "net/url" "time" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/generate" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" + "github.com/spf13/cobra" ) -// InteractiveCmd - Beacon only command to open an interactive session -func InteractiveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, _ []string) { +// InteractiveCmd - Beacon only command to open an interactive session. +func InteractiveCmd(cmd *cobra.Command, con *console.SliverClient, _ []string) { beacon := con.ActiveTarget.GetBeaconInteractive() if beacon == nil { return diff --git a/client/command/sessions/prune.go b/client/command/sessions/prune.go index fdab122411..31d673464a 100644 --- a/client/command/sessions/prune.go +++ b/client/command/sessions/prune.go @@ -21,15 +21,14 @@ package sessions import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/kill" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/spf13/cobra" ) -// SessionsPruneCmd - Forcefully kill stale sessions -func SessionsPruneCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SessionsPruneCmd - Forcefully kill stale sessions. +func SessionsPruneCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("%s\n", err) diff --git a/client/command/sessions/sessions.go b/client/command/sessions/sessions.go index c17ecf6c31..6f056319f8 100644 --- a/client/command/sessions/sessions.go +++ b/client/command/sessions/sessions.go @@ -25,19 +25,18 @@ import ( "strings" "time" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "golang.org/x/term" - "github.com/bishopfox/sliver/client/command/kill" "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" + "golang.org/x/term" ) -// SessionsCmd - Display/interact with sessions -func SessionsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SessionsCmd - Display/interact with sessions. +func SessionsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { interact, _ := cmd.Flags().GetString("interact") killFlag, _ := cmd.Flags().GetString("kill") killAll, _ := cmd.Flags().GetBool("kill-all") @@ -126,8 +125,8 @@ func SessionsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -// PrintSessions - Print the current sessions -func PrintSessions(sessions map[string]*clientpb.Session, filter string, filterRegex *regexp.Regexp, con *console.SliverConsoleClient) { +// PrintSessions - Print the current sessions. +func PrintSessions(sessions map[string]*clientpb.Session, filter string, filterRegex *regexp.Regexp, con *console.SliverClient) { width, _, err := term.GetSize(0) if err != nil { width = 999 @@ -237,7 +236,7 @@ func PrintSessions(sessions map[string]*clientpb.Session, filter string, filterR con.Printf("%s\n", tw.Render()) } -// ShortSessionID - Shorten the session ID +// ShortSessionID - Shorten the session ID. func ShortSessionID(id string) string { return strings.Split(id, "-")[0] } diff --git a/client/command/settings/beacons.go b/client/command/settings/beacons.go index 61cd88f51a..60ab8796f5 100644 --- a/client/command/settings/beacons.go +++ b/client/command/settings/beacons.go @@ -19,14 +19,13 @@ package settings */ import ( - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) -// SettingsBeaconsAutoResultCmd - The client settings command -func SettingsBeaconsAutoResultCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsBeaconsAutoResultCmd - The client settings command. +func SettingsBeaconsAutoResultCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() diff --git a/client/command/settings/commands.go b/client/command/settings/commands.go index c82e20bd38..3bba3d0eaf 100644 --- a/client/command/settings/commands.go +++ b/client/command/settings/commands.go @@ -1,16 +1,15 @@ package settings import ( - "github.com/reeflective/console/commands/readline" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/reeflective/console/commands/readline" + "github.com/spf13/cobra" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { settingsCmd := &cobra.Command{ Use: consts.SettingsStr, Short: "Manage client settings", diff --git a/client/command/settings/opsec.go b/client/command/settings/opsec.go index 40a4e99989..c9e1ec7a70 100644 --- a/client/command/settings/opsec.go +++ b/client/command/settings/opsec.go @@ -20,14 +20,13 @@ package settings import ( "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" + "github.com/spf13/cobra" ) -// SettingsAutoAdultCmd - The client settings command -func SettingsAutoAdultCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsAutoAdultCmd - The client settings command. +func SettingsAutoAdultCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() @@ -40,8 +39,8 @@ func SettingsAutoAdultCmd(cmd *cobra.Command, con *console.SliverConsoleClient, con.PrintInfof("Auto Adult = %v\n", con.Settings.AutoAdult) } -// IsUserAnAdult - This should be called for any dangerous (OPSEC-wise) functions -func IsUserAnAdult(con *console.SliverConsoleClient) bool { +// IsUserAnAdult - This should be called for any dangerous (OPSEC-wise) functions. +func IsUserAnAdult(con *console.SliverClient) bool { if GetAutoAdult(con) { return true } @@ -51,8 +50,8 @@ func IsUserAnAdult(con *console.SliverConsoleClient) bool { return confirm } -// GetAutoAdult - Get the current auto adult setting -func GetAutoAdult(con *console.SliverConsoleClient) bool { +// GetAutoAdult - Get the current auto adult setting. +func GetAutoAdult(con *console.SliverClient) bool { if con.Settings == nil { con.Settings, _ = assets.LoadSettings() } diff --git a/client/command/settings/settings.go b/client/command/settings/settings.go index c0da4c861c..621622a6fa 100644 --- a/client/command/settings/settings.go +++ b/client/command/settings/settings.go @@ -22,15 +22,14 @@ import ( "strconv" "github.com/AlecAivazis/survey/v2" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// SettingsCmd - The client settings command -func SettingsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsCmd - The client settings command. +func SettingsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() @@ -53,8 +52,8 @@ func SettingsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st con.Printf("%s\n", tw.Render()) } -// SettingsAlwaysOverflow - Toggle always overflow -func SettingsAlwaysOverflow(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsAlwaysOverflow - Toggle always overflow. +func SettingsAlwaysOverflow(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() @@ -67,8 +66,8 @@ func SettingsAlwaysOverflow(cmd *cobra.Command, con *console.SliverConsoleClient con.PrintInfof("Always overflow = %v\n", con.Settings.AlwaysOverflow) } -// SettingsConsoleLogs - Toggle console logs -func SettingsConsoleLogs(cmd *cobra.Command, con *console.SliverConsoleClient) { +// SettingsConsoleLogs - Toggle console logs. +func SettingsConsoleLogs(cmd *cobra.Command, con *console.SliverClient) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() @@ -81,8 +80,8 @@ func SettingsConsoleLogs(cmd *cobra.Command, con *console.SliverConsoleClient) { con.PrintInfof("Console Logs = %v\n", con.Settings.ConsoleLogs) } -// SettingsSmallTerm - Modify small terminal width value -func SettingsSmallTerm(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsSmallTerm - Modify small terminal width value. +func SettingsSmallTerm(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() @@ -111,8 +110,8 @@ func SettingsSmallTerm(cmd *cobra.Command, con *console.SliverConsoleClient, arg con.PrintInfof("Small terminal width set to %d\n", con.Settings.SmallTermWidth) } -// SettingsTablesCmd - The client settings command -func SettingsTablesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsTablesCmd - The client settings command. +func SettingsTablesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() @@ -143,8 +142,8 @@ func SettingsTablesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg } } -// SettingsSaveCmd - The client settings command -func SettingsSaveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsSaveCmd - The client settings command. +func SettingsSaveCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() @@ -161,8 +160,8 @@ func SettingsSaveCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args } } -// SettingsAlwaysOverflow - Toggle always overflow -func SettingsUserConnect(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// SettingsAlwaysOverflow - Toggle always overflow. +func SettingsUserConnect(cmd *cobra.Command, con *console.SliverClient, args []string) { var err error if con.Settings == nil { con.Settings, err = assets.LoadSettings() diff --git a/client/command/settings/tables.go b/client/command/settings/tables.go index a285605919..951eb64627 100644 --- a/client/command/settings/tables.go +++ b/client/command/settings/tables.go @@ -23,12 +23,11 @@ import ( "strings" "github.com/AlecAivazis/survey/v2" + "github.com/bishopfox/sliver/client/assets" + "github.com/bishopfox/sliver/client/console" "github.com/jedib0t/go-pretty/v6/table" "github.com/jedib0t/go-pretty/v6/text" "golang.org/x/term" - - "github.com/bishopfox/sliver/client/assets" - "github.com/bishopfox/sliver/client/console" ) var ( @@ -127,8 +126,8 @@ var ( } ) -// GetTableStyle - Get the current table style -func GetTableStyle(con *console.SliverConsoleClient) table.Style { +// GetTableStyle - Get the current table style. +func GetTableStyle(con *console.SliverClient) table.Style { if con.Settings == nil { con.Settings, _ = assets.LoadSettings() } @@ -140,8 +139,8 @@ func GetTableStyle(con *console.SliverConsoleClient) table.Style { return tableStyles[SliverDefault.Name] } -// GetTableWithBordersStyle - Get the table style with borders -func GetTableWithBordersStyle(con *console.SliverConsoleClient) table.Style { +// GetTableWithBordersStyle - Get the table style with borders. +func GetTableWithBordersStyle(con *console.SliverClient) table.Style { if con.Settings == nil { con.Settings, _ = assets.LoadSettings() } @@ -152,12 +151,12 @@ func GetTableWithBordersStyle(con *console.SliverConsoleClient) table.Style { return value } -// GetPageSize - Page size for tables +// GetPageSize - Page size for tables. func GetPageSize() int { return 10 } -// PagesOf - Return the pages of a table +// PagesOf - Return the pages of a table. func PagesOf(renderedTable string) [][]string { lines := strings.Split(renderedTable, "\n") if len(lines) < 2 { @@ -178,8 +177,8 @@ func PagesOf(renderedTable string) [][]string { return pages } -// PaginateTable - Render paginated table to console -func PaginateTable(tw table.Writer, skipPages int, overflow bool, interactive bool, con *console.SliverConsoleClient) { +// PaginateTable - Render paginated table to console. +func PaginateTable(tw table.Writer, skipPages int, overflow bool, interactive bool, con *console.SliverClient) { renderedTable := tw.Render() lineCount := strings.Count(renderedTable, "\n") if !overflow || con.Settings.AlwaysOverflow { diff --git a/client/command/shell/commands.go b/client/command/shell/commands.go index 954d647712..242794ee8a 100644 --- a/client/command/shell/commands.go +++ b/client/command/shell/commands.go @@ -10,7 +10,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { shellCmd := &cobra.Command{ Use: consts.ShellStr, Short: "Start an interactive shell", diff --git a/client/command/shell/shell.go b/client/command/shell/shell.go index 3775367c44..6dcebbbbe3 100644 --- a/client/command/shell/shell.go +++ b/client/command/shell/shell.go @@ -40,7 +40,7 @@ const ( ) // ShellCmd - Start an interactive shell on the remote system. -func ShellCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ShellCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -59,7 +59,7 @@ func ShellCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin con.Println("Shell exited") } -func runInteractive(cmd *cobra.Command, shellPath string, noPty bool, con *console.SliverConsoleClient) { +func runInteractive(cmd *cobra.Command, shellPath string, noPty bool, con *console.SliverClient) { con.Println() con.PrintInfof("Wait approximately 10 seconds after exit, and press to continue\n") con.PrintInfof("Opening shell tunnel (EOF to exit) ...\n\n") diff --git a/client/command/shikata-ga-nai/commands.go b/client/command/shikata-ga-nai/commands.go index 2d81134c19..92a1e93ff4 100644 --- a/client/command/shikata-ga-nai/commands.go +++ b/client/command/shikata-ga-nai/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { shikataGaNaiCmd := &cobra.Command{ Use: consts.ShikataGaNai, Short: "Polymorphic binary shellcode encoder (ノ ゜Д゜)ノ ︵ 仕方がない", diff --git a/client/command/shikata-ga-nai/sgn.go b/client/command/shikata-ga-nai/sgn.go index f63f4b6c07..e05af7015c 100644 --- a/client/command/shikata-ga-nai/sgn.go +++ b/client/command/shikata-ga-nai/sgn.go @@ -31,7 +31,7 @@ import ( ) // ShikataGaNaiCmd - Command wrapper for the Shikata Ga Nai shellcode encoder -func ShikataGaNaiCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ShikataGaNaiCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { shellcodeFile := args[0] rawShellcode, err := ioutil.ReadFile(shellcodeFile) if err != nil { diff --git a/client/command/sliver.go b/client/command/sliver.go index 2ba0a8c68e..cbb69f88a5 100644 --- a/client/command/sliver.go +++ b/client/command/sliver.go @@ -52,7 +52,7 @@ import ( ) // SliverCommands returns all commands bound to the implant menu. -func SliverCommands(con *client.SliverConsoleClient) console.Commands { +func SliverCommands(con *client.SliverClient) console.Commands { sliverCommands := func() *cobra.Command { sliver := &cobra.Command{ Short: "Implant commands", diff --git a/client/command/socks/commands.go b/client/command/socks/commands.go index 2768f24bbd..710984d625 100644 --- a/client/command/socks/commands.go +++ b/client/command/socks/commands.go @@ -12,7 +12,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { socksCmd := &cobra.Command{ Use: consts.Socks5Str, Short: "In-band SOCKS5 Proxy", diff --git a/client/command/socks/socks-start.go b/client/command/socks/socks-start.go index 9ecde46961..63cf7a9fa7 100644 --- a/client/command/socks/socks-start.go +++ b/client/command/socks/socks-start.go @@ -32,7 +32,7 @@ import ( ) // SocksStartCmd - Add a new tunneled port forward. -func SocksStartCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func SocksStartCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/socks/socks-stop.go b/client/command/socks/socks-stop.go index 00bd5f7868..0fcb2565aa 100644 --- a/client/command/socks/socks-stop.go +++ b/client/command/socks/socks-stop.go @@ -28,7 +28,7 @@ import ( ) // SocksStopCmd - Remove an existing tunneled port forward. -func SocksStopCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func SocksStopCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { socksID, _ := cmd.Flags().GetUint64("id") if socksID < 1 { con.PrintErrorf("Must specify a valid socks5 id\n") diff --git a/client/command/socks/socks.go b/client/command/socks/socks.go index 412f37acd7..0301822383 100644 --- a/client/command/socks/socks.go +++ b/client/command/socks/socks.go @@ -32,7 +32,7 @@ import ( ) // SocksCmd - Display information about tunneled port forward(s). -func SocksCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func SocksCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { socks := core.SocksProxies.List() if len(socks) == 0 { con.PrintInfof("No socks5 proxies\n") @@ -59,7 +59,7 @@ func SocksCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin } // SocksIDCompleter completes IDs of remote of socks proxy servers. -func SocksIDCompleter(_ *console.SliverConsoleClient) carapace.Action { +func SocksIDCompleter(_ *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/taskmany/taskmany.go b/client/command/taskmany/taskmany.go index 74cc826753..4e01aacc01 100644 --- a/client/command/taskmany/taskmany.go +++ b/client/command/taskmany/taskmany.go @@ -37,7 +37,7 @@ import ( "github.com/bishopfox/sliver/protobuf/commonpb" ) -func Command(con *console.SliverConsoleClient) []*cobra.Command { +func Command(con *console.SliverClient) []*cobra.Command { taskmanyCmd := &cobra.Command{ Use: consts.TaskmanyStr, Short: "Task many beacons or sessions", @@ -81,12 +81,12 @@ func Command(con *console.SliverConsoleClient) []*cobra.Command { } // TaskmanyCmd - Task many beacons / sessions -func TaskmanyCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func TaskmanyCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { con.PrintErrorf("Must specify subcommand. See taskmany --help for supported subcommands.\n") } // Helper function to wrap grumble commands with taskmany logic -func WrapCommand(c *cobra.Command, con *console.SliverConsoleClient) *cobra.Command { +func WrapCommand(c *cobra.Command, con *console.SliverClient) *cobra.Command { wc := &cobra.Command{ Use: c.Use, Short: c.Short, @@ -100,7 +100,7 @@ func WrapCommand(c *cobra.Command, con *console.SliverConsoleClient) *cobra.Comm } // Wrap a function to run it for each beacon / session -func wrapFunctionWithTaskmany(con *console.SliverConsoleClient, f func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string) { +func wrapFunctionWithTaskmany(con *console.SliverClient, f func(cmd *cobra.Command, args []string)) func(cmd *cobra.Command, args []string) { return func(cmd *cobra.Command, args []string) { defer con.Println() @@ -150,7 +150,7 @@ func wrapFunctionWithTaskmany(con *console.SliverConsoleClient, f func(cmd *cobr } } -func SelectMultipleBeaconsAndSessions(con *console.SliverConsoleClient) ([]*clientpb.Session, []*clientpb.Beacon, error) { +func SelectMultipleBeaconsAndSessions(con *console.SliverClient) ([]*clientpb.Session, []*clientpb.Beacon, error) { // Get and sort sessions sessionsObj, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { diff --git a/client/command/tasks/commands.go b/client/command/tasks/commands.go index 2f5bc11259..d92e1b2df0 100644 --- a/client/command/tasks/commands.go +++ b/client/command/tasks/commands.go @@ -1,18 +1,17 @@ package tasks import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { tasksCmd := &cobra.Command{ Use: consts.TasksStr, Short: "Beacon task management", diff --git a/client/command/tasks/fetch.go b/client/command/tasks/fetch.go index 61a11deb67..1c2ba517ad 100644 --- a/client/command/tasks/fetch.go +++ b/client/command/tasks/fetch.go @@ -26,11 +26,6 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/command/environment" "github.com/bishopfox/sliver/client/command/exec" "github.com/bishopfox/sliver/client/command/extensions" @@ -45,10 +40,14 @@ import ( "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/sliverpb" "github.com/bishopfox/sliver/util" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" + "github.com/spf13/pflag" + "google.golang.org/protobuf/proto" ) -// TasksFetchCmd - Manage beacon tasks -func TasksFetchCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// TasksFetchCmd - Manage beacon tasks. +func TasksFetchCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { beacon := con.ActiveTarget.GetBeaconInteractive() if beacon == nil { return @@ -124,8 +123,8 @@ func filterTasksByTaskType(taskType string, tasks []*clientpb.BeaconTask) []*cli return filteredTasks } -// PrintTask - Print the details of a beacon task -func PrintTask(task *clientpb.BeaconTask, con *console.SliverConsoleClient) { +// PrintTask - Print the details of a beacon task. +func PrintTask(task *clientpb.BeaconTask, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableWithBordersStyle(con)) tw.AppendRow(table.Row{console.Bold + "Beacon Task" + console.Normal, task.ID}) @@ -171,8 +170,8 @@ func emojiState(state string) string { } } -// Decode and render message specific content -func renderTaskResponse(task *clientpb.BeaconTask, con *console.SliverConsoleClient) { +// Decode and render message specific content. +func renderTaskResponse(task *clientpb.BeaconTask, con *console.SliverClient) { reqEnvelope := &sliverpb.Envelope{} proto.Unmarshal(task.Request, reqEnvelope) switch reqEnvelope.Type { @@ -743,7 +742,7 @@ func renderTaskResponse(task *clientpb.BeaconTask, con *console.SliverConsoleCli } } -func taskResponseDownload(download *sliverpb.Download, con *console.SliverConsoleClient) { +func taskResponseDownload(download *sliverpb.Download, con *console.SliverClient) { const ( dump = "Dump Contents" saveTo = "Save to File ..." @@ -766,7 +765,7 @@ func taskResponseDownload(download *sliverpb.Download, con *console.SliverConsol } } -func promptSaveToFile(data []byte, con *console.SliverConsoleClient) { +func promptSaveToFile(data []byte, con *console.SliverClient) { saveTo := "" saveToPrompt := &survey.Input{Message: "Save to: "} err := survey.AskOne(saveToPrompt, &saveTo) diff --git a/client/command/tasks/helpers.go b/client/command/tasks/helpers.go index 2b24a80084..6cdf28cd49 100644 --- a/client/command/tasks/helpers.go +++ b/client/command/tasks/helpers.go @@ -10,13 +10,12 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/rsteube/carapace" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/rsteube/carapace" ) -// SelectBeaconTask - Select a beacon task interactively +// SelectBeaconTask - Select a beacon task interactively. func SelectBeaconTask(tasks []*clientpb.BeaconTask) (*clientpb.BeaconTask, error) { // Render selection table buf := bytes.NewBufferString("") @@ -50,7 +49,7 @@ func SelectBeaconTask(tasks []*clientpb.BeaconTask) (*clientpb.BeaconTask, error } // BeaconTaskIDCompleter returns a structured list of tasks completions, grouped by state. -func BeaconTaskIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func BeaconTaskIDCompleter(con *console.SliverClient) carapace.Action { callback := func(ctx carapace.Context) carapace.Action { beacon := con.ActiveTarget.GetBeacon() if beacon == nil { @@ -114,8 +113,8 @@ func BeaconTaskIDCompleter(con *console.SliverConsoleClient) carapace.Action { return carapace.ActionCallback(callback) } -// BeaconPendingTasksCompleter completes pending tasks -func BeaconPendingTasksCompleter(con *console.SliverConsoleClient) carapace.Action { +// BeaconPendingTasksCompleter completes pending tasks. +func BeaconPendingTasksCompleter(con *console.SliverClient) carapace.Action { callback := func(ctx carapace.Context) carapace.Action { beacon := con.ActiveTarget.GetBeacon() if beacon == nil { diff --git a/client/command/tasks/tasks-cancel.go b/client/command/tasks/tasks-cancel.go index 3294af5977..c184c33b39 100644 --- a/client/command/tasks/tasks-cancel.go +++ b/client/command/tasks/tasks-cancel.go @@ -3,14 +3,13 @@ package tasks import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// TasksCancelCmd - Cancel a beacon task before it's sent to the implant -func TasksCancelCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// TasksCancelCmd - Cancel a beacon task before it's sent to the implant. +func TasksCancelCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { beacon := con.ActiveTarget.GetBeaconInteractive() if beacon == nil { return diff --git a/client/command/tasks/tasks.go b/client/command/tasks/tasks.go index 2f087096ca..bd025867e6 100644 --- a/client/command/tasks/tasks.go +++ b/client/command/tasks/tasks.go @@ -24,16 +24,15 @@ import ( "strings" "time" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/spf13/cobra" ) -// TasksCmd - Manage beacon tasks -func TasksCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// TasksCmd - Manage beacon tasks. +func TasksCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { beacon := con.ActiveTarget.GetBeaconInteractive() if beacon == nil { return @@ -46,8 +45,8 @@ func TasksCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []strin PrintBeaconTasks(beaconTasks.Tasks, cmd, con) } -// PrintBeaconTasks - Print beacon tasks -func PrintBeaconTasks(tasks []*clientpb.BeaconTask, cmd *cobra.Command, con *console.SliverConsoleClient) { +// PrintBeaconTasks - Print beacon tasks. +func PrintBeaconTasks(tasks []*clientpb.BeaconTask, cmd *cobra.Command, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) tw.AppendHeader(table.Row{ diff --git a/client/command/update/commands.go b/client/command/update/commands.go index 1f4f8cb0a9..7528fa8e1f 100644 --- a/client/command/update/commands.go +++ b/client/command/update/commands.go @@ -1,19 +1,18 @@ package update import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/completers" "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { updateCmd := &cobra.Command{ Use: consts.UpdateStr, Short: "Check for updates", diff --git a/client/command/update/update.go b/client/command/update/update.go index 06b6596b1e..d9d9d36d5a 100644 --- a/client/command/update/update.go +++ b/client/command/update/update.go @@ -36,19 +36,18 @@ import ( "time" "github.com/AlecAivazis/survey/v2" - "github.com/cheggaaa/pb/v3" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/client/version" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/util" + "github.com/cheggaaa/pb/v3" + "github.com/spf13/cobra" ) -// UpdateCmd - Check for updates -func UpdateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// UpdateCmd - Check for updates. +func UpdateCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { VerboseVersionsCmd(cmd, con, args) timeoutF, _ := cmd.Flags().GetInt("timeout") @@ -126,8 +125,8 @@ func UpdateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri } } -// VerboseVersionsCmd - Get verbose version information about the client and server -func VerboseVersionsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// VerboseVersionsCmd - Get verbose version information about the client and server. +func VerboseVersionsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { clientVer := version.FullVersion() serverVer, err := con.Rpc.GetVersion(context.Background(), &commonpb.Empty{}) if err != nil { @@ -219,7 +218,7 @@ func clientAssetForGOOS(assets []version.Asset) *version.Asset { return findAssetFor(prefix, suffixes, assets) } -func updateAvailable(con *console.SliverConsoleClient, client *http.Client, release *version.Release, saveTo string) { +func updateAvailable(con *console.SliverClient, client *http.Client, release *version.Release, saveTo string) { serverAsset := serverAssetForGOOS(release.Assets) clientAsset := clientAssetForGOOS(release.Assets) diff --git a/client/command/use/beacons.go b/client/command/use/beacons.go index 17a3835642..14328e8238 100644 --- a/client/command/use/beacons.go +++ b/client/command/use/beacons.go @@ -26,7 +26,7 @@ import ( ) // UseBeaconCmd - Change the active beacon -func UseBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func UseBeaconCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { beacon, err := beacons.SelectBeacon(con) if beacon != nil { con.ActiveTarget.Set(nil, beacon) diff --git a/client/command/use/commands.go b/client/command/use/commands.go index 0dd4ce5a1f..a8a0fe9177 100644 --- a/client/command/use/commands.go +++ b/client/command/use/commands.go @@ -13,7 +13,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { useCmd := &cobra.Command{ Use: consts.UseStr, Short: "Switch the active session or beacon", diff --git a/client/command/use/sessions.go b/client/command/use/sessions.go index 2b81ba13f7..3f8c8e64ee 100644 --- a/client/command/use/sessions.go +++ b/client/command/use/sessions.go @@ -26,7 +26,7 @@ import ( ) // UseSessionCmd - Change the active session -func UseSessionCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func UseSessionCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, err := sessions.SelectSession(false, con) if session != nil { con.ActiveTarget.Set(session, nil) diff --git a/client/command/use/use.go b/client/command/use/use.go index 1cacc26e7e..cae5a974ff 100644 --- a/client/command/use/use.go +++ b/client/command/use/use.go @@ -40,7 +40,7 @@ import ( var ErrNoSelection = errors.New("no selection") // UseCmd - Change the active session -func UseCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func UseCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var session *clientpb.Session var beacon *clientpb.Beacon var err error @@ -70,7 +70,7 @@ func UseCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) } // SessionOrBeaconByID - Select a session or beacon by ID -func SessionOrBeaconByID(id string, con *console.SliverConsoleClient) (*clientpb.Session, *clientpb.Beacon, error) { +func SessionOrBeaconByID(id string, con *console.SliverClient) (*clientpb.Session, *clientpb.Beacon, error) { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { return nil, nil, err @@ -95,7 +95,7 @@ func SessionOrBeaconByID(id string, con *console.SliverConsoleClient) (*clientpb } // SelectSessionOrBeacon - Select a session or beacon -func SelectSessionOrBeacon(con *console.SliverConsoleClient) (*clientpb.Session, *clientpb.Beacon, error) { +func SelectSessionOrBeacon(con *console.SliverClient) (*clientpb.Session, *clientpb.Beacon, error) { // Get and sort sessions sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { @@ -183,7 +183,7 @@ func SelectSessionOrBeacon(con *console.SliverConsoleClient) (*clientpb.Session, } // BeaconAndSessionIDCompleter - BeaconAndSessionIDCompleter for beacon / session ids -func BeaconAndSessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func BeaconAndSessionIDCompleter(con *console.SliverClient) carapace.Action { comps := func(ctx carapace.Context) carapace.Action { var action carapace.Action @@ -197,7 +197,7 @@ func BeaconAndSessionIDCompleter(con *console.SliverConsoleClient) carapace.Acti } // SessionIDCompleter completes session IDs -func SessionIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func SessionIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/wasm/commands.go b/client/command/wasm/commands.go index 96fd6f29dc..5567453e2a 100644 --- a/client/command/wasm/commands.go +++ b/client/command/wasm/commands.go @@ -11,7 +11,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { wasmCmd := &cobra.Command{ Use: consts.WasmStr, Short: "Execute a Wasm Module Extension", diff --git a/client/command/wasm/memfs.go b/client/command/wasm/memfs.go index 32fc448400..787e7f3f98 100644 --- a/client/command/wasm/memfs.go +++ b/client/command/wasm/memfs.go @@ -10,7 +10,7 @@ import ( "github.com/spf13/cobra" ) -func parseMemFS(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) (map[string][]byte, error) { +func parseMemFS(cmd *cobra.Command, con *console.SliverClient, args []string) (map[string][]byte, error) { memfs := make(map[string][]byte) totalSize := 0 diff --git a/client/command/wasm/wasm.go b/client/command/wasm/wasm.go index 0b517ab97a..a6b6c8c9aa 100644 --- a/client/command/wasm/wasm.go +++ b/client/command/wasm/wasm.go @@ -46,7 +46,7 @@ const ( var wasmRegistrationCache = make(map[string][]string) // WasmCmd - Execute a WASM module extension. -func WasmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WasmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -95,7 +95,7 @@ func WasmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } } -func isRegistered(name string, cmd *cobra.Command, con *console.SliverConsoleClient) bool { +func isRegistered(name string, cmd *cobra.Command, con *console.SliverClient) bool { // Check if we have already registered this wasm module if wasmRegistrationCache[idOf(con)] != nil { if util.Contains(wasmRegistrationCache[idOf(con)], name) { @@ -121,7 +121,7 @@ func isRegistered(name string, cmd *cobra.Command, con *console.SliverConsoleCli } // idOf - Quickly return the id of the current session or beacon. -func idOf(con *console.SliverConsoleClient) string { +func idOf(con *console.SliverClient) string { if con.ActiveTarget != nil { if session := con.ActiveTarget.GetSession(); session != nil { return session.ID @@ -133,7 +133,7 @@ func idOf(con *console.SliverConsoleClient) string { return "" } -func runNonInteractive(execWasmReq *sliverpb.ExecWasmExtensionReq, con *console.SliverConsoleClient) { +func runNonInteractive(execWasmReq *sliverpb.ExecWasmExtensionReq, con *console.SliverClient) { grpcCtx, cancel := con.GrpcContext(nil) defer cancel() execWasmResp, err := con.Rpc.ExecWasmExtension(grpcCtx, execWasmReq) @@ -159,7 +159,7 @@ func runNonInteractive(execWasmReq *sliverpb.ExecWasmExtensionReq, con *console. } } -func runInteractive(cmd *cobra.Command, execWasmReq *sliverpb.ExecWasmExtensionReq, con *console.SliverConsoleClient) { +func runInteractive(cmd *cobra.Command, execWasmReq *sliverpb.ExecWasmExtensionReq, con *console.SliverClient) { session := con.ActiveTarget.GetSession() if session == nil { con.PrintErrorf("No active session\n") @@ -227,7 +227,7 @@ func runInteractive(cmd *cobra.Command, execWasmReq *sliverpb.ExecWasmExtensionR } } -func registerWasmExtension(wasmFilePath string, cmd *cobra.Command, con *console.SliverConsoleClient) error { +func registerWasmExtension(wasmFilePath string, cmd *cobra.Command, con *console.SliverClient) error { grpcCtx, cancel := con.GrpcContext(cmd) defer cancel() data, err := os.ReadFile(wasmFilePath) @@ -254,7 +254,7 @@ func registerWasmExtension(wasmFilePath string, cmd *cobra.Command, con *console } // WasmLsCmd - Execute a WASM module extension. -func WasmLsCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WasmLsCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return diff --git a/client/command/websites/commands.go b/client/command/websites/commands.go index 862244b3cd..727de3521b 100644 --- a/client/command/websites/commands.go +++ b/client/command/websites/commands.go @@ -1,18 +1,17 @@ package websites import ( - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/spf13/pflag" - "github.com/bishopfox/sliver/client/command/flags" "github.com/bishopfox/sliver/client/command/help" "github.com/bishopfox/sliver/client/console" consts "github.com/bishopfox/sliver/client/constants" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" + "github.com/spf13/pflag" ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { websitesCmd := &cobra.Command{ Use: consts.WebsitesStr, Short: "Host static content (used with HTTP C2)", diff --git a/client/command/websites/websites-add-content.go b/client/command/websites/websites-add-content.go index e296545078..dc3e8386d4 100644 --- a/client/command/websites/websites-add-content.go +++ b/client/command/websites/websites-add-content.go @@ -28,14 +28,13 @@ import ( "path/filepath" "github.com/AlecAivazis/survey/v2" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// WebsitesAddContentCmd - Add static content to a website -func WebsitesAddContentCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// WebsitesAddContentCmd - Add static content to a website. +func WebsitesAddContentCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { websiteName, _ := cmd.Flags().GetString("website") if websiteName == "" { con.PrintErrorf("Must specify a website name via --website, see --help\n") diff --git a/client/command/websites/websites-rm-content.go b/client/command/websites/websites-rm-content.go index b0e4f1bce8..95b7d1f621 100644 --- a/client/command/websites/websites-rm-content.go +++ b/client/command/websites/websites-rm-content.go @@ -22,14 +22,13 @@ import ( "context" "strings" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// WebsitesRmContent - Remove static content from a website -func WebsitesRmContent(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// WebsitesRmContent - Remove static content from a website. +func WebsitesRmContent(cmd *cobra.Command, con *console.SliverClient, args []string) { name, _ := cmd.Flags().GetString("website") webPath, _ := cmd.Flags().GetString("web-path") recursive, _ := cmd.Flags().GetBool("recursive") diff --git a/client/command/websites/websites-rm.go b/client/command/websites/websites-rm.go index 8f1a19359b..e81873cc17 100644 --- a/client/command/websites/websites-rm.go +++ b/client/command/websites/websites-rm.go @@ -21,14 +21,13 @@ package websites import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// WebsiteRmCmd - Remove a website and all its static content -func WebsiteRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// WebsiteRmCmd - Remove a website and all its static content. +func WebsiteRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { var name string if len(args) > 0 { name = args[0] diff --git a/client/command/websites/websites-update-content.go b/client/command/websites/websites-update-content.go index d7e21e4788..d6d1b51919 100644 --- a/client/command/websites/websites-update-content.go +++ b/client/command/websites/websites-update-content.go @@ -21,14 +21,13 @@ package websites import ( "context" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" + "github.com/spf13/cobra" ) -// WebsitesUpdateContentCmd - Update metadata about static website content -func WebsitesUpdateContentCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// WebsitesUpdateContentCmd - Update metadata about static website content. +func WebsitesUpdateContentCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { websiteName, _ := cmd.Flags().GetString("website") if websiteName == "" { con.PrintErrorf("Must specify a website name via --website, see --help\n") diff --git a/client/command/websites/websites.go b/client/command/websites/websites.go index 2af253a990..e4f6918c59 100644 --- a/client/command/websites/websites.go +++ b/client/command/websites/websites.go @@ -23,14 +23,13 @@ import ( "sort" "strings" - "github.com/jedib0t/go-pretty/v6/table" - "github.com/rsteube/carapace" - "github.com/spf13/cobra" - "github.com/bishopfox/sliver/client/command/settings" "github.com/bishopfox/sliver/client/console" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" + "github.com/jedib0t/go-pretty/v6/table" + "github.com/rsteube/carapace" + "github.com/spf13/cobra" ) const ( @@ -38,8 +37,8 @@ const ( defaultMimeType = "application/octet-stream" ) -// WebsitesCmd - Manage websites -func WebsitesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// WebsitesCmd - Manage websites. +func WebsitesCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { if len(args) > 0 { websiteName := args[0] ListWebsiteContent(websiteName, con) @@ -48,8 +47,8 @@ func WebsitesCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st } } -// ListWebsites - Display a list of websites -func ListWebsites(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +// ListWebsites - Display a list of websites. +func ListWebsites(cmd *cobra.Command, con *console.SliverClient, args []string) { websites, err := con.Rpc.Websites(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("Failed to list websites %s", err) @@ -66,8 +65,8 @@ func ListWebsites(cmd *cobra.Command, con *console.SliverConsoleClient, args []s } } -// ListWebsiteContent - List the static contents of a website -func ListWebsiteContent(websiteName string, con *console.SliverConsoleClient) { +// ListWebsiteContent - List the static contents of a website. +func ListWebsiteContent(websiteName string, con *console.SliverClient) { website, err := con.Rpc.Website(context.Background(), &clientpb.Website{ Name: websiteName, }) @@ -83,7 +82,7 @@ func ListWebsiteContent(websiteName string, con *console.SliverConsoleClient) { } // PrintWebsite - Print a website and its contents, paths, etc. -func PrintWebsite(web *clientpb.Website, con *console.SliverConsoleClient) { +func PrintWebsite(web *clientpb.Website, con *console.SliverClient) { con.Println(console.Clearln + console.Info + web.Name) con.Println() tw := table.NewWriter() @@ -111,7 +110,7 @@ func PrintWebsite(web *clientpb.Website, con *console.SliverConsoleClient) { } // WebsiteNameCompleter completes the names of available websites. -func WebsiteNameCompleter(con *console.SliverConsoleClient) carapace.Action { +func WebsiteNameCompleter(con *console.SliverClient) carapace.Action { return carapace.ActionCallback(func(c carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/wireguard/commands.go b/client/command/wireguard/commands.go index dae1f74a09..5fab9a4e10 100644 --- a/client/command/wireguard/commands.go +++ b/client/command/wireguard/commands.go @@ -11,7 +11,7 @@ import ( ) // Commands returns the “ command and its subcommands. -func Commands(con *console.SliverConsoleClient) []*cobra.Command { +func Commands(con *console.SliverClient) []*cobra.Command { wgConfigCmd := &cobra.Command{ Use: consts.WgConfigStr, Short: "Generate a new WireGuard client config", @@ -36,7 +36,7 @@ func Commands(con *console.SliverConsoleClient) []*cobra.Command { } // SliverCommands returns all Wireguard commands that can be used on an active target. -func SliverCommands(con *console.SliverConsoleClient) []*cobra.Command { +func SliverCommands(con *console.SliverClient) []*cobra.Command { wgPortFwdCmd := &cobra.Command{ Use: consts.WgPortFwdStr, Short: "List ports forwarded by the WireGuard tun interface", diff --git a/client/command/wireguard/wg-config.go b/client/command/wireguard/wg-config.go index 7f08d3ec0a..760306fd73 100644 --- a/client/command/wireguard/wg-config.go +++ b/client/command/wireguard/wg-config.go @@ -52,7 +52,7 @@ type wgQuickConfig struct { } // WGConfigCmd - Generate a WireGuard client configuration. -func WGConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WGConfigCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { wgConfig, err := con.Rpc.GenerateWGClientConfig(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("Error: %s\n", err) diff --git a/client/command/wireguard/wg-portfwd-add.go b/client/command/wireguard/wg-portfwd-add.go index 28899c94da..4ca36a7771 100644 --- a/client/command/wireguard/wg-portfwd-add.go +++ b/client/command/wireguard/wg-portfwd-add.go @@ -28,7 +28,7 @@ import ( ) // WGPortFwdAddCmd - Add a new WireGuard port forward. -func WGPortFwdAddCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WGPortFwdAddCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/wireguard/wg-portfwd-rm.go b/client/command/wireguard/wg-portfwd-rm.go index 05ad176013..bd3f3555cd 100644 --- a/client/command/wireguard/wg-portfwd-rm.go +++ b/client/command/wireguard/wg-portfwd-rm.go @@ -30,7 +30,7 @@ import ( ) // WGPortFwdRmCmd - Remove a WireGuard port forward. -func WGPortFwdRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WGPortFwdRmCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -66,7 +66,7 @@ func WGPortFwdRmCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } // PortfwdIDCompleter completes IDs of WireGuard remote portforwarders. -func PortfwdIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func PortfwdIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/command/wireguard/wg-portfwd.go b/client/command/wireguard/wg-portfwd.go index 55614532ad..38882eeb7d 100644 --- a/client/command/wireguard/wg-portfwd.go +++ b/client/command/wireguard/wg-portfwd.go @@ -29,7 +29,7 @@ import ( ) // WGPortFwdListCmd - List WireGuard port forwards. -func WGPortFwdListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WGPortFwdListCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/wireguard/wg-socks-start.go b/client/command/wireguard/wg-socks-start.go index 4c3df6fc31..156aad40a3 100644 --- a/client/command/wireguard/wg-socks-start.go +++ b/client/command/wireguard/wg-socks-start.go @@ -27,7 +27,7 @@ import ( ) // WGSocksStartCmd - Start a WireGuard reverse SOCKS proxy. -func WGSocksStartCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WGSocksStartCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return diff --git a/client/command/wireguard/wg-socks-stop.go b/client/command/wireguard/wg-socks-stop.go index 6a808bc95b..c0239bfe74 100644 --- a/client/command/wireguard/wg-socks-stop.go +++ b/client/command/wireguard/wg-socks-stop.go @@ -28,7 +28,7 @@ import ( ) // WGSocksStopCmd - Stop a WireGuard SOCKS proxy. -func WGSocksStopCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WGSocksStopCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSession() if session == nil { return diff --git a/client/command/wireguard/wg-socks.go b/client/command/wireguard/wg-socks.go index f0fe2e2ea2..d2a88d5f00 100644 --- a/client/command/wireguard/wg-socks.go +++ b/client/command/wireguard/wg-socks.go @@ -31,7 +31,7 @@ import ( ) // WGSocksListCmd - List WireGuard SOCKS proxies. -func WGSocksListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func WGSocksListCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session := con.ActiveTarget.GetSessionInteractive() if session == nil { return @@ -73,7 +73,7 @@ func WGSocksListCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [ } // SocksIDCompleter IDs of WireGuard socks servers. -func SocksIDCompleter(con *console.SliverConsoleClient) carapace.Action { +func SocksIDCompleter(con *console.SliverClient) carapace.Action { callback := func(_ carapace.Context) carapace.Action { results := make([]string, 0) diff --git a/client/console/console.go b/client/console/console.go index fde4a37587..5742b7d124 100644 --- a/client/console/console.go +++ b/client/console/console.go @@ -32,13 +32,6 @@ import ( "sync" "time" - "github.com/gofrs/uuid" - "github.com/reeflective/console" - "github.com/reeflective/readline" - "github.com/spf13/cobra" - "golang.org/x/exp/slog" - "google.golang.org/protobuf/proto" - "github.com/bishopfox/sliver/client/assets" consts "github.com/bishopfox/sliver/client/constants" "github.com/bishopfox/sliver/client/core" @@ -48,6 +41,12 @@ import ( "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/protobuf/rpcpb" + "github.com/gofrs/uuid" + "github.com/reeflective/console" + "github.com/reeflective/readline" + "github.com/spf13/cobra" + "golang.org/x/exp/slog" + "google.golang.org/protobuf/proto" ) const ( @@ -55,7 +54,7 @@ const ( ) const ( - // ANSI Colors + // ANSI Colors. Normal = "\033[0m" Black = "\033[30m" Red = "\033[31m" @@ -71,25 +70,25 @@ const ( DownN = "\033[%dB" Underline = "\033[4m" - // Info - Display colorful information + // Info - Display colorful information. Info = Bold + Cyan + "[*] " + Normal - // Warn - Warn a user + // Warn - Warn a user. Warn = Bold + Red + "[!] " + Normal - // Debug - Display debug information + // Debug - Display debug information. Debug = Bold + Purple + "[-] " + Normal - // Woot - Display success + // Woot - Display success. Woot = Bold + Green + "[$] " + Normal - // Success - Diplay success + // Success - Diplay success. Success = Bold + Green + "[+] " + Normal ) -// Observer - A function to call when the sessions changes +// Observer - A function to call when the sessions changes. type ( Observer func(*clientpb.Session, *clientpb.Beacon) BeaconTaskCallback func(*clientpb.BeaconTask) ) -type SliverConsoleClient struct { +type SliverClient struct { App *console.Console Rpc rpcpb.SliverRPCClient ActiveTarget *ActiveTarget @@ -107,11 +106,11 @@ type SliverConsoleClient struct { // NewConsole creates the sliver client (and console), creating menus and prompts. // The returned console does neither have commands nor a working RPC connection yet, // thus has not started monitoring any server events, or started the application. -func NewConsole(isServer bool) *SliverConsoleClient { +func NewConsole(isServer bool) *SliverClient { assets.Setup(false, false) settings, _ := assets.LoadSettings() - con := &SliverConsoleClient{ + con := &SliverClient{ App: console.New("sliver"), ActiveTarget: &ActiveTarget{ observers: map[int]Observer{}, @@ -161,7 +160,7 @@ func NewConsole(isServer bool) *SliverConsoleClient { // Init requires a working RPC connection to the sliver server, and 2 different sets of commands. // If run is true, the console application is started, making this call blocking. Otherwise, commands and // RPC connection are bound to the console (making the console ready to run), but the console does not start. -func StartClient(con *SliverConsoleClient, rpc rpcpb.SliverRPCClient, serverCmds, sliverCmds console.Commands, run bool) error { +func StartClient(con *SliverClient, rpc rpcpb.SliverRPCClient, serverCmds, sliverCmds console.Commands, run bool) error { con.Rpc = rpc con.IsCLI = !run @@ -212,7 +211,7 @@ func StartClient(con *SliverConsoleClient, rpc rpcpb.SliverRPCClient, serverCmds return nil } -func (con *SliverConsoleClient) startEventLoop() { +func (con *SliverClient) startEventLoop() { eventStream, err := con.Rpc.Events(context.Background(), &commonpb.Empty{}) if err != nil { fmt.Printf(Warn+"%s\n", err) @@ -328,23 +327,23 @@ func (con *SliverConsoleClient) startEventLoop() { } } -// CreateEventListener - creates a new event listener and returns its ID -func (con *SliverConsoleClient) CreateEventListener() (string, <-chan *clientpb.Event) { +// CreateEventListener - creates a new event listener and returns its ID. +func (con *SliverClient) CreateEventListener() (string, <-chan *clientpb.Event) { listener := make(chan *clientpb.Event, 100) listenerID, _ := uuid.NewV4() con.EventListeners.Store(listenerID.String(), listener) return listenerID.String(), listener } -// RemoveEventListener - removes an event listener given its id -func (con *SliverConsoleClient) RemoveEventListener(listenerID string) { +// RemoveEventListener - removes an event listener given its id. +func (con *SliverClient) RemoveEventListener(listenerID string) { value, ok := con.EventListeners.LoadAndDelete(listenerID) if ok { close(value.(chan *clientpb.Event)) } } -func (con *SliverConsoleClient) triggerEventListeners(event *clientpb.Event) { +func (con *SliverClient) triggerEventListeners(event *clientpb.Event) { con.EventListeners.Range(func(key, value interface{}) bool { listener := value.(chan *clientpb.Event) listener <- event // Do not block while sending the event to the listener @@ -352,7 +351,7 @@ func (con *SliverConsoleClient) triggerEventListeners(event *clientpb.Event) { }) } -func (con *SliverConsoleClient) triggerReactions(event *clientpb.Event) { +func (con *SliverClient) triggerReactions(event *clientpb.Event) { reactions := core.Reactions.On(event.EventType) if len(reactions) == 0 { return @@ -388,8 +387,8 @@ func (con *SliverConsoleClient) triggerReactions(event *clientpb.Event) { } } -// triggerBeaconTaskCallback - Triggers the callback for a beacon task -func (con *SliverConsoleClient) triggerBeaconTaskCallback(data []byte) { +// triggerBeaconTaskCallback - Triggers the callback for a beacon task. +func (con *SliverClient) triggerBeaconTaskCallback(data []byte) { task := &clientpb.BeaconTask{} err := proto.Unmarshal(data, task) if err != nil { @@ -424,13 +423,13 @@ func (con *SliverConsoleClient) triggerBeaconTaskCallback(data []byte) { } } -func (con *SliverConsoleClient) AddBeaconCallback(taskID string, callback BeaconTaskCallback) { +func (con *SliverClient) AddBeaconCallback(taskID string, callback BeaconTaskCallback) { con.BeaconTaskCallbacksMutex.Lock() defer con.BeaconTaskCallbacksMutex.Unlock() con.BeaconTaskCallbacks[taskID] = callback } -func (con *SliverConsoleClient) GetPrompt() string { +func (con *SliverClient) GetPrompt() string { prompt := Underline + "sliver" + Normal if con.IsServer { prompt = Bold + "[server] " + Normal + Underline + "sliver" + Normal @@ -444,7 +443,7 @@ func (con *SliverConsoleClient) GetPrompt() string { return Clearln + prompt } -func (con *SliverConsoleClient) PrintLogo() { +func (con *SliverClient) PrintLogo() { serverVer, err := con.Rpc.GetVersion(context.Background(), &commonpb.Empty{}) if err != nil { panic(err.Error()) @@ -469,7 +468,7 @@ func (con *SliverConsoleClient) PrintLogo() { con.CheckLastUpdate() } -func (con *SliverConsoleClient) CheckLastUpdate() { +func (con *SliverClient) CheckLastUpdate() { now := time.Now() lastUpdate := getLastUpdateCheck() compiledAt, err := version.Compiled() @@ -503,7 +502,7 @@ func getLastUpdateCheck() *time.Time { return &lastUpdate } -func (con *SliverConsoleClient) GetSession(arg string) *clientpb.Session { +func (con *SliverClient) GetSession(arg string) *clientpb.Session { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintWarnf("%s", err) @@ -517,8 +516,8 @@ func (con *SliverConsoleClient) GetSession(arg string) *clientpb.Session { return nil } -// GetSessionsByName - Return all sessions for an Implant by name -func (con *SliverConsoleClient) GetSessionsByName(name string) []*clientpb.Session { +// GetSessionsByName - Return all sessions for an Implant by name. +func (con *SliverClient) GetSessionsByName(name string) []*clientpb.Session { sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{}) if err != nil { fmt.Printf(Warn+"%s\n", err) @@ -534,8 +533,8 @@ func (con *SliverConsoleClient) GetSessionsByName(name string) []*clientpb.Sessi } // GetActiveSessionConfig - Get the active sessions's config -// TODO: Switch to query config based on ConfigID -func (con *SliverConsoleClient) GetActiveSessionConfig() *clientpb.ImplantConfig { +// TODO: Switch to query config based on ConfigID. +func (con *SliverClient) GetActiveSessionConfig() *clientpb.ImplantConfig { session := con.ActiveTarget.GetSession() if session == nil { return nil @@ -562,7 +561,7 @@ func (con *SliverConsoleClient) GetActiveSessionConfig() *clientpb.ImplantConfig } // exitConsole prompts the user for confirmation to exit the console. -func (c *SliverConsoleClient) exitConsole(_ *console.Console) { +func (c *SliverClient) exitConsole(_ *console.Console) { reader := bufio.NewReader(os.Stdin) fmt.Print("Confirm exit (Y/y, Ctrl-C): ") text, _ := reader.ReadString('\n') @@ -574,18 +573,18 @@ func (c *SliverConsoleClient) exitConsole(_ *console.Console) { } // exitImplantMenu uses the background command to detach from the implant menu. -func (c *SliverConsoleClient) exitImplantMenu(_ *console.Console) { +func (c *SliverClient) exitImplantMenu(_ *console.Console) { root := c.App.Menu(consts.ImplantMenu).Command root.SetArgs([]string{"background"}) root.Execute() } -func (con *SliverConsoleClient) SpinUntil(message string, ctrl chan bool) { +func (con *SliverClient) SpinUntil(message string, ctrl chan bool) { go spin.Until(os.Stdout, message, ctrl) } -// FormatDateDelta - Generate formatted date string of the time delta between then and now -func (con *SliverConsoleClient) FormatDateDelta(t time.Time, includeDate bool, color bool) string { +// FormatDateDelta - Generate formatted date string of the time delta between then and now. +func (con *SliverClient) FormatDateDelta(t time.Time, includeDate bool, color bool) string { nextTime := t.Format(time.UnixDate) var interval string @@ -612,8 +611,8 @@ func (con *SliverConsoleClient) FormatDateDelta(t time.Time, includeDate bool, c return interval } -// GrpcContext - Generate a context for a GRPC request, if no grumble context or an invalid flag is provided 60 seconds is used instead -func (con *SliverConsoleClient) GrpcContext(cmd *cobra.Command) (context.Context, context.CancelFunc) { +// GrpcContext - Generate a context for a GRPC request, if no grumble context or an invalid flag is provided 60 seconds is used instead. +func (con *SliverClient) GrpcContext(cmd *cobra.Command) (context.Context, context.CancelFunc) { if cmd == nil { return context.WithTimeout(context.Background(), 60*time.Second) } @@ -635,10 +634,10 @@ type ActiveTarget struct { beacon *clientpb.Beacon observers map[int]Observer observerID int - con *SliverConsoleClient + con *SliverClient } -// GetSessionInteractive - Get the active target(s) +// GetSessionInteractive - Get the active target(s). func (s *ActiveTarget) GetInteractive() (*clientpb.Session, *clientpb.Beacon) { if s.session == nil && s.beacon == nil { fmt.Printf(Warn + "Please select a session or beacon via `use`\n") @@ -647,12 +646,12 @@ func (s *ActiveTarget) GetInteractive() (*clientpb.Session, *clientpb.Beacon) { return s.session, s.beacon } -// GetSessionInteractive - Get the active target(s) +// GetSessionInteractive - Get the active target(s). func (s *ActiveTarget) Get() (*clientpb.Session, *clientpb.Beacon) { return s.session, s.beacon } -// GetSessionInteractive - GetSessionInteractive the active session +// GetSessionInteractive - GetSessionInteractive the active session. func (s *ActiveTarget) GetSessionInteractive() *clientpb.Session { if s.session == nil { fmt.Printf(Warn + "Please select a session via `use`\n") @@ -661,12 +660,12 @@ func (s *ActiveTarget) GetSessionInteractive() *clientpb.Session { return s.session } -// GetSession - Same as GetSession() but doesn't print a warning +// GetSession - Same as GetSession() but doesn't print a warning. func (s *ActiveTarget) GetSession() *clientpb.Session { return s.session } -// GetBeaconInteractive - Get beacon interactive the active session +// GetBeaconInteractive - Get beacon interactive the active session. func (s *ActiveTarget) GetBeaconInteractive() *clientpb.Beacon { if s.beacon == nil { fmt.Printf(Warn + "Please select a beacon via `use`\n") @@ -675,7 +674,7 @@ func (s *ActiveTarget) GetBeaconInteractive() *clientpb.Beacon { return s.beacon } -// GetBeacon - Same as GetBeacon() but doesn't print a warning +// GetBeacon - Same as GetBeacon() but doesn't print a warning. func (s *ActiveTarget) GetBeacon() *clientpb.Beacon { return s.beacon } @@ -685,7 +684,7 @@ func (s *ActiveTarget) IsSession() bool { return s.session != nil } -// AddObserver - Observers to notify when the active session changes +// AddObserver - Observers to notify when the active session changes. func (s *ActiveTarget) AddObserver(observer Observer) int { s.observerID++ s.observers[s.observerID] = observer @@ -722,7 +721,7 @@ func (s *ActiveTarget) Request(cmd *cobra.Command) *commonpb.Request { return req } -// Set - Change the active session +// Set - Change the active session. func (s *ActiveTarget) Set(session *clientpb.Session, beacon *clientpb.Beacon) { if session != nil && beacon != nil { s.con.PrintErrorf("cannot set both an active beacon and an active session") @@ -776,7 +775,7 @@ func (s *ActiveTarget) Set(session *clientpb.Session, beacon *clientpb.Beacon) { } } -// Background - Background the active session +// Background - Background the active session. func (s *ActiveTarget) Background() { defer s.con.App.ShowCommands() @@ -794,7 +793,7 @@ func (s *ActiveTarget) Background() { // Expose or hide commands if the active target does support them (or not). // Ex; hide Windows commands on Linux implants, Wireguard tools on HTTP C2, etc. -func (con *SliverConsoleClient) ExposeCommands() { +func (con *SliverClient) ExposeCommands() { con.App.ShowCommands() if con.ActiveTarget.session == nil && con.ActiveTarget.beacon == nil { diff --git a/client/console/log.go b/client/console/log.go index cb2d0d35c3..dde03bf9d2 100644 --- a/client/console/log.go +++ b/client/console/log.go @@ -28,14 +28,13 @@ import ( "strings" "time" - "github.com/moloch--/asciicast" - "golang.org/x/exp/slog" - "golang.org/x/term" - "github.com/bishopfox/sliver/client/assets" "github.com/bishopfox/sliver/protobuf/clientpb" "github.com/bishopfox/sliver/protobuf/commonpb" "github.com/bishopfox/sliver/protobuf/rpcpb" + "github.com/moloch--/asciicast" + "golang.org/x/exp/slog" + "golang.org/x/term" ) // ConsoleClientLogger is an io.Writer that sends data to the server. @@ -54,7 +53,7 @@ func (l *ConsoleClientLogger) Write(buf []byte) (int, error) { // ClientLogStream requires a log stream name, used to save the logs // going through this stream in a specific log subdirectory/file. -func (con *SliverConsoleClient) ClientLogStream(name string) (*ConsoleClientLogger, error) { +func (con *SliverClient) ClientLogStream(name string) (*ConsoleClientLogger, error) { stream, err := con.Rpc.ClientLog(context.Background()) if err != nil { return nil, err @@ -62,7 +61,7 @@ func (con *SliverConsoleClient) ClientLogStream(name string) (*ConsoleClientLogg return &ConsoleClientLogger{name: name, Stream: stream}, nil } -func (con *SliverConsoleClient) setupLogger(writers ...io.Writer) { +func (con *SliverClient) setupLogger(writers ...io.Writer) { logWriter := io.MultiWriter(writers...) jsonOptions := &slog.HandlerOptions{ Level: slog.LevelDebug, @@ -74,7 +73,7 @@ func (con *SliverConsoleClient) setupLogger(writers ...io.Writer) { } // logCommand logs non empty commands to the client log file. -func (con *SliverConsoleClient) logCommand(args []string) ([]string, error) { +func (con *SliverClient) logCommand(args []string) ([]string, error) { if len(args) == 0 { return args, nil } @@ -83,7 +82,7 @@ func (con *SliverConsoleClient) logCommand(args []string) ([]string, error) { return args, nil } -func (con *SliverConsoleClient) setupAsciicastRecord(logFile *os.File, server io.Writer) { +func (con *SliverClient) setupAsciicastRecord(logFile *os.File, server io.Writer) { x, y, err := term.GetSize(int(os.Stdin.Fd())) if err != nil { x, y = 80, 80 @@ -139,8 +138,8 @@ func getConsoleAsciicastFile() *os.File { // These below will print their output regardless of the currently active menu (server/implant), // while those in the log package tie their output to the current menu. -// PrintAsyncResponse - Print the generic async response information -func (con *SliverConsoleClient) PrintAsyncResponse(resp *commonpb.Response) { +// PrintAsyncResponse - Print the generic async response information. +func (con *SliverClient) PrintAsyncResponse(resp *commonpb.Response) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() beacon, err := con.Rpc.GetBeacon(ctx, &clientpb.Beacon{ID: resp.BeaconID}) @@ -151,7 +150,7 @@ func (con *SliverConsoleClient) PrintAsyncResponse(resp *commonpb.Response) { con.PrintInfof("Tasked beacon %s (%s)\n", beacon.Name, strings.Split(resp.TaskID, "-")[0]) } -func (con *SliverConsoleClient) Printf(format string, args ...any) { +func (con *SliverClient) Printf(format string, args ...any) { logger := slog.NewLogLogger(con.jsonHandler, slog.LevelInfo) logger.Printf(format, args...) @@ -159,7 +158,7 @@ func (con *SliverConsoleClient) Printf(format string, args ...any) { } // Println prints an output without status and immediately below the last line of output. -func (con *SliverConsoleClient) Println(args ...any) { +func (con *SliverClient) Println(args ...any) { logger := slog.New(con.jsonHandler) format := strings.Repeat("%s", len(args)) logger.Info(fmt.Sprintf(format, args)) @@ -167,7 +166,7 @@ func (con *SliverConsoleClient) Println(args ...any) { } // PrintInfof prints an info message immediately below the last line of output. -func (con *SliverConsoleClient) PrintInfof(format string, args ...any) { +func (con *SliverClient) PrintInfof(format string, args ...any) { logger := slog.New(con.jsonHandler) logger.Info(fmt.Sprintf(format, args...)) @@ -176,7 +175,7 @@ func (con *SliverConsoleClient) PrintInfof(format string, args ...any) { } // PrintSuccessf prints a success message immediately below the last line of output. -func (con *SliverConsoleClient) PrintSuccessf(format string, args ...any) { +func (con *SliverClient) PrintSuccessf(format string, args ...any) { logger := slog.New(con.jsonHandler) logger.Info(fmt.Sprintf(format, args...)) @@ -185,7 +184,7 @@ func (con *SliverConsoleClient) PrintSuccessf(format string, args ...any) { } // PrintWarnf a warning message immediately below the last line of output. -func (con *SliverConsoleClient) PrintWarnf(format string, args ...any) { +func (con *SliverClient) PrintWarnf(format string, args ...any) { logger := slog.New(con.jsonHandler) logger.Warn(fmt.Sprintf(format, args...)) @@ -194,7 +193,7 @@ func (con *SliverConsoleClient) PrintWarnf(format string, args ...any) { } // PrintErrorf prints an error message immediately below the last line of output. -func (con *SliverConsoleClient) PrintErrorf(format string, args ...any) { +func (con *SliverClient) PrintErrorf(format string, args ...any) { logger := slog.New(con.jsonHandler) logger.Error(fmt.Sprintf(format, args...)) @@ -203,7 +202,7 @@ func (con *SliverConsoleClient) PrintErrorf(format string, args ...any) { } // PrintEventInfof prints an info message with a leading/trailing newline for emphasis. -func (con *SliverConsoleClient) PrintEventInfof(format string, args ...any) { +func (con *SliverClient) PrintEventInfof(format string, args ...any) { logger := slog.New(con.jsonHandler).With(slog.String("type", "event")) logger.Info(fmt.Sprintf(format, args...)) @@ -212,7 +211,7 @@ func (con *SliverConsoleClient) PrintEventInfof(format string, args ...any) { } // PrintEventErrorf prints an error message with a leading/trailing newline for emphasis. -func (con *SliverConsoleClient) PrintEventErrorf(format string, args ...any) { +func (con *SliverClient) PrintEventErrorf(format string, args ...any) { logger := slog.New(con.jsonHandler).With(slog.String("type", "event")) logger.Error(fmt.Sprintf(format, args...)) @@ -221,7 +220,7 @@ func (con *SliverConsoleClient) PrintEventErrorf(format string, args ...any) { } // PrintEventSuccessf a success message with a leading/trailing newline for emphasis. -func (con *SliverConsoleClient) PrintEventSuccessf(format string, args ...any) { +func (con *SliverClient) PrintEventSuccessf(format string, args ...any) { logger := slog.New(con.jsonHandler).With(slog.String("type", "event")) logger.Info(fmt.Sprintf(format, args...)) From 2ad8aa482981bc39573142bf77c7c67c73361f21 Mon Sep 17 00:00:00 2001 From: rkervella Date: Tue, 2 Jan 2024 16:13:26 -0800 Subject: [PATCH 13/14] Fix last merge issues --- client/command/c2profiles/c2profiles.go | 6 +++--- client/command/extensions/remove.go | 2 +- client/command/filesystem/grep.go | 4 ++-- client/command/filesystem/head.go | 2 +- client/command/generate/implants-stage.go | 2 +- client/command/generate/profiles-stage.go | 2 +- client/command/loot/remote.go | 2 +- client/command/monitor/config.go | 8 ++++---- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/client/command/c2profiles/c2profiles.go b/client/command/c2profiles/c2profiles.go index e056cfcdd5..921796bcec 100644 --- a/client/command/c2profiles/c2profiles.go +++ b/client/command/c2profiles/c2profiles.go @@ -39,7 +39,7 @@ import ( ) // C2ProfileCmd list available http profiles -func C2ProfileCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func C2ProfileCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { profileName, _ := cmd.Flags().GetString("name") if profileName == constants.DefaultC2Profile { @@ -61,7 +61,7 @@ func C2ProfileCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s PrintC2Profiles(profile, con) } -func ImportC2ProfileCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ImportC2ProfileCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { protocols := []string{constants.HttpStr, constants.HttpsStr} profileName, _ := cmd.Flags().GetString("name") if profileName == "" { @@ -248,7 +248,7 @@ func C2ConfigToProtobuf(profileName string, config *assets.HTTPC2Config) *client } // PrintImplantBuilds - Print the implant builds on the server -func PrintC2Profiles(profile *clientpb.HTTPC2Config, con *console.SliverConsoleClient) { +func PrintC2Profiles(profile *clientpb.HTTPC2Config, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) diff --git a/client/command/extensions/remove.go b/client/command/extensions/remove.go index 498e21651a..9cd81f1341 100644 --- a/client/command/extensions/remove.go +++ b/client/command/extensions/remove.go @@ -81,7 +81,7 @@ func RemoveExtensionByCommandName(commandName string, con *console.SliverClient) } // RemoveExtensionByManifestName - remove by the named manifest, returns true if manifest was removed, false if no manifest with that name was found -func RemoveExtensionByManifestName(manifestName string, con *console.SliverConsoleClient) (bool, error) { +func RemoveExtensionByManifestName(manifestName string, con *console.SliverClient) (bool, error) { if manifestName == "" { return false, errors.New("command name is required") } diff --git a/client/command/filesystem/grep.go b/client/command/filesystem/grep.go index 107cd73693..14da934671 100644 --- a/client/command/filesystem/grep.go +++ b/client/command/filesystem/grep.go @@ -83,7 +83,7 @@ func processFlags(searchPattern string, insensitive bool, exact bool) string { return processedSearchPattern } -func GrepCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func GrepCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return @@ -152,7 +152,7 @@ func GrepCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string } // printGrep - Print the results from the grep operation to stdout -func printGrep(grep *sliverpb.Grep, searchPattern string, searchPath string, cmd *cobra.Command, con *console.SliverConsoleClient) { +func printGrep(grep *sliverpb.Grep, searchPattern string, searchPath string, cmd *cobra.Command, con *console.SliverClient) { saveLoot, _ := cmd.Flags().GetBool("loot") lootName, _ := cmd.Flags().GetString("name") colorize, _ := cmd.Flags().GetBool("colorize-output") diff --git a/client/command/filesystem/head.go b/client/command/filesystem/head.go index 9a0c782fb7..4cf9dec8c8 100644 --- a/client/command/filesystem/head.go +++ b/client/command/filesystem/head.go @@ -29,7 +29,7 @@ import ( "google.golang.org/protobuf/proto" ) -func HeadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string, head bool) { +func HeadCmd(cmd *cobra.Command, con *console.SliverClient, args []string, head bool) { session, beacon := con.ActiveTarget.GetInteractive() if session == nil && beacon == nil { return diff --git a/client/command/generate/implants-stage.go b/client/command/generate/implants-stage.go index d046563578..8a8094941b 100644 --- a/client/command/generate/implants-stage.go +++ b/client/command/generate/implants-stage.go @@ -12,7 +12,7 @@ import ( ) // ImplantsStageCmd - Serve a previously generated build -func ImplantsStageCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ImplantsStageCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { builds, err := con.Rpc.ImplantBuilds(context.Background(), &commonpb.Empty{}) if err != nil { con.PrintErrorf("Unable to load implant builds '%s'\n", err) diff --git a/client/command/generate/profiles-stage.go b/client/command/generate/profiles-stage.go index d06052beec..99d6ed8cbd 100644 --- a/client/command/generate/profiles-stage.go +++ b/client/command/generate/profiles-stage.go @@ -30,7 +30,7 @@ import ( ) // ProfilesStageCmd - Generate an encrypted/compressed implant binary based on a profile -func ProfilesStageCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func ProfilesStageCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { name, _ := cmd.Flags().GetString("name") profileName := args[0] aesEncryptKey, _ := cmd.Flags().GetString("aes-encrypt-key") diff --git a/client/command/loot/remote.go b/client/command/loot/remote.go index 985d78532b..f1100a610b 100644 --- a/client/command/loot/remote.go +++ b/client/command/loot/remote.go @@ -198,7 +198,7 @@ func LootDownload(download *sliverpb.Download, lootName string, fileType clientp } } -func LootText(text string, lootName string, lootFileName string, fileType clientpb.FileType, con *console.SliverConsoleClient) { +func LootText(text string, lootName string, lootFileName string, fileType clientpb.FileType, con *console.SliverClient) { lootMessage := CreateLootMessage(con.ActiveTarget.GetHostUUID(), lootFileName, lootName, fileType, []byte(text)) SendLootMessage(lootMessage, con) } diff --git a/client/command/monitor/config.go b/client/command/monitor/config.go index 5dded70628..b4abc3b42a 100644 --- a/client/command/monitor/config.go +++ b/client/command/monitor/config.go @@ -31,7 +31,7 @@ import ( "github.com/spf13/cobra" ) -func MonitorConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func MonitorConfigCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { resp, err := con.Rpc.MonitorListConfig(context.Background(), &commonpb.Empty{}) if err != nil { @@ -41,7 +41,7 @@ func MonitorConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args PrintWTConfig(resp, con) } -func MonitorAddConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func MonitorAddConfigCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { apiKey, _ := cmd.Flags().GetString("apiKey") apiPassword, _ := cmd.Flags().GetString("apiPassword") @@ -65,7 +65,7 @@ func MonitorAddConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, a con.PrintInfof("Added monitoring configuration\n") } -func MonitorDelConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) { +func MonitorDelConfigCmd(cmd *cobra.Command, con *console.SliverClient, args []string) { resp, err := con.Rpc.MonitorListConfig(context.Background(), &commonpb.Empty{}) if err != nil { @@ -88,7 +88,7 @@ func MonitorDelConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, a } // PrintWTConfig - Print the current watchtower configuration -func PrintWTConfig(configs *clientpb.MonitoringProviders, con *console.SliverConsoleClient) { +func PrintWTConfig(configs *clientpb.MonitoringProviders, con *console.SliverClient) { tw := table.NewWriter() tw.SetStyle(settings.GetTableStyle(con)) From 77fea4f81ca5d990ba4cfaaa85e41490e57e0443 Mon Sep 17 00:00:00 2001 From: rkervella Date: Wed, 3 Jan 2024 13:14:19 -0800 Subject: [PATCH 14/14] Update readline lib --- go.mod | 2 +- go.sum | 2 + .../github.com/reeflective/readline/emacs.go | 3 +- .../reeflective/readline/inputrc/parse.go | 415 +++++++++++------- .../readline/internal/completion/group.go | 3 +- .../readline/internal/keymap/cursor.go | 9 +- .../readline/internal/ui/prompt.go | 2 + vendor/modules.txt | 2 +- 8 files changed, 262 insertions(+), 176 deletions(-) diff --git a/go.mod b/go.mod index d1444d34a4..28e15fefa5 100644 --- a/go.mod +++ b/go.mod @@ -35,7 +35,7 @@ require ( github.com/moloch--/memmod v0.0.0-20211120144554-8b37cc654945 github.com/ncruces/go-sqlite3 v0.7.2 github.com/reeflective/console v0.1.6 - github.com/reeflective/readline v1.0.11 + github.com/reeflective/readline v1.0.13 github.com/rsteube/carapace v0.36.3 github.com/sirupsen/logrus v1.9.3 github.com/spf13/cobra v1.8.0 diff --git a/go.sum b/go.sum index eec75dda98..a3e840492e 100644 --- a/go.sum +++ b/go.sum @@ -354,6 +354,8 @@ github.com/reeflective/console v0.1.6 h1:BhhvQU/m8QOpaIRzrXfwcbtkGQJX9jVR5qIqAy/ github.com/reeflective/console v0.1.6/go.mod h1:7owTBE9k2lg2QpVw7g4DrK1HxEgr/5DQCmA3O2Znoek= github.com/reeflective/readline v1.0.11 h1:4+aiebj7a89hTRJOMM98H+md1Kxu+v1XkfdCs0n6odQ= github.com/reeflective/readline v1.0.11/go.mod h1:mcD0HxNVJVteVwDm9caXKg52nQACVyfh8EyuBmgVlzY= +github.com/reeflective/readline v1.0.13 h1:TeJmYw9B7VRPZWfNExr9QHxL1m0iSicyqBSQIRn39Ss= +github.com/reeflective/readline v1.0.13/go.mod h1:3iOe/qyb2jEy0KqLrNlb/CojBVqxga9ACqz/VU22H6A= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE= github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= diff --git a/vendor/github.com/reeflective/readline/emacs.go b/vendor/github.com/reeflective/readline/emacs.go index a8d267ebbc..5dfbe148ba 100644 --- a/vendor/github.com/reeflective/readline/emacs.go +++ b/vendor/github.com/reeflective/readline/emacs.go @@ -7,13 +7,14 @@ import ( "strings" "unicode" + "github.com/rivo/uniseg" + "github.com/reeflective/readline/inputrc" "github.com/reeflective/readline/internal/color" "github.com/reeflective/readline/internal/completion" "github.com/reeflective/readline/internal/keymap" "github.com/reeflective/readline/internal/strutil" "github.com/reeflective/readline/internal/term" - "github.com/rivo/uniseg" ) // standardCommands returns all standard/emacs commands. diff --git a/vendor/github.com/reeflective/readline/inputrc/parse.go b/vendor/github.com/reeflective/readline/inputrc/parse.go index 7f2f1d3b3f..429aa128ad 100644 --- a/vendor/github.com/reeflective/readline/inputrc/parse.go +++ b/vendor/github.com/reeflective/readline/inputrc/parse.go @@ -15,6 +15,13 @@ import ( "unicode/utf8" ) +const ( + emacs = "emacs" + hexValNum = 10 + metaSeqLength = 6 + setDirectiveLen = 4 +) + // Parser is a inputrc parser. type Parser struct { haltOnErr bool @@ -32,48 +39,53 @@ type Parser struct { // New creates a new inputrc parser. func New(opts ...Option) *Parser { // build parser state - p := &Parser{ + parser := &Parser{ line: 1, } for _, o := range opts { - o(p) + o(parser) } - return p + + return parser } // Parse parses inputrc data from the reader, passing sets and binding keys to // h based on the configured options. -func (p *Parser) Parse(r io.Reader, h Handler) error { +func (p *Parser) Parse(stream io.Reader, handler Handler) error { var err error // reset parser state - p.keymap, p.line, p.conds, p.errs = "emacs", 1, append(p.conds[:0], true), p.errs[:0] + p.keymap, p.line, p.conds, p.errs = emacs, 1, append(p.conds[:0], true), p.errs[:0] // scan file by lines var line []rune - var i, end int - s := bufio.NewScanner(r) - for ; s.Scan(); p.line++ { - line = []rune(s.Text()) + var pos, end int + scanner := bufio.NewScanner(stream) + + for ; scanner.Scan(); p.line++ { + line = []rune(scanner.Text()) end = len(line) - if i = findNonSpace(line, 0, end); i == end { + + if pos = findNonSpace(line, 0, end); pos == end { continue } // skip blank/comment - switch line[i] { + switch line[pos] { case 0, '\r', '\n', '#': continue } // next - if err = p.next(h, line, i, end); err != nil { + if err = p.next(handler, line, pos, end); err != nil { p.errs = append(p.errs, err) if p.haltOnErr { return err } } } - if err = s.Err(); err != nil { + + if err = scanner.Err(); err != nil { p.errs = append(p.errs, err) return err } + return nil } @@ -83,53 +95,60 @@ func (p *Parser) Errs() []error { } // next handles the next statement. -func (p *Parser) next(h Handler, r []rune, i, end int) error { - a, b, tok, err := p.readNext(r, i, end) +func (p *Parser) next(handler Handler, seq []rune, pos, end int) error { + directive, val, tok, err := p.readNext(seq, pos, end) if err != nil { return err } + switch tok { case tokenBind, tokenBindMacro: - return p.doBind(h, a, b, tok == tokenBindMacro) + return p.doBind(handler, directive, val, tok == tokenBindMacro) case tokenSet: - return p.doSet(h, a, b) + return p.doSet(handler, directive, val) case tokenConstruct: - return p.do(h, a, b) + return p.do(handler, directive, val) } + return nil } // readNext reads the next statement. -func (p *Parser) readNext(r []rune, i, end int) (string, string, token, error) { - i = findNonSpace(r, i, end) +func (p *Parser) readNext(seq []rune, pos, end int) (string, string, token, error) { + pos = findNonSpace(seq, pos, end) + switch { - case r[i] == 's' && grab(r, i+1, end) == 'e' && grab(r, i+2, end) == 't' && unicode.IsSpace(grab(r, i+3, end)): + case seq[pos] == 's' && grab(seq, pos+1, end) == 'e' && grab(seq, pos+2, end) == 't' && unicode.IsSpace(grab(seq, pos+3, end)): // read set - return p.readSymbols(r, i+4, end, tokenSet) - case r[i] == '$': + return p.readSymbols(seq, pos+setDirectiveLen, end, tokenSet, true) + case seq[pos] == '$': // read construct - return p.readSymbols(r, i, end, tokenConstruct) + return p.readSymbols(seq, pos, end, tokenConstruct, false) } - // read key seq - var seq string - if r[i] == '"' || r[i] == '\'' { - start, ok := i, false - if i, ok = findStringEnd(r, i, end); !ok { + // read key keySeq + var keySeq string + + if seq[pos] == '"' || seq[pos] == '\'' { + var ok bool + start := pos + + if pos, ok = findStringEnd(seq, pos, end); !ok { return "", "", tokenNone, &ParseError{ Name: p.name, Line: p.line, - Text: string(r[start:]), + Text: string(seq[start:]), Err: ErrBindMissingClosingQuote, } } - seq = unescapeRunes(r, start+1, i-1) + + keySeq = unescapeRunes(seq, start+1, pos-1) } else { var err error - if seq, i, err = decodeKey(r, i, end); err != nil { + if keySeq, pos, err = decodeKey(seq, pos, end); err != nil { return "", "", tokenNone, &ParseError{ Name: p.name, Line: p.line, - Text: string(r), + Text: string(seq), Err: err, } } @@ -139,44 +158,61 @@ func (p *Parser) readNext(r []rune, i, end int) (string, string, token, error) { // does not bind a key) if a space follows the key declaration. made a // decision to instead return an error if the : is missing in all cases. // seek : - for ; i < end && r[i] != ':'; i++ { + for ; pos < end && seq[pos] != ':'; pos++ { } - if i == end || r[i] != ':' { + + if pos == end || seq[pos] != ':' { return "", "", tokenNone, &ParseError{ Name: p.name, Line: p.line, - Text: string(r), + Text: string(seq), Err: ErrMissingColon, } } // seek non space - if i = findNonSpace(r, i+1, end); i == end || r[i] == '#' { - return seq, "", tokenNone, nil + if pos = findNonSpace(seq, pos+1, end); pos == end || seq[pos] == '#' { + return keySeq, "", tokenNone, nil } // seek - if r[i] == '"' || r[i] == '\'' { - start, ok := i, false - if i, ok = findStringEnd(r, i, end); !ok { + if seq[pos] == '"' || seq[pos] == '\'' { + var ok bool + start := pos + + if pos, ok = findStringEnd(seq, pos, end); !ok { return "", "", tokenNone, &ParseError{ Name: p.name, Line: p.line, - Text: string(r[start:]), + Text: string(seq[start:]), Err: ErrMacroMissingClosingQuote, } } - return seq, unescapeRunes(r, start+1, i-1), tokenBindMacro, nil + + return keySeq, unescapeRunes(seq, start+1, pos-1), tokenBindMacro, nil } - return seq, string(r[i:findEnd(r, i, end)]), tokenBind, nil + + return keySeq, string(seq[pos:findEnd(seq, pos, end)]), tokenBind, nil } // readSet reads the next two symbols. -func (p *Parser) readSymbols(r []rune, i, end int, tok token) (string, string, token, error) { - start := findNonSpace(r, i, end) - i = findEnd(r, start, end) - a := string(r[start:i]) - start = findNonSpace(r, i, end) - i = findEnd(r, start, end) - return a, string(r[start:i]), tok, nil +func (p *Parser) readSymbols(seq []rune, pos, end int, tok token, allowStrings bool) (string, string, token, error) { + start := findNonSpace(seq, pos, end) + pos = findEnd(seq, start, end) + val := string(seq[start:pos]) + start = findNonSpace(seq, pos, end) + var ok bool + + if c := grab(seq, start, end); allowStrings || c == '"' || c == '\'' { + var epos int + if epos, ok = findStringEnd(seq, start, end); ok { + pos = epos + } + } + + if !allowStrings || !ok { + pos = findEnd(seq, start, end) + } + + return val, string(seq[start:pos]), tok, nil } // doBind handles a bind. @@ -184,14 +220,16 @@ func (p *Parser) doBind(h Handler, sequence, action string, macro bool) error { if !p.conds[len(p.conds)-1] { return nil } + return h.Bind(p.keymap, sequence, action, macro) } // doSet handles a set. -func (p *Parser) doSet(h Handler, name, value string) error { +func (p *Parser) doSet(handler Handler, name, value string) error { if !p.conds[len(p.conds)-1] { return nil } + switch name { case "keymap": if p.strict { @@ -209,8 +247,11 @@ func (p *Parser) doSet(h Handler, name, value string) error { } } } + p.keymap = value + return nil + case "editing-mode": switch value { case "emacs", "vi": @@ -222,55 +263,66 @@ func (p *Parser) doSet(h Handler, name, value string) error { Err: ErrInvalidEditingMode, } } - return h.Set(name, value) + + return handler.Set(name, value) } - if v := h.Get(name); v != nil { + + if val := handler.Get(name); val != nil { // defined in vars, so pass to set only as that type - var z interface{} - switch v.(type) { + var data interface{} + switch val.(type) { case bool: - z = strings.ToLower(value) == "on" || value == "1" + data = strings.ToLower(value) == "on" || value == "1" case string: - z = value + data = value case int: i, err := strconv.Atoi(value) if err != nil { return err } - z = i + + data = i + default: - panic(fmt.Sprintf("unsupported type %T", v)) + panic(fmt.Sprintf("unsupported type %T", val)) } - return h.Set(name, z) + + return handler.Set(name, data) } // not set, so try to convert to usable value if i, err := strconv.Atoi(value); err == nil { - return h.Set(name, i) + return handler.Set(name, i) } + switch strings.ToLower(value) { case "off": - return h.Set(name, false) + return handler.Set(name, false) case "on": - return h.Set(name, true) + return handler.Set(name, true) } - return h.Set(name, value) + + return handler.Set(name, value) } // do handles a construct. -func (p *Parser) do(h Handler, a, b string) error { - switch a { +func (p *Parser) do(handler Handler, keyword, val string) error { + switch keyword { case "$if": var eval bool + switch { - case strings.HasPrefix(b, "mode="): - eval = strings.TrimPrefix(b, "mode=") == p.mode - case strings.HasPrefix(b, "term="): - eval = strings.TrimPrefix(b, "term=") == p.term + case strings.HasPrefix(val, "mode="): + eval = strings.TrimPrefix(val, "mode=") == p.mode + case strings.HasPrefix(val, "term="): + eval = strings.TrimPrefix(val, "term=") == p.term default: - eval = strings.ToLower(b) == p.app + eval = strings.ToLower(val) == p.app } + p.conds = append(p.conds, eval) + return nil + case "$else": if len(p.conds) == 1 { return &ParseError{ @@ -280,8 +332,11 @@ func (p *Parser) do(h Handler, a, b string) error { Err: ErrElseWithoutMatchingIf, } } + p.conds[len(p.conds)-1] = !p.conds[len(p.conds)-1] + return nil + case "$endif": if len(p.conds) == 1 { return &ParseError{ @@ -291,34 +346,42 @@ func (p *Parser) do(h Handler, a, b string) error { Err: ErrEndifWithoutMatchingIf, } } + p.conds = p.conds[:len(p.conds)-1] + return nil + case "$include": if !p.conds[len(p.conds)-1] { return nil } - path := expandIncludePath(b) - buf, err := h.ReadFile(path) + + path := expandIncludePath(val) + buf, err := handler.ReadFile(path) + switch { case err != nil && errors.Is(err, os.ErrNotExist): return nil case err != nil: return err } - return Parse(bytes.NewReader(buf), h, WithName(b), WithApp(p.app), WithTerm(p.term), WithMode(p.mode)) + + return Parse(bytes.NewReader(buf), handler, WithName(val), WithApp(p.app), WithTerm(p.term), WithMode(p.mode)) } + if !p.conds[len(p.conds)-1] { return nil } // delegate unknown construct - if err := h.Do(a, b); err != nil { + if err := handler.Do(keyword, val); err != nil { return &ParseError{ Name: p.name, Line: p.line, - Text: a + " " + b, + Text: keyword + " " + val, Err: err, } } + return nil } @@ -381,6 +444,7 @@ func (err *ParseError) Error() string { if err.Name != "" { s = " " + err.Name + ":" } + return fmt.Sprintf("inputrc:%s line %d: %s: %v", s, err.Line, err.Text, err.Err) } @@ -415,6 +479,7 @@ func (tok token) String() string { case tokenConstruct: return "construct" } + return fmt.Sprintf("token(%d)", tok) } @@ -431,22 +496,26 @@ func findEnd(r []rune, i, end int) int { for c := grab(r, i+1, end); i < end && c != '#' && !unicode.IsSpace(c) && !unicode.IsControl(c); i++ { c = grab(r, i+1, end) } + return i } // findStringEnd finds end of the string, returning end if not found. -func findStringEnd(r []rune, i, end int) (int, bool) { - quote, c := r[i], rune(0) - for i++; i < end; i++ { - switch c = r[i]; { - case c == '\\': - i++ +func findStringEnd(seq []rune, pos, end int) (int, bool) { + var char rune + quote := seq[pos] + + for pos++; pos < end; pos++ { + switch char = seq[pos]; { + case char == '\\': + pos++ continue - case c == quote: - return i + 1, true + case char == quote: + return pos + 1, true } } - return i, false + + return pos, false } // grab returns r[i] when i < end, 0 otherwise. @@ -454,62 +523,70 @@ func grab(r []rune, i, end int) rune { if i < end { return r[i] } + return 0 } // decodeKey decodes named key sequence. -func decodeKey(r []rune, i, end int) (string, int, error) { +func decodeKey(seq []rune, pos, end int) (string, int, error) { // seek end of sequence - start := i - for c := grab(r, i+1, end); i < end && c != ':' && c != '#' && !unicode.IsSpace(c) && !unicode.IsControl(c); i++ { - c = grab(r, i+1, end) + start := pos + for c := grab(seq, pos+1, end); pos < end && c != ':' && c != '#' && !unicode.IsSpace(c) && !unicode.IsControl(c); pos++ { + c = grab(seq, pos+1, end) } - s := strings.ToLower(string(r[start:i])) + + val := strings.ToLower(string(seq[start:pos])) meta, control := false, false - for i := strings.Index(s, "-"); i != -1; i = strings.Index(s, "-") { - switch s[:i] { + + for idx := strings.Index(val, "-"); idx != -1; idx = strings.Index(val, "-") { + switch val[:idx] { case "control", "ctrl", "c": control = true case "meta", "m": meta = true default: - return "", i, ErrUnknownModifier + return "", idx, ErrUnknownModifier } - s = s[i+1:] + + val = val[idx+1:] } - var c rune - switch s { + + var char rune + + switch val { case "": - return "", i, nil + return "", pos, nil case "delete", "del", "rubout": - c = Delete + char = Delete case "escape", "esc": - c = Esc + char = Esc case "newline", "linefeed", "lfd": - c = Newline + char = Newline case "return", "ret": - c = Return + char = Return case "tab": - c = Tab + char = Tab case "space", "spc": - c = Space + char = Space case "formfeed", "ffd": - c = Formfeed + char = Formfeed case "vertical", "vrt": - c = Vertical + char = Vertical default: - c, _ = utf8.DecodeRuneInString(s) + char, _ = utf8.DecodeRuneInString(val) } + switch { case control && meta: - return string([]rune{Esc, Encontrol(c)}), i, nil + return string([]rune{Esc, Encontrol(char)}), pos, nil case control: - c = Encontrol(c) + char = Encontrol(char) case meta: - c = Enmeta(c) + char = Enmeta(char) } - return string(c), i, nil + + return string(char), pos, nil } /* @@ -540,87 +617,94 @@ func decodeRunes(r []rune, i, end int) string { // unescapeRunes decodes escaped string sequence. func unescapeRunes(r []rune, i, end int) string { - var s []rune - var c0, c1, c2, c3, c4, c5 rune + var seq []rune + var char0, char1, char2, char3, char4, char5 rune + for ; i < end; i++ { - if c0 = r[i]; c0 == '\\' { - c1, c2, c3, c4, c5 = grab(r, i+1, end), grab(r, i+2, end), grab(r, i+3, end), grab(r, i+4, end), grab(r, i+5, end) + if char0 = r[i]; char0 == '\\' { + char1, char2, char3, char4, char5 = grab(r, i+1, end), grab(r, i+2, end), grab(r, i+3, end), grab(r, i+4, end), grab(r, i+5, end) + switch { - case c1 == 'a': // \a alert (bell) - s = append(s, Alert) + case char1 == 'a': // \a alert (bell) + seq = append(seq, Alert) i++ - case c1 == 'b': // \b backspace - s = append(s, Backspace) + case char1 == 'b': // \b backspace + seq = append(seq, Backspace) i++ - case c1 == 'd': // \d delete - s = append(s, Delete) + case char1 == 'd': // \d delete + seq = append(seq, Delete) i++ - case c1 == 'e': // \e escape - s = append(s, Esc) + case char1 == 'e': // \e escape + seq = append(seq, Esc) i++ - case c1 == 'f': // \f form feed - s = append(s, Formfeed) + case char1 == 'f': // \f form feed + seq = append(seq, Formfeed) i++ - case c1 == 'n': // \n new line - s = append(s, Newline) + case char1 == 'n': // \n new line + seq = append(seq, Newline) i++ - case c1 == 'r': // \r carriage return - s = append(s, Return) + case char1 == 'r': // \r carriage return + seq = append(seq, Return) i++ - case c1 == 't': // \t tab - s = append(s, Tab) + case char1 == 't': // \t tab + seq = append(seq, Tab) i++ - case c1 == 'v': // \v vertical - s = append(s, Vertical) + case char1 == 'v': // \v vertical + seq = append(seq, Vertical) i++ - case c1 == '\\', c1 == '"', c1 == '\'': // \\ \" \' literal - s = append(s, c1) + case char1 == '\\', char1 == '"', char1 == '\'': // \\ \" \' literal + seq = append(seq, char1) i++ - case c1 == 'x' && hexDigit(c2) && hexDigit(c3): // \xHH hex - s = append(s, hexVal(c2)<<4|hexVal(c3)) + case char1 == 'x' && hexDigit(char2) && hexDigit(char3): // \xHH hex + seq = append(seq, hexVal(char2)<<4|hexVal(char3)) i += 2 - case c1 == 'x' && hexDigit(c2): // \xH hex - s = append(s, hexVal(c2)) + case char1 == 'x' && hexDigit(char2): // \xH hex + seq = append(seq, hexVal(char2)) i++ - case octDigit(c1) && octDigit(c2) && octDigit(c3): // \nnn octal - s = append(s, (c1-'0')<<6|(c2-'0')<<3|(c3-'0')) + case octDigit(char1) && octDigit(char2) && octDigit(char3): // \nnn octal + seq = append(seq, (char1-'0')<<6|(char2-'0')<<3|(char3-'0')) i += 3 - case octDigit(c1) && octDigit(c2): // \nn octal - s = append(s, (c1-'0')<<3|(c2-'0')) + case octDigit(char1) && octDigit(char2): // \nn octal + seq = append(seq, (char1-'0')<<3|(char2-'0')) i += 2 - case octDigit(c1): // \n octal - s = append(s, c1-'0') + case octDigit(char1): // \n octal + seq = append(seq, char1-'0') i++ - case ((c1 == 'C' && c4 == 'M') || (c1 == 'M' && c4 == 'C')) && c2 == '-' && c3 == '\\' && c5 == '-': + case ((char1 == 'C' && char4 == 'M') || (char1 == 'M' && char4 == 'C')) && char2 == '-' && char3 == '\\' && char5 == '-': // \C-\M- or \M-\C- control meta prefix - if c6 := grab(r, i+6, end); c6 != 0 { - s = append(s, Esc, Encontrol(c6)) + if c6 := grab(r, i+metaSeqLength, end); c6 != 0 { + seq = append(seq, Esc, Encontrol(c6)) } + i += 6 - case c1 == 'C' && c2 == '-': // \C- control prefix - if c3 == '?' { - s = append(s, Delete) + case char1 == 'C' && char2 == '-': // \C- control prefix + if char3 == '?' { + seq = append(seq, Delete) } else { - s = append(s, Encontrol(c3)) + seq = append(seq, Encontrol(char3)) } + i += 3 - case c1 == 'M' && c2 == '-': // \M- meta prefix - if c3 == 0 { - s = append(s, Esc) + case char1 == 'M' && char2 == '-': // \M- meta prefix + if char3 == 0 { + seq = append(seq, Esc) i += 2 } else { - s = append(s, Enmeta(c3)) + seq = append(seq, Enmeta(char3)) i += 3 } default: - s = append(s, c1) + seq = append(seq, char1) i++ } + continue } - s = append(s, c0) + + seq = append(seq, char0) } - return string(s) + + return string(seq) } // octDigit returns true when r is 0-7. @@ -634,14 +718,15 @@ func hexDigit(c rune) bool { } // hexVal converts a rune to its hex value. -func hexVal(c rune) rune { +func hexVal(char rune) rune { switch { - case 'a' <= c && c <= 'f': - return c - 'a' + 10 - case 'A' <= c && c <= 'F': - return c - 'A' + 10 + case 'a' <= char && char <= 'f': + return char - 'a' + hexValNum + case 'A' <= char && char <= 'F': + return char - 'A' + hexValNum } - return c - '0' + + return char - '0' } // expandIncludePath handles tilde home directory expansion in $include path directives. diff --git a/vendor/github.com/reeflective/readline/internal/completion/group.go b/vendor/github.com/reeflective/readline/internal/completion/group.go index 2298baf79f..cd1eecc4bf 100644 --- a/vendor/github.com/reeflective/readline/internal/completion/group.go +++ b/vendor/github.com/reeflective/readline/internal/completion/group.go @@ -327,7 +327,6 @@ func (g *group) longestValueDescribed(vals []Candidate) int { if val.descLen > longestDesc { longestDesc = val.descLen - } if val.descLen > longestDesc { @@ -344,7 +343,7 @@ func (g *group) longestValueDescribed(vals []Candidate) int { } // Always add one: there is at least one space between each column. - return longestVal + longestDesc + 1 + return longestVal + longestDesc + 2 } func (g *group) trimDisplay(comp Candidate, pad, col int) (candidate, padded string) { diff --git a/vendor/github.com/reeflective/readline/internal/keymap/cursor.go b/vendor/github.com/reeflective/readline/internal/keymap/cursor.go index 2f7d476f30..c52ce8896e 100644 --- a/vendor/github.com/reeflective/readline/internal/keymap/cursor.go +++ b/vendor/github.com/reeflective/readline/internal/keymap/cursor.go @@ -15,6 +15,7 @@ func (c CursorStyle) String() string { if !found { return string(cursorUserDefault) } + return cursor } @@ -49,10 +50,6 @@ var defaultCursors = map[Mode]CursorStyle{ // PrintCursor prints the cursor for the given keymap mode, // either default value or the one specified in inputrc file. -// TODO: I've been quite vicious here, I need to admit: the logic -// is not made to use the default user cursor in insert-mode. -// It didn't bother. And if that can help some getting to use -// .inputrc, so be it. func (m *Engine) PrintCursor(keymap Mode) { var cursor CursorStyle @@ -65,8 +62,8 @@ func (m *Engine) PrintCursor(keymap Mode) { return } - if cursor, valid := defaultCursors[keymap]; valid { - fmt.Print(cursors[cursor]) + if defaultCur, valid := defaultCursors[keymap]; valid { + fmt.Print(cursors[defaultCur]) return } diff --git a/vendor/github.com/reeflective/readline/internal/ui/prompt.go b/vendor/github.com/reeflective/readline/internal/ui/prompt.go index 44ef0ac0ff..43774efe59 100644 --- a/vendor/github.com/reeflective/readline/internal/ui/prompt.go +++ b/vendor/github.com/reeflective/readline/internal/ui/prompt.go @@ -249,8 +249,10 @@ func (p *Prompt) formatLastPrompt(prompt string) string { begin := regexp.MustCompile(`\\1`) end := regexp.MustCompile(`\\2`) + // Remove delimiters, and replace quoted escape sequences status = begin.ReplaceAllString(status, "") status = end.ReplaceAllString(status, "") + status = strings.ReplaceAll(status, "\\e", "\x1b") return status + prompt } diff --git a/vendor/modules.txt b/vendor/modules.txt index ba638bd44f..b8d98044bb 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -545,7 +545,7 @@ github.com/pmezard/go-difflib/difflib ## explicit; go 1.20 github.com/reeflective/console github.com/reeflective/console/commands/readline -# github.com/reeflective/readline v1.0.11 +# github.com/reeflective/readline v1.0.13 ## explicit; go 1.21 github.com/reeflective/readline github.com/reeflective/readline/inputrc