From 1fee1f718deae6ac4e35481633dc8d97ee5ba471 Mon Sep 17 00:00:00 2001 From: Hasibul Hasan Anik Date: Thu, 5 Mar 2020 12:56:04 +0600 Subject: [PATCH 1/5] Remove unnecessary fmt.Sprintf the tui.Bold function already returning a string. There has not need to convert it ot string by using fmt.Sprintf --- modules/events_stream/events_view_http.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/events_stream/events_view_http.go b/modules/events_stream/events_view_http.go index e7e4a9da..6d08c84a 100644 --- a/modules/events_stream/events_view_http.go +++ b/modules/events_stream/events_view_http.go @@ -75,7 +75,7 @@ func (mod *EventsStream) dumpForm(body []byte) string { if err != nil { value = v } - form = append(form, fmt.Sprintf("%s", tui.Bold(tui.Red(value)))) + form = append(form, tui.Bold(tui.Red(value))) } } return "\n" + strings.Join(form, "&") + "\n" @@ -113,7 +113,7 @@ func (mod *EventsStream) dumpJSON(body []byte) string { if err := json.Indent(&buf, body, "", " "); err != nil { pretty = string(body) } else { - pretty = string(buf.Bytes()) + pretty = buf.String() } return "\n" + reJsonKey.ReplaceAllString(pretty, tui.Green(`$1:`)) + "\n" From 050bd28511ec53149652944dfc9e3713023beb58 Mon Sep 17 00:00:00 2001 From: Hasibul Hasan Anik Date: Thu, 5 Mar 2020 12:58:22 +0600 Subject: [PATCH 2/5] Kepp sync.WorkerGroup.Add() outside of goroutine The workergroup should be added before starting the worker. The worker routine itself should not start the worker. It causes race condition. --- modules/syn_scan/syn_scan.go | 2 +- modules/wifi/wifi_assoc.go | 3 +-- modules/wifi/wifi_deauth.go | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/modules/syn_scan/syn_scan.go b/modules/syn_scan/syn_scan.go index 0eaa2dde..afa8bfa0 100644 --- a/modules/syn_scan/syn_scan.go +++ b/modules/syn_scan/syn_scan.go @@ -227,8 +227,8 @@ func (mod *SynScanner) synScan() error { mod.State.Store("progress", 0.0) // start the collector + mod.waitGroup.Add(1) go func() { - mod.waitGroup.Add(1) defer mod.waitGroup.Done() for packet := range mod.packets { diff --git a/modules/wifi/wifi_assoc.go b/modules/wifi/wifi_assoc.go index a2fb66c9..43f69a0c 100644 --- a/modules/wifi/wifi_assoc.go +++ b/modules/wifi/wifi_assoc.go @@ -88,9 +88,8 @@ func (mod *WiFiModule) startAssoc(to net.HardwareAddr) error { } return fmt.Errorf("%s is an unknown BSSID or it is in the association skip list.", to.String()) } - + mod.writes.Add(1) go func() { - mod.writes.Add(1) defer mod.writes.Done() // since we need to change the wifi adapter channel for each diff --git a/modules/wifi/wifi_deauth.go b/modules/wifi/wifi_deauth.go index d4f77427..5f79a8ac 100644 --- a/modules/wifi/wifi_deauth.go +++ b/modules/wifi/wifi_deauth.go @@ -113,8 +113,8 @@ func (mod *WiFiModule) startDeauth(to net.HardwareAddr) error { return fmt.Errorf("%s is an unknown BSSID, is in the deauth skip list, or doesn't have detected clients.", to.String()) } + mod.writes.Add(1) go func() { - mod.writes.Add(1) defer mod.writes.Done() // since we need to change the wifi adapter channel for each From 8c3f60641e544ef1e7b08331776c34039cca35d2 Mon Sep 17 00:00:00 2001 From: Hasibul Hasan Anik Date: Thu, 5 Mar 2020 13:01:17 +0600 Subject: [PATCH 3/5] Remove unnecessary and empty if block. The if block itself is empty. Calling recover is enough to recover from panic --- session/events.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/session/events.go b/session/events.go index c62b6c9f..31564f25 100644 --- a/session/events.go +++ b/session/events.go @@ -65,9 +65,7 @@ func (p *EventPool) Listen() <-chan Event { go func() { for i := len(p.events) - 1; i >= 0; i-- { defer func() { - if recover() != nil { - - } + recover() }() l <- p.events[i] } From 3b57b0cb386fbff257f66eb50421fe1b9d2c92dc Mon Sep 17 00:00:00 2001 From: Hasibul Hasan Anik Date: Thu, 5 Mar 2020 13:01:46 +0600 Subject: [PATCH 4/5] Remove nil check for empty map. --- modules/net_sniff/net_sniff_upnp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/net_sniff/net_sniff_upnp.go b/modules/net_sniff/net_sniff_upnp.go index f0b7d48b..cf2f8ffd 100644 --- a/modules/net_sniff/net_sniff_upnp.go +++ b/modules/net_sniff/net_sniff_upnp.go @@ -13,7 +13,7 @@ import ( ) func upnpParser(ip *layers.IPv4, pkt gopacket.Packet, udp *layers.UDP) bool { - if data := packets.UPNPGetMeta(pkt); data != nil && len(data) > 0 { + if data := packets.UPNPGetMeta(pkt); len(data) > 0 { s := "" for name, value := range data { s += fmt.Sprintf("%s:%s ", tui.Blue(name), tui.Yellow(value)) From b253e6b4dfa2af83ba8f4af18a8c2b7b95f7014e Mon Sep 17 00:00:00 2001 From: Hasibul Hasan Anik Date: Thu, 5 Mar 2020 13:02:30 +0600 Subject: [PATCH 5/5] Remove unnecessary variable assignment --- modules/mysql_server/mysql_server.go | 2 +- modules/wifi/wifi_hopping.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/mysql_server/mysql_server.go b/modules/mysql_server/mysql_server.go index 3ddb1d97..09167a62 100644 --- a/modules/mysql_server/mysql_server.go +++ b/modules/mysql_server/mysql_server.go @@ -121,7 +121,7 @@ func (mod *MySQLServer) Start() error { if _, err := conn.Write(packets.MySQLGreeting); err != nil { mod.Warning("error while writing server greeting: %s", err) continue - } else if read, err = reader.Read(readBuffer); err != nil { + } else if _, err = reader.Read(readBuffer); err != nil { mod.Warning("error while reading client message: %s", err) continue } diff --git a/modules/wifi/wifi_hopping.go b/modules/wifi/wifi_hopping.go index a89f8b4f..0dfb78db 100644 --- a/modules/wifi/wifi_hopping.go +++ b/modules/wifi/wifi_hopping.go @@ -92,7 +92,7 @@ func (mod *WiFiModule) channelHopper() { } select { - case _ = <-mod.hopChanges: + case <-mod.hopChanges: mod.Debug("hop changed") break loopCurrentChannels case <-time.After(delay):