From 0de6f3a76eb0155ed9971abc60974e4199361705 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Tue, 24 Apr 2018 18:26:16 +0200 Subject: [PATCH] more lint driven refactoring --- Gopkg.lock | 2 +- firewall/firewall_darwin.go | 2 +- firewall/firewall_windows.go | 4 +-- main.go | 2 +- modules/ble_options_linux.go | 6 ++++- modules/events_stream.go | 2 +- modules/http_proxy.go | 2 +- modules/http_proxy_base.go | 12 ++++----- modules/http_proxy_base_cookietracker.go | 2 +- modules/http_proxy_base_hosttracker.go | 4 +-- modules/http_proxy_base_sslstriper.go | 23 +++++++++--------- modules/http_proxy_cert_cache.go | 2 +- modules/http_proxy_js_request.go | 12 +++------ modules/http_proxy_js_response.go | 9 ++----- modules/http_server.go | 5 ++-- modules/https_proxy.go | 4 +-- modules/mac_changer.go | 2 +- modules/mysql_server.go | 31 ++++++++---------------- modules/net_probe.go | 4 +-- modules/net_recon.go | 3 +-- modules/net_recon_show.go | 21 +++------------- modules/net_recon_sort.go | 8 +++--- modules/net_sniff.go | 25 ++++--------------- modules/net_sniff_dns.go | 6 ++--- modules/net_sniff_parsers.go | 13 ++++------ modules/net_sniff_stats.go | 5 ++-- modules/net_sniff_views.go | 5 ---- modules/packet_proxy_linux_amd64.go | 8 +++--- modules/syn_scan.go | 6 ++--- modules/tcp_proxy.go | 4 +-- modules/tcp_proxy_script.go | 2 +- modules/ticker.go | 4 +-- modules/utils.go | 2 +- modules/wifi.go | 27 +++++++++------------ modules/wifi_ap.go | 6 ++--- modules/wifi_deauth.go | 10 ++++---- modules/wifi_hopping.go | 4 +-- modules/wifi_recon.go | 12 ++++----- modules/wifi_show.go | 6 ++--- modules/wol.go | 18 +++----------- network/aliases.go | 2 +- network/arp.go | 6 ++--- network/ble.go | 4 +-- network/lan.go | 4 +-- network/meta.go | 4 +-- network/net.go | 2 +- network/oui.go | 2 +- network/wifi.go | 2 +- network/wifi_ap.go | 4 +-- packets/dot11.go | 10 ++++---- packets/ntlm.go | 2 +- packets/queue.go | 4 +-- session/environment.go | 6 ++--- session/events.go | 2 +- session/module.go | 8 +++--- session/session.go | 10 ++++---- session/session_core_handlers.go | 12 ++++----- 57 files changed, 168 insertions(+), 241 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index 51d35324..f0c30978 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -195,6 +195,6 @@ [solve-meta] analyzer-name = "dep" analyzer-version = 1 - inputs-digest = "16887d6924226ea7174b18c0c2a92da30997904da44648f7df6927b3ec8e8de1" + inputs-digest = "2b0f222c61ea5761232c564da1ab8bd87de5daf61b4ba4ebc89e8f0965a89f95" solver-name = "gps-cdcl" solver-version = 1 diff --git a/firewall/firewall_darwin.go b/firewall/firewall_darwin.go index 635edc57..f80c032c 100644 --- a/firewall/firewall_darwin.go +++ b/firewall/firewall_darwin.go @@ -122,7 +122,7 @@ func (f *PfFirewall) enable(enabled bool) { func (f PfFirewall) EnableRedirection(r *Redirection, enabled bool) error { rule := f.generateRule(r) - if enabled == true { + if enabled { fd, err := os.OpenFile(f.filename, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0600) if err != nil { return err diff --git a/firewall/firewall_windows.go b/firewall/firewall_windows.go index 753a2b39..2503860e 100644 --- a/firewall/firewall_windows.go +++ b/firewall/firewall_windows.go @@ -54,7 +54,7 @@ func (f WindowsFirewall) generateRule(r *Redirection, enabled bool) []string { fmt.Sprintf("listenport=%d", r.SrcPort), } - if enabled == true { + if enabled { rule = append(rule, fmt.Sprintf("connectport=%d", r.DstPort)) rule = append(rule, fmt.Sprintf("connectaddress=%s", r.DstAddress)) rule = append(rule, fmt.Sprintf("protocol=%s", r.Protocol)) @@ -93,7 +93,7 @@ func (f *WindowsFirewall) EnableRedirection(r *Redirection, enabled bool) error } rule := f.generateRule(r, enabled) - if enabled == true { + if enabled { rule = append([]string{"interface", "portproxy", "add", "v4tov4"}, rule...) } else { rule = append([]string{"interface", "portproxy", "delete", "v4tov4"}, rule...) diff --git a/main.go b/main.go index f109f342..07e297aa 100644 --- a/main.go +++ b/main.go @@ -20,7 +20,7 @@ func main() { defer sess.Close() if core.HasColors == false { - if *sess.Options.NoColors == true { + if *sess.Options.NoColors { fmt.Printf("\n\nWARNING: Terminal colors have been disabled, view will be very limited.\n\n") } else { fmt.Printf("\n\nWARNING: This terminal does not support colors, view will be very limited.\n\n") diff --git a/modules/ble_options_linux.go b/modules/ble_options_linux.go index c05feb35..c5286130 100644 --- a/modules/ble_options_linux.go +++ b/modules/ble_options_linux.go @@ -2,7 +2,7 @@ package modules import ( "github.com/bettercap/gatt" - "github.com/bettercap/gatt/linux/cmd" + // "github.com/bettercap/gatt/linux/cmd" ) var defaultBLEClientOptions = []gatt.Option{ @@ -10,6 +10,8 @@ var defaultBLEClientOptions = []gatt.Option{ gatt.LnxDeviceID(-1, true), } +/* + var defaultBLEServerOptions = []gatt.Option{ gatt.LnxMaxConnections(255), gatt.LnxDeviceID(-1, true), @@ -19,3 +21,5 @@ var defaultBLEServerOptions = []gatt.Option{ AdvertisingChannelMap: 0x7, }), } + +*/ diff --git a/modules/events_stream.go b/modules/events_stream.go index 1fc6e644..6c5597f8 100644 --- a/modules/events_stream.go +++ b/modules/events_stream.go @@ -157,7 +157,7 @@ func (s *EventsStream) Start() error { s.waitChan <- &e } - if s.ignoreList.Ignored(e) == false { + if !s.ignoreList.Ignored(e) { s.View(e, true) } else { log.Debug("Skipping ignored event %v", e) diff --git a/modules/http_proxy.go b/modules/http_proxy.go index 82b9a91e..876d3665 100644 --- a/modules/http_proxy.go +++ b/modules/http_proxy.go @@ -72,7 +72,7 @@ func (p *HttpProxy) Configure() error { var scriptPath string var stripSSL bool - if p.Running() == true { + if p.Running() { return session.ErrAlreadyStarted } else if err, address = p.StringParam("http.proxy.address"); err != nil { return err diff --git a/modules/http_proxy_base.go b/modules/http_proxy_base.go index 15c76466..38ba658f 100644 --- a/modules/http_proxy_base.go +++ b/modules/http_proxy_base.go @@ -69,8 +69,8 @@ func NewHTTPProxy(s *session.Session) *HTTPProxy { p.Proxy.Logger.SetOutput(ioutil.Discard) p.Proxy.NonproxyHandler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { - if p.doProxy(req) == true { - if p.isTLS == false { + if p.doProxy(req) { + if !p.isTLS { req.URL.Scheme = "http" } req.URL.Host = req.Host @@ -127,7 +127,7 @@ func (p *HTTPProxy) Configure(address string, proxyPort int, httpPort int, scrip WriteTimeout: httpWriteTimeout, } - if p.sess.Firewall.IsForwardingEnabled() == false { + if !p.sess.Firewall.IsForwardingEnabled() { log.Info("Enabling forwarding.") p.sess.Firewall.EnableForwarding(true) } @@ -303,13 +303,13 @@ func (p *HTTPProxy) Start() { var err error strip := core.Yellow("enabled") - if p.stripper.Enabled() == false { + if !p.stripper.Enabled() { strip = core.Dim("disabled") } log.Info("%s started on %s (sslstrip %s)", core.Green(p.Name), p.Server.Addr, strip) - if p.isTLS == true { + if p.isTLS { err = p.httpsWorker() } else { err = p.httpWorker() @@ -332,7 +332,7 @@ func (p *HTTPProxy) Stop() error { p.sess.UnkCmdCallback = nil - if p.isTLS == true { + if p.isTLS { p.isRunning = false p.sniListener.Close() return nil diff --git a/modules/http_proxy_base_cookietracker.go b/modules/http_proxy_base_cookietracker.go index 34369ce4..d60f7802 100644 --- a/modules/http_proxy_base_cookietracker.go +++ b/modules/http_proxy_base_cookietracker.go @@ -54,7 +54,7 @@ func (t *CookieTracker) IsClean(req *http.Request) bool { defer t.RUnlock() // was it already processed? - if _, found := t.set[t.keyOf(req)]; found == true { + if _, found := t.set[t.keyOf(req)]; found { return true } diff --git a/modules/http_proxy_base_hosttracker.go b/modules/http_proxy_base_hosttracker.go index f78f7795..4543bb49 100644 --- a/modules/http_proxy_base_hosttracker.go +++ b/modules/http_proxy_base_hosttracker.go @@ -42,7 +42,7 @@ type HostTracker struct { func NewHostTracker() *HostTracker { return &HostTracker{ - hosts: make(map[string]*Host, 0), + hosts: make(map[string]*Host), } } @@ -55,7 +55,7 @@ func (t *HostTracker) Track(host, stripped string) { func (t *HostTracker) Unstrip(stripped string) *Host { t.RLock() defer t.RUnlock() - if host, found := t.hosts[stripped]; found == true { + if host, found := t.hosts[stripped]; found { return host } return nil diff --git a/modules/http_proxy_base_sslstriper.go b/modules/http_proxy_base_sslstriper.go index a8322101..5d2142ae 100644 --- a/modules/http_proxy_base_sslstriper.go +++ b/modules/http_proxy_base_sslstriper.go @@ -62,7 +62,7 @@ func (s *SSLStripper) dnsReply(pkt gopacket.Packet, peth *layers.Ethernet, pudp redir := fmt.Sprintf("(->%s)", address) who := target.String() - if t, found := s.session.Lan.Get(target.String()); found == true { + if t, found := s.session.Lan.Get(target.String()); found { who = t.String() } @@ -160,7 +160,7 @@ func (s *SSLStripper) onPacket(pkt gopacket.Packet) { func (s *SSLStripper) Enable(enabled bool) { s.enabled = enabled - if enabled == true && s.handle == nil { + if enabled && s.handle == nil { var err error if s.handle, err = pcap.OpenLive(s.session.Interface.Name(), 65536, true, pcap.BlockForever); err != nil { @@ -181,7 +181,7 @@ func (s *SSLStripper) Enable(enabled bool) { src := gopacket.NewPacketSource(s.handle, s.handle.LinkType()) s.pktSourceChan = src.Packets() for packet := range s.pktSourceChan { - if s.enabled == false { + if !s.enabled { break } @@ -249,7 +249,7 @@ func (s *SSLStripper) processURL(url string) string { } } // fallback - if found == false { + if !found { url = strings.Replace(url, "://", "://wwww.", 1) } @@ -262,7 +262,7 @@ func (s *SSLStripper) processURL(url string) string { // - handling stripped domains // - making unknown session cookies expire func (s *SSLStripper) Preprocess(req *http.Request, ctx *goproxy.ProxyCtx) (redir *http.Response) { - if s.enabled == false { + if !s.enabled { return } @@ -284,7 +284,7 @@ func (s *SSLStripper) Preprocess(req *http.Request, ctx *goproxy.ProxyCtx) (redi req.Header.Set("Host", original.Hostname) } - if s.cookies.IsClean(req) == false { + if !s.cookies.IsClean(req) { // check if we need to redirect the user in order // to make unknown session cookies expire log.Info("[%s] Sending expired cookies for %s to %s", core.Green("sslstrip"), core.Yellow(req.Host), req.RemoteAddr) @@ -297,7 +297,7 @@ func (s *SSLStripper) Preprocess(req *http.Request, ctx *goproxy.ProxyCtx) (redi func (s *SSLStripper) isMaxRedirs(hostname string) bool { // did we already track redirections for this host? - if nredirs, found := s.redirs[hostname]; found == true { + if nredirs, found := s.redirs[hostname]; found { // reached the threshold? if nredirs >= maxRedirs { log.Warning("[%s] Hit max redirections for %s, serving HTTPS.", core.Green("sslstrip"), hostname) @@ -312,12 +312,11 @@ func (s *SSLStripper) isMaxRedirs(hostname string) bool { // start tracking redirections s.redirs[hostname] = 1 } - return false } func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) { - if s.enabled == false { + if !s.enabled { return } @@ -355,7 +354,7 @@ func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) { // if we have a text or html content type, fetch the body // and perform sslstripping - if s.isContentStrippable(res) == true { + if s.isContentStrippable(res) { raw, err := ioutil.ReadAll(res.Body) if err != nil { log.Error("Could not read response body: %s", err) @@ -363,12 +362,12 @@ func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) { } body := string(raw) - urls := make(map[string]string, 0) + urls := make(map[string]string) matches := httpsLinksParser.FindAllString(body, -1) for _, u := range matches { // make sure we only strip stuff we're able to // resolve and process - if strings.ContainsRune(u, '.') == true { + if strings.ContainsRune(u, '.') { urls[u] = s.processURL(u) } } diff --git a/modules/http_proxy_cert_cache.go b/modules/http_proxy_cert_cache.go index 38f39c19..1a5e70d3 100644 --- a/modules/http_proxy_cert_cache.go +++ b/modules/http_proxy_cert_cache.go @@ -17,7 +17,7 @@ func getCachedCert(domain string, port int) *tls.Certificate { certLock.Lock() defer certLock.Unlock() - if cert, found := certCache[key]; found == true { + if cert, found := certCache[key]; found { return cert } return nil diff --git a/modules/http_proxy_js_request.go b/modules/http_proxy_js_request.go index 48555fa8..67fa1822 100644 --- a/modules/http_proxy_js_request.go +++ b/modules/http_proxy_js_request.go @@ -77,15 +77,11 @@ func (j *JSRequest) UpdateHash() { func (j *JSRequest) WasModified() bool { // body was read - if j.bodyRead == true { + if j.bodyRead { return true } // check if any of the fields has been changed - newHash := j.NewHash() - if newHash != j.refHash { - return true - } - return false + return j.NewHash() != j.refHash } func (j *JSRequest) GetHeader(name, deflt string) string { @@ -137,7 +133,7 @@ func (j *JSRequest) ParseForm() map[string]string { j.Body = j.ReadBody() } - form := make(map[string]string, 0) + form := make(map[string]string) parts := strings.Split(j.Body, "&") for _, part := range parts { @@ -171,7 +167,7 @@ func (j *JSRequest) ToRequest() (req *http.Request) { } } - if hadType == false && j.ContentType != "" { + if !hadType && j.ContentType != "" { req.Header.Set("Content-Type", j.ContentType) } diff --git a/modules/http_proxy_js_response.go b/modules/http_proxy_js_response.go index c7469bc4..303d5182 100644 --- a/modules/http_proxy_js_response.go +++ b/modules/http_proxy_js_response.go @@ -64,20 +64,15 @@ func (j *JSResponse) UpdateHash() { } func (j *JSResponse) WasModified() bool { - if j.bodyRead == true { + if j.bodyRead { // body was read return true } else if j.Body != "" { // body was not read but just set return true } - // check if any of the fields has been changed - newHash := j.NewHash() - if newHash != j.refHash { - return true - } - return false + return j.NewHash() != j.refHash } func (j *JSResponse) GetHeader(name, deflt string) string { diff --git a/modules/http_server.go b/modules/http_server.go index 1180cbd3..e9177fb0 100644 --- a/modules/http_server.go +++ b/modules/http_server.go @@ -89,7 +89,7 @@ func (httpd *HttpServer) Configure() error { var certFile string var keyFile string - if httpd.Running() == true { + if httpd.Running() { return session.ErrAlreadyStarted } @@ -130,7 +130,7 @@ func (httpd *HttpServer) Configure() error { } if certFile != "" && keyFile != "" { - if core.Exists(certFile) == false || core.Exists(keyFile) == false { + if !core.Exists(certFile) || !core.Exists(keyFile) { log.Info("Generating server TLS key to %s", keyFile) log.Info("Generating server TLS certificate to %s", certFile) if err := tls.Generate(certFile, keyFile); err != nil { @@ -155,7 +155,6 @@ func (httpd *HttpServer) Start() error { return httpd.SetRunning(true, func() { var err error - if httpd.isTLS() { log.Info("HTTPS server starting on https://%s", httpd.server.Addr) err = httpd.server.ListenAndServeTLS(httpd.certFile, httpd.keyFile) diff --git a/modules/https_proxy.go b/modules/https_proxy.go index 2d9d3cf0..b8ee65f8 100644 --- a/modules/https_proxy.go +++ b/modules/https_proxy.go @@ -87,7 +87,7 @@ func (p *HttpsProxy) Configure() error { var keyFile string var stripSSL bool - if p.Running() == true { + if p.Running() { return session.ErrAlreadyStarted } else if err, address = p.StringParam("https.proxy.address"); err != nil { return err @@ -109,7 +109,7 @@ func (p *HttpsProxy) Configure() error { return err } - if core.Exists(certFile) == false || core.Exists(keyFile) == false { + if !core.Exists(certFile) || !core.Exists(keyFile) { log.Info("Generating proxy certification authority TLS key to %s", keyFile) log.Info("Generating proxy certification authority TLS certificate to %s", certFile) if err := tls.Generate(certFile, keyFile); err != nil { diff --git a/modules/mac_changer.go b/modules/mac_changer.go index 2ca70fda..efc1c366 100644 --- a/modules/mac_changer.go +++ b/modules/mac_changer.go @@ -101,7 +101,7 @@ func (mc *MacChanger) setMac(mac net.HardwareAddr) error { } func (mc *MacChanger) Start() error { - if mc.Running() == true { + if mc.Running() { return session.ErrAlreadyStarted } else if err := mc.Configure(); err != nil { return err diff --git a/modules/mysql_server.go b/modules/mysql_server.go index edef8cbf..7874fd2c 100644 --- a/modules/mysql_server.go +++ b/modules/mysql_server.go @@ -69,30 +69,19 @@ func (mysql *MySQLServer) Configure() error { var address string var port int - if mysql.Running() == true { + if mysql.Running() { return session.ErrAlreadyStarted - } - - if err, mysql.infile = mysql.StringParam("mysql.server.infile"); err != nil { + } else if err, mysql.infile = mysql.StringParam("mysql.server.infile"); err != nil { + return err + } else if err, address = mysql.StringParam("mysql.server.address"); err != nil { + return err + } else if err, port = mysql.IntParam("mysql.server.port"); err != nil { + return err + } else if mysql.address, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", address, port)); err != nil { + return err + } else if mysql.listener, err = net.ListenTCP("tcp", mysql.address); err != nil { return err } - - if err, address = mysql.StringParam("mysql.server.address"); err != nil { - return err - } - - if err, port = mysql.IntParam("mysql.server.port"); err != nil { - return err - } - - if mysql.address, err = net.ResolveTCPAddr("tcp", fmt.Sprintf("%s:%d", address, port)); err != nil { - return err - } - - if mysql.listener, err = net.ListenTCP("tcp", mysql.address); err != nil { - return err - } - return nil } diff --git a/modules/net_probe.go b/modules/net_probe.go index 47559b92..334b26fc 100644 --- a/modules/net_probe.go +++ b/modules/net_probe.go @@ -103,9 +103,9 @@ func (p *Prober) Start() error { for p.Running() { for _, ip := range addresses { - if p.Running() == false { + if !p.Running() { return - } else if p.Session.Skip(ip) == true { + } else if p.Session.Skip(ip) { log.Debug("Skipping address %s from UDP probing.", ip) continue } diff --git a/modules/net_recon.go b/modules/net_recon.go index fc6643e5..a973820b 100644 --- a/modules/net_recon.go +++ b/modules/net_recon.go @@ -73,7 +73,7 @@ func (d *Discovery) runDiff(cache network.ArpTable) { var rem network.ArpTable = make(network.ArpTable) d.Session.Lan.EachHost(func(mac string, e *network.Endpoint) { - if _, found := cache[mac]; found == false { + if _, found := cache[mac]; !found { rem[mac] = e.IpAddress } }) @@ -100,7 +100,6 @@ func (d *Discovery) Start() error { return d.SetRunning(true, func() { every := time.Duration(1) * time.Second iface := d.Session.Interface.Name() - for d.Running() { if table, err := network.ArpUpdate(iface); err != nil { log.Error("%s", err) diff --git a/modules/net_recon_show.go b/modules/net_recon_show.go index ecc0b4cf..23f2b938 100644 --- a/modules/net_recon_show.go +++ b/modules/net_recon_show.go @@ -31,28 +31,13 @@ func (p ProtoPairList) Len() int { return len(p) } func (p ProtoPairList) Less(i, j int) bool { return p[i].Hits < p[j].Hits } func (p ProtoPairList) Swap(i, j int) { p[i], p[j] = p[j], p[i] } -func rankByProtoHits(protos map[string]uint64) (ProtoPairList, uint64) { - pl := make(ProtoPairList, len(protos)) - max := uint64(0) - i := 0 - for k, v := range protos { - pl[i] = ProtoPair{k, v} - if v > max { - max = v - } - i++ - } - sort.Sort(sort.Reverse(pl)) - return pl, max -} - func (d *Discovery) getRow(e *network.Endpoint, withMeta bool) []string { sinceStarted := time.Since(d.Session.StartedAt) sinceFirstSeen := time.Since(e.FirstSeen) addr := e.IpAddress mac := e.HwAddress - if d.Session.Lan.WasMissed(e.HwAddress) == true { + if d.Session.Lan.WasMissed(e.HwAddress) { // if endpoint was not found in ARP at least once addr = core.Dim(addr) mac = core.Dim(mac) @@ -75,7 +60,7 @@ func (d *Discovery) getRow(e *network.Endpoint, withMeta bool) []string { var traffic *packets.Traffic var found bool - if traffic, found = d.Session.Queue.Traffic[e.IpAddress]; found == false { + if traffic, found = d.Session.Queue.Traffic[e.IpAddress]; !found { traffic = &packets.Traffic{} } @@ -135,7 +120,7 @@ func (d *Discovery) Show(by string) error { hasMeta := false for _, t := range targets { - if t.Meta.Empty() == false { + if !t.Meta.Empty() { hasMeta = true break } diff --git a/modules/net_recon_sort.go b/modules/net_recon_sort.go index ecf3a399..8111ed9f 100644 --- a/modules/net_recon_sort.go +++ b/modules/net_recon_sort.go @@ -35,11 +35,11 @@ func (a BySentSorter) Less(i, j int) bool { var aTraffic *packets.Traffic = nil var bTraffic *packets.Traffic = nil - if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; found == false { + if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; !found { aTraffic = &packets.Traffic{} } - if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; found == false { + if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found { bTraffic = &packets.Traffic{} } @@ -58,11 +58,11 @@ func (a ByRcvdSorter) Less(i, j int) bool { var aTraffic *packets.Traffic = nil var bTraffic *packets.Traffic = nil - if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; found == false { + if aTraffic, found = session.I.Queue.Traffic[a[i].IpAddress]; !found { aTraffic = &packets.Traffic{} } - if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; found == false { + if bTraffic, found = session.I.Queue.Traffic[a[j].IpAddress]; !found { bTraffic = &packets.Traffic{} } diff --git a/modules/net_sniff.go b/modules/net_sniff.go index 67749267..cd2eeb84 100644 --- a/modules/net_sniff.go +++ b/modules/net_sniff.go @@ -2,7 +2,6 @@ package modules import ( "fmt" - "net" "time" "github.com/bettercap/bettercap/session" @@ -91,20 +90,6 @@ func (s Sniffer) Author() string { return "Simone Margaritelli " } -func same(a, b net.HardwareAddr) bool { - if len(a) != len(b) { - return false - } - - for idx, v := range a { - if b[idx] != v { - return false - } - } - - return true -} - func (s Sniffer) isLocalPacket(packet gopacket.Packet) bool { ipl := packet.Layer(layers.LayerTypeIPv4) if ipl != nil { @@ -117,7 +102,7 @@ func (s Sniffer) isLocalPacket(packet gopacket.Packet) bool { } func (s *Sniffer) onPacketMatched(pkt gopacket.Packet) { - if mainParser(pkt, s.Ctx.Verbose) == true { + if mainParser(pkt, s.Ctx.Verbose) { s.Stats.NumDumped++ } } @@ -125,7 +110,7 @@ func (s *Sniffer) onPacketMatched(pkt gopacket.Packet) { func (s *Sniffer) Configure() error { var err error - if s.Running() == true { + if s.Running() { return session.ErrAlreadyStarted } else if err, s.Ctx = s.GetContext(); err != nil { if s.Ctx != nil { @@ -149,7 +134,7 @@ func (s *Sniffer) Start() error { src := gopacket.NewPacketSource(s.Ctx.Handle, s.Ctx.Handle.LinkType()) s.pktSourceChan = src.Packets() for packet := range s.pktSourceChan { - if s.Running() == false { + if !s.Running() { break } @@ -164,9 +149,9 @@ func (s *Sniffer) Start() error { s.Stats.NumLocal++ } - if s.Ctx.DumpLocal == true || isLocal == false { + if s.Ctx.DumpLocal || !isLocal { data := packet.Data() - if s.Ctx.Compiled == nil || s.Ctx.Compiled.Match(data) == true { + if s.Ctx.Compiled == nil || s.Ctx.Compiled.Match(data) { s.Stats.NumMatched++ s.onPacketMatched(packet) diff --git a/modules/net_sniff_dns.go b/modules/net_sniff_dns.go index ff5274bc..02ff99f0 100644 --- a/modules/net_sniff_dns.go +++ b/modules/net_sniff_dns.go @@ -11,7 +11,7 @@ import ( func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool { dns, parsed := pkt.Layer(layers.LayerTypeDNS).(*layers.DNS) - if parsed == false { + if !parsed { return false } @@ -19,14 +19,14 @@ func dnsParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool { return false } - m := make(map[string][]string, 0) + m := make(map[string][]string) for _, a := range dns.Answers { if a.IP == nil { continue } hostname := string(a.Name) - if _, found := m[hostname]; found == false { + if _, found := m[hostname]; !found { m[hostname] = make([]string, 0) } diff --git a/modules/net_sniff_parsers.go b/modules/net_sniff_parsers.go index 32c3f1e1..d86821ef 100644 --- a/modules/net_sniff_parsers.go +++ b/modules/net_sniff_parsers.go @@ -20,7 +20,7 @@ func tcpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) { return } else if httpParser(ip, pkt, tcp) { return - } else if verbose == true { + } else if verbose { NewSnifferEvent( pkt.Metadata().Timestamp, "tcp", @@ -47,7 +47,7 @@ func udpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) { return } else if krb5Parser(ip, pkt, udp) { return - } else if verbose == true { + } else if verbose { NewSnifferEvent( pkt.Metadata().Timestamp, "udp", @@ -68,7 +68,7 @@ func udpParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) { } func unkParser(ip *layers.IPv4, pkt gopacket.Packet, verbose bool) { - if verbose == true { + if verbose { NewSnifferEvent( pkt.Metadata().Timestamp, pkt.TransportLayer().LayerType().String(), @@ -111,13 +111,10 @@ func mainParser(pkt gopacket.Packet, verbose bool) bool { unkParser(ip, pkt, verbose) } return true - } - - // are we sniffing in monitor mode? - if ok, radiotap, dot11 := packets.Dot11Parse(pkt); ok == true { + } else if ok, radiotap, dot11 := packets.Dot11Parse(pkt); ok { + // are we sniffing in monitor mode? dot11Parser(radiotap, dot11, pkt, verbose) return true } - return false } diff --git a/modules/net_sniff_stats.go b/modules/net_sniff_stats.go index 815ccffe..f4ccab9a 100644 --- a/modules/net_sniff_stats.go +++ b/modules/net_sniff_stats.go @@ -31,11 +31,10 @@ func (s *SnifferStats) Print() error { first := "never" last := "never" - if s.FirstPacket.IsZero() == false { + if !s.FirstPacket.IsZero() { first = s.FirstPacket.String() } - - if s.LastPacket.IsZero() == false { + if !s.LastPacket.IsZero() { last = s.LastPacket.String() } diff --git a/modules/net_sniff_views.go b/modules/net_sniff_views.go index c1c1137e..b0579867 100644 --- a/modules/net_sniff_views.go +++ b/modules/net_sniff_views.go @@ -3,7 +3,6 @@ package modules import ( "fmt" "net" - "time" "github.com/google/gopacket/layers" @@ -11,10 +10,6 @@ import ( "github.com/bettercap/bettercap/session" ) -func vTime(t time.Time) string { - return t.Format("15:04:05") -} - func vIP(ip net.IP) string { if session.I.Interface.IP.Equal(ip) { return core.Dim("local") diff --git a/modules/packet_proxy_linux_amd64.go b/modules/packet_proxy_linux_amd64.go index 557550c9..76f603a0 100644 --- a/modules/packet_proxy_linux_amd64.go +++ b/modules/packet_proxy_linux_amd64.go @@ -100,7 +100,7 @@ func (pp *PacketProxy) destroyQueue() { func (pp *PacketProxy) runRule(enable bool) (err error) { action := "-A" - if enable == false { + if !enable { action = "-D" } @@ -142,7 +142,7 @@ func (pp *PacketProxy) Configure() (err error) { if pp.pluginPath == "" { return fmt.Errorf("The parameter %s can not be empty.", core.Bold("packet.proxy.plugin")) - } else if core.Exists(pp.pluginPath) == false { + } else if !core.Exists(pp.pluginPath) { return fmt.Errorf("%s does not exist.", pp.pluginPath) } @@ -155,7 +155,7 @@ func (pp *PacketProxy) Configure() (err error) { return } else if sym, err = pp.plugin.Lookup("OnPacket"); err != nil { return - } else if pp.queueCb, ok = sym.(func(*nfqueue.Payload) int); ok == false { + } else if pp.queueCb, ok = sym.(func(*nfqueue.Payload) int); !ok { return fmt.Errorf("Symbol OnPacket is not a valid callback function.") } @@ -187,7 +187,7 @@ func dummyCallback(payload *nfqueue.Payload) int { } func (pp *PacketProxy) Start() error { - if pp.Running() == true { + if pp.Running() { return session.ErrAlreadyStarted } else if err := pp.Configure(); err != nil { return err diff --git a/modules/syn_scan.go b/modules/syn_scan.go index 89b691c1..a202c103 100644 --- a/modules/syn_scan.go +++ b/modules/syn_scan.go @@ -41,7 +41,7 @@ func NewSynScanner(s *session.Session) *SynScanner { ss.AddHandler(session.NewModuleHandler("syn.scan IP-RANGE [START-PORT] [END-PORT]", "syn.scan ([^\\s]+) ?(\\d+)?([\\s\\d]*)?", "Perform a syn port scanning against an IP address within the provided ports range.", func(args []string) error { - if ss.Running() == true { + if ss.Running() { return fmt.Errorf("A scan is already running, wait for it to end before starting a new one.") } @@ -176,7 +176,7 @@ func (s *SynScanner) synScan() error { // start sending SYN packets and wait for _, address := range s.addresses { - if s.Running() == false { + if !s.Running() { break } mac, err := findMAC(s.Session, address, true) @@ -186,7 +186,7 @@ func (s *SynScanner) synScan() error { } for dstPort := s.startPort; dstPort < s.endPort+1; dstPort++ { - if s.Running() == false { + if !s.Running() { break } diff --git a/modules/tcp_proxy.go b/modules/tcp_proxy.go index 48ab90f7..8454b6cc 100644 --- a/modules/tcp_proxy.go +++ b/modules/tcp_proxy.go @@ -83,7 +83,7 @@ func (p *TcpProxy) Configure() error { var proxyAddress string var scriptPath string - if p.Running() == true { + if p.Running() { return session.ErrAlreadyStarted } else if err, address = p.StringParam("tcp.address"); err != nil { return err @@ -111,7 +111,7 @@ func (p *TcpProxy) Configure() error { } } - if p.Session.Firewall.IsForwardingEnabled() == false { + if !p.Session.Firewall.IsForwardingEnabled() { log.Info("Enabling forwarding.") p.Session.Firewall.EnableForwarding(true) } diff --git a/modules/tcp_proxy_script.go b/modules/tcp_proxy_script.go index 7a59a162..05370dab 100644 --- a/modules/tcp_proxy_script.go +++ b/modules/tcp_proxy_script.go @@ -83,7 +83,7 @@ func (s *TcpProxyScript) OnData(from, to net.Addr, data []byte) []byte { return nil } - if ret.IsUndefined() == false && ret.IsString() { + if !ret.IsUndefined() && ret.IsString() { return []byte(ret.String()) } } diff --git a/modules/ticker.go b/modules/ticker.go index 5ddddc6d..a913608a 100644 --- a/modules/ticker.go +++ b/modules/ticker.go @@ -59,7 +59,7 @@ func (t *Ticker) Configure() error { var commands string var period int - if t.Running() == true { + if t.Running() { return session.ErrAlreadyStarted } else if err, commands = t.StringParam("ticker.commands"); err != nil { return err @@ -82,7 +82,7 @@ func (t *Ticker) Start() error { log.Info("Ticker running with period %.fs.", t.Period.Seconds()) tick := time.NewTicker(t.Period) for range tick.C { - if t.Running() == false { + if !t.Running() { break } diff --git a/modules/utils.go b/modules/utils.go index 74840209..06bb6eb8 100644 --- a/modules/utils.go +++ b/modules/utils.go @@ -18,7 +18,7 @@ func findMAC(s *session.Session, ip net.IP, probe bool) (net.HardwareAddr, error // do we have this ip mac address? mac, err = network.ArpLookup(s.Interface.Name(), ip.String(), false) - if err != nil && probe == true { + if err != nil && probe { from := s.Interface.IP from_hw := s.Interface.HW diff --git a/modules/wifi.go b/modules/wifi.go index 2e1daabd..ada4f99a 100644 --- a/modules/wifi.go +++ b/modules/wifi.go @@ -69,7 +69,7 @@ func NewWiFiModule(s *session.Session) *WiFiModule { bssid, err := net.ParseMAC(args[0]) if err != nil { return err - } else if ap, found := w.Session.WiFi.Get(bssid.String()); found == true { + } else if ap, found := w.Session.WiFi.Get(bssid.String()); found { w.ap = ap w.stickChan = network.Dot11Freq2Chan(ap.Frequency) return nil @@ -79,14 +79,11 @@ func NewWiFiModule(s *session.Session) *WiFiModule { w.AddHandler(session.NewModuleHandler("wifi.recon clear", "", "Remove the 802.11 base station filter.", - func(args []string) error { + func(args []string) (err error) { w.ap = nil w.stickChan = 0 - var err error - if w.frequencies, err = network.GetSupportedFrequencies(w.Session.Interface.Name()); err != nil { - return err - } - return nil + w.frequencies, err = network.GetSupportedFrequencies(w.Session.Interface.Name()) + return err })) w.AddHandler(session.NewModuleHandler("wifi.deauth BSSID", `wifi\.deauth ((?:[0-9A-Fa-f]{2}[:-]){5}(?:[0-9A-Fa-f]{2}))`, @@ -253,19 +250,19 @@ func (w *WiFiModule) updateStats(dot11 *layers.Dot11, packet gopacket.Packet) { bytes := uint64(len(packet.Data())) dst := dot11.Address1.String() - if station, found := w.Session.WiFi.Get(dst); found == true { + if station, found := w.Session.WiFi.Get(dst); found { station.Received += bytes } src := dot11.Address2.String() - if station, found := w.Session.WiFi.Get(src); found == true { + if station, found := w.Session.WiFi.Get(src); found { station.Sent += bytes } } - if ok, enc, cipher, auth := packets.Dot11ParseEncryption(packet, dot11); ok == true { + if ok, enc, cipher, auth := packets.Dot11ParseEncryption(packet, dot11); ok { bssid := dot11.Address3.String() - if station, found := w.Session.WiFi.Get(bssid); found == true { + if station, found := w.Session.WiFi.Get(bssid); found { station.Encryption = enc station.Cipher = cipher station.Authentication = auth @@ -293,7 +290,7 @@ func (w *WiFiModule) Start() error { src := gopacket.NewPacketSource(w.handle, w.handle.LinkType()) w.pktSourceChan = src.Packets() for packet := range w.pktSourceChan { - if w.Running() == false { + if !w.Running() { break } else if packet == nil { continue @@ -302,9 +299,9 @@ func (w *WiFiModule) Start() error { w.Session.Queue.TrackPacket(uint64(len(packet.Data()))) // perform initial dot11 parsing and layers validation - if ok, radiotap, dot11 := packets.Dot11Parse(packet); ok == true { + if ok, radiotap, dot11 := packets.Dot11Parse(packet); ok { // check FCS checksum - if w.skipBroken && dot11.ChecksumValid() == false { + if w.skipBroken && !dot11.ChecksumValid() { log.Debug("Skipping dot11 packet with invalid checksum.") continue } @@ -326,7 +323,7 @@ func (w *WiFiModule) Stop() error { // wait any pending write operation w.writes.Wait() // signal the main for loop we want to exit - if w.pktSourceChanClosed == false { + if !w.pktSourceChanClosed { w.pktSourceChan <- nil } // close the pcap handle to make the main for exit diff --git a/modules/wifi_ap.go b/modules/wifi_ap.go index bf40db7d..ef3cf7ec 100644 --- a/modules/wifi_ap.go +++ b/modules/wifi_ap.go @@ -16,7 +16,6 @@ var errNoRecon = errors.New("Module wifi.ap requires module wifi.recon to be act func (w *WiFiModule) parseApConfig() (err error) { var bssid string - if err, w.apConfig.SSID = w.StringParam("wifi.ap.ssid"); err != nil { return } else if err, bssid = w.StringParam("wifi.ap.bssid"); err != nil { @@ -28,13 +27,12 @@ func (w *WiFiModule) parseApConfig() (err error) { } else if err, w.apConfig.Encryption = w.BoolParam("wifi.ap.encryption"); err != nil { return } - return } func (w *WiFiModule) startAp() error { // we need channel hopping and packet injection for this - if w.Running() == false { + if w.Running() { return errNoRecon } else if w.apRunning { return session.ErrAlreadyStarted @@ -47,7 +45,7 @@ func (w *WiFiModule) startAp() error { }() enc := core.Yellow("WPA2") - if w.apConfig.Encryption == false { + if !w.apConfig.Encryption { enc = core.Green("Open") } log.Info("Sending beacons as SSID %s (%s) on channel %d (%s).", diff --git a/modules/wifi_deauth.go b/modules/wifi_deauth.go index 7f48ef86..abfdea40 100644 --- a/modules/wifi_deauth.go +++ b/modules/wifi_deauth.go @@ -42,7 +42,7 @@ func (w *WiFiModule) sendDeauthPacket(ap net.HardwareAddr, client net.HardwareAd func (w *WiFiModule) startDeauth(to net.HardwareAddr) error { // if not already running, temporarily enable the pcap handle // for packet injection - if w.Running() == false { + if !w.Running() { if err := w.Configure(); err != nil { return err } @@ -55,12 +55,12 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error { bssid := to.String() // are we deauthing every client of a given access point? - if ap, found := w.Session.WiFi.Get(bssid); found == true { + if ap, found := w.Session.WiFi.Get(bssid); found { clients := ap.Clients() log.Info("Deauthing %d clients from AP %s ...", len(clients), ap.ESSID()) w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() { for _, c := range clients { - if w.Running() == false { + if !w.Running() { break } w.sendDeauthPacket(ap.HW, c.HW) @@ -73,9 +73,9 @@ func (w *WiFiModule) startDeauth(to net.HardwareAddr) error { // search for a client aps := w.Session.WiFi.List() for _, ap := range aps { - if w.Running() == false { + if !w.Running() { break - } else if c, found := ap.Get(bssid); found == true { + } else if c, found := ap.Get(bssid); found { log.Info("Deauthing client %s from AP %s ...", c.HwAddress, ap.ESSID()) w.onChannel(network.Dot11Freq2Chan(ap.Frequency), func() { w.sendDeauthPacket(ap.HW, c.HW) diff --git a/modules/wifi_hopping.go b/modules/wifi_hopping.go index 8fcb099e..558b590b 100644 --- a/modules/wifi_hopping.go +++ b/modules/wifi_hopping.go @@ -28,7 +28,7 @@ func (w *WiFiModule) channelHopper() { log.Info("Channel hopper started.") - for w.Running() == true { + for w.Running() { delay := w.hopPeriod // if we have both 2.4 and 5ghz capabilities, we have // more channels, therefore we need to increase the time @@ -53,7 +53,7 @@ func (w *WiFiModule) channelHopper() { } time.Sleep(delay) - if w.Running() == false { + if !w.Running() { return } } diff --git a/modules/wifi_recon.go b/modules/wifi_recon.go index b27c86e5..239da8b3 100644 --- a/modules/wifi_recon.go +++ b/modules/wifi_recon.go @@ -28,7 +28,7 @@ func (w *WiFiModule) stationPruner() { defer w.reads.Done() log.Debug("WiFi stations pruner started.") - for w.Running() == true { + for w.Running() { for _, s := range w.Session.WiFi.List() { sinceLastSeen := time.Since(s.LastSeen) if sinceLastSeen > maxStationTTL { @@ -42,15 +42,15 @@ func (w *WiFiModule) stationPruner() { func (w *WiFiModule) discoverAccessPoints(radiotap *layers.RadioTap, dot11 *layers.Dot11, packet gopacket.Packet) { // search for Dot11InformationElementIDSSID - if ok, ssid := packets.Dot11ParseIDSSID(packet); ok == true { + if ok, ssid := packets.Dot11ParseIDSSID(packet); ok { from := dot11.Address3 // skip stuff we're sending - if w.apRunning && bytes.Compare(from, w.apConfig.BSSID) == 0 { + if w.apRunning && bytes.Equal(from, w.apConfig.BSSID) { return } - if network.IsZeroMac(from) == false && network.IsBroadcastMac(from) == false { + if !network.IsZeroMac(from) && !network.IsBroadcastMac(from) { var frequency int bssid := from.String() @@ -76,7 +76,7 @@ func (w *WiFiModule) discoverProbes(radiotap *layers.RadioTap, dot11 *layers.Dot } req, ok := reqLayer.(*layers.Dot11MgmtProbeReq) - if ok == false { + if !ok { return } @@ -106,7 +106,7 @@ func (w *WiFiModule) discoverProbes(radiotap *layers.RadioTap, dot11 *layers.Dot func (w *WiFiModule) discoverClients(radiotap *layers.RadioTap, dot11 *layers.Dot11, packet gopacket.Packet) { w.Session.WiFi.EachAccessPoint(func(bssid string, ap *network.AccessPoint) { // packet going to this specific BSSID? - if packets.Dot11IsDataFor(dot11, ap.HW) == true { + if packets.Dot11IsDataFor(dot11, ap.HW) { ap.AddClient(dot11.Address2.String(), int(radiotap.ChannelFrequency), radiotap.DBMAntennaSignal) } }) diff --git a/modules/wifi_show.go b/modules/wifi_show.go index 827e4b92..d977d2f8 100644 --- a/modules/wifi_show.go +++ b/modules/wifi_show.go @@ -88,7 +88,7 @@ func (w *WiFiModule) getRow(station *network.Station) ([]string, bool) { // method handle both access point and clients // transparently clients := "" - if ap, found := w.Session.WiFi.Get(station.HwAddress); found == true { + if ap, found := w.Session.WiFi.Get(station.HwAddress); found { if ap.NumClients() > 0 { clients = strconv.Itoa(ap.NumClients()) } @@ -114,7 +114,7 @@ func (w *WiFiModule) Show(by string) error { apSelected := w.isApSelected() if apSelected { - if ap, found := w.Session.WiFi.Get(w.ap.HwAddress); found == true { + if ap, found := w.Session.WiFi.Get(w.ap.HwAddress); found { stations = ap.Clients() } else { return fmt.Errorf("Could not find station %s", w.ap.HwAddress) @@ -135,7 +135,7 @@ func (w *WiFiModule) Show(by string) error { rows := make([][]string, 0) for _, s := range stations { - if row, include := w.getRow(s); include == true { + if row, include := w.getRow(s); include { rows = append(rows, row) } } diff --git a/modules/wol.go b/modules/wol.go index 1542c2d5..54be2419 100644 --- a/modules/wol.go +++ b/modules/wol.go @@ -54,7 +54,7 @@ func parseMAC(args []string) (string, error) { if len(args) == 1 { tmp := core.Trim(args[0]) if tmp != "" { - if reMAC.MatchString(tmp) == false { + if !reMAC.MatchString(tmp) { return "", fmt.Errorf("%s is not a valid MAC address.", tmp) } else { mac = tmp @@ -91,9 +91,7 @@ func (w *WOL) Stop() error { func buildPayload(mac string) []byte { raw, _ := net.ParseMAC(mac) - payload := make([]byte, 0) - - payload = append(payload, layers.EthernetBroadcast...) + payload := []byte{0xff, 0xff, 0xff, 0xff, 0xff, 0xff} for i := 0; i < 16; i++ { payload = append(payload, raw...) } @@ -118,11 +116,7 @@ func (w *WOL) wolETH(mac string) error { } raw = append(raw, payload...) - if err := w.Session.Queue.Send(raw); err != nil { - return err - } - - return nil + return w.Session.Queue.Send(raw) } func (w *WOL) wolUDP(mac string) error { @@ -159,9 +153,5 @@ func (w *WOL) wolUDP(mac string) error { } raw = append(raw, payload...) - if err := w.Session.Queue.Send(raw); err != nil { - return err - } - - return nil + return w.Session.Queue.Send(raw) } diff --git a/network/aliases.go b/network/aliases.go index 6e3dd797..84e238f4 100644 --- a/network/aliases.go +++ b/network/aliases.go @@ -65,7 +65,7 @@ func (a *Aliases) Get(mac string) string { a.Lock() defer a.Unlock() - if alias, found := a.data[mac]; found == true { + if alias, found := a.data[mac]; found { return alias } return "" diff --git a/network/arp.go b/network/arp.go index cf851460..95dbda80 100644 --- a/network/arp.go +++ b/network/arp.go @@ -58,7 +58,7 @@ func ArpUpdate(iface string) (ArpTable, error) { func ArpLookup(iface string, address string, refresh bool) (string, error) { // Refresh ARP table if first run or if a force refresh has been instructed. - if ArpParsed() == false || refresh == true { + if ArpParsed() == false || refresh { if _, err := ArpUpdate(iface); err != nil { return "", err } @@ -68,7 +68,7 @@ func ArpLookup(iface string, address string, refresh bool) (string, error) { defer arpLock.RUnlock() // Lookup the hardware address of this ip. - if mac, found := arpTable[address]; found == true { + if mac, found := arpTable[address]; found { return mac, nil } @@ -76,7 +76,7 @@ func ArpLookup(iface string, address string, refresh bool) (string, error) { } func ArpInverseLookup(iface string, mac string, refresh bool) (string, error) { - if ArpParsed() == false || refresh == true { + if ArpParsed() == false || refresh { if _, err := ArpUpdate(iface); err != nil { return "", err } diff --git a/network/ble.go b/network/ble.go index 586302da..1612742e 100644 --- a/network/ble.go +++ b/network/ble.go @@ -58,7 +58,7 @@ func (b *BLE) AddIfNew(id string, p gatt.Peripheral, a *gatt.Advertisement, rssi defer b.Unlock() id = NormalizeMac(id) - if dev, found := b.devices[id]; found == true { + if dev, found := b.devices[id]; found { dev.LastSeen = time.Now() dev.RSSI = rssi dev.Advertisement = a @@ -80,7 +80,7 @@ func (b *BLE) Remove(id string) { defer b.Unlock() id = NormalizeMac(id) - if dev, found := b.devices[id]; found == true { + if dev, found := b.devices[id]; found { delete(b.devices, id) if b.lostCb != nil { b.lostCb(dev) diff --git a/network/lan.go b/network/lan.go index 3199a4b6..573561e9 100644 --- a/network/lan.go +++ b/network/lan.go @@ -77,7 +77,7 @@ func (lan *LAN) Get(mac string) (*Endpoint, bool) { lan.Lock() defer lan.Unlock() - if e, found := lan.hosts[mac]; found == true { + if e, found := lan.hosts[mac]; found { return e, true } return nil, false @@ -106,7 +106,7 @@ func (lan *LAN) WasMissed(mac string) bool { lan.Lock() defer lan.Unlock() - if ttl, found := lan.ttl[mac]; found == true { + if ttl, found := lan.ttl[mac]; found { return ttl < LANDefaultttl } return true diff --git a/network/meta.go b/network/meta.go index 86f39ff5..48ab2f9f 100644 --- a/network/meta.go +++ b/network/meta.go @@ -42,7 +42,7 @@ func (m *Meta) Get(name string) interface{} { m.Lock() defer m.Unlock() - if v, found := m.m[name]; found == true { + if v, found := m.m[name]; found { return v } return "" @@ -75,7 +75,7 @@ func (m *Meta) GetOr(name string, dflt interface{}) interface{} { m.Lock() defer m.Unlock() - if v, found := m.m[name]; found == true { + if v, found := m.m[name]; found { return v } return dflt diff --git a/network/net.go b/network/net.go index 0e18997e..ab8affbe 100644 --- a/network/net.go +++ b/network/net.go @@ -90,7 +90,7 @@ func ParseTargets(targets string, aliasMap *Aliases) (ips []net.IP, macs []net.H // check and resolve aliases for _, alias := range aliasParser.FindAllString(targets, -1) { - if mac, found := aliasMap.Find(alias); found == true { + if mac, found := aliasMap.Find(alias); found { mac = NormalizeMac(mac) hw, err := net.ParseMAC(mac) if err != nil { diff --git a/network/oui.go b/network/oui.go index eb77e9d6..8f7d9621 100644 --- a/network/oui.go +++ b/network/oui.go @@ -22936,7 +22936,7 @@ func OuiLookup(mac string) string { octects := strings.Split(mac, ":") if len(octects) > 3 { prefix := octects[0] + octects[1] + octects[2] - if vendor, found := oui[prefix]; found == true { + if vendor, found := oui[prefix]; found { return vendor } } diff --git a/network/wifi.go b/network/wifi.go index 64ec588d..c53b0cb6 100644 --- a/network/wifi.go +++ b/network/wifi.go @@ -162,7 +162,7 @@ func (w *WiFi) GetClient(mac string) (*Station, bool) { mac = NormalizeMac(mac) for _, ap := range w.aps { - if client, found := ap.Get(mac); found == true { + if client, found := ap.Get(mac); found { return client, true } } diff --git a/network/wifi_ap.go b/network/wifi_ap.go index ba414a82..8900c207 100644 --- a/network/wifi_ap.go +++ b/network/wifi_ap.go @@ -43,7 +43,7 @@ func (ap *AccessPoint) Get(bssid string) (*Station, bool) { defer ap.Unlock() bssid = NormalizeMac(bssid) - if s, found := ap.clients[bssid]; found == true { + if s, found := ap.clients[bssid]; found { return s, true } return nil, false @@ -55,7 +55,7 @@ func (ap *AccessPoint) AddClient(bssid string, frequency int, rssi int8) *Statio bssid = NormalizeMac(bssid) - if s, found := ap.clients[bssid]; found == true { + if s, found := ap.clients[bssid]; found { // update s.Frequency = frequency s.RSSI = rssi diff --git a/packets/dot11.go b/packets/dot11.go index 14ebec09..eec6ff2c 100644 --- a/packets/dot11.go +++ b/packets/dot11.go @@ -45,7 +45,7 @@ func Dot11Info(id layers.Dot11InformationElementID, info []byte) *layers.Dot11In func NewDot11Beacon(conf Dot11ApConfig, seq uint16) (error, []byte) { flags := openFlags - if conf.Encryption == true { + if conf.Encryption { flags = wpaFlags } @@ -70,7 +70,7 @@ func NewDot11Beacon(conf Dot11ApConfig, seq uint16) (error, []byte) { Dot11Info(layers.Dot11InformationElementIDDSSet, []byte{byte(conf.Channel & 0xff)}), } - if conf.Encryption == true { + if conf.Encryption { stack = append(stack, &layers.Dot11InformationElement{ ID: layers.Dot11InformationElementIDRSNInfo, Length: uint8(len(wpaRSN) & 0xff), @@ -125,7 +125,7 @@ func Dot11ParseIDSSID(packet gopacket.Packet) (bool, string) { for _, layer := range packet.Layers() { if layer.LayerType() == layers.LayerTypeDot11InformationElement { dot11info, ok := layer.(*layers.Dot11InformationElement) - if ok == true && dot11info.ID == layers.Dot11InformationElementIDSSID { + if ok && dot11info.ID == layers.Dot11InformationElementIDSSID { if len(dot11info.Info) == 0 { return true, "" } @@ -152,7 +152,7 @@ func Dot11ParseEncryption(packet gopacket.Packet, dot11 *layers.Dot11) (bool, st for _, layer := range packet.Layers() { if layer.LayerType() == layers.LayerTypeDot11InformationElement { info, ok := layer.(*layers.Dot11InformationElement) - if ok == true { + if ok { found = true if info.ID == layers.Dot11InformationElementIDRSNInfo { enc = "WPA2" @@ -203,7 +203,7 @@ func Dot11ParseDSSet(packet gopacket.Packet) (bool, int) { found := false for _, layer := range packet.Layers() { info, ok := layer.(*layers.Dot11InformationElement) - if ok == true { + if ok { if info.ID == layers.Dot11InformationElementIDDSSet { channel, _ = Dot11InformationElementIDDSSetDecode(info.Info) found = true diff --git a/packets/ntlm.go b/packets/ntlm.go index 08f1030b..657cb6ba 100644 --- a/packets/ntlm.go +++ b/packets/ntlm.go @@ -99,7 +99,7 @@ func (s *NTLMState) AddClientResponse(seq uint32, value string, cb func(data NTL s.Lock() defer s.Unlock() - if chall, found := s.Responses[seq]; found == true { + if chall, found := s.Responses[seq]; found { pair := NTLMChallengeResponse{ Challenge: chall, Response: value, diff --git a/packets/queue.go b/packets/queue.go index 2b4c2749..e795e5d8 100644 --- a/packets/queue.go +++ b/packets/queue.go @@ -65,7 +65,7 @@ func NewQueue(iface *network.Endpoint) (q *Queue, err error) { pktCb: nil, } - if q.active == true { + if q.active { if q.handle, err = pcap.OpenLive(iface.Name(), 1024, true, pcap.BlockForever); err != nil { return } @@ -229,7 +229,7 @@ func (q *Queue) Stop() { q.Lock() defer q.Unlock() - if q.active == true { + if q.active { // wait for write operations to be completed q.writes.Wait() // signal the main loop to exit and close the handle diff --git a/session/environment.go b/session/environment.go index cf1eee4d..be3bbfab 100644 --- a/session/environment.go +++ b/session/environment.go @@ -95,7 +95,7 @@ func (env *Environment) Set(name, value string) string { old, _ := env.Data[name] env.Data[name] = value - if cb, hasCallback := env.cbs[name]; hasCallback == true { + if cb, hasCallback := env.cbs[name]; hasCallback { cb(value) } @@ -113,7 +113,7 @@ func (env *Environment) Get(name string) (bool, string) { env.Lock() defer env.Unlock() - if value, found := env.Data[name]; found == true { + if value, found := env.Data[name]; found { return true, value } @@ -121,7 +121,7 @@ func (env *Environment) Get(name string) (bool, string) { } func (env *Environment) GetInt(name string) (error, int) { - if found, value := env.Get(name); found == true { + if found, value := env.Get(name); found { if i, err := strconv.Atoi(value); err == nil { return nil, i } else { diff --git a/session/events.go b/session/events.go index f65f4e53..9d4da4d6 100644 --- a/session/events.go +++ b/session/events.go @@ -99,7 +99,7 @@ func (p *EventPool) Add(tag string, data interface{}) { func (p *EventPool) Log(level int, format string, args ...interface{}) { if level == core.DEBUG && p.debug == false { return - } else if level < core.ERROR && p.silent == true { + } else if level < core.ERROR && p.silent { return } diff --git a/session/module.go b/session/module.go index bea1feab..1bc6b701 100644 --- a/session/module.go +++ b/session/module.go @@ -75,7 +75,7 @@ func (m SessionModule) ListParam(name string) (err error, values []string) { } func (m SessionModule) StringParam(name string) (error, string) { - if p, found := m.params[name]; found == true { + if p, found := m.params[name]; found { if err, v := p.Get(m.Session); err != nil { return err, "" } else { @@ -87,7 +87,7 @@ func (m SessionModule) StringParam(name string) (error, string) { } func (m SessionModule) IntParam(name string) (error, int) { - if p, found := m.params[name]; found == true { + if p, found := m.params[name]; found { if err, v := p.Get(m.Session); err != nil { return err, 0 } else { @@ -136,7 +136,7 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error { m.Started = running m.StatusLock.Unlock() - if *m.Session.Options.Debug == true { + if *m.Session.Options.Debug { if running { m.Session.Events.Add("mod.started", m.Name) } else { @@ -145,7 +145,7 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error { } if cb != nil { - if running == true { + if running { // this is the worker, start async go cb() } else { diff --git a/session/session.go b/session/session.go index d2ff71bd..8d2de5c3 100644 --- a/session/session.go +++ b/session/session.go @@ -294,7 +294,7 @@ func (s *Session) startNetMon() { return } - if s.IsOn("net.recon") == true && event.Source == true { + if s.IsOn("net.recon") && event.Source == true { addr := event.IP.String() mac := event.MAC.String() @@ -423,7 +423,7 @@ func (s *Session) Start() error { } func (s *Session) Skip(ip net.IP) bool { - if ip.IsLoopback() == true { + if ip.IsLoopback() { return true } else if bytes.Compare(ip, s.Interface.IP) == 0 { return true @@ -549,7 +549,7 @@ func (s *Session) Run(line string) error { // is it a core command? for _, h := range s.CoreHandlers { - if parsed, args := h.Parse(line); parsed == true { + if parsed, args := h.Parse(line); parsed { return h.Exec(args, s) } } @@ -557,7 +557,7 @@ func (s *Session) Run(line string) error { // is it a module command? for _, m := range s.Modules { for _, h := range m.Handlers() { - if parsed, args := h.Parse(line); parsed == true { + if parsed, args := h.Parse(line); parsed { return h.Exec(args) } } @@ -569,7 +569,7 @@ func (s *Session) Run(line string) error { } // is it a proxy module custom command? - if s.UnkCmdCallback != nil && s.UnkCmdCallback(line) == true { + if s.UnkCmdCallback != nil && s.UnkCmdCallback(line) { return nil } diff --git a/session/session_core_handlers.go b/session/session_core_handlers.go index 468b17a2..ce86b8a2 100644 --- a/session/session_core_handlers.go +++ b/session/session_core_handlers.go @@ -178,7 +178,7 @@ func (s *Session) getHandler(args []string, sess *Session) error { } } fmt.Println() - } else if found, value := s.Env.Get(key); found == true { + } else if found, value := s.Env.Get(key); found { fmt.Println() fmt.Printf(" %s: '%s'\n", key, value) fmt.Println() @@ -245,7 +245,7 @@ func (s *Session) aliasHandler(args []string, sess *Session) error { mac := args[0] alias := core.Trim(args[1]) - if s.Lan.SetAliasFor(mac, alias) == true { + if s.Lan.SetAliasFor(mac, alias) { return nil } else { return fmt.Errorf("Could not find endpoint %s", mac) @@ -266,7 +266,7 @@ func (s *Session) registerCoreHandlers() { prefix = core.Trim(prefix[4:]) modNames := []string{""} for _, m := range s.Modules { - if prefix == "" || strings.HasPrefix(m.Name(), prefix) == true { + if prefix == "" || strings.HasPrefix(m.Name(), prefix) { modNames = append(modNames, m.Name()) } } @@ -299,7 +299,7 @@ func (s *Session) registerCoreHandlers() { prefix = core.Trim(prefix[3:]) varNames := []string{""} for key := range s.Env.Data { - if prefix == "" || strings.HasPrefix(key, prefix) == true { + if prefix == "" || strings.HasPrefix(key, prefix) { varNames = append(varNames, key) } } @@ -314,7 +314,7 @@ func (s *Session) registerCoreHandlers() { prefix = core.Trim(prefix[3:]) varNames := []string{""} for key := range s.Env.Data { - if prefix == "" || strings.HasPrefix(key, prefix) == true { + if prefix == "" || strings.HasPrefix(key, prefix) { varNames = append(varNames, key) } } @@ -362,7 +362,7 @@ func (s *Session) registerCoreHandlers() { prefix = core.Trim(prefix[5:]) macs := []string{""} s.Lan.EachHost(func(mac string, e *network.Endpoint) { - if prefix == "" || strings.HasPrefix(mac, prefix) == true { + if prefix == "" || strings.HasPrefix(mac, prefix) { macs = append(macs, mac) } })