diff --git a/cmd/wsmancer/main.go b/cmd/wsmancer/main.go index d591d1d..fb6a276 100644 --- a/cmd/wsmancer/main.go +++ b/cmd/wsmancer/main.go @@ -64,13 +64,10 @@ func run() int { ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM) defer stop() - if !jsonMode { + if !jsonMode && !opts.Quiet { fmt.Fprintf(os.Stderr, "%s %s\n", c.Blue("Info:"), "auth: "+sess.AuthMode()) via := "connecting to " + sess.Endpoint() if sess.ProxyAddr() != "" { - // Worth a line of its own: the whole failure mode --proxy exists to - // prevent is a dial quietly going out of the wrong interface, so the - // operator should be able to see that it did not. via += " via socks5 " + sess.ProxyAddr() } fmt.Fprintf(os.Stderr, "%s %s\n", c.Blue("Info:"), via) diff --git a/internal/cli/options.go b/internal/cli/options.go index 4f6e978..227de1f 100644 --- a/internal/cli/options.go +++ b/internal/cli/options.go @@ -67,6 +67,7 @@ type Options struct { Timeout int // connect timeout in seconds; 0 means default (60) NoColors bool NoRPath bool + Quiet bool Log bool // History opts into an on-disk, per-connection command history. Off by @@ -177,6 +178,7 @@ func Parse(argv []string, stderr io.Writer) (*Options, error) { boolean(&o.SSL, "S", "ssl") boolean(&o.NoColors, "n", "no-colors") boolean(&o.NoRPath, "N", "no-rpath-completion") + boolean(&o.Quiet, "q", "quiet") boolean(&o.Log, "l", "log") boolean(&o.History, "Y", "history") // Long-form only: registering "" as a short name would define a nameless flag. @@ -433,6 +435,8 @@ Execution and output: can keep several -l, --log write a timestamped transcript to ~/.wsmancer/logs// ($WSMANCER_LOG_DIR) + -q, --quiet suppress informational output (Info: lines); + errors still print. Useful with -o json -x -n, --no-colors disable colors -N, --no-rpath-completion disable remote path completion diff --git a/internal/shell/bypass4msi.go b/internal/shell/bypass4msi.go index d1a7cda..775df5b 100644 --- a/internal/shell/bypass4msi.go +++ b/internal/shell/bypass4msi.go @@ -62,7 +62,7 @@ const jumpMarker = "#jump" // works without it. func (sh *Shell) bypass4MSI(ctx context.Context, sigs <-chan os.Signal) error { if sh.amsiPatched { - if !sh.json { + if !sh.json && !sh.quiet { fmt.Fprintf(sh.out, "%s AMSI is already patched in this runspace\n", sh.c.Blue("Info:")) } return nil @@ -71,7 +71,7 @@ func (sh *Shell) bypass4MSI(ctx context.Context, sigs <-chan os.Signal) error { script := obfuscateBypass(bypass4MSITemplate, rand.New(rand.NewSource(cryptoSeed()))) steps := strings.Split(script, jumpMarker) - if !sh.json { + if !sh.json && !sh.quiet { fmt.Fprintf(sh.out, "%s patching AMSI in %d steps (~%s)...\n", sh.c.Blue("Info:"), len(steps), (time.Duration(len(steps)-1) * bypassStepPause).Round(time.Second)) } @@ -116,7 +116,7 @@ func (sh *Shell) bypass4MSI(ctx context.Context, sigs <-chan os.Signal) error { sh.amsiPatched = true sh.log.Event("[bypass-4msi] AmsiScanBuffer patched") - if !sh.json { + if !sh.json && !sh.quiet { fmt.Fprintf(sh.out, "%s AMSI patched in this runspace\n", sh.c.Blue("Info:")) } return nil diff --git a/internal/shell/donutloader.go b/internal/shell/donutloader.go index ef77949..b3e5fd0 100644 --- a/internal/shell/donutloader.go +++ b/internal/shell/donutloader.go @@ -69,7 +69,7 @@ func (sh *Shell) donutLoader(ctx context.Context, sigs <-chan os.Signal, line st sh.log.Event("[donut-loader] %s (%d bytes) -> pid %s (%s)", file, len(data), pid, target) // The loader prints nothing on success, so say what was done, otherwise a // successful injection and a silent no-op look identical. - if !sh.json { + if !sh.json && !sh.quiet { fmt.Fprintf(sh.out, "%s injecting %d bytes into pid %s (%s)\n", sh.c.Blue("Info:"), len(data), pid, target) } diff --git a/internal/shell/oneshot.go b/internal/shell/oneshot.go index d289f6c..1296938 100644 --- a/internal/shell/oneshot.go +++ b/internal/shell/oneshot.go @@ -100,12 +100,13 @@ func (sh *Shell) startOnceLog(line string) { // history is set in exactly one place. func newShell(s *session.Session, o *cli.Options, stdout io.Writer) *Shell { return &Shell{ - s: s, - o: o, - c: output.NewColors(!o.NoColors && !output.EnvDisablesColor()), - out: stdout, - json: o.Output == "json", - tty: isTerminal(stdout), - tx: transfer.NewWithChunk(s, o.ChunkKB*1024), + s: s, + o: o, + c: output.NewColors(!o.NoColors && !output.EnvDisablesColor()), + out: stdout, + json: o.Output == "json", + quiet: o.Quiet, + tty: isTerminal(stdout), + tx: transfer.NewWithChunk(s, o.ChunkKB*1024), } } diff --git a/internal/shell/postex.go b/internal/shell/postex.go index 28add3c..0bdc694 100644 --- a/internal/shell/postex.go +++ b/internal/shell/postex.go @@ -84,7 +84,7 @@ func (sh *Shell) loadScript(ctx context.Context, sigs <-chan os.Signal, path str if err != nil { return err // the script loaded, but we could not enumerate it } - if !sh.json { + if !sh.json && !sh.quiet { fmt.Fprintf(sh.out, "%s loaded %s (%d function%s available; `menu` to list)\n", sh.c.Blue("Info:"), filepath.Base(path), len(added), plural(len(added))) } diff --git a/internal/shell/shell.go b/internal/shell/shell.go index 9b470d0..55a9ef0 100644 --- a/internal/shell/shell.go +++ b/internal/shell/shell.go @@ -40,9 +40,10 @@ type Shell struct { o *cli.Options c output.Colors ed lineedit.Editor - out io.Writer - json bool - tty bool // progress bars only make sense on a terminal + out io.Writer + json bool + quiet bool // suppress Info: lines + tty bool // progress bars only make sense on a terminal tx *transfer.Client log *transcript.Log // nil unless -l/--log; all methods are nil-safe hist *history.Store // nil unless -Y/--history; all methods are nil-safe @@ -275,7 +276,7 @@ func (sh *Shell) Run(ctx context.Context) error { signal.Notify(sigs, os.Interrupt, syscall.SIGTERM) defer signal.Stop(sigs) - if !sh.json { + if !sh.json && !sh.quiet { fmt.Fprintf(sh.out, "%s\n", sh.c.Bold("wsmancer shell "+cli.Version)) fmt.Fprintf(sh.out, "%s %s\n", sh.c.Blue("Info:"), "type `help` for port status, `exit` to quit") } @@ -332,7 +333,7 @@ func (sh *Shell) startLog() { } sh.log = lg sh.log.Event("=== session start: %s (%s) ===", sh.o.IP, sh.s.AuthMode()) - if !sh.json { + if !sh.json && !sh.quiet { fmt.Fprintf(sh.out, "%s session log: %s\n", sh.c.Blue("Info:"), lg.Path()) } } @@ -423,8 +424,10 @@ func (sh *Shell) transferCmd(ctx context.Context, sigs <-chan os.Signal, verb, l DurationMS: time.Since(start).Milliseconds(), }) } - fmt.Fprintf(sh.out, "%s %s complete: %s (%s in %s)\n", - sh.c.Blue("Info:"), verb, src, humanBytes(moved), time.Since(start).Round(time.Millisecond)) + if !sh.quiet { + fmt.Fprintf(sh.out, "%s %s complete: %s (%s in %s)\n", + sh.c.Blue("Info:"), verb, src, humanBytes(moved), time.Since(start).Round(time.Millisecond)) + } dst2 := dst if dst2 == "" { dst2 = "(default)" @@ -808,7 +811,7 @@ Line editing (on a terminal): // tool's default posture, and a persisted history is exactly the sort of thing // that should never be quietly on. func (sh *Shell) announceHistory() { - if sh.hist == nil || sh.json { + if sh.hist == nil || sh.json || sh.quiet { return } fmt.Fprintf(sh.out, "%s command history: %s %s\n", sh.c.Blue("Info:"), sh.hist.Path(),