aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/args.go172
-rw-r--r--cmd/root.go46
-rw-r--r--cmd/wmi.go2
3 files changed, 115 insertions, 105 deletions
diff --git a/cmd/args.go b/cmd/args.go
index b176c75..4936784 100644
--- a/cmd/args.go
+++ b/cmd/args.go
@@ -1,139 +1,139 @@
package cmd
import (
- "context"
- "errors"
- "fmt"
- "github.com/spf13/cobra"
- "github.com/spf13/pflag"
- "os"
+ "context"
+ "errors"
+ "fmt"
+ "github.com/spf13/cobra"
+ "github.com/spf13/pflag"
+ "os"
)
func registerRpcFlags(cmd *cobra.Command) {
- rpcFlags := pflag.NewFlagSet("RPC", pflag.ExitOnError)
+ rpcFlags := pflag.NewFlagSet("RPC", pflag.ExitOnError)
- rpcFlags.BoolVar(&rpcClient.NoEpm, "no-epm", false, "Do not use EPM to automatically detect endpoints")
- //rpcFlags.BoolVar(&rpcClient.Options.EpmAuto, "epm-auto", false, "Automatically detect endpoints instead of using the module defaults")
- rpcFlags.BoolVar(&rpcClient.NoSign, "no-sign", false, "Disable signing on DCE messages")
- rpcFlags.BoolVar(&rpcClient.NoSeal, "no-seal", false, "Disable packet stub encryption on DCE messages")
- rpcFlags.StringVar(&rpcClient.Filter, "epm-filter", "", "String binding to filter endpoints returned by EPM")
- rpcFlags.StringVar(&rpcClient.Endpoint, "endpoint", "", "Explicit RPC endpoint definition")
+ rpcFlags.BoolVar(&rpcClient.NoEpm, "no-epm", false, "Do not use EPM to automatically detect endpoints")
+ //rpcFlags.BoolVar(&rpcClient.Options.EpmAuto, "epm-auto", false, "Automatically detect endpoints instead of using the module defaults")
+ rpcFlags.BoolVar(&rpcClient.NoSign, "no-sign", false, "Disable signing on DCE messages")
+ rpcFlags.BoolVar(&rpcClient.NoSeal, "no-seal", false, "Disable packet stub encryption on DCE messages")
+ rpcFlags.StringVar(&rpcClient.Filter, "epm-filter", "", "String binding to filter endpoints returned by EPM")
+ rpcFlags.StringVar(&rpcClient.Endpoint, "endpoint", "", "Explicit RPC endpoint definition")
- cmd.PersistentFlags().AddFlagSet(rpcFlags)
+ cmd.PersistentFlags().AddFlagSet(rpcFlags)
- cmd.MarkFlagsMutuallyExclusive("endpoint", "epm-filter")
- cmd.MarkFlagsMutuallyExclusive("no-epm", "epm-filter")
+ cmd.MarkFlagsMutuallyExclusive("endpoint", "epm-filter")
+ cmd.MarkFlagsMutuallyExclusive("no-epm", "epm-filter")
}
func registerProcessExecutionArgs(cmd *cobra.Command) {
- group := pflag.NewFlagSet("Execution", pflag.ExitOnError)
+ group := pflag.NewFlagSet("Execution", pflag.ExitOnError)
- group.StringVarP(&exec.Input.Arguments, "args", "a", "", "Command line arguments")
- group.StringVarP(&exec.Input.Command, "command", "c", "", "Windows process command line (executable & arguments)")
- group.StringVarP(&exec.Input.Executable, "executable", "e", "", "Windows executable to invoke")
+ group.StringVarP(&exec.Input.Arguments, "args", "a", "", "Command line arguments")
+ group.StringVarP(&exec.Input.Command, "command", "c", "", "Windows process command line (executable & arguments)")
+ group.StringVarP(&exec.Input.Executable, "executable", "e", "", "Windows executable to invoke")
- cmd.PersistentFlags().AddFlagSet(group)
+ cmd.PersistentFlags().AddFlagSet(group)
- cmd.MarkFlagsOneRequired("executable", "command")
- cmd.MarkFlagsMutuallyExclusive("executable", "command")
+ cmd.MarkFlagsOneRequired("executable", "command")
+ cmd.MarkFlagsMutuallyExclusive("executable", "command")
}
func registerExecutionOutputArgs(cmd *cobra.Command) {
- group := pflag.NewFlagSet("Output", pflag.ExitOnError)
+ group := pflag.NewFlagSet("Output", pflag.ExitOnError)
- group.StringVarP(&outputPath, "output", "o", "", `Fetch execution output to file or "-" for standard output`)
- group.StringVarP(&outputMethod, "output-method", "m", "smb", "Method to fetch execution output")
- group.StringVar(&exec.Output.RemotePath, "remote-output", "", "Location to temporarily store output on remote filesystem")
- group.BoolVar(&exec.Output.NoDelete, "no-delete-output", false, "Preserve output file on remote filesystem")
+ group.StringVarP(&outputPath, "output", "o", "", `Fetch execution output to file or "-" for standard output`)
+ group.StringVarP(&outputMethod, "output-method", "m", "smb", "Method to fetch execution output")
+ group.StringVar(&exec.Output.RemotePath, "remote-output", "", "Location to temporarily store output on remote filesystem")
+ group.BoolVar(&exec.Output.NoDelete, "no-delete-output", false, "Preserve output file on remote filesystem")
- cmd.PersistentFlags().AddFlagSet(group)
+ cmd.PersistentFlags().AddFlagSet(group)
}
func args(reqs ...func(*cobra.Command, []string) error) (fn func(*cobra.Command, []string) error) {
- return func(cmd *cobra.Command, args []string) (err error) {
+ return func(cmd *cobra.Command, args []string) (err error) {
- for _, req := range reqs {
- if err = req(cmd, args); err != nil {
- return
- }
- }
- return
- }
+ for _, req := range reqs {
+ if err = req(cmd, args); err != nil {
+ return
+ }
+ }
+ return
+ }
}
func argsTarget(proto string) func(cmd *cobra.Command, args []string) error {
- return func(cmd *cobra.Command, args []string) (err error) {
+ return func(cmd *cobra.Command, args []string) (err error) {
- if len(args) != 1 {
- return errors.New("command require exactly one positional argument: [target]")
- }
+ if len(args) != 1 {
+ return errors.New("command require exactly one positional argument: [target]")
+ }
- if credential, target, err = authOpts.WithTarget(context.TODO(), proto, args[0]); err != nil {
- return fmt.Errorf("failed to parse target: %w", err)
- }
+ if credential, target, err = adAuthOpts.WithTarget(context.TODO(), proto, args[0]); err != nil {
+ return fmt.Errorf("failed to parse target: %w", err)
+ }
- if credential == nil {
- return errors.New("no credentials supplied")
- }
- if target == nil {
- return errors.New("no target supplied")
- }
- return
- }
+ if credential == nil {
+ return errors.New("no credentials supplied")
+ }
+ if target == nil {
+ return errors.New("no target supplied")
+ }
+ return
+ }
}
func argsSmbClient() func(cmd *cobra.Command, args []string) error {
- return args(
- argsTarget("cifs"),
+ return args(
+ argsTarget("cifs"),
- func(_ *cobra.Command, _ []string) error {
+ func(_ *cobra.Command, _ []string) error {
- smbClient.Credential = credential
- smbClient.Target = target
- smbClient.Proxy = proxy
+ smbClient.Credential = credential
+ smbClient.Target = target
+ smbClient.Proxy = proxy
- return smbClient.Parse(context.TODO())
- },
- )
+ return smbClient.Parse(context.TODO())
+ },
+ )
}
func argsRpcClient(proto string) func(cmd *cobra.Command, args []string) error {
- return args(
- argsTarget(proto),
+ return args(
+ argsTarget(proto),
- func(cmd *cobra.Command, args []string) (err error) {
+ func(cmd *cobra.Command, args []string) (err error) {
- rpcClient.Target = target
- rpcClient.Credential = credential
- rpcClient.Proxy = proxy
+ rpcClient.Target = target
+ rpcClient.Credential = credential
+ rpcClient.Proxy = proxy
- return rpcClient.Parse(context.TODO())
- },
- )
+ return rpcClient.Parse(context.TODO())
+ },
+ )
}
func argsOutput(methods ...string) func(cmd *cobra.Command, args []string) error {
- var as []func(*cobra.Command, []string) error
+ var as []func(*cobra.Command, []string) error
- for _, method := range methods {
- if method == "smb" {
- as = append(as, argsSmbClient())
- }
- }
+ for _, method := range methods {
+ if method == "smb" {
+ as = append(as, argsSmbClient())
+ }
+ }
- return args(append(as, func(*cobra.Command, []string) (err error) {
+ return args(append(as, func(*cobra.Command, []string) (err error) {
- if outputPath != "" {
- if outputPath == "-" {
- exec.Output.Writer = os.Stdout
+ if outputPath != "" {
+ if outputPath == "-" {
+ exec.Output.Writer = os.Stdout
- } else if exec.Output.Writer, err = os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
- log.Fatal().Err(err).Msg("Failed to open output file")
- }
- }
- return
- })...)
+ } else if exec.Output.Writer, err = os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644); err != nil {
+ log.Fatal().Err(err).Msg("Failed to open output file")
+ }
+ }
+ return
+ })...)
}
diff --git a/cmd/root.go b/cmd/root.go
index 46e8595..300588d 100644
--- a/cmd/root.go
+++ b/cmd/root.go
@@ -40,7 +40,7 @@ var (
Output: new(goexec.ExecutionOutput),
}
- authOpts *adauth.Options
+ adAuthOpts *adauth.Options
credential *adauth.Credential
target *adauth.Target
@@ -103,6 +103,13 @@ var (
)
func init() {
+ // Auth init
+ {
+ gssapi.AddMechanism(ssp.SPNEGO)
+ gssapi.AddMechanism(ssp.NTLM)
+ gssapi.AddMechanism(ssp.KRB5)
+ }
+
// Cobra init
{
cobra.EnableCommandSorting = false
@@ -127,24 +134,27 @@ func init() {
rootCmd.PersistentFlags().AddFlagSet(netOpts)
}
- dcomCmdInit()
- rootCmd.AddCommand(dcomCmd)
- wmiCmdInit()
- rootCmd.AddCommand(wmiCmd)
- scmrCmdInit()
- rootCmd.AddCommand(scmrCmd)
- tschCmdInit()
- rootCmd.AddCommand(tschCmd)
- }
-
- // Auth init
- {
- gssapi.AddMechanism(ssp.SPNEGO)
- gssapi.AddMechanism(ssp.NTLM)
- gssapi.AddMechanism(ssp.KRB5)
+ // Authentication flags
+ {
+ adAuthOpts = &adauth.Options{
+ Debug: log.Debug().Msgf,
+ }
+ authOpts := pflag.NewFlagSet("Authentication", pflag.ExitOnError)
+ adAuthOpts.RegisterFlags(authOpts)
+ rootCmd.PersistentFlags().AddFlagSet(authOpts)
+ }
- authOpts = &adauth.Options{Debug: log.Debug().Msgf}
- authOpts.RegisterFlags(rootCmd.PersistentFlags())
+ // Modules init
+ {
+ dcomCmdInit()
+ rootCmd.AddCommand(dcomCmd)
+ wmiCmdInit()
+ rootCmd.AddCommand(wmiCmd)
+ scmrCmdInit()
+ rootCmd.AddCommand(scmrCmd)
+ tschCmdInit()
+ rootCmd.AddCommand(tschCmd)
+ }
}
}
diff --git a/cmd/wmi.go b/cmd/wmi.go
index b75df12..6bd003e 100644
--- a/cmd/wmi.go
+++ b/cmd/wmi.go
@@ -54,7 +54,7 @@ var (
wmiCmd = &cobra.Command{
Use: "wmi",
- Short: "Establish execution via WMI",
+ Short: "Establish execution via Windows Management Instrumentation Remote Protocol (MS-WMI)",
Args: cobra.NoArgs,
}