aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorBryan McNulty <bryanmcnulty@protonmail.com>2025-04-17 02:26:28 -0500
committerBryan McNulty <bryanmcnulty@protonmail.com>2025-04-17 02:26:28 -0500
commit22e4fc56cca0a8c466bf09a6f529573063ce5cb6 (patch)
tree05675cb02426f4718bacff88be672ca7e4a285e5 /cmd
parent5f0928b65e1e1c2a92818ecea0eb81aa547f4a95 (diff)
downloadgoexec-22e4fc56cca0a8c466bf09a6f529573063ce5cb6.tar.gz
goexec-22e4fc56cca0a8c466bf09a6f529573063ce5cb6.zip
Validate output flag before method execution
Diffstat (limited to 'cmd')
-rw-r--r--cmd/args.go18
-rw-r--r--cmd/tsch.go35
2 files changed, 20 insertions, 33 deletions
diff --git a/cmd/args.go b/cmd/args.go
index 50e7c74..b2b6fe2 100644
--- a/cmd/args.go
+++ b/cmd/args.go
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
+ "os"
)
func registerRpcFlags(cmd *cobra.Command) {
@@ -122,5 +123,20 @@ func argsOutput(methods ...string) func(cmd *cobra.Command, args []string) error
as = append(as, argsSmbClient())
}
}
- return args(as...)
+
+ return args(append(as, func(*cobra.Command, []string) (err error) {
+
+ if outputPath != "" {
+ if outputPath == "-" {
+ exec.Output.Writer = os.Stdout
+
+ } else if outputPath != "" {
+
+ if exec.Output.Writer, err = os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE, 0644); err != nil {
+ log.Fatal().Err(err).Msg("Failed to open output file")
+ }
+ }
+ }
+ return
+ })...)
}
diff --git a/cmd/tsch.go b/cmd/tsch.go
index d08126b..9192b0a 100644
--- a/cmd/tsch.go
+++ b/cmd/tsch.go
@@ -7,7 +7,6 @@ import (
tschexec "github.com/FalconOpsLLC/goexec/pkg/goexec/tsch"
"github.com/oiweiwei/go-msrpc/ssp/gssapi"
"github.com/spf13/cobra"
- "os"
"time"
)
@@ -64,6 +63,7 @@ func tschCreateCmdInit() {
tschCreateCmd.Flags().StringVar(&tschCreate.UserSid, "sid", "S-1-5-18", "User SID to impersonate")
registerProcessExecutionArgs(tschCreateCmd)
+ registerExecutionOutputArgs(tschCreateCmd)
tschCreateCmd.MarkFlagsMutuallyExclusive("name", "path")
}
@@ -92,7 +92,7 @@ References:
`,
Args: args(
argsRpcClient("cifs"),
- argsSmbClient(),
+ argsOutput("smb"),
argsTschDemand,
),
@@ -108,17 +108,6 @@ References:
ctx := log.WithContext(gssapi.NewSecurityContext(context.TODO()))
- if outputPath == "-" {
- exec.Output.Writer = os.Stdout
-
- } else if outputPath != "" {
-
- if exec.Output.Writer, err = os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE, 0644); err != nil {
- log.Fatal().Err(err).Msg("Failed to open output file")
- }
- defer exec.Output.Writer.Close()
- }
-
if err = goexec.ExecuteCleanMethod(ctx, &tschDemand, &exec); err != nil {
log.Fatal().Err(err).Msg("Operation failed")
}
@@ -141,7 +130,7 @@ References:
`,
Args: args(
argsRpcClient("cifs"),
- argsSmbClient(),
+ argsOutput("smb"),
argsTschCreate,
),
@@ -157,27 +146,9 @@ References:
ctx := log.WithContext(gssapi.NewSecurityContext(context.TODO()))
- if outputPath == "-" {
- exec.Output.Writer = os.Stdout
-
- } else if outputPath != "" {
-
- if exec.Output.Writer, err = os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE, 0644); err != nil {
- log.Fatal().Err(err).Msg("Failed to open output file")
- }
- defer exec.Output.Writer.Close()
- }
-
if err = goexec.ExecuteCleanMethod(ctx, &tschCreate, &exec); err != nil {
log.Fatal().Err(err).Msg("Operation failed")
}
-
- if outputPath != "" {
- if err = tschCreate.IO.GetOutput(ctx); err != nil {
- log.Error().Err(err).Msg("Failed to get process execution output")
- returnCode = 4
- }
- }
},
}
)