From 4e7093671cc77d2d6b9b550e30169110d621017e Mon Sep 17 00:00:00 2001 From: moloch-- <875022+moloch--@users.noreply.github.com> Date: Fri, 15 Jul 2022 09:44:52 -0700 Subject: [PATCH] Update to Go v1.18.4 and bump grumble --- Dockerfile | 2 +- go-assets.sh | 2 +- go.mod | 2 +- go.sum | 4 +- server/cryptography/cryptography.go | 2 +- server/generate/binaries.go | 1 - vendor/github.com/desertbit/grumble/README.md | 46 +++++++++- vendor/github.com/desertbit/grumble/app.go | 92 ++++++++++++------- .../github.com/desertbit/grumble/command.go | 9 +- .../github.com/desertbit/grumble/commands.go | 51 ++++++++-- vendor/github.com/desertbit/grumble/config.go | 6 ++ vendor/github.com/desertbit/grumble/flags.go | 5 +- vendor/modules.txt | 2 +- 13 files changed, 168 insertions(+), 56 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6bf3e7ced1..6e3d08231a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1.18.3 +FROM golang:1.18.4 # # IMPORTANT: This Dockerfile is used for testing, I do not recommend deploying diff --git a/go-assets.sh b/go-assets.sh index 54753ab108..e378e01fed 100755 --- a/go-assets.sh +++ b/go-assets.sh @@ -20,7 +20,7 @@ set -e # Creates the static go asset archives -GO_VER="1.18.3" +GO_VER="1.18.4" GARBLE_VER="1.18.0" GO_ARCH_1="amd64" diff --git a/go.mod b/go.mod index b3dc4936e8..e7650e0d25 100644 --- a/go.mod +++ b/go.mod @@ -2,7 +2,7 @@ module github.com/bishopfox/sliver go 1.17 -replace github.com/desertbit/grumble v1.1.1 => github.com/moloch--/grumble v1.1.4 +replace github.com/desertbit/grumble v1.1.1 => github.com/moloch--/grumble v1.1.6 require ( github.com/AlecAivazis/survey/v2 v2.2.2 diff --git a/go.sum b/go.sum index 404864b8d0..77fcb929a0 100644 --- a/go.sum +++ b/go.sum @@ -648,8 +648,8 @@ github.com/modern-go/reflect2 v0.0.0-20180320133207-05fbef0ca5da/go.mod h1:bx2lN github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mohae/deepcopy v0.0.0-20170308212314-bb9b5e7adda9/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= -github.com/moloch--/grumble v1.1.4 h1:/utJ405bbS2/Kx73XE03zqP1a3ZE9p3vqD3ePvsrG8o= -github.com/moloch--/grumble v1.1.4/go.mod h1:r7j3ShNy5EmOsegRD2DzTutIaGiLiA3M5yBTXXeLwcs= +github.com/moloch--/grumble v1.1.6 h1:FjPkuGOIwGL8nGkEH0EegnQgsl6Rn0R0fhBW/kcA0s8= +github.com/moloch--/grumble v1.1.6/go.mod h1:r7j3ShNy5EmOsegRD2DzTutIaGiLiA3M5yBTXXeLwcs= github.com/moloch--/memmod v0.0.0-20211120144554-8b37cc654945 h1:m3yCfV8Vqp4MF1B+gPPjbjINdufl0UXqyYplE0aGhx8= github.com/moloch--/memmod v0.0.0-20211120144554-8b37cc654945/go.mod h1:1grVt4HaTofvhFUZYtofeRbGXfczNwCie9MYoM4lP/o= github.com/mrunalp/fileutils v0.5.0/go.mod h1:M1WthSahJixYnrXQl/DFQuteStB1weuxD2QJNHXfbSQ= diff --git a/server/cryptography/cryptography.go b/server/cryptography/cryptography.go index 4f43de1bd2..95fe07bae3 100644 --- a/server/cryptography/cryptography.go +++ b/server/cryptography/cryptography.go @@ -109,7 +109,7 @@ func (e *ECCKeyPair) PrivateBase64() string { return base64.RawStdEncoding.EncodeToString(e.Private[:]) } -// RandomeECCKeyPair - Generate a random Curve 25519 key pair +// RandomECCKeyPair - Generate a random Curve 25519 key pair func RandomECCKeyPair() (*ECCKeyPair, error) { public, private, err := box.GenerateKey(rand.Reader) if err != nil { diff --git a/server/generate/binaries.go b/server/generate/binaries.go index 2cf7b1b544..5be84e9f26 100644 --- a/server/generate/binaries.go +++ b/server/generate/binaries.go @@ -894,7 +894,6 @@ const ( // GoPrivate - The default Go private arg to garble when obfuscation is enabled. // Wireguard dependencies prevent the use of wildcard github.com/* and golang.org/*. // The current packages below aren't definitive and need to be tidied up. - // GoPrivate = "github.com/bishopfox/*,github.com/Microsoft/*,github.com/burntsushi/*,github.com/kbinani/*,github.com/lxn/*,github.com/golang/*,github.com/shm/*,github.com/lesnuages/*" wgGoPrivate = "github.com/*,golang.org/*,golang.zx2c4.com/*,google.golang.org/*" allGoPrivate = "*" ) diff --git a/vendor/github.com/desertbit/grumble/README.md b/vendor/github.com/desertbit/grumble/README.md index 77c4ac6990..7bd85a3c55 100644 --- a/vendor/github.com/desertbit/grumble/README.md +++ b/vendor/github.com/desertbit/grumble/README.md @@ -81,11 +81,55 @@ Builtin support for multiple lines. ... command ``` +## Separate flags and args specifically +If you need to pass a flag-like value as positional argument, you can do so by using a double dash: +`>>> command --flag1=something -- --myPositionalArg` + +## Remote shell access with readline +By calling RunWithReadline() rather than Run() you can pass instance of readline.Instance. +One of interesting usages is having a possibility of remote access to your shell: + +```go +handleFunc := func(rl *readline.Instance) { + + var app = grumble.New(&grumble.Config{ + // override default interrupt handler to avoid remote shutdown + InterruptHandler: func(a *grumble.App, count int) { + // do nothing + }, + + // your usual grumble configuration + }) + + // add commands + + app.RunWithReadline(rl) + +} + +cfg := &readline.Config{} +readline.ListenRemote("tcp", ":5555", cfg, handleFunc) +``` + +In the client code just use readline built in DialRemote function: + +```go +if err := readline.DialRemote("tcp", ":5555"); err != nil { + fmt.Errorf("An error occurred: %s \n", err.Error()) +} +``` + ## Samples Check out the [sample directory](/sample) for some detailed examples. -The [grml project](https://github.com/desertbit/grml) uses grumble. +## Projects using Grumble + +- grml - A simple build automation tool written in Go: https://github.com/desertbit/grml +- orbit - A RPC-like networking backend written in Go: https://github.com/desertbit/orbit + +## Known issues +- Windows unicode not fully supported ([issue](https://github.com/desertbit/grumble/issues/48)) ## Additional Useful Packages diff --git a/vendor/github.com/desertbit/grumble/app.go b/vendor/github.com/desertbit/grumble/app.go index bfa257c7f0..ad86edc9ed 100644 --- a/vendor/github.com/desertbit/grumble/app.go +++ b/vendor/github.com/desertbit/grumble/app.go @@ -80,6 +80,9 @@ func New(c *Config) (a *App) { printCommandHelp: defaultPrintCommandHelp, interruptHandler: defaultInterruptHandler, } + if c.InterruptHandler != nil { + a.interruptHandler = c.InterruptHandler + } // Register the builtin flags. a.flags.Bool("h", "help", false, "display help") @@ -118,6 +121,7 @@ func (a *App) Config() *Config { } // Commands returns the app's commands. +// Access is not thread-safe. Only access during command execution. func (a *App) Commands() *Commands { return &a.commands } @@ -277,8 +281,21 @@ func (a *App) RunCommand(args []string) error { // Run the application and parse the command line arguments. // This method blocks. func (a *App) Run() (err error) { + // Create the readline instance. + config := &readline.Config{} + a.setReadlineDefaults(config) + rl, err := readline.NewEx(config) + if err != nil { + return err + } + return a.RunWithReadline(rl) +} + +func (a *App) RunWithReadline(rl *readline.Instance) (err error) { defer a.Close() + a.setReadlineDefaults(rl.Config) + // Sort all commands by their name. a.commands.SortRecursive() @@ -323,6 +340,7 @@ func (a *App) Run() (err error) { a.printCommandHelp(a, cmd, a.isShell) return nil }, + isBuiltin: true, }, false) // Check if help should be displayed. @@ -331,6 +349,30 @@ func (a *App) Run() (err error) { return nil } + // Add shell builtin commands. + // Ensure to add all commands before running the init hook. + // If the init hook does something with the app commands, then these should also be included. + if a.isShell { + a.AddCommand(&Command{ + Name: "exit", + Help: "exit the shell", + Run: func(c *Context) error { + c.Stop() + return nil + }, + isBuiltin: true, + }) + a.AddCommand(&Command{ + Name: "clear", + Help: "clear the screen", + Run: func(c *Context) error { + readline.ClearScreen(a.rl) + return nil + }, + isBuiltin: true, + }) + } + // Run the init hook. if a.initHook != nil { err = a.initHook(a, a.flagMap) @@ -344,36 +386,8 @@ func (a *App) Run() (err error) { return a.RunCommand(args) } - // Add shell builtin commands. - a.AddCommand(&Command{ - Name: "exit", - Help: "exit the shell", - Run: func(c *Context) error { - c.Stop() - return nil - }, - }) - a.AddCommand(&Command{ - Name: "clear", - Help: "clear the screen", - Run: func(c *Context) error { - readline.ClearScreen(a.rl) - return nil - }, - }) - - // Create the readline instance. - a.rl, err = readline.NewEx(&readline.Config{ - Prompt: a.currentPrompt, - HistorySearchFold: true, // enable case-insensitive history searching - DisableAutoSaveHistory: true, - HistoryFile: a.config.HistoryFile, - HistoryLimit: a.config.HistoryLimit, - AutoComplete: newCompleter(&a.commands), - }) - if err != nil { - return err - } + // Assign readline instance + a.rl = rl a.OnClose(a.rl.Close) // Run the shell hook. @@ -393,6 +407,16 @@ func (a *App) Run() (err error) { return a.runShell() } +func (a *App) setReadlineDefaults(config *readline.Config) { + config.Prompt = a.currentPrompt + config.HistorySearchFold = true + config.DisableAutoSaveHistory = true + config.HistoryFile = a.config.HistoryFile + config.HistoryLimit = a.config.HistoryLimit + config.AutoComplete = newCompleter(&a.commands) + config.VimMode = a.config.VimMode +} + func (a *App) runShell() error { var interruptCount int var lines []string @@ -461,7 +485,13 @@ Loop: err = a.RunCommand(args) if err != nil { a.PrintError(err) - continue Loop + // Do not continue the Loop here. We want to handle command changes below. + } + + // Sort the commands again if they have changed (Add or remove action). + if a.commands.hasChanged() { + a.commands.SortRecursive() + a.commands.unsetChanged() } } diff --git a/vendor/github.com/desertbit/grumble/command.go b/vendor/github.com/desertbit/grumble/command.go index 1200e439a0..b4d3de2dd6 100644 --- a/vendor/github.com/desertbit/grumble/command.go +++ b/vendor/github.com/desertbit/grumble/command.go @@ -67,10 +67,11 @@ type Command struct { // A non-nil Completer overrides the default behaviour. Completer func(prefix string, args []string) []string - parent *Command - flags Flags - args Args - commands Commands + parent *Command + flags Flags + args Args + commands Commands + isBuiltin bool // Whenever this is a build-in command not added by the user. } func (c *Command) validate() error { diff --git a/vendor/github.com/desertbit/grumble/commands.go b/vendor/github.com/desertbit/grumble/commands.go index c2d28401b5..9b1ea61220 100644 --- a/vendor/github.com/desertbit/grumble/commands.go +++ b/vendor/github.com/desertbit/grumble/commands.go @@ -30,29 +30,43 @@ import ( // Commands collection. type Commands struct { - list []*Command + list []*Command + changed bool // Used to resort if something changes. } // Add the command to the slice. // Duplicates are ignored. func (c *Commands) Add(cmd *Command) { c.list = append(c.list, cmd) + c.changed = true } // Remove a command from the slice. -func (c *Commands) Remove(name string) { - var index int - var cmd *Command - found := false - for index, cmd = range c.list { +func (c *Commands) Remove(name string) (found bool) { + for index, cmd := range c.list { if cmd.Name == name { found = true - break + c.changed = true + c.list = append(c.list[:index], c.list[index+1:]...) + return } } - if found { - c.list = append(c.list[:index], c.list[index+1:]...) + return +} + +func (c *Commands) RemoveAll() { + var builtins []*Command + + // Hint: There are no built-in sub commands. Ignore them. + for _, cmd := range c.list { + if cmd.isBuiltin { + builtins = append(builtins, cmd) + } } + + // Only keep the builtins. + c.list = builtins + c.changed = true } // All returns a slice of all commands. @@ -108,6 +122,25 @@ func (c *Commands) SortRecursive() { } } +func (c *Commands) hasChanged() bool { + if c.changed { + return true + } + for _, sc := range c.list { + if sc.commands.hasChanged() { + return true + } + } + return false +} + +func (c *Commands) unsetChanged() { + c.changed = false + for _, sc := range c.list { + sc.commands.unsetChanged() + } +} + // parse the args and return a command path to the root. // cmds slice is empty, if no command was found. func (c *Commands) parse( diff --git a/vendor/github.com/desertbit/grumble/config.go b/vendor/github.com/desertbit/grumble/config.go index e8ac5b7e3f..b62f25f138 100644 --- a/vendor/github.com/desertbit/grumble/config.go +++ b/vendor/github.com/desertbit/grumble/config.go @@ -54,6 +54,9 @@ type Config struct { // NoColor defines if color output should be disabled. NoColor bool + // VimMode defines if Readline is to use VimMode for line navigation. + VimMode bool + // Prompt defines the shell prompt. Prompt string PromptColor *color.Color @@ -70,6 +73,9 @@ type Config struct { HelpHeadlineUnderline bool HelpSubCommands bool HelpHeadlineColor *color.Color + + // Override default iterrupt handler + InterruptHandler func(a *App, count int) } // SetDefaults sets the default values if not set. diff --git a/vendor/github.com/desertbit/grumble/flags.go b/vendor/github.com/desertbit/grumble/flags.go index 0afc8f6da2..5ef98a88ef 100644 --- a/vendor/github.com/desertbit/grumble/flags.go +++ b/vendor/github.com/desertbit/grumble/flags.go @@ -26,7 +26,6 @@ package grumble import ( "fmt" - "runtime" "sort" "strconv" "strings" @@ -130,9 +129,9 @@ Loop: } args = args[1:] - // A double dash (--) is used in most Bash commands to signify the end of command options, + // A double dash (--) is used to signify the end of command options, // after which only positional arguments are accepted. - if a == "--" && runtime.GOOS == "linux" { + if a == "--" { break Loop } diff --git a/vendor/modules.txt b/vendor/modules.txt index b6d5184103..8f7c330a9a 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -107,7 +107,7 @@ github.com/desertbit/columnize # github.com/desertbit/go-shlex v0.1.1 ## explicit; go 1.14 github.com/desertbit/go-shlex -# github.com/desertbit/grumble v1.1.1 => github.com/moloch--/grumble v1.1.4 +# github.com/desertbit/grumble v1.1.1 => github.com/moloch--/grumble v1.1.6 ## explicit; go 1.12 github.com/desertbit/grumble # github.com/desertbit/readline v1.5.1