From 7e952865cc518bb0921adb3afcfc37d3b42b169d Mon Sep 17 00:00:00 2001 From: alexmozzhakov Date: Sat, 21 Jul 2018 15:23:49 +0300 Subject: [PATCH 1/3] This is a fix for showing MAC,BSSID and other CAPSed options --- session/session.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/session/session.go b/session/session.go index c5a65d26..a8ae7bf7 100644 --- a/session/session.go +++ b/session/session.go @@ -206,7 +206,7 @@ func (s *Session) setupReadline() error { var appendedOption = strings.Join(parts[1:], " ") - if len(appendedOption) > 0 { + if len(appendedOption) > 0 && !containsCapitals(appendedOption) { tree[name] = append(tree[name], appendedOption) } } @@ -239,6 +239,15 @@ func (s *Session) setupReadline() error { return err } +func containsCapitals(s string) bool { + for _, ch := range s { + if ch < 133 && ch > 101 { + return false + } + } + return true +} + func (s *Session) Close() { fmt.Printf("\nStopping modules and cleaning session state ...\n") From 17d931a07429f7a679078a21e25eb1aca7ac235a Mon Sep 17 00:00:00 2001 From: alexmozzhakov Date: Sat, 21 Jul 2018 15:28:13 +0300 Subject: [PATCH 2/3] Adding search for caplets into autocomplete (only /caplets/ will be searched recursively) --- session/session.go | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/session/session.go b/session/session.go index a8ae7bf7..8e759856 100644 --- a/session/session.go +++ b/session/session.go @@ -24,6 +24,7 @@ import ( "github.com/bettercap/bettercap/packets" "github.com/adrianmo/go-nmea" + "io/ioutil" ) const HistoryFile = "~/bettercap.history" @@ -212,6 +213,15 @@ func (s *Session) setupReadline() error { } } + searchForCap("./", tree, false) + searchForCap("./caplets/", tree, true) + capspath := core.Trim(os.Getenv("CAPSPATH")) + var paths []string + paths = append(paths, core.SepSplit(capspath, ":")...) + for _, path := range paths { + searchForCap(path, tree, false) + } + for root, subElems := range tree { item := readline.PcItem(root) item.Children = []readline.PrefixCompleterInterface{} @@ -239,6 +249,23 @@ func (s *Session) setupReadline() error { return err } +func searchForCap(path string, tree map[string][]string, recursive bool) { + _searchForCap(path, tree, recursive, path) +} + +func _searchForCap(path string, tree map[string][]string, recursive bool, prefix string) { + subFiles, _ := ioutil.ReadDir(path) + + for _, subF := range subFiles { + if strings.HasSuffix(subF.Name(), ".cap") { + fmt.Println(path + strings.Replace(subF.Name(), ".cap", "", -1)) + tree[strings.TrimPrefix(path, prefix)+strings.Replace(subF.Name(), ".cap", "", -1)] = []string{} + } else if subF.IsDir() && recursive { + _searchForCap(path+subF.Name()+"/", tree, true, prefix) + } + } +} + func containsCapitals(s string) bool { for _, ch := range s { if ch < 133 && ch > 101 { From bad9b4191832efc617f0ec08e3c8be9d69f34e82 Mon Sep 17 00:00:00 2001 From: alexmozzhakov Date: Sat, 21 Jul 2018 15:32:23 +0300 Subject: [PATCH 3/3] Removed debug log --- session/session.go | 1 - 1 file changed, 1 deletion(-) diff --git a/session/session.go b/session/session.go index 8e759856..e868aca0 100644 --- a/session/session.go +++ b/session/session.go @@ -258,7 +258,6 @@ func _searchForCap(path string, tree map[string][]string, recursive bool, prefix for _, subF := range subFiles { if strings.HasSuffix(subF.Name(), ".cap") { - fmt.Println(path + strings.Replace(subF.Name(), ".cap", "", -1)) tree[strings.TrimPrefix(path, prefix)+strings.Replace(subF.Name(), ".cap", "", -1)] = []string{} } else if subF.IsDir() && recursive { _searchForCap(path+subF.Name()+"/", tree, true, prefix)