Add -q/--quiet flag to suppress Info: lines

This commit is contained in:
SREsAreHumanToo
2026-11-21 11:05:22 -05:00
parent 448a8f50e0
commit 3445dfb2bf
7 changed files with 29 additions and 24 deletions
+1 -4
View File
@@ -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)
+4
View File
@@ -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/<host>/ ($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
+3 -3
View File
@@ -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
+1 -1
View File
@@ -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)
}
+8 -7
View File
@@ -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),
}
}
+1 -1
View File
@@ -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)))
}
+11 -8
View File
@@ -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(),